← ClaudeAtlas

pattern-engineer-fastapilisted

FastAPI bullets — wire what the contract already decided. `APIRouter` with explicit prefix; `Depends()` injection; Pydantic at the boundary only; app-level exception handlers mapping to the contracted envelope; `RequestIdMiddleware` registered last; named path constants shared by route + tests; `Depends`-based auth guards; async-by-default; lifespan for startup/shutdown; `dependency_overrides` + per-test factory in tests. Activate on FastAPI routes, deps, middleware, handlers, wiring.
MartinKChen/harness-claude-code · ★ 0 · API & Backend · score 72
Install: claude install-skill MartinKChen/harness-claude-code
# pattern-engineer-fastapi FastAPI implementation patterns for routes, dependencies, middleware, exception handlers, and app wiring. The api contract (`docs/api-contract/<entity>.yaml`) decides path / verb / status / shape — this skill is HOW you wire them in FastAPI without contradicting the contract. ## When to activate Activate when editing FastAPI route handlers (`@router.get` / `@router.post` / …), `APIRouter` mounts, `Depends()` graphs, Pydantic request/response models, middleware (`app.add_middleware(...)`), exception handlers (`@app.exception_handler(...)`), `create_app()` / `main.py` wiring, OpenAPI customization, or `Depends`-based dependency injection. Skip for non-FastAPI Python code. ## Project memory overlay After loading this skill, also check `$MAIN_ROOT/.claude/memory/patterns/pattern-engineer-fastapi.md` in the consuming project (resolve `MAIN_ROOT="$(dirname "$(git rev-parse --path-format=absolute --git-common-dir)")"`). If present, load it as an **additive overlay** to the rules below; if absent, skip silently. See `memory-convention` for the full contract (additivity, severity floor, conflict surfacing). ## Patterns ### Routes + routers - Mount each router with the contracted prefix: `app.include_router(users_router, prefix="/api/v1/users", tags=["users"])`. Prefix matches the api contract verbatim. - Path inside the router is sourced from a module-level constant when shared with tests: `USERS_PATH = "/api/v1/users"`; both `@router.post(USERS_PATH