Modules par domaine, validation des DTO, injection de dépendances, un test par provider.
Constitution — NestJS service
Version 1.0.0 · Ratified 2026-11-10
These principles hold for every spec, plan and task of the project. A spec may add rules; it never weakens these.
-
Modules by domain. Each business domain is one
@Modulethat owns its controllers, providers and entities and exports only what other modules need. Nocommonorsharedmodule grows business logic; a circular import between modules fails the review. -
DTO validation. Every controller input is a DTO validated by a global
ValidationPipewithwhitelistandforbidNonWhitelisted(or by zod schemas throughnestjs-zod). Unknown fields are rejected with a 400, never passed on. -
Dependency injection only. Providers get their collaborators through constructor injection. No
newof a service, repository or client inside another provider, and noforwardRefwithout a note in the plan explaining the cycle. -
A test per provider. Every provider has a unit test built with
Test.createTestingModuleand its dependencies replaced by mocks. A provider without a test does not merge. -
Thin controllers. Controllers map HTTP to a service call or a CQRS command or query and back. Business rules live in providers or in plain domain classes that import nothing from
@nestjs/*. -
Exceptions mapped at the edge. Domain code throws typed domain errors; one exception filter maps them to HTTP status codes. Throwing
HttpExceptionfrom a domain service fails the review. -
Typed configuration. Configuration is read through
@nestjs/configwith a validated schema at startup. The app refuses to start with a missing or malformed variable, and no provider readsprocess.envdirectly. -
End-to-end tests per route. Each controller route has an e2e test that boots the real module with
createNestApplicationand calls it with supertest, covering the success path and one rejected input.