fastapi-best-practices

FastAPI production-grade best practices and guidelines for building scalable, high-performance web APIs. Covers project structure, async concurrency, Pydantic validation, dependency injection, and database patterns.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "fastapi-best-practices" with this command: npx skills add ahmed6ww/ax-agents/ahmed6ww-ax-agents-fastapi-best-practices

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

PriorityCategoryImpactPrefix
1Async & ConcurrencyCRITICALasync-
2Project StructureHIGHstructure-
3Pydantic PatternsHIGHpydantic-
4Dependency InjectionMEDIUM-HIGHdependency-
5Database & StorageMEDIUMdb-
6REST & API DesignMEDIUMapi-
7Testing & ToolingLOW-MEDIUMtooling-
8Code MaintenanceLOWmaintenance-
9Performance OptimizationMEDIUMperformance-
10TDD StrategyHIGHtdd-

Quick Reference

1. Async & Concurrency (CRITICAL)

  • async-io-intensive - Use async def for awaitables, def for blocking I/O
  • async-cpu-intensive - Offload CPU work to multiprocessing/Celery
  • async-sync-sdk - Use run_in_threadpool for 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 serialization
  • pydantic-config - Split BaseSettings by domain
  • pydantic-value-error - Raise ValueError for validation errors

4. Dependency Injection (MEDIUM-HIGH)

  • dependency-validation - Use Depends for DB-backed validation
  • dependency-chaining - Chain dependencies for reuse
  • dependency-decoupling - Decouple into small reusable units
  • dependency-async - Prefer async dependencies

5. Database & Storage (MEDIUM)

  • db-naming-conventions - Strict naming (snake_case, singular, etc.)
  • db-index-naming - Explicit index naming conventions
  • db-sql-first - Prefer SQL for complex data logic
  • db-migrations - Static, descriptive, reversible migrations

6. REST & API Design (MEDIUM)

  • api-path-naming - Consistent path vars for dependency reuse
  • api-response-serialization - Minimize serialization overhead
  • api-docs-hiding - Hide docs in production
  • api-docs-customization - Detailed OpenAPI metadata

7. Testing & Tooling (LOW-MEDIUM)

  • tooling-test-client - Use AsyncClient/httpx for tests
  • tooling-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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

nextjs-structure

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

code-cleaner

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

enterprise-code-architect

No summary provided by upstream source.

Repository SourceNeeds Review
General

fastapi-best-practices

No summary provided by upstream source.

Repository SourceNeeds Review