Generated projects
This page describes what every project that fastkit init creates has in common: the HTTP API it serves, its settings, its dependency files, the metadata block that the other fastkit commands read, and the comments fastkit leaves in the code. The Levels and features page lists where each level puts its files.
HTTP API
The layered, domain and production levels serve the same example API, and every resource that fastkit addroute adds follows the same rules. These are the routes of a domain project:
| Method and path | Success | Errors |
|---|---|---|
GET /health |
200 {"status": "ok"} |
|
GET /api/v1/items?limit=&offset= |
200, one page of items | 422 |
POST /api/v1/items |
201 with a Location header |
422 |
GET /api/v1/items/{item_id} |
200 | 404, 422 |
PUT /api/v1/items/{item_id} |
200 | 404, 422 |
PATCH /api/v1/items/{item_id} |
200 | 404, 422 |
DELETE /api/v1/items/{item_id} |
204, empty body | 404, 422 |
The rules behind the table:
- Business routes live under the
API_V1_PREFIXsetting,/api/v1by default. Paths have no trailing slash. GET /healthsits at the root and answers without authentication and without touching a database.- With a database or a Redis cache,
GET /readyis added at the root. It answers 200{"status": "ok"}, or 503{"status": "unavailable"}when a check fails or takes longer than 2 seconds. - List endpoints take
limit(1 to 100, default 20) andoffset(0 or more) and return{"items": [...], "total": 0, "limit": 20, "offset": 0}. A value out of range gets a 422 response; it is not clamped. POSTanswers 201 with aLocationheader that holds the full URL of the new item.PUTreplaces the item and takes the same body asPOST.PATCHchanges only the fields you send.DELETEanswers 204 with an empty body.- A missing item answers 404 with
{"detail": "Item not found"}. Every 401 response carries aWWW-Authenticateheader. - Request and response bodies use the schemas
ItemCreate(POST,PUT),ItemUpdate(PATCH) andItemRead(responses). The list response isPage[ItemRead].
The fields of an item differ between levels. layered items have name, description, price and category; domain and production items have name, price and in_stock. production adds POST /api/v1/auth/register, POST /api/v1/auth/token (form-encoded), GET /api/v1/users/me and GET /api/v1/users/{user_id}.
Two levels are smaller. hello serves GET /, POST /items (201, no Location header) and GET /items/{item_id} (404 when missing) from one main.py, with no prefix and no /health. single-file serves GET / and GET /health until you add routes.
Settings
Every level except hello has one settings module, built on pydantic-settings: src/main.py or src/core/config.py at single-file, src/core/config.py at layered and src/app/core/config.py at domain and production. It reads environment variables first and then .env.
.env.exampleis the shareable copy, with placeholder values and a comment for each setting..envis created by fastkit from.env.examplewith a uniqueSECRET_KEY..gitignorekeeps.envand.env.*out of git and lets.env.examplein.ENVIRONMENTisdevelopment,stagingorproduction(defaultdevelopment).- With
ENVIRONMENT=stagingorproduction, the application refuses to start whenSECRET_KEYis not set explicitly, is a public example value such aschangethis, or is shorter than 32 bytes. Indevelopmentan example value only prints a warning. BACKEND_CORS_ORIGINSlists the browser origins allowed to call the API, comma-separated or as a JSON list. Without origins the CORS middleware is not installed; with*, credentials are turned off.
This is the refusal with a short key, in a domain project:
$ ENVIRONMENT=production SECRET_KEY=short uv run python -c "import src.app.core.config"
...
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
Value error, SECRET_KEY must be at least 32 bytes when ENVIRONMENT=production. Generate one with `python -c "import secrets; print(secrets.token_urlsafe(32))"` and set it as SECRET_KEY in the environment or .env. [type=value_error, input_value={'ENVIRONMENT': 'producti..., 'SECRET_KEY': 'short'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.14/v/value_error
Dependency files
Every project has the dependencies in two forms, so it works with every package manager:
pyproject.toml:[project].dependenciesholds the runtime packages and thedevdependency group ([dependency-groups]) holds the test and lint tools. Atlayered,domainandproductionthe same tools are also listed under[project.optional-dependencies] dev.requirements.txtholds the runtime packages only; aDockerfileinstalls this file.requirements-dev.txtstarts with-r requirements.txtand adds the tools.
uv sync, pdm install and poetry install read pyproject.toml; with pip you run pip install -r requirements-dev.txt. The project's README.md shows the commands for the package manager you chose.
Test and tool settings
All tool settings are in pyproject.toml; there is no pytest.ini or setup.cfg. [tool.pytest.ini_options] configures pytest at every level. From single-file on, [tool.coverage.run] and [tool.coverage.report] make pytest --cov measure the code in src/ and list the lines the tests never ran, and [tool.black], [tool.isort], [tool.mypy] and [tool.ruff] configure the lint tools. In a layered project:
$ uv run pytest --cov -q
...
TOTAL 232 4 98%
============================== 74 passed in 1.13s ==============================
With a SQL database, [tool.coverage.run] also sets concurrency = ["greenlet", "thread"], so coverage counts the lines that run after an awaited query.
The [tool.fastapi-fastkit] block
pyproject.toml ends with a block that records how the project was made. This one comes from a production project:
[tool.fastapi-fastkit]
managed = true
version = "2.0.0"
template = "fastapi-domain-starter"
preset = "domain-starter"
package_manager = "uv"
app_module = "src.app.main:app"
features = ["database:PostgreSQL", "authentication:JWT", "testing:Coverage", "migrations:Alembic", "logging:structured", "tooling:ruff", "tooling:github-actions", "deployment:Docker", "deployment:docker-compose"]
| Key | Meaning |
|---|---|
managed |
Marks the folder as a fastkit project. fastkit addroute, fastkit doctor and fastkit deleteproject look for it. |
version |
The fastkit version that created the project. |
template |
The template the project started from. |
preset |
The preset of the level; absent at hello. |
package_manager |
The package manager the project was set up for; fastkit runserver uses it in the commands it prints when .venv is missing. |
app_module |
The application fastkit runserver serves (main:app at hello, src.main:app at single-file and layered). |
features |
The selected options as axis:option; empty when no feature was selected. |
The description in [project] also starts with [FastAPI-fastkit templated]. Keep the block when you edit pyproject.toml: without it, fastkit doctor needs --force and skips the checks that use it.
Next steps in README.md
Each generated README.md holds the Next steps that fastkit init prints at the end, written for a fresh checkout of the project (no cd, a step that creates the environment, uvicorn to start the server), between two comment lines:
When you select features, the block also has a "Selected features" section with one heading per option (for example ### Database: PostgreSQL): what the option adds, its files, its settings and a documentation link. Text outside the two comment lines is yours; when fastkit writes the README again, it replaces only what lies between them.
Concept comments
In a project created from a level, the template's code and the code that features add explain each FastAPI construct where it first appears, with a two-line comment: one sentence, then the address of the FastAPI documentation page about it. The example templates have no such comments; the How-to page on example projects lists the concepts each one shows.
# `app` is the FastAPI application that uvicorn serves: `uvicorn src.main:app`.
# https://fastapi.tiangolo.com/tutorial/first-steps/
app = FastAPI(
A project carries at most one comment per concept, and the addresses come from the list in FastAPI concepts. Code that fastkit addroute writes has no concept comments.
Comment lines in main.py
Templates mark two places in main.py, and in the router module that collects the resource routers (src/api/api.py at layered, src/app/api/router.py at domain and production):
from src.app.domains.items import router as items_router
# fastkit:imports
# One APIRouter collects every domain's router; main.py mounts it under the prefix.
# https://fastapi.tiangolo.com/tutorial/bigger-applications/
api_router = APIRouter()
api_router.include_router(items_router.router)
# fastkit:routes
fastkit init adds the imports and router registrations of selected features at these lines, and fastkit addroute adds those of a new resource. Leave both lines in place when you edit these files. In a single-file project, src/main.py also has # fastkit:settings-start and # fastkit:settings-end around the settings, which fastkit moves to src/core/config.py when a generated module needs them.