REST API developed in Java with Spring Boot for managing users, dependents, contracts, expenses and incomes.
The application is available in a cloud environment and can be tested in real time.
π https://transparence-api-production.up.railway.app
π Swagger:
π https://transparence-api-production.up.railway.app/swagger-ui.html
The API is deployed in a production environment using Railway, with a MySQL cloud database and configuration through environment variables.
- Java 17+
- Spring Boot
- Spring Web
- Spring Data JPA
- Hibernate
- Spring Security
- JWT Authentication
- Swagger / OpenAPI
- Flyway (Database Migration)
- Maven
- JUnit / Mockito
- Docker
- MySQL
- H2 Database
The project follows a layered architecture, separating responsibilities clearly.
- Responsible for receiving and responding to HTTP requests
- Works exclusively with DTOs
- Documented using Swagger/OpenAPI
- RequestDTO β input data
- ResponseDTO β output data
- Prevents direct exposure of JPA entities
- Contains the business rules
- Controls states and validations
- Uses separated interfaces and implementations
- Uses
@Transactionalfor transaction control - Includes logs for operation traceability
- Data access layer using Spring Data JPA
- Represents the domain of the application
- Mapped with JPA/Hibernate
- Create user
- Update user
- Find user by ID
- Delete user
- Create dependent
- Update dependent
- Find dependent by ID
- Delete dependent
- Create contract
- Find contract by ID
- Suspend contract
- Reactivate contract
- Close contract
- Delete contract
The contract has status control (ACTIVE, SUSPENDED, CLOSED) and its transitions are controlled exclusively in the service layer.
- Create expense
- Update expense
- Find expense by ID
- List expenses
- Delete expense
Expenses can only be created, updated or deleted if the contract is active.
- Create income
- Update income
- Find income by ID
- List incomes
- Delete income
Incomes also depend on the contract status.
The API uses JWT (JSON Web Token) for authentication.
Flow:
- User performs login
- API returns a JWT token
- The token must be sent in the header of protected requests
Authorization: Bearer {token}
Swagger also supports authentication using a token to test protected endpoints.
The service layer uses @Transactional to guarantee integrity of operations.
- Write methods use full transactions
- Read methods use
readOnly = true
The application includes a GlobalExceptionHandler responsible for:
- Standardizing error responses
- Returning the correct HTTP status codes
- Adding traceability to error responses
- Logs implemented in the service layer
- Correlation ID for request tracing
- Better error traceability
- H2 support for development environment
- MySQL support for production environment
- Database versioning using Flyway
- Index creation for query optimization
- Constraints to ensure data integrity
The application uses profiles to separate environments:
h2β developmentmysqlβ production
Database switching occurs only through configuration, without the need to change code.
The project includes docker-compose to start the full environment:
docker-compose up -d
Services:
- MySQL
- Spring Boot Application
Project prepared for cloud deployment (Railway), including:
- MySQL driver configuration
- Environment variable configuration
- Production profile adjustments
- Automatic Flyway migrations on startup
Unit tests were implemented for the service layer, ensuring:
- Validation of business rules
- Reliability of operations
- Ease of maintenance
After starting the application, access:
http://localhost:8080/swagger-ui.html
Or in production:
https://transparence-api-production.up.railway.app/swagger-ui.html
The documentation is organized by API resources:
- Auth
- Users
- Dependents
- Contracts
- Incomes
- Expenses
- Java 17+
- Maven
- Docker (optional)
mvn spring-boot:run
docker-compose up -d
- Layered architecture
- DTO Pattern
- Separation between API contract and domain
- Business rules centralized in the service layer
- Global exception handling
- Logs and traceability
- JWT authentication
- Database versioning with Flyway
- Transaction control with Spring
- Unit testing
- Multiple environment profiles
- Cloud deployment preparation
π Project completed as a backend architecture study using Spring Boot and best development practices.
Gustavo Batista
Project developed focusing on practical learning, clean architecture and backend development best practices.