Backend Structure
Overview of the backend project directories
Below is the project structure:
src
├── main
│ ├── java
│ │ └── com.bootcamp.spring
│ │ ├── controller
│ │ │ ├── HealthController.java
│ │ │ └── ProdutoController.java
│ │ │
│ │ ├── dto
│ │ │ ├── ProdutoRequestDTO.java
│ │ │ └── ProdutoResponseDTO.java
│ │ │
│ │ ├── exception
│ │ │ ├── GlobalExceptionHandler.java
│ │ │ ├── ProdutoNotFoundException.java
│ │ │ └── ProdutoValidationException.java
│ │ │
│ │ ├── mapper
│ │ │ └── ProdutoMapper.java
│ │ │
│ │ ├── model
│ │ │ └── Produto.java
│ │ │
│ │ ├── repository
│ │ │ └── ProdutoRepository.java
│ │ │
│ │ ├── service
│ │ │ ├── ProdutoService.java
│ │ │ ├── ProdutoValidationService.java
│ │ │ └── impl
│ │ │ ├── ProdutoServiceImpl.java
│ │ │ └── ProdutoValidationServiceImpl.java
│ │ │
│ │ └── Application.java
│ │
│ └── resources
│ └── application.properties
│
├── test
│ └── java
│ └── com.bootcamp.spring
│ └── ApplicationTests.java
│
└── HELP.md
└── README.md
└── mvnw
└── mvnw.cmd
└── pom.xmlController - Presentation Layer
Responsibility: Manage HTTP requests and responses
| File | Features |
|---|---|
| ProdutoController.java | Full CRUD for products (GET, POST, PUT, DELETE) |
| HealthController.java | Health check for monitoring |
Main Features:
- Global automatic validations with Bean Validation.
- Swagger documentation on all endpoints.
- Standardized HTTP responses (200, 201, 400, 404, 500).
Service - Business Layer
Responsibility: Implement business rules and validations
| File | Features |
|---|---|
| ProdutoService.java | Interface with business contracts |
| ProdutoServiceImpl.java | Implementation of product rules |
| ProdutoValidationService.java | Custom business validations |
Main Features:
- Business validations (positive price, mandatory name).
- Specific exception handling.
- Separation of responsibilities with interfaces.
- Dependency injection with Spring.
Repository - Persistence Layer
Responsibility: Manage database operations
| File | Features |
|---|---|
| ProdutoRepository.java | JPA interface for CRUD operations |
Main Features:
- JPA Repository with standard methods.
- Custom queries when necessary.
- Spring-managed automatic transactions.
- Hibernate cache and optimizations.
DTOs - Data Transfer Objects
Responsibility: Define input and output contracts
| File | Features |
|---|---|
| ProdutoRequestDTO.java | Data for creation/update |
| ProdutoResponseDTO.java | Data for API responses |
Main Features:
- Bean Validation (
@NotBlank,@Positive). - Automatic JSON serialization.
- Separation of concerns (entity vs API).
- Automatic Swagger documentation.
Model - Database Entities
Responsibility: Define data structure
| File | Features |
|---|---|
| Produto.java | Main entity of the application |
Main Features:
- JPA annotations (
@Entity,@Id,@GeneratedValue). - Relationships (when necessary).
- Database indexes and constraints.
- Lifecycle callbacks (
@PrePersist,@PreUpdate).
Mapper - Data Conversions
Responsibility: Convert between Entity and DTO
| File | Features |
|---|---|
| ProdutoMapper.java | Entity ↔ DTO conversions |
Main Features:
- Bidirectional mapping (request → entity, entity → response).
- Manual conversions for specific cases.
- Reusable across the application.
Exception - Error Handling
Responsibility: Manage exceptions centrally
| File | Features |
|---|---|
| GlobalExceptionHandler.java | Global exception handling |
| ProdutoNotFoundException.java | Exception for product not found |
| ProdutoValidationException.java | Exception for validation errors |
Main Features:
- Standardized responses with
ErrorResponse. - Automatic error logging.
- Different HTTP statuses by error type.
- Swagger documentation for errors.