mir-backend-python-fastapilisted
Install: claude install-skill anantbhandarkar/make-it-right
# /mir-backend-python-fastapi · Make It Right (FastAPI)
Bottom tier of the chain: `mir-backend` (generic gates) → `mir-backend-python` (CPython runtime model) → **this** (FastAPI/Starlette/SQLAlchemy library mechanics). Run the gates first; load the Python runtime tier for the concurrency/process model; reach for *this* at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. **Runtime-level concerns (GIL, async-vs-sync, blocking the event loop, fork-safe pools, cold start) live in `mir-backend-python` — not here.**
**Stack assumed**, versions verified 13 Aug 2026: FastAPI **0.141.x** (requires Python ≥3.10) · Starlette **1.6.x** · Pydantic **2.13.x** (there is no Pydantic v3) · SQLAlchemy **2.0.52** async (`AsyncSession`, `asyncpg` or `psycopg` 3) · PostgreSQL · Alembic **1.19.1** (requires Python ≥3.10) · Redis · Uvicorn **0.52.x**. SQLAlchemy **2.1 is still in beta** (2.1.0b3, June 2026) — 2.0.x is the production line; don't put a beta in a Gate 5 design without saying so. If the project uses sync SQLAlchemy or a different DB, note the divergence before applying these.
## The FastAPI footguns AI walks into most
These are the stack-specific cousins of the failure-mode catalog. Each is something async-FastAPI code gets wrong even when the *logic* is right.
### 1. Async session lifecycle — the #1 source of mystery bugs
- **One `AsyncSession` per request, via a `Depends` dependency.** Never a module-level/global session — it's not concurrency-safe and you