← Alle Vorlagen

Pakete nach Feature, Konstruktor-Injection, Testcontainers für Integrationstests.

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.

  1. 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.

  2. Constructor injection. Beans receive dependencies through a single constructor with final fields. @Autowired on fields or setters fails the review.

  3. 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.

  4. Schema through migrations. The schema is owned by Flyway or Liquibase migrations; spring.jpa.hibernate.ddl-auto is validate or none in every environment except throwaway tests.

  5. Transactions at the service layer. @Transactional sits 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-view is false.

  6. Validated input and Problem Details. Request bodies are records validated with Bean Validation (@Valid). A @RestControllerAdvice maps exceptions to RFC 9457 ProblemDetail responses; entities never appear in API responses.

  7. Typed configuration. Settings are bound to @ConfigurationProperties records with @Validated. No @Value scattered across beans, and the app fails to start on a missing property.

  8. Production-ready by default. Actuator exposes health, readiness and liveness probes and Micrometer metrics; other endpoints are closed. Graceful shutdown is enabled.