FastAPI + uv Architect Skill
When to use
Use this skill when the user asks to:
- •Create a new FastAPI service with best practices (uv + src/ layout + Dockerfile).
- •Refactor an existing FastAPI codebase into a clean, versioned API layout.
- •Enforce consistent conventions: settings via pydantic-settings, structured logging, thin endpoints, and external client singletons (only when required).
Non-goals
- •Do not invent domain/business logic.
- •Do not add heavy abstractions or excessive comments.
- •Do not introduce new frameworks unless required.
Core standards (must follow)
- •Project uses uv and defines
pyproject.toml. - •Code lives under
src/and is importable (Docker usesPYTHONPATH=/app/src). - •API versioning is explicit in
src/main.py:- •
app.include_router(<project_relevant>_router, prefix="/v1", tags=["<project_relevant>"]) - •optionally
/v2as well.
- •
- •External clients go in
src/services/clients/ONLY when the project needs them (HTTP APIs, DB, Redis, etc.). - •When external clients exist,
src/services/clients/*must use a singleton pattern. - •Utilities (small helpers) go in
src/utils/. - •Comments are only the essentials and in English.
- •After any major change, always run
uv run task lint_fixas the final step.
Workflow
A) If the user does NOT have a project yet (scaffold)
- •Scaffold without clients (default):
- •
uv run python {baseDir}/scripts/scaffold_fastapi_uv.py --project-dir <path> --service-name <name> --app-title "<title>"
- •
- •If the project requires an HTTP client (external APIs), scaffold with clients:
- •
uv run python {baseDir}/scripts/scaffold_fastapi_uv.py --project-dir <path> --service-name <name> --app-title "<title>" --with-http-client
- •
- •Then in the new project directory:
- •
uv sync - •
uv run task lint_fix - •
uv run task test
- •
- •Run locally:
- •
uv run uvicorn main:app --host 0.0.0.0 --port 8000 --app-dir src
- •
- •If any major changes are applied during setup, run:
- •
uv run task lint_fix(final step)
- •
B) If the user ALREADY has a project (audit + plan + refactor)
- •Run:
- •
uv run python {baseDir}/scripts/audit_fastapi_project.py --project-dir <path>
- •
- •Produce an objective, numbered plan:
- •What to move/rename
- •What to add/remove
- •What to fix (imports, routers, settings, tests)
- •External clients section is included only if clients are actually used
- •Apply changes incrementally:
- •Keep diffs small
- •Update imports
- •Ensure
/v1routing works with a project-relevant router alias and tags
- •Finish with quality gates:
- •
uv run task lint_fix(required final step after major changes) - •
uv run task test
- •
Singleton clients (only when needed)
- •Implement singleton clients in
src/services/clients/*. - •Prefer an
@lru_cachefactory to guarantee one instance per process. - •Close clients on shutdown using FastAPI
lifespan.
Deliverables checklist
- •
pyproject.tomlwith minimal runtime deps + dev tooling. - •
src/main.pywith/v1(and optionally/v2) routing using a project-relevant router alias and tags. - •
src/core/config.pyusingpydantic-settings. - •
src/core/log_config.py+src/core/logger_func.py. - •
src/api/deps.pyfor shared dependencies. - •
tests/with a basic health test (andconftest.pyto ensuresrc/is importable). - •Dockerfile using uv.
- •
src/services/clients/only if required by the project.
Notes
- •Use
fastapi[standard]unless the user explicitly requests otherwise. - •Prefer FastAPI
lifespanto manage startup/shutdown resources.