← Tutti i modelli

Moduli per dominio, validazione dei DTO, dependency injection, un test per 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.

  1. Modules by domain. Each business domain is one @Module that owns its controllers, providers and entities and exports only what other modules need. No common or shared module grows business logic; a circular import between modules fails the review.

  2. DTO validation. Every controller input is a DTO validated by a global ValidationPipe with whitelist and forbidNonWhitelisted (or by zod schemas through nestjs-zod). Unknown fields are rejected with a 400, never passed on.

  3. Dependency injection only. Providers get their collaborators through constructor injection. No new of a service, repository or client inside another provider, and no forwardRef without a note in the plan explaining the cycle.

  4. A test per provider. Every provider has a unit test built with Test.createTestingModule and its dependencies replaced by mocks. A provider without a test does not merge.

  5. 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/*.

  6. Exceptions mapped at the edge. Domain code throws typed domain errors; one exception filter maps them to HTTP status codes. Throwing HttpException from a domain service fails the review.

  7. Typed configuration. Configuration is read through @nestjs/config with a validated schema at startup. The app refuses to start with a missing or malformed variable, and no provider reads process.env directly.

  8. End-to-end tests per route. Each controller route has an e2e test that boots the real module with createNestApplication and calls it with supertest, covering the success path and one rejected input.