Package per funzionalità, injection via costruttore, Testcontainers per i test di integrazione.
Constitution — Spring Boot 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.
-
Packages by feature. Code is grouped by business feature (
orders,billing), each package holding its controller, service, repository and entities. Classes are package-private unless another feature needs them; ArchUnit tests enforce the boundaries. -
Constructor injection. Beans receive dependencies through a single constructor with
finalfields.@Autowiredon fields or setters fails the review. -
Testcontainers for integration tests. Integration tests run against real PostgreSQL, Kafka or Redis in Testcontainers, wired with
@ServiceConnection. H2 or other in-memory substitutes for the production database are not used. -
Schema through migrations. The schema is owned by Flyway or Liquibase migrations;
spring.jpa.hibernate.ddl-autoisvalidateornonein every environment except throwaway tests. -
Transactions at the service layer.
@Transactionalsits on service methods, read-only where possible, and never on controllers. Lazy relations are fetched explicitly with fetch joins or entity graphs;spring.jpa.open-in-viewis false. -
Validated input and Problem Details. Request bodies are records validated with Bean Validation (
@Valid). A@RestControllerAdvicemaps exceptions to RFC 9457ProblemDetailresponses; entities never appear in API responses. -
Typed configuration. Settings are bound to
@ConfigurationPropertiesrecords with@Validated. No@Valuescattered across beans, and the app fails to start on a missing property. -
Production-ready by default. Actuator exposes health, readiness and liveness probes and Micrometer metrics; other endpoints are closed. Graceful shutdown is enabled.