Levels and features
This page lists what fastkit init can create: the five levels, the feature options and the rules between them, the package managers and the example projects. The tables come from the catalog that the command line and the web generator also read. Choose a level and Customise features show how to pick them.
Levels
| Level | Description | Template | Database question | Read first |
|---|---|---|---|---|
hello |
One main.py: 3 endpoints, in-memory data, tests. | fastapi-hello |
No | Read main.py from top to bottom: each comment links the FastAPI tutorial page that explains it. |
single-file |
The whole app in one module, with settings and tests. | fastapi-single-module (preset single-module) |
Yes (default: None) | Read src/main.py: the settings, the app and its routes in one module. |
layered |
Separate layers: routes, CRUD, schemas, core config. | fastapi-default (preset classic-layered) |
Yes (default: None) | Read src/main.py, then src/api/routes/items.py, src/crud/items.py and src/schemas/items.py. |
domain |
One package per domain: router, service, repository. | fastapi-domain-starter (preset domain-starter) |
Yes (default: None) | Read src/app/main.py, then src/app/domains/items/: router.py, service.py and repository.py. |
production |
domain plus PostgreSQL, Alembic, JWT, CI and Docker. | fastapi-domain-starter (preset domain-starter) |
Yes (default: PostgreSQL) | Read src/app/main.py, then src/app/domains/items/; README.md describes each selected feature. |
hello copies fastapi-hello as it is and takes no feature options. The other levels each name a preset, and the preset names the template the project starts from. production is the domain-starter preset with a fixed selection on top: PostgreSQL, Alembic, JWT, Coverage, structured logging, ruff, GitHub Actions, Docker and docker-compose. You can change that selection in the customise step or with --feature. Configuration files from fastkit 1.x that name the minimal preset still load: minimal now means single-module.
Where generated files go
Each preset puts the modules that features generate next to the template's own code:
| Module | single-module (single-file) |
classic-layered (layered) |
domain-starter (domain, production) |
|---|---|---|---|
| Settings | src/main.py; src/core/config.py once a generated module reads them |
src/core/config.py |
src/app/core/config.py |
| Database | src/core/database.py |
src/core/database.py |
src/app/core/database.py |
| Authentication | src/auth/ |
src/auth/ |
src/app/domains/auth/ |
| Readiness probe (with a database or a Redis cache) | src/features/readiness.py |
src/features/readiness.py |
src/app/features/readiness.py |
| Pagination | src/core/pagination.py when features are selected |
src/core/pagination.py |
src/app/core/pagination.py |
Generated modules read their configuration from the settings module, which loads .env. With layered, domain or production and PostgreSQL, MySQL or SQLite, the example /items API stores its items in that database. With MongoDB or Redis it keeps its own store, and fastkit says so in a note and in README.md.
Test and lint tools
| Level | Dev dependencies | Tool settings |
|---|---|---|
hello |
pytest, httpx | [tool.pytest.ini_options] in pyproject.toml |
single-file |
pytest, pytest-cov, httpx, black, isort, mypy, ruff | pyproject.toml: pytest, coverage, black, isort, mypy and ruff |
layered, domain |
the same | the same, plus scripts/lint.sh (black, isort, mypy src, ruff check) |
production |
the same, plus aiosqlite, httpx2 and pytest-asyncio | the same |
uv run pytest --cov reports coverage at every level after hello. When you select features, fastkit also writes a conftest.py at the project root that sets test-only settings before the tests import the application.
How features are wired into main.py
Every level keeps the template's main.py. fastkit adds each feature at two comment lines in it:
# fastkit:imports: the import lines of the generated modules.# fastkit:routes: one statement per feature. Business routers such as the authentication routes are mounted undersettings.API_V1_PREFIX(/api/v1by default); the database lifespan router and the/readyprobe are mounted at the root.
Middleware setup, such as setup_logging(app) for structured logging, goes above the CORS block, so CORS stays the outermost middleware. fastkit --debug init prints a line Wired generated features into src/app/main.py: ... that lists what fastkit added.
What fastkit does not change
fastkit changes a template's main.py only by adding import lines and single statements at the two comment lines. It does not rewrite template code or the template's lifespan: a feature that needs startup or shutdown work brings it in its own router. The one exception is single-file: when a generated module needs the settings, fastkit moves them from src/main.py to src/core/config.py and prints a note, because the module would otherwise import src.main.
Features
Database
Database and ORM selection. Select with --database OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
PostgreSQL |
PostgreSQL through async SQLAlchemy (asyncpg) | asyncpg, sqlalchemy[asyncio] |
SQL databases | |
MySQL |
MySQL through async SQLAlchemy (aiomysql) | aiomysql[rsa], sqlalchemy[asyncio] |
SQL databases | |
MongoDB |
MongoDB through PyMongo's async client | pymongo>=4.13 |
Lifespan events | |
Redis |
Redis as a key-value store (redis-py asyncio client) | redis[hiredis] |
Lifespan events | |
SQLite |
SQLite file through async SQLAlchemy (aiosqlite), no server needed | sqlalchemy[asyncio], aiosqlite |
SQL databases |
Authentication
User authentication and authorization. Select with --feature authentication=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
JWT |
OAuth2 password flow with JWT (recommended for APIs) | pyjwt[crypto], pwdlib[argon2], email-validator, python-multipart |
OAuth2 with password and JWT tokens | |
OAuth2 |
OAuth2 with authlib | authlib, itsdangerous, httpx2 |
Middleware | |
FastAPI-Users |
Complete user management (JWT; SQL databases only) | fastapi-users[sqlalchemy]>=15.0.5,<16 |
OAuth2 with password and JWT tokens | |
Session-based |
Traditional session-based authentication | itsdangerous, pwdlib[argon2], email-validator |
Middleware |
Background tasks
Background task processing. Select with --feature async_tasks=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
Celery |
Celery worker with Redis as the broker | celery[redis], redis[hiredis] |
Background tasks | |
Dramatiq |
Dramatiq worker with Redis as the broker | dramatiq[redis], redis[hiredis] |
Background tasks |
Testing
Testing framework and tools. Select with --feature testing=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
Basic |
pytest + httpx for API testing | pytest, pytest-asyncio, httpx, httpx2 |
Testing | |
Coverage |
Basic + code coverage | pytest, pytest-asyncio, pytest-cov, httpx, httpx2 |
Testing | |
Advanced |
Coverage + faker + factory-boy for fixtures | pytest, pytest-asyncio, pytest-cov, httpx, httpx2, faker, factory-boy |
Testing |
Caching
Response and data caching. Select with --feature caching=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
Redis |
Response caching on Redis (fastapi-cache2) | redis[hiredis], fastapi-cache2, jinja2 |
Documentation |
Monitoring
Application monitoring and logging. Select with --feature monitoring=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
Loguru |
Enhanced logging with Loguru | loguru |
Documentation | |
OpenTelemetry |
Distributed tracing and metrics | opentelemetry-api, opentelemetry-sdk, opentelemetry-instrumentation-fastapi, opentelemetry-exporter-otlp-proto-http |
Middleware | |
Prometheus |
Prometheus metrics instrumentation | prometheus-client, prometheus-fastapi-instrumentator |
Documentation |
Utilities
Additional utilities and middleware. Select with --feature utilities=OPTION; several options are separated by commas.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
CORS |
Built in to every project. | CORS | ||
Rate-Limiting |
Per-client API rate limits (limits) | limits>=3.4 |
Middleware | |
Pagination |
Built in to every project. | Query parameters | ||
WebSocket |
Example WebSocket endpoint (websockets) | websockets |
WebSockets |
Migrations
Database schema migrations. Select with --feature migrations=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
Alembic |
alembic.ini + async alembic/env.py + scripts/migrate.sh | alembic |
Documentation |
Developer tooling
Developer tooling and CI configuration. Select with --feature tooling=OPTION; several options are separated by commas.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
ruff |
ruff + ruff-format config in pyproject.toml (replaces black/isort) | ruff |
Documentation | |
pre-commit |
.pre-commit-config.yaml | pre-commit |
Documentation | |
github-actions |
.github/workflows/test.yml (Python 3.12) | Documentation | ||
devcontainer |
.devcontainer/devcontainer.json | Documentation | ||
makefile |
Makefile with install/test/lint/format/run | Documentation |
Logging
Application logging format. Select with --feature logging=OPTION.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
structured |
JSON logs + X-Request-ID correlation middleware (stdlib only) | Middleware |
Deployment
Container deployment files. Select with --feature deployment=OPTION; several options are separated by commas.
| Option | Summary | Runtime packages | Dev packages | Learn more |
|---|---|---|---|---|
Docker |
Generate Dockerfile | FastAPI in containers (Docker) | ||
docker-compose |
Generate docker-compose.yml (includes Docker) | FastAPI in containers (Docker) |
Rules
- Authentication
FastAPI-Usersneeds DatabasePostgreSQL,MySQLorSQLite. - Deployment
docker-composealso selects DeploymentDocker. - Database
PostgreSQLorMySQLaddsaiosqlite(dev). - Caching
Redisand Background tasksCeleryorDramatiq: Redis will be used for both caching and task queue (shared dependency).
Package managers
| Package manager | Dependency file | Description |
|---|---|---|
pip |
requirements.txt |
Standard Python package manager |
uv |
pyproject.toml |
Fast Python package manager |
pdm |
pyproject.toml |
Modern Python dependency management |
poetry |
pyproject.toml |
Python dependency management and packaging |
Example projects
| Template | Description | Read first |
|---|---|---|
fastapi-custom-response |
Async Item Management API with Custom Response System | Read src/main.py, then src/helper/responses.py and src/api/routes/items.py to see the response envelope. |
fastapi-auth-jwt |
FastAPI JWT Authentication | Read src/app/main.py, then src/app/domains/auth/ and src/app/core/security.py. |
fastapi-sqlmodel |
FastAPI SQLModel | Read src/app/main.py, then src/app/domains/items/ and src/app/db/session.py; the README explains how to switch to PostgreSQL or MySQL. |
fastapi-mcp |
FastAPI MCP Project | Read src/main.py, then src/mcp_server/router.py and src/auth/. |
fastapi-llm-agent |
FastAPI LLM Agent | Read src/app/main.py, then src/app/api/chat.py and src/app/llm/agent.py. |
FastAPI concepts
- First steps
- Path parameters
- Query parameters
- Request body
- Response model
- Response status codes
- Handling errors
- Dependencies
- Dependencies with yield
- Bigger applications with multiple files
- Settings and environment variables
- Lifespan events
- SQL databases
- OAuth2 with password and JWT tokens
- CORS
- Middleware
- Testing
- Background tasks
- WebSockets
- FastAPI in containers (Docker)
- Concurrency and async / await