springboot-patterns

Spring Boot architecture patterns, REST API design, layered services, data access, caching, async processing, and logging. Use for Java Spring Boot backend work. Use when building or reviewing a Spring Boot backend — REST layer, services, data access, caching, or async work.

By affaan-m · 3,039 installs

npx skills add affaan-m/ecc --skill springboot-patterns

Source repository · Upstream listing

Spring Boot Development Patterns Spring Boot architecture and API patterns for scalable, production grade services. When to Activate Building REST APIs with Spring MVC or WebFlux Structuring controller → service → repository layers Configuring Spring Data JPA, caching, or async processing Adding validation, exception handling, or pagination Setting up profiles for dev/staging/production environments Implementing event driven patterns with Spring Events or Kafka REST API Structure Repository Pattern (Spring Data JPA) Service Layer with Transactions DTOs and Validation Exception Handling Caching Requires @EnableCaching on a configuration class. Async Processing Requires @EnableAsync on a configuration class. Logging (SLF4J) Middleware / Filters Pagination and Sorting Error Resilient External Calls Rate Limiting (Filter + Bucket4j) Security Note : The X Forwarded For header is untrusted by default because clients can spoof it. Only use forwarded headers when: 1. Your app is behind a trusted reverse proxy (nginx, AWS ALB, etc.) 2. You have registered ForwardedHeaderFilter as a bean 3. You have configured server.forward headers strategy=NATIVE or FRAMEWORK in application properties 4. Your proxy is configured to overwrite (not append to) the X Forwarded For header When ForwardedHeaderFilter is properly configured, request.getRemoteAddr() will automatically return the correct client IP from the forwarded headers. Without this configuration, use request.getRemoteAddr() directly—it returns the immediate connection IP, which is the only trustworthy value. Background Jobs Use Spring’s @Scheduled or integrate with queues (e.g., Kafka, SQS, RabbitMQ). Keep handlers idempotent and observable. Observability Structured logging (JSON) via Logback encoder Metrics: Micrometer + Prometheus/OTel Tracing: Micrometer Tracing with OpenTelemetry or Brave backend Production Defaults Prefer constructor injection, avoid field injection Enable spring.mvc.problemdetails.enabled=true for RFC 7807 errors (Spring Boot 3+) Configure HikariCP pool sizes for workload, set timeouts Use @Transactional(readOnly = true) for queries Enforce null safety via @NonNull and Optional where appropriate Remember : Keep controllers thin, services focused, repositories simple, and errors handled centrally. Optimize for maintainability and testability.