springboot-patterns
This skill teaches Spring Boot's layered architecture pattern, organizing code into controllers, services, repositories, and entities. It covers REST endpoint design, JPA relationships with lazy loading, DTOs for request/response handling, transactional boundaries, and global exception handling.
Spring Boot Patterns teaches you how to structure applications using layered architecture with controllers, services, and repositories.
AI-generated summary based on this skill's SKILL.md
Install
rohitg00/awesome-claude-code-toolkit/springboot-patterns · repository language: JavaScript
git clone https://github.com/rohitg00/awesome-claude-code-toolkit
cp -r awesome-claude-code-toolkit/skills/springboot-patterns ~/.claude/skills/springboot-patternsnpx skillfed install rohitg00/awesome-claude-code-toolkit/springboot-patternsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is the layered architecture Spring Boot example structure?
springboot-patterns teaches a four-layer architecture: controllers handle HTTP requests, services contain business logic, repositories manage data access via JPA, and entities represent database models. This separation ensures each layer has a single responsibility, making code testable and maintainable. Controllers delegate to services, services orchestrate repositories, and repositories abstract database operations.
How do springboot-patterns REST controllers implement best practices?
springboot-patterns covers REST controller design including proper HTTP method mapping, request/response DTOs for data transfer, validation annotations, and status code handling. Controllers should be thin, delegating business logic to services. Use @GetMapping, @PostMapping, etc., and return appropriate HTTP responses through ResponseEntity or @RestControllerAdvice for consistent error handling.
What JPA repository patterns does springboot-patterns teach to avoid N+1 queries?
springboot-patterns addresses N+1 query prevention through entity graphs, fetch type configuration (lazy vs eager loading), and custom repository queries. Use @EntityGraph to load related entities efficiently, configure @ManyToOne and @OneToMany with appropriate fetch strategies, and write JPQL or native queries that join necessary associations in a single query rather than triggering multiple database calls.
How should springboot-patterns guide service layer design and transactional boundaries?
springboot-patterns emphasizes services as the transactional boundary using @Transactional. Services orchestrate repositories, apply business rules, and handle DTOs. Mark read-only operations with @Transactional(readOnly=true) for optimization. Services transform entities to DTOs before returning to controllers, maintaining separation between internal domain models and external APIs.
How does springboot-patterns handle validation and global exception handling?
springboot-patterns teaches @Valid and constraint annotations for request validation, with @ControllerAdvice for global exception handling. Use @ExceptionHandler methods to catch specific exceptions and return structured error responses. Implement proper HTTP status codes and error detail messages, optionally using ProblemDetail for RFC 7807 compliant error responses.
What Spring Boot anti-patterns does this skill help identify and fix?
springboot-patterns identifies common mistakes: business logic in controllers, missing @Transactional boundaries, N+1 queries from improper lazy loading, DTOs not used for API contracts, and unhandled exceptions. It teaches proper layering, transactional management, entity graph optimization, and structured error handling to replace these anti-patterns with production-ready patterns.
SKILL.md
rendered from the published skill — quoted content, verbatim
Spring Boot Patterns
Layered Architecture
src/main/java/com/example/app/
config/ # @Configuration beans
controller/ # @RestController (thin, delegates to service)
service/ # @Service (business logic)
repository/ # @Repository (data access via JPA)
model/
entity/ # @Entity JPA classes
dto/ # Request/response DTOs
mapper/ # MapStruct or manual mapping
exception/ # @ControllerAdvice, custom exceptions
security/ # SecurityFilterChain, JWT filters
Controllers handle HTTP concerns. Services contain business logic. Repositories handle persistence.
REST Controller
```java @RestController @RequestMapping("/api/v1/orders") @RequiredArgsConstructor public class OrderController {
private final OrderService orderService;
@GetMapping
public Page<OrderResponse> list(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size) {
return
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
skills/springboot-patterns/SKILL.md