spring-boot-patterns

Implements layered architecture patterns for Java 21+ Spring Boot REST APIs.

39|3|Updated Jul 28, 2025
One-click install
npx skills add https://github.com/mzivkovicdev/spring-crud-generator --skill spring-boot-patterns-mzivkovicdev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: spring-boot-patterns
Source: https://github.com/mzivkovicdev/spring-crud-generator/tree/main/.agents/skills/spring-boot-patterns
Command: npx skills add https://github.com/mzivkovicdev/spring-crud-generator --skill spring-boot-patterns-mzivkovicdev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Spring Boot codebases often accumulate architectural drift: fat controllers, entities leaking into API contracts, unclear transaction boundaries, and inconsistent error responses. This Skill enforces a consistent, reviewable architecture for every new REST endpoint or change to controllers, services, mappers, validation, and error handling. ## Core Features & Use Cases - Layered Architecture Enforcement: Defines clear boundaries between REST controllers, transport objects, application services, aggregate services, domain models, mappers, and repositories, with rules for what may cross each boundary. - RFC 9457 Error Contract: Provides a single error catalog pattern with ProblemDetail responses, contention handling (409 vs 503 with Retry-After), and correct delegation of security denials to the filter chain. - Transaction and Idempotency Guidance: Establishes where the transaction boundary sits, the two service levels, after-commit external effects, and single-phase versus two-phase idempotency claim shapes. - Use Case: When adding a new REST endpoint to a Spring Boot 3 or 4 project, use this Skill to place each type in the right layer, wire the transaction boundary correctly, and produce a contract-compliant error response. ## Quick Start Ask the AI to implement a new REST endpoint for your Spring Boot project following the spring-boot-patterns architecture rules.

Frequently Asked Questions about spring-boot-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Spring Boot REST API with clean architecture?▼

Use thin REST controllers that delegate to one service per handler, keep entities inside the persistence boundary, and split services into aggregate services (one per aggregate root) and application services (cross-aggregate use cases). Map between layers with dedicated REST and domain mappers.

How to implement RFC 9457 ProblemDetail error handling in Spring Boot?▼

Declare every caller-visible failure once in a single error catalog enum carrying status, type URI, title, and detail. Use one RestControllerAdvice extending ResponseEntityExceptionHandler, with the type URI as the only machine-readable identifier and correlationId as the sole extension member.

Does this architecture work with both Spring Boot 3 and Spring Boot 4?▼

Yes, the architecture is identical on both generations: controllers, services, domain models, transaction boundaries, and the error contract do not change. Only surrounding details differ, such as the JSON library, mapper bean, and retry engine, plus Spring Boot 4's automatic Jackson module registration.

Where should the transaction boundary sit in a Spring Boot service layer?▼

The transaction boundary is the highest service the use case enters. An application service opens the transaction for multi-aggregate use cases, while an aggregate service opens its own when the operation stays within one aggregate. Both levels use @Transactional with default propagation.

Why do concurrent modification errors return 500 instead of 409 in Spring?▼

This happens when the exception advice only handles project exception types. Exhausted lock retries propagate Spring framework exceptions like OptimisticLockingFailureException, so the advice needs explicit handlers for those parent types to map them to 409 or 503 with Retry-After.

When should I use single-phase versus two-phase idempotency claims?▼

Single-phase is the default: the claim commits with the effect in one transaction. Two-phase is required only when the use case makes a synchronous external call whose result the caller receives, and it mandates a lease deadline so a crash does not block the key forever.