How fer-gc05/apihexagonal works
Main Components
• Domain Layer: This includes the core business logic. Represent the "src/domain" folder, which contains entities (e.g., comment, post, user) and domain-specific exceptions.
• Application Layer: This encapsulates the application logic using use cases and ports. Include:
• Use cases: "src/application/use_cases" (with separate directories for comment, post, and user operations like create, update, delete, login, register).
• Ports: "src/application/ports" (interfaces for repositories such as comment_repository, post_repository, user_repository).
• Infrastructure Layer: This deals with the technical implementations and external integrations. Add nodes for:
• API layer: "src/infrastructure/api" which holds the FastAPI application entry point (main.py under infrastructure/api), routers (for auth, comments, posts, users), dependencies, and API schemas.
• Database layer: "src/infrastructure/database" contains configuration, migration scripts (with Alembic) and data models (SQLAlchemy models for comment, post, user).
• Repositories: "src/infrastructure/repositories" which implement the interfaces defined in the ports using SQLAlchemy.
• Configuration & Environment: Represent configuration files and environment setups (e.g., ".env.example", "src/config/config.py" and the root main.py) to highlight how configurations and external settings influence the system.
• Testing: Although not the focus of the live system, include a component for tests (located in "src/test") to indicate unit test coverage.
Relationships and Interactions
• The Application Layer invokes domain logic and interacts with ports.
• Ports (interfaces) are implemented by repositories in the Infrastructure Layer.
• The API layer receives HTTP requests and routes these to the appropriate use cases in the application.
• Database interactions flow from repository implementations to the MySQL database (managed via SQLAlchemy and Alembic migrations).
• Data flow from the client (through the API) to the use cases and how that propagates to the domain and infrastructure layers.
Architectural Patterns and Principles
• Hexagonal Architecture by illustrating the separation into three concentric circles or layers: the Domain at the center, surrounded by the Application (with use cases and ports), and further by the Infrastructure (adapters such as API and database).
• Dependency inversion where the domain does not directly depend on the infrastructure, but instead the Application layer interacts with it via abstract ports.
• Framework-specific implementations like FastAPI (for the API entry point) and the role of Alembic for handling database migrations.
Relevant Technologies, Frameworks, and Libraries
• FastAPI for building the RESTful API.
• SQLAlchemy for ORM support and database model management.
• Alembic for handling database migrations.
• MySQL as the underlying database.
• JWT-based authentication as part of the API’s security (as indicated in the README).