@tank/fastapi-mastery
Installation
SKILL.md
FastAPI Mastery
Core Philosophy
- Type hints are the contract -- FastAPI derives validation, serialization, and OpenAPI docs from type annotations. Invest in precise types and Pydantic models; everything downstream improves.
- Dependencies replace globals -- Use
Depends()for database sessions, settings, auth, and shared logic. Dependencies are composable, testable, and self-documenting. - Async by default, sync when blocking -- Use
async deffor I/O-bound routes (database, HTTP calls). Usedeffor CPU-bound work so FastAPI runs it in a thread pool automatically. - Thin routes, fat services -- Route functions validate input and return output. Business logic belongs in service classes injected via dependencies.
- Test through the API -- Use
TestClientwith dependency overrides. Test behavior, not implementation. Override only what varies between environments.
Quick-Start: Common Problems
"How should I structure my FastAPI project?"
| Project Size | Structure |
|---|---|
| Small (< 10 routes) | Single main.py with inline routes |
| Medium (10-50 routes) | Feature-based: app/{feature}/router.py, service.py, models.py |
| Large (50+ routes) | Layered: routers -> services -> repositories + shared core/ |