How cicerojuniorf/python-clean-arch-showcase works
Overall Project Type and Purpose
• This is a backend API service. Its primary function is to handle customer data and their associated favorite products. It follows best practices by separating concerns into application logic, domain rules (entities and business rules), and infrastructure (persistence, gateway, queries, and security).
• It supports OAuth2-based service-to-service authentication, making it ideally suited as a microservice or standalone backend component.
Main Components
• Presentation Layer:
• Represented by the files in src/presentation (e.g., auth_controller.py, customer_controller.py, favorite_product_controller.py).
• This layer handles incoming API calls (e.g., via Swagger endpoints).
• Application Layer:
• Found in src/application, this contains use-case services such as create_customer, update_customer, add_product_to_favorites, and remove_customer actions.
• Also contains error handling logic specific to application flows.
• Domain Layer:
• Includes core business entities (customer, favorite_product) in src/domain/entities and business rules or validations.
• Interfaces for repositories, gateways, and ID generation are defined here (src/domain/interfaces).
• Infrastructure Layer:
• Implements the abstractions defined in the Domain layer.
• Contains implementations for persistence in both MongoDB and in-memory versions (src/infrastructure/repositories, src/infrastructure/queries, src/infrastructure/gateway).
• Also includes the OAuth2 client credentials service in src/infrastructure/security and ID generators.
• Configuration & Dependencies:
• Files like src/config.py, src/dependencies.py, .env, docker-compose.yml, and makefile indicate external configuration, environment management, and container orchestration.
Relationships & Data Flow
• API gateway receiving HTTP requests (Authentication, Customer Endpoints), passing them through to the corresponding controllers in the Presentation layer.
• The controllers interact with the Application layer, which then leverages Domain logic and performs business validations.
• Domain logic then calls on Infrastructure components (Repositories, Queries, and Gateway implementations) to persist data or call external services (like the product service or MongoDB) as needed.
• Authentication is handled via an infrastructure-level OAuth2 service that validates client credentials for secured endpoints.
Architectural Patterns
• Layered (or hexagonal) architecture: clear separation into presentation, application, domain, and infrastructure layers.
• Use of dependency inversion: Domain interfaces (like repositories or gateways) allow switching between in-memory and MongoDB implementations.
• Security concerns are separated into a dedicated infrastructure security module.
Specific Technical Elements
• Mention key libraries or technologies if known (i.e., Python, Docker, docker-compose, MongoDB).
• Interface definitions and how multiple implementations (memory vs. MongoDB) are connected through dependency injection.
• Call out OAuth2 authentication flow details based on the provided fixed credentials.