How zhanymkanov/fastapi-best-practices works
Main Components
a. Core Application Layer:
• FastAPI Application Instance
• Router Layer (showing modular routing structure)
• Dependency Injection System
• Pydantic Models Layer
• Service Layer
• Database Layer
b. Module Structure (show the recommended project structure):
• Auth Module
• AWS Module
• Posts Module
• Common/Shared Components
Key Relationships to Highlight
a. Request Flow:
• Client Request → FastAPI Router
• Router → Dependencies
• Dependencies → Services
• Services → Database
• Response Path Back to Client
b. Cross-cutting Concerns:
• Authentication Flow
• Validation Flow
• Error Handling
• Background Tasks
Specific Design Elements
• Rectangles: Modules and Components
• Diamonds: Decision Points (like dependency validation)
• Blue: Core FastAPI Components
• Green: Successful Flows
• Yellow: Validation/Processing Steps
• Red: Error Handling
• Gray: External Services
Important Details
a. Async Flow Handling:
• Parallel processing capabilities
• Thread pool for sync operations
• Async vs sync routes
b. Dependency Chain:
• How dependencies can be chained
• Dependency caching
• Validation flow
c. Data Validation:
• Pydantic model validation
• Custom validation in dependencies
• Database constraints
Dependency injection flow
b. Use clear labels and annotations:
• Async vs sync operations
• Validation points
• Error handling paths
c. Important notes:
• Caching behavior
• Thread pool usage
• Database naming conventions
• Migration handling