Directory Structure
Understanding how Fastman organizes your code.
Feature Pattern (Default)β
The feature pattern uses vertical slicesβeach feature contains everything it needs.
my-api/
βββ app/
β βββ core/ # Shared infrastructure
β β βββ __init__.py
β β βββ config.py # Settings from environment
β β βββ database.py # SQLAlchemy session
β β βββ dependencies.py # FastAPI dependencies
β β
β βββ features/ # Feature modules
β β βββ user/
β β β βββ __init__.py
β β β βββ models.py # User SQLAlchemy model
β β β βββ schemas.py # User Pydantic schemas
β β β βββ service.py # User business logic
β β β βββ router.py # User API endpoints
β β β
β β βββ post/
β β βββ models.py
β β βββ schemas.py
β β βββ service.py
β β βββ router.py
β β
β βββ main.py # App entry point
β
βββ database/
β βββ migrations/ # Alembic migrations
β β βββ versions/
β βββ seeders/ # Database seeders
β
βββ tests/
β βββ factories/ # Model factories
β βββ test_*.py # Test files
β
βββ .env # Default environment variables
βββ .env.development # Development settings
βββ .env.staging # Staging settings
βββ .env.production # Production settings
βββ alembic.ini # Migration config
βββ pyproject.toml # Dependencies
API Patternβ
The API pattern groups code by HTTP resource:
app/
βββ api/
β βββ v1/
β β βββ users.py
β β βββ posts.py
β βββ v2/
βββ models/
βββ schemas/
βββ services/
Layer Patternβ
The layer pattern separates by technical concern:
app/
βββ controllers/
βββ models/
βββ repositories/
βββ schemas/
βββ services/
Key Filesβ
| File | Purpose |
|---|---|
app/main.py | Application factory, router mounting |
app/core/config.py | Pydantic settings, loads env file by ENVIRONMENT |
app/core/database.py | SQLAlchemy engine and session |
alembic.ini | Database migration configuration |
.env | Fallback environment variables (never commit!) |
.env.development | Development environment settings |
.env.staging | Staging environment settings |
.env.production | Production environment settings |