How neonkid/fastapi-ddd-example works
Main Components
a) Core Layers:
• Domain Layer (modules/*/domain)
• Application Layer (modules/*/usecase)
• Infrastructure Layer (modules/*/infrastructure)
• Presentation Layer (FastAPI routes)
b) Cross-Cutting Components:
• Event System
• Dependency Injection Container
• Common Protocols
• Error Handling
Architectural Patterns to Highlight
• CQRS (Command Query Responsibility Segregation)
• Event-Driven Architecture
• Repository Pattern
• Unit of Work Pattern
• Domain Events
Detailed Component Breakdown
API Layer:
┌─────────────────────────────────────────┐
• FastAPI Routes │
• ┘
Use Cases Layer:
┌─────────────────────────────────────────┐
• Command Use Cases │ Query Use Cases│
• (State Modification) │ (Data Fetch) │
• ┘
Domain Layer:
┌─────────────────────────────────────────┐
• Book Aggregate │ Author Aggregate │
• Domain Model │ - Domain Model │
• Value Objects │ - Value Objects │
• ┘
Infrastructure Layer:
┌─────────────────────────────────────────┐
• Persistence │ Query │
• Repositories │ - DTOs │
• Unit of Work │ - Repositories │
• ┘
Event System Flow
Domain Event → Event Dispatcher → Event Handlers
Important Relationships
• One-way dependencies pointing downward (following clean architecture)
• Event flow between bounded contexts
• CQRS separation between read and write operations
• Dependency injection flow
Additional Elements
A separate section showing:
• Snowflake ID generation
• Database schema (as shown in README)
• Protocol interfaces
• Error handling flow
Implementation Details
• FastAPI dependency injection system
• SQLAlchemy classical mapping
• Event processing flow
• Repository pattern implementation
• Unit of Work transaction boundaries
Notes
Important notes about:
• Explicit dependency injection
• Transaction boundaries
• Event handling asynchronous nature
• CQRS implementation details
Remember to keep the abstraction level high enough to be understandable but detailed enough to show the important architectural decisions made in the project.