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
β
βββ public/ # Static files (HTML, images, CSS, JS)
βββ 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:
my-api/
βββ app/
β βββ api/
β β βββ v1/
β β β βββ users.py
β β β βββ posts.py
β β βββ v2/
β βββ models/
β βββ schemas/
β βββ services/
βββ public/ # Static files
βββ tests/
βββ ...
Layer Patternβ
The layer pattern separates by technical concern:
my-api/
βββ app/
β βββ controllers/
β βββ models/
β βββ repositories/
β βββ schemas/
β βββ services/
βββ public/ # Static files
βββ tests/
βββ ...
Key Filesβ
| File | Purpose |
|---|---|
app/main.py | Application factory, router mounting, static files |
app/core/config.py | Pydantic settings, loads env file by ENVIRONMENT |
app/core/database.py | SQLAlchemy engine and session |
public/ | Static files served at /public (HTML, images, CSS, JS) |
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 |