NestJS Foundation
Purpose
Define the foundation of an approved NestJS API: module boundaries per domain, DI/provider conventions, the request lifecycle (pipes → guards → interceptors → filters), and configuration — so the framework's structure serves the domains rather than ceremony.
When to Use
- After
backend-stack-selection chose NestJS and Gate 2 approved it.
- Not for Express (
express-foundation) or before the stack decision.
Inputs
- Approved stack decision and architecture (
../../architecture-design).
- Domain list, team conventions, async/realtime needs (queues, WebSockets, schedules).
Discovery Questions
- What are the domains, and which share providers?
- Which cross-cutting concerns are global (validation pipe, auth guard, exception filter)?
- Are queues/WebSockets/scheduling in scope now (Nest modules for each)?
Responsibilities
- Define modules per domain, each owning its controllers, services, and data providers; shared code in explicit shared modules — no circular imports.
- Set the request lifecycle: global ValidationPipe (whitelist, transform), guards for authn/authz, interceptors for logging/serialization, exception filters mapping to the error contract (
backend-error-handling).
- Plan
ConfigModule with validated env schema (fail fast).
- Note where Nest's ecosystem covers approved needs (queues, WebSocket gateways, schedule module) — each still a justified choice.
- Keep providers injectable and testable; no service locators or hidden singletons.
Required Workflow
- Confirm approval + architecture inputs.
- Map domains → modules; mark shared modules explicitly.
- Define global pipes/guards/interceptors/filters and their order.
- Define config + env validation.
- Record the foundation plan; implementation follows approved tasks only.
Decision Rules
- One module per domain; split only when a module grows multiple concerns.
- Global validation pipe with
whitelist: true — unknown fields never reach services.
- Authorization is a guard + service-level check, not controller
ifs (backend-authorization).
- Prefer Nest-native integrations for queues/WebSockets/scheduling when those needs are approved — coherence is why NestJS was chosen.
Rules
- No scaffolding or dependency installation before task approval (Gate 4).
- Module boundaries mirror the architecture's domain boundaries.
- Every global concern (pipe/guard/filter) recorded — they are invisible in handlers.
Anti-Patterns
- One giant
AppModule with everything registered globally.
- Circular module imports patched with
forwardRef instead of fixing boundaries.
- Business logic in controllers or guards.
- Adopting every Nest feature (CQRS, microservices) without a requirement.
Validation Checklist
Definition of Done
A recorded NestJS foundation plan — module map, request lifecycle, config, conventions — ready to drive approved implementation tasks for a multi-developer codebase.
Related Skills
backend-stack-selection, backend-api-architecture, backend-validation, backend-error-handling, backend-authorization, queues, realtime-communication, scheduled-jobs.
Related Knowledge
../../../knowledge/ (domain boundaries, team conventions).
Related References
../../../references/backend/nestjs/ (module examples, when populated).
Context Loading Guidance
- Requires: approved stack decision, domain list, architecture summary.
- Does not require: database internals, other packs, unrelated references.
- May load:
backend-api-architecture, backend-authorization (guard design).
- Stop when: the foundation plan is recorded.
Token Efficiency Guidance
Plan at module-map altitude; a domain→module table beats generated code. Delegate lifecycle details to the specialist skills.
1---2name: nestjs-foundation3description: Use to plan a NestJS foundation after NestJS is approved — module boundaries, dependency injection, providers, pipes/guards/interceptors/filters, config module, conventions for a multi-developer codebase. Plans only; scaffolds nothing without task approval.4---56# NestJS Foundation78## Purpose910Define the foundation of an approved NestJS API: module boundaries per domain, DI/provider conventions, the request lifecycle (pipes → guards → interceptors → filters), and configuration — so the framework's structure serves the domains rather than ceremony.1112## When to Use1314- After `backend-stack-selection` chose NestJS and Gate 2 approved it.15- **Not** for Express (`express-foundation`) or before the stack decision.1617## Inputs1819- Approved stack decision and architecture (`../../architecture-design`).20- Domain list, team conventions, async/realtime needs (queues, WebSockets, schedules).2122## Discovery Questions2324- What are the domains, and which share providers?25- Which cross-cutting concerns are global (validation pipe, auth guard, exception filter)?26- Are queues/WebSockets/scheduling in scope now (Nest modules for each)?2728## Responsibilities2930- Define **modules per domain**, each owning its controllers, services, and data providers; shared code in explicit shared modules — no circular imports.31- Set the request lifecycle: global **ValidationPipe** (whitelist, transform), **guards** for authn/authz, **interceptors** for logging/serialization, **exception filters** mapping to the error contract (`backend-error-handling`).32- Plan `ConfigModule` with validated env schema (fail fast).33- Note where Nest's ecosystem covers approved needs (queues, WebSocket gateways, schedule module) — each still a justified choice.34- Keep providers injectable and testable; no service locators or hidden singletons.3536## Required Workflow37381. Confirm approval + architecture inputs.392. Map domains → modules; mark shared modules explicitly.403. Define global pipes/guards/interceptors/filters and their order.414. Define config + env validation.425. Record the foundation plan; implementation follows approved tasks only.4344## Decision Rules4546- One module per domain; split only when a module grows multiple concerns.47- Global validation pipe with `whitelist: true` — unknown fields never reach services.48- Authorization is a guard + service-level check, not controller `if`s (`backend-authorization`).49- Prefer Nest-native integrations for queues/WebSockets/scheduling when those needs are approved — coherence is why NestJS was chosen.5051## Rules5253- No scaffolding or dependency installation before task approval (Gate 4).54- Module boundaries mirror the architecture's domain boundaries.55- Every global concern (pipe/guard/filter) recorded — they are invisible in handlers.5657## Anti-Patterns5859- One giant `AppModule` with everything registered globally.60- Circular module imports patched with `forwardRef` instead of fixing boundaries.61- Business logic in controllers or guards.62- Adopting every Nest feature (CQRS, microservices) without a requirement.6364## Validation Checklist6566- [ ] Domain → module map defined; shared modules explicit; no cycles.67- [ ] Global pipes/guards/interceptors/filters planned and ordered.68- [ ] Config module + env validation planned (fail fast).69- [ ] Async/realtime module needs noted against approvals.70- [ ] Nothing installed or scaffolded yet.7172## Definition of Done7374A recorded NestJS foundation plan — module map, request lifecycle, config, conventions — ready to drive approved implementation tasks for a multi-developer codebase.7576## Related Skills7778`backend-stack-selection`, `backend-api-architecture`, `backend-validation`, `backend-error-handling`, `backend-authorization`, `queues`, `realtime-communication`, `scheduled-jobs`.7980## Related Knowledge8182`../../../knowledge/` (domain boundaries, team conventions).8384## Related References8586`../../../references/backend/nestjs/` (module examples, when populated).8788## Context Loading Guidance8990- **Requires:** approved stack decision, domain list, architecture summary.91- **Does not require:** database internals, other packs, unrelated references.92- **May load:** `backend-api-architecture`, `backend-authorization` (guard design).93- **Stop when:** the foundation plan is recorded.9495## Token Efficiency Guidance9697Plan at module-map altitude; a domain→module table beats generated code. Delegate lifecycle details to the specialist skills.