1---2name: spring-boot-server3description: Stack-specific coding rules for long-running Java Spring Boot server applications, covering Spring MVC REST controllers, dependency injection, Jackson JSON, validation, configuration, persistence integration, testing (unit/integration/system), observability, security, and Maven/Gradle project conventions. Use whenever creating, generating, scaffolding, writing, migrating, troubleshooting, or reviewing Spring Boot server code. This skill is architecture-neutral, it can be composed it with BCE, package-by-feature, package-by-layer, SDD4J, or another architecture skill when the project or user specifies an architecture. Not for serverless deployments, one-off Java CLI applications, or non-Spring Jakarta/MicroProfile services.4---56## Composition7- compose with `java-conventions` for all language-level Java rules (syntax, style, naming, visibility, interfaces/classes, methods/lambdas, streams/collections, exceptions, comments/JavaDoc)8- compose with an architecture skill when architecture is specified or already present, such as `bce`, `sdd4j-bce`, `sdd4j-package-by-feature`, or `sdd4j-package-by-layer`9- when no architecture is specified, infer and preserve the existing project organization instead of introducing BCE, package-by-feature, or package-by-layer by default10- this skill specializes only the Spring Boot server stack and does not restate language-level Java or architecture-level rules1112## Dependencies13- prefer dependencies in this order: Java SE, Spring Boot starters already present in the project, Spring ecosystem modules already used by the project14- avoid adding dependencies for problems already solved by Spring Boot, Java SE, or the existing project stack15- ask before changing Maven `pom.xml`, Gradle build files, dependency versions, Java version, Spring Boot version, or plugin configuration16- do not introduce a second web stack; Spring MVC and WebFlux should not be mixed unless the existing project already does so deliberately1718## Architecture Fit19- treat Spring Boot as the application stack, not as the architecture20- preserve the architecture already used by the project, including package-by-feature, package-by-layer, BCE, hexagonal, clean architecture, modular monolith, or a local project convention21- do not rename packages, introduce architectural layers, or reorganize code solely because this skill is active22- when adding new code, place it where equivalent Spring components already live23- when no convention exists, choose the smallest clear structure for the requested change and avoid committing the project to a broad architecture prematurely24- keep Spring framework annotations at application entry points, application services, configuration, adapters, and persistence integration points; avoid leaking Spring concerns into domain code unless the project already follows an active-record or Spring-centric model2526## Web/API Entry Points27- place Spring MVC controllers, REST API DTO mapping, request/response models, scheduled entry points, messaging listeners, external API clients, health indicators, and protocol adapters according to the existing architecture28- name REST controllers in plural after the resource they expose, e.g. `SpeakersController` rather than `SpeakerController`29- keep controllers coarse-grained and free of business logic; validate and translate HTTP input, then delegate to application services, handlers, or use cases30- use `@RestController` for JSON HTTP APIs and `@Controller` only when rendering views or redirects is intentional31- declare request mappings at class level where it clarifies the resource path32- return `ResponseEntity<T>` when status, headers, or empty responses matter; return DTOs directly only for straightforward successful responses33- put `@Transactional` on request-sized use case methods when the transaction boundary is intentionally tied to that entry point34- avoid calling repositories directly from controllers except for trivial generated code explicitly requested by the user3536## Application Logic37- implement procedural business logic and application use cases in the project's existing service/application/use-case location38- use Spring stereotypes such as `@Service` or `@Component` for injectable application classes39- keep application services independent of HTTP, servlet, controller, and JSON serialization details40- let application methods express use cases in domain terms rather than transport terms41- place `@Transactional` on application service/use-case methods when the transaction is intentionally scoped to reusable application logic42- prefer constructor injection; avoid field injection4344## Domain And Data Model45- maintain domain objects, data classes, JPA entities, value objects, enums, and domain behavior in the project's existing model/domain/entity location46- entities maintain state and corresponding behavior47- model stable value objects as records or enums when appropriate48- direct references across independent modules, features, or components are allowed when they fit the existing architecture, but aim for maximal cohesion and minimal coupling49- if a relation exists in the database, the entity model must carry a corresponding reference, id field, or association; the DB schema is the source of truth when it already exists50- excessive cross-module references or shared configuration are refactoring signals; split, merge, or rebalance responsibilities to restore cohesion51- keep JPA annotations out of DTOs and controller request/response types5253## Repositories And Persistence54- place Spring Data repositories near the aggregate, feature, service, or persistence package that owns the persistent concept according to the existing architecture55- repositories may live in application, domain, persistence, infrastructure, adapter, feature, or entity packages depending on the project convention; follow that convention consistently56- do not expose Spring Data repositories directly as REST resources unless the project already uses Spring Data REST and the user explicitly wants that style57- avoid leaking `Pageable`, `Page`, `Specification`, or persistence-specific types outside Spring-facing API/application code unless the existing API contract already exposes them58- prefer explicit query methods or small custom queries over broad generic repository use in business logic5960## Exceptions And HTTP Errors61- represent domain failures with domain/application exceptions, not HTTP-specific exceptions in application or domain code62- map exceptions to HTTP status codes in the web/API layer with `@ControllerAdvice` and `@ExceptionHandler`63- use `ResponseStatusException` only for small web/API-local cases; prefer centralized exception mapping for reusable APIs64- for Spring Boot 3+, prefer `ProblemDetail` for structured API errors when the project already uses Spring Framework 6 error conventions or when adding a new API error format65- never construct successful and error response payloads ad hoc across multiple controllers when a shared error format exists6667## JSON Serialization68- use Jackson as the default JSON mechanism in Spring Boot applications69- map JSON at the web/API edge to request/response DTOs or command/query objects; do not bind external API shapes directly to rich domain entities unless the API is intentionally internal70- prefer records for immutable request/response DTOs when validation, serialization, and project style allow it71- keep Jackson annotations at the DTO/API model level when possible; avoid polluting domain entities with transport-specific JSON annotations unless persistence/API compatibility requires it72- use `@JsonFormat`, `@JsonProperty`, and custom serializers sparingly and only when the API contract requires them7374## Validation75- use Bean Validation on request DTOs for syntactic request validation76- place business validation in application/domain code so it remains independent of HTTP and can be tested without Spring MVC77- use `@Valid` or `@Validated` at controller entry points when consuming validated request bodies or parameters78- do not use validation annotations as the only enforcement for domain invariants that must hold outside HTTP requests7980## Configuration81- use `application.yml` or `application.properties` consistently with the existing project82- prefer typed `@ConfigurationProperties` over scattered `@Value` fields when more than one related property is used83- keep environment-specific values in profiles, environment variables, or deployment configuration, not hardcoded in source84- do not introduce new profiles, property namespaces, or configuration files without checking existing conventions first85- avoid reading configuration directly from deep domain code; inject typed configuration into Spring-managed components or adapters that need it8687## Observability88- use Spring Boot Actuator for health, info, metrics, and readiness/liveness endpoints when observability is needed89- create custom health indicators near the component, feature, adapter, or integration whose health they expose90- create metrics with Micrometer and prefer OpenTelemetry-compatible naming and labels91- avoid high-cardinality metric tags such as user ids, request ids, emails, or raw URLs92- log at application edges for incoming/outgoing integration events and in application services for meaningful business milestones; do not log sensitive data9394## Security95- use Spring Security when authentication or authorization is needed96- keep authorization decisions close to controllers, handlers, or application use cases; do not scatter role checks through domain entities97- prefer method security for use-case authorization when it improves readability and testability98- do not disable CSRF, CORS, authentication, or authorization globally unless the project context explicitly requires it and the user agrees99- never add secrets, tokens, passwords, or private keys to source files or test fixtures100101## Testing102- write unit tests for application/domain behavior without starting the Spring context when possible103- write Spring MVC slice tests with `@WebMvcTest` for controller behavior and HTTP mapping104- write persistence slice tests with `@DataJpaTest` when verifying repository/query behavior105- write integration tests with `@SpringBootTest` only when the Spring container, configuration, wiring, or end-to-end behavior is the subject under test106- use Testcontainers when external infrastructure is needed and the project already uses it or the user approves adding it107- do not overuse `@MockBean`/`@MockitoBean`; prefer smaller unit tests or focused slices when possible108- integration tests should follow the project's naming convention; when there is no convention, use `*IT` for integration tests and keep unit tests as `*Test`109- execute relevant tests after every meaningful change unless the user explicitly activates demo/showtime mode110111## System Tests112- create system tests as a separate module or clearly separated test source set when the project already has that convention or when the service is tested as a deployed process113- prefer HTTP clients already used by the project; otherwise use Spring `WebTestClient`, `RestClient`, or JDK `HttpClient` depending on the test boundary114- system tests should exercise the running service through public interfaces, not through Spring internals115- avoid RestAssured unless the project already standardizes on it116- execute system tests after major service changes when feasible117118## README Guidelines119- write brief, to-the-point README.md files for advanced developers120- use precise and concise language; avoid generic adjectives like "simple" or "lightweight"121- do not include detailed project structure file/folder listings; high-level module descriptions are acceptable122- do not list every REST endpoint in READMEs; link to API docs when present123- if modules are listed, provide links124- do not use the term "Orchestrates"; use more specific alternatives125126## Project Management127- on opening existing projects, load `AGENTS.md` if present before making changes128- do not create or change files on opening existing projects; stop after initialization and wait for instructions when the user only asked to inspect or initialize129- do not generate code initially in an empty project unless the user explicitly asks to scaffold or implement something130- always inspect existing package, test, build, and dependency conventions before adding code131- keep changes minimal and aligned with the project's current Spring Boot major version132- do not migrate between Spring Boot major versions unless the user explicitly requests a migration