Hierarchy Structure
π inventory_management_backend/
βββ π app/
Main application package
β βββ π domain/
Business entities and pure domain logic
β β βββ π models/
Domain entities
β β β βββ π user.py
β β β βββ π product.py
β β βββ π services/
β β βββ π inventory_service.py
β βββ π application/
Use cases, DTOs, orchestrators, event handlers
β β βββ π use_cases/
Business operations
β β β βββ π product/
β β β β βββ π create_product.py
β β β β βββ π get_product.py
β β β β βββ π update_product.py
β β β β βββ π delete_product.py
β β β βββ π user/
β β β βββ π register_user.py
β β β βββ π login_user.py
β β βββ π dto/
DTOs for requests/responses
β β β βββ π product_dto.py
β β β βββ π user_dto.py
β β βββ π event_handlers/
β β βββ π inventory_events.py
β βββ π ports/
Abstract interfaces for repositories, auth, event bus
β β βββ π product_repository.py
β β βββ π user_repository.py
β β βββ π event_bus.py
β βββ π adapters/
Infrastructure implementations (DB, auth, events)
β β βββ π repositories/
β β β βββ π product_repository_impl.py
β β β βββ π user_repository_impl.py
β β βββ π db/
β β β βββ π base.py
β β β βββ π session.py
β β βββ π auth/
β β β βββ π jwt_manager.py
β β βββ π events/
β β βββ π event_publisher.py
β βββ π api/
FastAPI routers/controllers
β β βββ π v1/
β β β βββ π product_router.py
β β β βββ π user_router.py
β β βββ π dependencies.py
β βββ π config/
β β βββ π settings.py
β βββ π main.py
β βββ π events.py
βββ π tests/
Unit & integration tests
β βββ π domain/
β βββ π application/
β βββ π adapters/
β βββ π api/
β βββ π conftest.py
βββ π requirements.txt
βββ π README.md
βββ π alembic/
DB migrations
π domain/
Defines pure business logic and entities, independent of frameworks/infrastructure. Purpose: Isolate and reuse core logic.
π application/
Orchestrates domain logic, use cases, DTOs, and event handlers. Purpose: Implements business workflows.
π ports/
Abstract interfaces for repositories, auth, event bus. Purpose: Decouples business logic from infrastructure.
π adapters/
Infrastructure implementationsβrepositories, DB, auth, event publisher. Purpose: Bridges core to external systems.
π api/
FastAPI routers/controllers as entry points. Purpose: Adapts HTTP requests to business logic.
π config/
App configuration, secrets, DB settings. Purpose: Technical details kept out of core logic.
π main.py
App entry point, wires dependencies. Purpose: Bootstraps hexagonal application.
π app/
Microservice boundary (can split into submodules/services). Purpose: Enables independent deployment and scaling.
π main.py
Microservice entry point. Purpose: Run services independently.
π config/
Service-specific configuration. Purpose: Environment setup per microservice.
π adapters/events/
Messaging adapters for each service. Purpose: Enables async communication between microservices.
π tests/
Service/module-level tests. Purpose: Reliability and separation of concerns.
π alembic/
Service-specific DB migrations. Purpose: Schema evolution per microservice.
π application/event_handlers/
Handles events and triggers workflows. Purpose: Responds to system changes asynchronously.
π adapters/events/
Event publisher for domain/integration events. Purpose: Publishes events to brokers.
π events.py
Centralized event definitions. Purpose: Maintains event registry.
π application/dto/*_dto.py
Event payload DTOs. Purpose: Ensures structured event data.
π ports/event_bus.py
Event bus interface. Purpose: Decouples event logic from messaging technology.