FastAPI Project Skill 🧩
This skill scaffolds new FastAPI projects or upgrades existing ones with a production-ready layout and operational practices suitable for large systems.
Scope and alignment 🧭
Mandatory reads (must be loaded before using this skill):
Inputs to confirm ✅
- Project name and Python version
- API surface (REST only, GraphQL, or mixed)
- Database (SQLite/PostgreSQL) and cache (Redis/none)
- Background jobs (Celery/Arq/RQ/none) and async worker needs
- Deployment target (container, PaaS, serverless)
- Environment split (local/staging/prod) and secrets strategy
Quick reference 🧠
| Capability |
Purpose |
Key Outputs |
| Project scaffold |
Create a working FastAPI foundation aligned with Python instructions |
pyproject.toml, src/ layout, app core, routers |
| Large-system structure |
Keep growth manageable with clear boundaries |
Domain routers, service layers, adapters |
| Observability baseline |
Operational visibility from day one |
Structured logs, request IDs, health endpoints |
| Security baseline |
Protect data and reduce risk |
Secure defaults, auth boundaries, dependency scanning |
| Resilience and availability |
Survive failures and scale safely |
Timeouts, retries, graceful degradation |
| Quality gates |
Enforce fast feedback |
make targets or uv commands for lint/typecheck/test |
Capabilities 🧰
1. Project scaffold (foundation)
Use this for new projects or to align an existing project with the standard layout.
Core requirements:
- Use
pyproject.toml as the single source of truth. If available, start from the template and set:
- project metadata (name, version, requires-python)
- dependency groups for dev tooling
- ruff, mypy, pytest configuration
- Use
uv for deterministic installs and lockfile management.
- Pin Python in
.python-version and requires-python.
- Scaffold with a
src/ layout so imports are explicit and testable.
- Define app settings with
pydantic-settings and environment variables.
- Keep the ASGI entrypoint thin; wire routers and dependencies in
main.py.
Recommended layout:
.
├── .python-version
├── pyproject.toml
├── src/
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py
│ │ ├── api/
│ │ │ ├── __init__.py
│ │ │ ├── v1/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── routes/
│ │ │ │ └── schemas/
│ │ ├── core/
│ │ │ ├── config.py
│ │ │ ├── logging.py
│ │ │ └── observability.py
│ │ ├── services/
│ │ ├── adapters/
│ │ └── health.py
└── tests/
Dependency defaults (adjust to requirements):
fastapi
uvicorn (or gunicorn + uvicorn workers for production)
pydantic-settings
httpx (for outbound HTTP)
pytest
ruff, mypy
2. Large-system structure and boundaries
Use these patterns when the system is expected to grow:
- Group routers by domain in
api/v1/routes/<domain>.py; keep routing thin.
- Put business logic in services; keep I/O inside adapters/selectors.
- Use dependency injection for shared concerns (auth, DB sessions, clients).
- Use explicit schemas at boundaries; avoid leaking ORM models.
- Separate infrastructure wiring (clients, pools) from request handling.
3. Observability baseline
Observability is non-negotiable for production workloads:
- Configure structured logging and include required fields from the structured logging baseline.
- Add request ID/correlation ID middleware and propagate IDs into logs.
- Provide health endpoints (
/healthz, /readyz) with clear dependency checks.
- Add optional hooks for metrics and tracing (Prometheus or OpenTelemetry) but keep them toggled by configuration.
- Never log secrets or raw personal data.
4. Security baseline
Protect data and enforce secure defaults:
- Load secrets from environment or a secret manager; never commit or log secrets.
- Configure CORS narrowly; never use
* in production for credentialed routes.
- Enforce authn/authz at router boundaries; keep public vs private APIs explicit.
- Disable or restrict interactive docs in production when required.
- Use dependency pinning and vulnerability scanning; keep lock files updated.
5. Resilience and availability baseline
Build for failure and recovery:
- Set explicit timeouts on outbound HTTP/DB calls; never rely on defaults.
- Use retries with bounded backoff and jitter for transient failures; avoid retrying non-idempotent operations without safeguards.
- Use connection pooling and sensible concurrency limits for the ASGI server.
- Provide graceful shutdown and ensure background tasks are interruptible.
- Use caching for hot paths and provide safe fallbacks when caches fail.
6. Quality gates and verification
Align with Python quality gates:
- Prefer
make format, make lint, make typecheck, make test when Makefile targets exist.
- Otherwise use
uv run ruff format ., uv run ruff check ., uv run mypy ., uv run pytest.
- Add a lightweight ASGI startup check (import app, load settings) before shipping.
Output expectations 📦
When executing this skill, produce:
- A scaffolded FastAPI project or a concrete refactor plan for an existing codebase
- A list of decisions made for observability, security, resilience, and availability
- A short validation checklist using the canonical quality gates
When information is missing, record Unknown from code – {suggested action} instead of guessing.
Version: 1.0.0
Last Amended: 2026-01-18
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: fastapi-project3description: Scaffold and evolve FastAPI projects with uv-based tooling, structured settings, and production-ready observability, resilience, availability, and security patterns aligned with python.instructions.md. Use when this capability is needed.4---56# FastAPI Project Skill 🧩78This skill scaffolds new FastAPI projects or upgrades existing ones with a production-ready layout and operational practices suitable for large systems.910## Scope and alignment 🧭1112Mandatory reads (must be loaded before using this skill):1314- [Python instructions](../../instructions/python.instructions.md) — use its identifiers when describing compliance.15- [Local-first dev baseline](../../instructions/includes/local-first-dev-baseline.include.md)16- [Quality gates baseline](../../instructions/includes/quality-gates-baseline.include.md)17- [Observability logging baseline](../../instructions/includes/observability-baseline.include.md)18- [AI-assisted change baseline](../../instructions/includes/ai-assisted-change-baseline.include.md)1920## Inputs to confirm ✅2122- Project name and Python version23- API surface (REST only, GraphQL, or mixed)24- Database (SQLite/PostgreSQL) and cache (Redis/none)25- Background jobs (Celery/Arq/RQ/none) and async worker needs26- Deployment target (container, PaaS, serverless)27- Environment split (local/staging/prod) and secrets strategy2829## Quick reference 🧠3031| Capability | Purpose | Key Outputs |32| --------------------------- | -------------------------------------------------------------------- | ----------------------------------------------------- |33| Project scaffold | Create a working FastAPI foundation aligned with Python instructions | `pyproject.toml`, `src/` layout, app core, routers |34| Large-system structure | Keep growth manageable with clear boundaries | Domain routers, service layers, adapters |35| Observability baseline | Operational visibility from day one | Structured logs, request IDs, health endpoints |36| Security baseline | Protect data and reduce risk | Secure defaults, auth boundaries, dependency scanning |37| Resilience and availability | Survive failures and scale safely | Timeouts, retries, graceful degradation |38| Quality gates | Enforce fast feedback | `make` targets or uv commands for lint/typecheck/test |3940---4142## Capabilities 🧰4344### 1. Project scaffold (foundation)4546Use this for new projects or to align an existing project with the standard layout.4748Core requirements:4950- Use `pyproject.toml` as the single source of truth. If available, start from [the template](../../instructions/templates/pyproject.toml) and set:51 - project metadata (name, version, requires-python)52 - dependency groups for dev tooling53 - ruff, mypy, pytest configuration54- Use `uv` for deterministic installs and lockfile management.55- Pin Python in `.python-version` and `requires-python`.56- Scaffold with a `src/` layout so imports are explicit and testable.57- Define app settings with `pydantic-settings` and environment variables.58- Keep the ASGI entrypoint thin; wire routers and dependencies in `main.py`.5960Recommended layout:6162```text63.64├── .python-version65├── pyproject.toml66├── src/67│ ├── app/68│ │ ├── __init__.py69│ │ ├── main.py70│ │ ├── api/71│ │ │ ├── __init__.py72│ │ │ ├── v1/73│ │ │ │ ├── __init__.py74│ │ │ │ ├── routes/75│ │ │ │ └── schemas/76│ │ ├── core/77│ │ │ ├── config.py78│ │ │ ├── logging.py79│ │ │ └── observability.py80│ │ ├── services/81│ │ ├── adapters/82│ │ └── health.py83└── tests/84```8586Dependency defaults (adjust to requirements):8788- `fastapi`89- `uvicorn` (or `gunicorn` + `uvicorn` workers for production)90- `pydantic-settings`91- `httpx` (for outbound HTTP)92- `pytest`93- `ruff`, `mypy`9495### 2. Large-system structure and boundaries9697Use these patterns when the system is expected to grow:9899- Group routers by domain in `api/v1/routes/<domain>.py`; keep routing thin.100- Put business logic in services; keep I/O inside adapters/selectors.101- Use dependency injection for shared concerns (auth, DB sessions, clients).102- Use explicit schemas at boundaries; avoid leaking ORM models.103- Separate infrastructure wiring (clients, pools) from request handling.104105### 3. Observability baseline106107Observability is non-negotiable for production workloads:108109- Configure structured logging and include required fields from the structured logging baseline.110- Add request ID/correlation ID middleware and propagate IDs into logs.111- Provide health endpoints (`/healthz`, `/readyz`) with clear dependency checks.112- Add optional hooks for metrics and tracing (Prometheus or OpenTelemetry) but keep them toggled by configuration.113- Never log secrets or raw personal data.114115### 4. Security baseline116117Protect data and enforce secure defaults:118119- Load secrets from environment or a secret manager; never commit or log secrets.120- Configure CORS narrowly; never use `*` in production for credentialed routes.121- Enforce authn/authz at router boundaries; keep public vs private APIs explicit.122- Disable or restrict interactive docs in production when required.123- Use dependency pinning and vulnerability scanning; keep lock files updated.124125### 5. Resilience and availability baseline126127Build for failure and recovery:128129- Set explicit timeouts on outbound HTTP/DB calls; never rely on defaults.130- Use retries with bounded backoff and jitter for transient failures; avoid retrying non-idempotent operations without safeguards.131- Use connection pooling and sensible concurrency limits for the ASGI server.132- Provide graceful shutdown and ensure background tasks are interruptible.133- Use caching for hot paths and provide safe fallbacks when caches fail.134135### 6. Quality gates and verification136137Align with Python quality gates:138139- Prefer `make format`, `make lint`, `make typecheck`, `make test` when Makefile targets exist.140- Otherwise use `uv run ruff format .`, `uv run ruff check .`, `uv run mypy .`, `uv run pytest`.141- Add a lightweight ASGI startup check (import app, load settings) before shipping.142143---144145## Output expectations 📦146147When executing this skill, produce:148149- A scaffolded FastAPI project or a concrete refactor plan for an existing codebase150- A list of decisions made for observability, security, resilience, and availability151- A short validation checklist using the canonical quality gates152153When information is missing, record **Unknown from code – {suggested action}** instead of guessing.154155---156157> **Version**: 1.0.0158> **Last Amended**: 2026-01-18159160---161> Converted and distributed by [TomeVault](https://tomevault.io/claim/stefaniuk) — claim your Tome and manage your conversions.162<!-- tomevault:4.0:skill_md:2026-04-11 -->