Deloitte

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.xml

Controller - Presentation Layer

Responsibility: Manage HTTP requests and responses

FileFeatures
ProdutoController.javaFull CRUD for products (GET, POST, PUT, DELETE)
HealthController.javaHealth 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

FileFeatures
ProdutoService.javaInterface with business contracts
ProdutoServiceImpl.javaImplementation of product rules
ProdutoValidationService.javaCustom 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

FileFeatures
ProdutoRepository.javaJPA 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

FileFeatures
ProdutoRequestDTO.javaData for creation/update
ProdutoResponseDTO.javaData 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

FileFeatures
Produto.javaMain 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

FileFeatures
ProdutoMapper.javaEntity ↔ 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

FileFeatures
GlobalExceptionHandler.javaGlobal exception handling
ProdutoNotFoundException.javaException for product not found
ProdutoValidationException.javaException for validation errors

Main Features:

  • Standardized responses with ErrorResponse.
  • Automatic error logging.
  • Different HTTP statuses by error type.
  • Swagger documentation for errors.

On this page