Agent skill
module-scaffold
Scaffold a new NestJS domain module for PMTL_VN following project conventions. Creates the correct file structure with module, controller, service, repository, schemas, mapper, and policy files. Use when starting to implement a new domain module from the design.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/module-scaffold
SKILL.md
Module Scaffold (Tạo khung Module NestJS)
Tạo đầy đủ file structure cho domain module $ARGUMENTS theo chuẩn PMTL_VN.
Bước 1: Đọc design contracts
Trước khi tạo bất kỳ file nào, đọc:
design/<module-number>-$ARGUMENTS/module-map.md— hiểu objectives và boundariesdesign/<module-number>-$ARGUMENTS/contracts.md— hiểu routes, input schemas, rulesdesign/<module-number>-$ARGUMENTS/schema.dbml— hiểu DB schemadesign/<module-number>-$ARGUMENTS/use-cases/— đọc tất cả use-case filesdesign/baseline/nest-baseline.md— chuẩn NestJS của projectdesign/01-identity/PERMISSION_MATRIX.md— per-module permission scope cho module này
Nếu không tìm thấy module trong design/, hỏi lại tên chính xác trước khi tiếp tục.
Bước 2: Xác nhận trước khi tạo
Tóm tắt cho user:
- Module này sở hữu collections nào
- Routes sẽ được tạo
- Permission scope cho từng role
- Dependencies vào module khác
Hỏi: "Xác nhận tạo scaffold cho module này không?"
Bước 3: Tạo file structure
Target path: apps/api/src/modules/$ARGUMENTS/
File structure cần tạo:
apps/api/src/modules/$ARGUMENTS/
├── $ARGUMENTS.module.ts # NestJS module definition
├── $ARGUMENTS.controller.ts # HTTP layer — thin, chỉ validate + delegate
├── $ARGUMENTS.service.ts # Business logic
├── $ARGUMENTS.repository.ts # Prisma queries — không có business logic
├── $ARGUMENTS.schemas.ts # Zod schemas cho tất cả inputs
├── $ARGUMENTS.mapper.ts # Entity → DTO mapping (không expose raw DB)
├── $ARGUMENTS.policy.ts # Authorization rules (role + business rule)
└── dto/
├── create-$ARGUMENTS.dto.ts # Response DTOs
└── $ARGUMENTS-response.dto.ts
Rules cho mỗi file:
$ARGUMENTS.module.ts
- Import PrismaModule, AuditModule, platform modules cần thiết
- Exports service nếu module khác cần đọc
$ARGUMENTS.controller.ts
@UseGuards(JwtAuthGuard, RolesGuard)trên routes cần auth@RateLimit(...)trên auth/write/upload endpoints- Chỉ validate input (dùng schema từ
.schemas.ts) + gọi service - Không có business logic trong controller
- Mỗi route return DTO đã mapped, không phải raw Prisma entity
$ARGUMENTS.service.ts
- Inject repository, auditService, feature flags
- Mọi write operation phải:
- Validate business invariants
- Execute canonical write (qua repository)
auditService.append(...)với actor + action + entityId- Return mapped DTO
- Side effects async (outbox phase 2+ / inline sync phase 1)
$ARGUMENTS.repository.ts
- Chỉ Prisma queries
- Không có business logic
- Trả về Prisma entity — mapping xảy ra ở service/mapper
- Tên method rõ ràng:
findByPublicId,createOne,updateStatus, etc.
$ARGUMENTS.schemas.ts
- Zod schema cho mọi input: request body, query params, path params
- Export const theo tên:
CreateXxxSchema,UpdateXxxSchema,XxxQuerySchema - Không dùng
z.any()hoặcz.unknown()trừ khi có lý do rõ
$ARGUMENTS.mapper.ts
toResponseDto(entity: PrismaEntity): XxxResponseDto- Không expose: password_hash, raw tokens, internal IDs, sensitive fields
- publicId thay cho id trong responses
$ARGUMENTS.policy.ts
canRead(actor: AuthUser, entity: Xxx): booleancanWrite(actor: AuthUser, entity?: Xxx): booleancanDelete(actor: AuthUser, entity: Xxx): boolean- Tách rõ: role check vs business rule vs deletion policy
Bước 4: Thêm placeholder comments
Mỗi file phải có comment ở đầu:
/**
* @module $ARGUMENTS
* @owner PMTL_VN $ARGUMENTS module
* @ref design/<number>-$ARGUMENTS/contracts.md
*
* Canonical collections: [list từ module-map.md]
* Does NOT own: [list từ module-map.md]
*/
Bước 5: Tạo migration placeholder
Tạo file prisma/migrations/PLACEHOLDER_$ARGUMENTS/README.md với:
- Schema tables cần tạo (từ schema.dbml)
- Reminder: phải có migration thật trước khi implement
Bước 6: Báo cáo kết quả
Liệt kê tất cả file đã tạo và:
- Những gì cần implement tiếp (business logic chưa có)
- Use-case files cần đọc trước khi code từng feature
- Audit events bắt buộc cho module này (từ tracking/audit-policy.md)
Quan trọng
- Không tạo file nếu chưa đọc design contracts
- Không implement business logic thật — chỉ scaffold structure và comments
- Không bỏ qua
.schemas.ts— mọi input phải có Zod schema - Không để controller có business logic
- Không expose raw Prisma entity trong response — phải qua mapper
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?