How juanpabloleonf/microservice-user works
Main Components
• Entry Point & Server: Mark main.py as your starting point, which initializes Uvicorn with the FastAPI app.
• Configuration Layer: Represent the “app/configuration” directory which sets up the server parameters, environment variables, exception handlers, CORS policies, dependency injection, modular routing, and Swagger API documentation.
• Application Layer: This includes the “app/src/application” directory. It covers:
• Data Transfer Objects (DTOs): request_user, response_user, and response_error.
• Handlers that process incoming user requests.
• Mappers to convert between domain models and DTOs.
• Domain Layer: Found in “app/src/domain”, this is the core of your business logic. It contains:
• Domain models (user_model).
• Persistence ports that define interfaces for data storage (i_persistence_port_user).
• Domain services and use cases (e.g., use_case_user) that encapsulate business rules.
• Utility functions (e.g., util_bcrypt for password encryption).
• Infrastructure Layer: In “app/src/infrastructure”, separate into two parts:
• Inputs (REST controllers): This includes controllers, REST-specific DTOs, and mappers for handling API requests.
• Outputs (MySQL adapters and repositories): Contains the MySQL adapter, entity mapping, repository implementations, and database configurations.
Representing Relationships & Data Flow
• Data flowing from the external API request (via REST controllers in the Infrastructure Inputs section) into the Application layer (handlers and mappers), then into the Domain layer where the business logic and use cases reside.
• From the Domain’s output ports, illustrate how calls pass into the Infrastructure Outputs (MySQL adapters, repositories) for data storage, and then back the response path.
Architectural Patterns & Design Principles
• Separation of concerns inherent in the hexagonal architecture: adapters (external interactions) vs. the core domain logic.
• Dependency Injection as seen in the configuration for routers and module injector for the user.
• That error handling, CORS, and environment configurations are applied at the entry configuration layer.
Technologies, Frameworks, & External Services
• MySQL as the external database service.
• Docker and Docker Compose as orchestration and deployment layers that package and run the microservice in containers.