How hienhaobn/tutorials-spring-boot-3 works
Main Components
• Hello Spring Boot Service:
– This is a basic Spring Boot application (located in the hello-spring-boot directory).
– Contains a main entry point (HelloSpringBootApplication.java) and at least one controller (HelloSpringController.java) handling simple endpoints.
• Identity Service:
– This service (in the identity-service directory) is more feature-rich.
– It handles authentication, user, role, and permission management.
– It is structured into distinct layers such as configuration (e.g. SecurityConfig, JwtAuthenticationEntryPoint, ApplicationInitConfig), controllers (AuthenticationController, PermissionController, RoleController, UserController), service layer (AuthenticationService, PermissionService, RoleService, UserService), data access (repositories for User, Role, and Permission) and exception handling (GlobalExceptionHandler, custom exceptions).
– It employs DTOs (data transfer objects) and mappers to convert between entity representations and API responses.
Architectural Layers and Interactions
• For each Spring Boot application, identify the standard layers:
– Presentation Layer: Controllers managing REST endpoints.
– Business Logic Layer: Service classes containing the core logic.
– Data Access Layer: Repositories interacting with the database (even if not explicitly mentioned, Spring Data JPA is likely used given the standard structure).
– Configuration & Security: Identity Service contains several configuration classes for JWT-based authentication and general security setup.
– Exception Handling: Centralized error handling within Identity Service.
• Data Flow:
– A client sends HTTP requests to the respective controller endpoints.
– Controllers invoke service methods.
– Services interact with repositories to perform CRUD operations and validation.
– In Identity Service, requests may pass through security filters (configured in SecurityConfig and JwtAuthenticationEntryPoint) ensuring only authenticated and authorized requests are processed.
Architectural Patterns or Design Principles
• Both services follow Spring Boot’s layered architecture, commonly seen in MVC applications.
• The Identity Service in particular employs elements of the microservices design pattern where each service is self-contained and structured by components (controllers, services, repositories) with clear separation of concerns.
• Utilization of DTOs and mappers exemplifies the pattern of decoupling internal database models from external API representations.