How noureddinefatimi/savings-account-api works
1. This is a Spring Boot 2.7 REST API for savings-account management, built with Java 11 and Maven and persisted in MySQL. The runtime boundary is a single backend service: HTTP requests come in, are secured, mapped to controllers, translated through DTOs/services, and stored via Spring Data repositories.
2. The application entry point is com.example.demo.DemoApplication. Configuration lives in src/main/resources/application.properties, which is where the MySQL connection and other runtime settings are expected to be defined.
3. The domain model is centered on four entities in com.example.model: User, Role, Contrat, and Prelevement. These represent the core business objects for account holders, authorization roles, savings contracts, and withdrawal operations.
4. The API surface is split by business capability:
- AdminController for administrative endpoints
- ContratController for contract management
- PrelevementController for withdrawal processing
The README describes the external REST paths as user-, contract-, and withdrawal-oriented APIs.
5. Request/response boundaries are explicit. Each major resource has DTOs in com.example.dto:
- UserRequestDTO / UserResponseDTO
- RoleRequestDTO / RoleResponseDTO
- ContratRequestDTO / ContratResponseDTO
- PrelevementRequestDTO / PrelevementResponseDTO
This indicates the API does not expose JPA entities directly; controllers exchange shaped payloads with clients.
6. Persistence is handled through Spring Data repositories in com.example.repository: UserRepository, RoleRepository, ContratRepository, and PrelevementRepository. These form the direct data-access layer between business logic and MySQL.
7. The service layer is present for user and role concerns via UserService and RoleService. That suggests business rules, validation, and role/user lifecycle logic are centralized there, while the domain controllers likely orchestrate their respective use cases above the repositories.
8. Security is a first-class subsystem. SecurityConfig defines the Spring Security setup, and the custom CustomAuthenticationEntryPoint and CustomAccessDeniedHandler indicate standardized handling for unauthenticated and unauthorized requests. The README states JWT authentication, so the intended architecture is a secured API rather than an open public service.
9. Error handling is centralized in com.example.Exceptions and com.example.ErrorDetails. GlobalException, Result, StatusCode, and ErrorDetails imply a shared error-response contract so controllers can return consistent failure payloads instead of ad hoc exceptions.
10. API documentation is part of the delivery surface. The README points to Swagger UI/OpenAPI, and the src/main/resources/static images suggest the repo includes documentation assets and screenshots rather than a separate front end.
11. From an architectural-diagram perspective, the main flow is: client → Spring Security filter/config → controller → DTO mapping → service/business logic → repository → MySQL, with exceptions routed through the global error layer and standardized responses returned to the client.
12. Test coverage appears minimal in the tree: there is only the default DemoApplicationTests, so the repo is currently structured more as a feature-complete API skeleton than as a heavily tested system.
Main entry points: AdminController.java Admin API · README.md README · ContratController.java Contrat API · PrelevementController.java Prelevement API
Components 25
Runtime
Spring Boot application entry and runtime settings.
- DemoApp · Spring Boot entry point.
src/main/java/com/example/demo/DemoApplication.java
API
HTTP controllers and request/response boundary.
- Admin API · Administrative endpoints.
src/main/java/com/example/controller/AdminController.java - Contrat API · Savings contract endpoints.
src/main/java/com/example/controller/ContratController.java - Prelevement API · Withdrawal endpoints.
src/main/java/com/example/controller/PrelevementController.java - User DTOs · User request and response payloads.
src/main/java/com/example/dto/UserRequestDTO.java - Role DTOs · Role request and response payloads.
src/main/java/com/example/dto/RoleRequestDTO.java - Contrat DTOs · Contract request and response payloads.
src/main/java/com/example/dto/ContratRequestDTO.java - Prelevement DTOs · Withdrawal request and response payloads.
src/main/java/com/example/dto/PrelevementRequestDTO.java
Domain
Core business objects and persistence-facing contracts.
- User Service · User lifecycle and business rules.
src/main/java/com/example/service/UserService.java - Role Service · Role-related business logic.
src/main/java/com/example/service/RoleService.java - User · Account holder domain model.
src/main/java/com/example/model/User.java - Role · Authorization role domain model.
src/main/java/com/example/model/Role.java - Contrat · Savings contract domain model.
src/main/java/com/example/model/Contrat.java - Prelevement · Withdrawal operation domain model.
src/main/java/com/example/model/Prelevement.java
Infrastructure
Security, persistence wiring, and application configuration.
- App Config · Runtime settings such as MySQL connection.
src/main/resources/application.properties - Security · JWT-oriented security configuration and access handling.
src/main/java/com/example/config/SecurityConfig.java - Auth Entry · Handles unauthenticated requests.
src/main/java/com/example/config/CustomAuthenticationEntryPoint.java - Access Denied · Handles unauthorized requests.
src/main/java/com/example/config/CustomAccessDeniedHandler.java - User Repo · Spring Data access for users.
src/main/java/com/example/repository/UserRepository.java - Role Repo · Spring Data access for roles.
src/main/java/com/example/repository/RoleRepository.java - Contrat Repo · Spring Data access for contracts.
src/main/java/com/example/repository/ContratRepository.java - Prelevement Repo · Spring Data access for withdrawals.
src/main/java/com/example/repository/PrelevementRepository.java
Cross-cutting
Shared error and response handling.
- Errors · Shared exception and response format.
src/main/java/com/example/Exceptions/GlobalException.java - Error Details · Standardized error response body.
src/main/java/com/example/ErrorDetails/ErrorDetails.java
Docs
Repository documentation and examples.
- README · API overview, Swagger notes, and usage examples.
README.md
Connections 26
- DemoApp → Security: boots with · Application starts with security configuration.
- DemoApp → App Config: reads · Loads runtime properties.
- Security → Auth Entry: uses · Configures unauthenticated handling.
- Security → Access Denied: uses · Configures unauthorized handling.
- Admin API → User DTOs: exchanges · Uses shaped request/response payloads.
- Contrat API → Contrat DTOs: exchanges · Uses shaped request/response payloads.
- Prelevement API → Prelevement DTOs: exchanges · Uses shaped request/response payloads.
- Admin API → User Service: orchestrates · Delegates user admin logic.
- Admin API → Role Service: orchestrates · Delegates role logic.
- User Service → User Repo: persists via · Reads and writes user data.
- User Service → Role Repo: persists via · Resolves roles for users.
- Role Service → Role Repo: persists via · Reads and writes role data.
- Contrat API → Contrat Repo: loads/saves · Contract lifecycle persistence.
- Prelevement API → Prelevement Repo: loads/saves · Withdrawal lifecycle persistence.
- User Repo → User: maps · Repository manages user entity state.
- Role Repo → Role: maps · Repository manages role entity state.
- Contrat Repo → Contrat: maps · Repository manages contract entity state.
- Prelevement Repo → Prelevement: maps · Repository manages withdrawal entity state.
- Contrat API → Errors: handles via · Uses global exception contract.
- Prelevement API → Errors: handles via · Uses global exception contract.
- Admin API → Errors: handles via · Uses global exception contract.
- Errors → Error Details: formats · Produces standardized error bodies.
- README → Security: describes · Documents secured API behavior.
- README → Admin API: describes · Documents admin endpoints.
- README → Contrat API: describes · Documents contract endpoints.
- README → Prelevement API: describes · Documents withdrawal endpoints.