Prompt file imported from karlkyck/humansreadcode-springboot-exemplar (
.github/prompts/setup-spring-component.prompt.md). Copyright stays with the author.
Setup Spring Boot Component
You are tasked with creating a new Spring Boot component following the project's established patterns and conventions.
Information Required
Ask for the following if not provided:
- Component Type: Controller, Service, Repository, Entity, or complete module
- Domain Name: The business domain (e.g., Order, Customer, Product)
- Operations: What operations/methods should be included
- Database Integration: Whether database persistence is needed
Project Conventions
Spring Modulith Structure
src/main/java/com/humansreadcode/springboot_exemplar/
├── {domain}/
│ ├── {Domain}Controller.java
│ ├── {Domain}Service.java
│ ├── {Domain}ServiceImpl.java
│ ├── {Domain}Repository.java
│ ├── {Domain}Entity.java
│ ├── dto/
│ │ ├── {Domain}Request.java
│ │ └── {Domain}Response.java
│ └── internal/
│ └── {Domain}InternalService.java
Component Guidelines
Controllers:
- Thin controllers that delegate to services
- Use request/response DTOs
- Include validation annotations
- Implement proper error handling
- Use meaningful HTTP status codes
Services:
- Implement interfaces for better testability
- Use service DTOs for input/output
- Include proper transaction boundaries
- Implement comprehensive logging
- Handle business logic and validation
Repositories:
- Extend Spring Data JPA interfaces
- Use custom queries when needed
- Follow naming conventions
- Include proper indexing hints
Entities:
- Use JPA annotations appropriately
- Include audit fields (created/updated timestamps)
- Implement proper equals/hashCode
- Use appropriate relationships
Required Files
For a complete module, create:
- Entity - JPA entity with proper annotations
- DTOs - Request and Response DTOs in dto package
- Repository - Spring Data JPA repository interface
- Service Interface - Service contract
- Service Implementation - Business logic implementation
- Controller - REST API endpoints
- Tests - Unit and integration tests
- Migration - Flyway database migration if needed
Code Style Requirements
- Use constructor injection for dependencies
- Follow Java naming conventions
- Include comprehensive Javadoc
- Use appropriate validation annotations
- Implement proper exception handling
- Follow project logging standards
Testing Requirements
- Create unit tests for service layer
- Create integration tests with Testcontainers
- Test all public methods and edge cases
- Use meaningful test names and assertions
- Follow AAA (Arrange-Act-Assert) pattern
Database Considerations
If database integration is needed:
- Create appropriate Flyway migration
- Use proper indexing strategy
- Follow database naming conventions
- Include foreign key constraints
- Consider performance implications
Example Output
When creating an Order module, generate:
- Database migration for orders table
- Order entity with JPA annotations
- OrderRequest and OrderResponse DTOs
- OrderRepository interface
- OrderService interface and implementation
- OrderController with REST endpoints
- Comprehensive unit and integration tests
Ensure all components follow Spring Boot best practices, project conventions, and include proper documentation.
