How hiddro/back_clinic works
Main Components of the System
a. Application Entry Point & Configuration:
• ClinicApplication.java – the main class to bootstrap the application.
• Configuration classes (MongoConfig, ResourceWebPropertiesConfig) that set up the database and web-related properties.
• application.yml – external configuration including database, server, and other environment-specific settings.
b. Controllers (Presentation Layer):
• LoginController, RoleController, and UserController handle incoming HTTP requests.
• They serve as the interface exposing the API endpoints.
c. Service Layer:
• Services such as CrudService, UserService, RoleService, and TokenService (with corresponding implementations) encapsulate the business logic.
• They process input from controllers and coordinate with the repositories.
d. Repository Layer (Data Access):
• GenericRepo, RoleRepositories, and UserRepositories are responsible for interacting with MongoDB (as suggested by MongoConfig).
• This layer ensures data retrieval and persistence.
e. Security Infrastructure:
• Security config (e.g., WebSecurityConfig) and classes like AuthenticationManager, SecurityContextRepository, and JWTUtil manage authentication and authorization.
• Contains builder classes for token and user request/response transformation.
f. Utilities and Builders:
• Builder classes (e.g., RoleRequestBuilder, UserResponseBuilder, etc.) help in constructing request and response objects.
• Commons utilities, constants, and exception handlers standardize operations and error responses.
Relationships and Interactions
• Upon receiving an HTTP request, one of the Controllers routes the request.
• The Controllers invoke corresponding Service methods which implement business logic.
• Services, in turn, interact with Repositories to perform database CRUD operations.
• The Security layer intercepts requests for authentication/authorization and uses JWTUtil and AuthenticationManager.
• The Builders all support conversion between different object layers (e.g., converting a database model to a response DTO) enhancing separation of concerns.
• Exception handling is performed via custom handlers (e.g., WebExceptionHandler and ExceptionHandler from commons).
Architectural Patterns and Design Principles
• Layered Architecture: Clear separation between controllers (API), services (business logic), and repositories (data access).
• Builder Pattern: Used for constructing and translating various request/response objects.
• Externalized Configuration: Use of application.yml and configuration classes for managing environment-specific settings.
• Security Best Practices: Implementing JWT and centralized authentication via Spring Security configurations.
• Dependency Injection: Likely using Spring Boot’s dependency injection to wire components together.
• Exception Handling: Dedicated classes to manage and encapsulate error responses.