Skip to main content

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​

FilePurpose
app/main.pyApplication factory, router mounting
app/core/config.pyPydantic settings, loads env file by ENVIRONMENT
app/core/database.pySQLAlchemy engine and session
alembic.iniDatabase migration configuration
.envFallback environment variables (never commit!)
.env.developmentDevelopment environment settings
.env.stagingStaging environment settings
.env.productionProduction environment settings