1.8 KiB
description
| description |
|---|
| Create a new NestJS backend feature module following project standards |
Create NestJS Backend Module
Use this workflow when creating a new feature module in backend/src/modules/.
Follows specs/05-Engineering-Guidelines/05-02-backend-guidelines.md and ADR-005.
Steps
-
Verify requirements exist — confirm the feature is in
specs/01-Requirements/before starting -
Check schema — read
specs/03-Data-and-Storage/lcbp3-v1.7.0-schema.sqlfor relevant tables -
Scaffold module folder
backend/src/modules/<module-name>/
├── <module-name>.module.ts
├── <module-name>.controller.ts
├── <module-name>.service.ts
├── dto/
│ ├── create-<module-name>.dto.ts
│ └── update-<module-name>.dto.ts
├── entities/
│ └── <module-name>.entity.ts
└── <module-name>.controller.spec.ts
-
Create Entity — map ONLY columns defined in the schema SQL. Use TypeORM decorators. Add
@VersionColumn()if the entity needs optimistic locking. -
Create DTOs — use
class-validatordecorators. Never useany. Validate all inputs. -
Create Service — inject repository via constructor DI. Use transactions for multi-step writes. Add
Idempotency-Keyguard for POST/PUT/PATCH operations. -
Create Controller — apply
@UseGuards(JwtAuthGuard, CaslAbilityGuard). Use proper HTTP status codes. Document with@ApiTagsand@ApiOperation. -
Register in Module — add to
imports,providers,controllers,exportsas needed. -
Register in AppModule — import the new module in
app.module.ts. -
Write unit test — cover service methods with Jest mocks. Run:
pnpm test:watch
- Citation — confirm implementation references
specs/01-Requirements/andspecs/05-Engineering-Guidelines/05-02-backend-guidelines.md