Non-negotiable rules:
- Read
references/stack.md first to understand the project's NestJS version, ORM, and locked decisions.
- Then load only the references needed for the actual task.
- One module per domain — controllers, services, DTOs, and entities live together in their module directory.
- Controllers are thin — validate (DTO + pipe), delegate (service), return. No business logic.
- All input validated via DTOs — class-validator decorators on every DTO,
ValidationPipe globally.
- Dependency injection everywhere — never
new Service(). Inject via constructor, provide via module.
- No circular dependencies — use
forwardRef() only as a last resort, prefer restructuring.
- Keep the heavy NestJS guidance in
references/, not inline here.
nestjs
Inputs
$request: The NestJS module, endpoint, subsystem, or feature being worked on
Goal
Route NestJS work through the project's module-based architecture so implementation follows the established patterns for dependency injection, validation, data access, and request lifecycle.
Step 0: Read the stack contract
Always start with:
That establishes: NestJS version, ORM (TypeORM/Prisma/Drizzle), package manager, auth strategy, queue system, and locked dependency choices.
Success criteria: The project's NestJS architecture and locked decisions are explicit before implementation starts.
Step 1: Load only the relevant references
Use the routing table to pick reference files. Do not bulk-load the full reference tree.
| Task |
Read |
| NestJS version, ORM, key deps, CLI, project layout |
references/stack.md |
| Folder conventions, module organization, barrel exports |
references/project-structure.md |
| Creating or editing a module |
references/modules.md |
| Controllers, route decorators, request lifecycle |
references/controllers.md |
| Services, providers, dependency injection |
references/providers.md |
| DTOs, class-validator, ValidationPipe, transformation |
references/validation.md |
| TypeORM entities, repositories, migrations |
references/typeorm.md |
| Prisma integration with NestJS |
references/prisma.md |
| Guards, authentication, authorization, JWT, Passport |
references/auth.md |
| Interceptors, logging, caching, response mapping |
references/interceptors.md |
| Pipes, custom validation, parameter transformation |
references/pipes.md |
| Exception filters, custom exceptions, error responses |
references/error-handling.md |
| BullMQ queues, processors, flows |
references/queues.md |
| WebSocket gateways, events, rooms |
references/websockets.md |
| Microservices, transports, message patterns |
references/microservices.md |
| OpenAPI/Swagger decorators, schema generation |
references/openapi.md |
| Unit tests, e2e tests, testing module, mocking |
references/testing.md |
| Configuration, ConfigModule, env validation |
references/config.md |
| Middleware, lifecycle hooks, shutdown |
references/middleware.md |
| Logging with pino or built-in logger |
references/logging.md |
| Health checks, Terminus |
references/health.md |
| CQRS, events, sagas |
references/cqrs.md |
| Scheduling, cron jobs, intervals |
references/scheduling.md |
| Docker, deployment, production setup |
references/docker.md |
Multiple tasks? Read multiple files. The references are self-contained.
Success criteria: Only the task-relevant NestJS conventions are in play.
Step 2: Implement with the core NestJS guardrails
Keep these rules active:
- every module declares its controllers, providers, imports, and exports explicitly
- controllers validate via DTOs +
ValidationPipe, delegate to services, return typed responses
- services contain business logic, injected via constructor — never instantiated with
new
- entities/models are separate from DTOs — never return a raw entity from a controller
- guards handle auth/authz, interceptors handle cross-cutting concerns, pipes handle transformation
- all external input has a DTO with class-validator decorators
- database mutations wrapped in transactions where atomicity matters
- use
@nestjs/config with Zod or Joi validation for env vars
Success criteria: The change fits the project's NestJS module architecture instead of bypassing the framework.
Step 3: Verify the affected surface
Use the narrowest relevant verification:
- unit tests (
jest --testPathPattern=<module>)
- e2e tests (
jest --config test/jest-e2e.json)
- type checking (
tsc --noEmit)
- linting (
eslint .)
- OpenAPI spec regeneration if decorators changed
Success criteria: The changed NestJS surface still builds, type-checks, and passes tests.
Guardrails
- Do not inline the whole NestJS handbook in
SKILL.md.
- Do not skip
references/stack.md.
- Do not put business logic in controllers — delegate to services.
- Do not return raw entities — use DTOs or serialization interceptors.
- Do not bypass dependency injection — never
new Service().
- Do not create circular module dependencies without exhausting alternatives first.
- Do not use
@nestjs/common barrel imports for types — import from specific subpaths when possible.
- Do not add
disable-model-invocation; this is a normal domain skill.
When To Load References
Output Contract
Report:
- which NestJS references were loaded
- the module and architecture pattern chosen
- the change made
- the verification run
1---2name: nestjs3description: Build NestJS the way THIS project's module architecture already does it, not by framework defaults — a reference carrying the real module boundaries and dependency-injection discipline behind thin controllers, class-validator DTOs, TypeORM/Prisma data access, guards, interceptors, pipes, exception filters, BullMQ queues, WebSockets, microservices, OpenAPI, and testing, so a change lands idiomatic and review-ready instead of bypassing the framework. Use when a task touches this project's NestJS modules and should follow its DI-driven architecture rather than framework defaults.4---5
6<EXTREMELY-IMPORTANT>
7This skill is a routing shell over the NestJS reference set.
8
9Non-negotiable rules:
101. Read `references/stack.md` first to understand the project's NestJS version, ORM, and locked decisions.
112. Then load only the references needed for the actual task.
123. **One module per domain** — controllers, services, DTOs, and entities live together in their module directory.
134. **Controllers are thin** — validate (DTO + pipe), delegate (service), return. No business logic.
145. **All input validated via DTOs** — class-validator decorators on every DTO, `ValidationPipe` globally.
156. **Dependency injection everywhere** — never `new Service()`. Inject via constructor, provide via module.
167. **No circular dependencies** — use `forwardRef()` only as a last resort, prefer restructuring.
178. **Keep the heavy NestJS guidance in `references/`, not inline here.**
18</EXTREMELY-IMPORTANT>
19
20# nestjs
21
22## Inputs
23
24- `$request`: The NestJS module, endpoint, subsystem, or feature being worked on
25
26## Goal
27
28Route NestJS work through the project's module-based architecture so implementation follows the established patterns for dependency injection, validation, data access, and request lifecycle.
29
30## Step 0: Read the stack contract
31
32Always start with:
33
34- `references/stack.md`
35
36That establishes: NestJS version, ORM (TypeORM/Prisma/Drizzle), package manager, auth strategy, queue system, and locked dependency choices.
37
38**Success criteria**: The project's NestJS architecture and locked decisions are explicit before implementation starts.
39
40## Step 1: Load only the relevant references
41
42Use the routing table to pick reference files. Do not bulk-load the full reference tree.
43
44| Task | Read |
45|------|------|
46| NestJS version, ORM, key deps, CLI, project layout | `references/stack.md` |
47| Folder conventions, module organization, barrel exports | `references/project-structure.md` |
48| Creating or editing a module | `references/modules.md` |
49| Controllers, route decorators, request lifecycle | `references/controllers.md` |
50| Services, providers, dependency injection | `references/providers.md` |
51| DTOs, class-validator, ValidationPipe, transformation | `references/validation.md` |
52| TypeORM entities, repositories, migrations | `references/typeorm.md` |
53| Prisma integration with NestJS | `references/prisma.md` |
54| Guards, authentication, authorization, JWT, Passport | `references/auth.md` |
55| Interceptors, logging, caching, response mapping | `references/interceptors.md` |
56| Pipes, custom validation, parameter transformation | `references/pipes.md` |
57| Exception filters, custom exceptions, error responses | `references/error-handling.md` |
58| BullMQ queues, processors, flows | `references/queues.md` |
59| WebSocket gateways, events, rooms | `references/websockets.md` |
60| Microservices, transports, message patterns | `references/microservices.md` |
61| OpenAPI/Swagger decorators, schema generation | `references/openapi.md` |
62| Unit tests, e2e tests, testing module, mocking | `references/testing.md` |
63| Configuration, ConfigModule, env validation | `references/config.md` |
64| Middleware, lifecycle hooks, shutdown | `references/middleware.md` |
65| Logging with pino or built-in logger | `references/logging.md` |
66| Health checks, Terminus | `references/health.md` |
67| CQRS, events, sagas | `references/cqrs.md` |
68| Scheduling, cron jobs, intervals | `references/scheduling.md` |
69| Docker, deployment, production setup | `references/docker.md` |
70
71Multiple tasks? Read multiple files. The references are self-contained.
72
73**Success criteria**: Only the task-relevant NestJS conventions are in play.
74
75## Step 2: Implement with the core NestJS guardrails
76
77Keep these rules active:
78
79- every module declares its controllers, providers, imports, and exports explicitly
80- controllers validate via DTOs + `ValidationPipe`, delegate to services, return typed responses
81- services contain business logic, injected via constructor — never instantiated with `new`
82- entities/models are separate from DTOs — never return a raw entity from a controller
83- guards handle auth/authz, interceptors handle cross-cutting concerns, pipes handle transformation
84- all external input has a DTO with class-validator decorators
85- database mutations wrapped in transactions where atomicity matters
86- use `@nestjs/config` with Zod or Joi validation for env vars
87
88**Success criteria**: The change fits the project's NestJS module architecture instead of bypassing the framework.
89
90## Step 3: Verify the affected surface
91
92Use the narrowest relevant verification:
93
94- unit tests (`jest --testPathPattern=<module>`)
95- e2e tests (`jest --config test/jest-e2e.json`)
96- type checking (`tsc --noEmit`)
97- linting (`eslint .`)
98- OpenAPI spec regeneration if decorators changed
99
100**Success criteria**: The changed NestJS surface still builds, type-checks, and passes tests.
101
102## Guardrails
103
104- Do not inline the whole NestJS handbook in `SKILL.md`.
105- Do not skip `references/stack.md`.
106- Do not put business logic in controllers — delegate to services.
107- Do not return raw entities — use DTOs or serialization interceptors.
108- Do not bypass dependency injection — never `new Service()`.
109- Do not create circular module dependencies without exhausting alternatives first.
110- Do not use `@nestjs/common` barrel imports for types — import from specific subpaths when possible.
111- Do not add `disable-model-invocation`; this is a normal domain skill.
112
113## When To Load References
114
115- `references/stack.md`
116 Always.
117
118- then only the task-relevant files under `references/`
119
120## Output Contract
121
122Report:
123
1241. which NestJS references were loaded
1252. the module and architecture pattern chosen
1263. the change made
1274. the verification run