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
β”‚
β”œβ”€β”€ 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 / local override (gitignored)
β”œβ”€β”€ .env.develop # Development settings
β”œβ”€β”€ .env.staging # Staging settings
β”œβ”€β”€ .fastmanrc # Project shape + env lock (gitignored)
β”œβ”€β”€ 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​

FilePurpose
app/main.pyApplication factory, router mounting, static files
app/core/config.pyPydantic settings, loads env file by ENVIRONMENT
app/core/database.pySQLAlchemy engine and session
public/Static files served at /public (HTML, images, CSS, JS)
alembic.iniDatabase migration configuration
.envFallback / local override (gitignored)
.env.developDevelopment environment settings
.env.stagingStaging environment settings
.fastmanrcProject shape (pattern, db, package manager) and persisted env lock
note

There is no .env.production. Production secrets should be injected by your deployment platform (AWS SSM, Vault, Kubernetes Secrets, etc.) rather than scaffolded into a committed file. See the deployment guide for details.