fastapi-best-practices
SKILL.md
FastAPI Best Practices
Comprehensive production-grade best practices for FastAPI applications. Contains rules across 7 categories to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Setting up a new FastAPI project structure
- Implementing async routes and handling blocking I/O
- Designing Pydantic models and validation logic
- Structuring dependencies for reusable validation and injection
- Integrating databases with SQLAlchemy and Alembic
- Writing tests and configuring CI/CD tooling
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Async & Concurrency | CRITICAL | async- |
| 2 | Project Structure | HIGH | structure- |
| 3 | Pydantic Patterns | HIGH | pydantic- |
| 4 | Dependency Injection | MEDIUM-HIGH | dependency- |
| 5 | Database & Storage | MEDIUM | db- |
| 6 | REST & API Design | MEDIUM | api- |
| 7 | Testing & Tooling | LOW-MEDIUM | tooling- |
| 8 | Code Maintenance | LOW | maintenance- |
| 9 | Performance Optimization | MEDIUM | performance- |
| 10 | TDD Strategy | HIGH | tdd- |
Quick Reference
1. Async & Concurrency (CRITICAL)
async-io-intensive- Useasync deffor awaitables,deffor blocking I/Oasync-cpu-intensive- Offload CPU work to multiprocessing/Celeryasync-sync-sdk- Userun_in_threadpoolfor sync SDKs in async routes
2. Project Structure (HIGH)
structure-domain-driven- Organize by domain (src/{domain}), not file type
3. Pydantic Patterns (HIGH)
pydantic-validation- Use built-in regex, enums, etc.pydantic-custom-base- Use custom base model for global serializationpydantic-config- Split BaseSettings by domainpydantic-value-error- Raise ValueError for validation errors
4. Dependency Injection (MEDIUM-HIGH)
dependency-validation- Use Depends for DB-backed validationdependency-chaining- Chain dependencies for reusedependency-decoupling- Decouple into small reusable unitsdependency-async- Prefer async dependencies
5. Database & Storage (MEDIUM)
db-naming-conventions- Strict naming (snake_case, singular, etc.)db-index-naming- Explicit index naming conventionsdb-sql-first- Prefer SQL for complex data logicdb-migrations- Static, descriptive, reversible migrations
6. REST & API Design (MEDIUM)
api-path-naming- Consistent path vars for dependency reuseapi-response-serialization- Minimize serialization overheadapi-docs-hiding- Hide docs in productionapi-docs-customization- Detailed OpenAPI metadata
7. Testing & Tooling (LOW-MEDIUM)
tooling-test-client- Use AsyncClient/httpx for teststooling-linter- Use Ruff for all linting
8. New Capabilities (Merged)
- Scripts: Helper scripts available in
scripts/(e.g.,run_ruff.py). - References: Additional guides in
references/(e.g.,quad_strategy.md). - TDD: Explicit testing strategies in
rules/tdd-strategy.md.
How to Use
Read individual rule files for detailed explanations and code examples:
rules/async-io-intensive.md
rules/structure-domain-driven.md
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
Weekly Installs
13
Repository
ahmed6ww/ax-agentsGitHub Stars
1
First Seen
Jan 27, 2026
Security Audits
Installed on
opencode12
github-copilot12
codex12
gemini-cli12
amp11
kimi-cli11