fastapi-patterns
FastAPI best practices covering project structure, Pydantic v2 schemas, dependency injection, async handlers, authentication, authorization, transactional service layers, and testing with httpx and pytest. Use when building or reviewing FastAPI apps — Pydantic schemas, dependencies, async handlers, auth, or tests.
Target: Software development & testing. Automatically collected · unverified.
Excerpt from the author’s documentation
Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.
Read the original English text
Topics in the source
- FastAPI Patterns
- Project Structure
- App Factory and Lifespan
- Configuration with pydantic-settings
- Pydantic Schemas (v2)
- Dependency Injection
- Router and Endpoint Design
- Service Layer
Modern, production-grade FastAPI development: project layout, Pydantic v2 schemas, dependency injection, async patterns, auth, transactional service methods, and testing. -- -- -- -- -- -- Note on Database Design: Application-level unique handling requires an underlying unique database index (e.g., unique=True on your SQLAlchemy mapping attributes). Without underlying constraints, application layer error-catching cannot safely prevent concurrent race conditions. -- -- -- Always declare a typed responsemodel to prevent accidental PII/data leaks and output clean OpenAPI schemas. Consolidate standard middleware dependency injections via type-aliasing: DbDep = Annotated[AsyncSession, Depends(getdb)]. Wrap database mutation boundaries gracefully within transactions inside your service layer, catching structural database errors directly. Parse JWT parameters defensively, expecting potential string/integer cast mismatches from modern payload variations. Enforce deterministic sorting (e.g., .orderby(Model.id)) on all offset/limit paginated endpoints to avoid data skips. Isolate authorization checks from core authentication dependencies to provide precise REST status signals (401 vs 403).
- Source repository
- affaan-m/ECC
- Source file
- pi/core/skills/fastapi-patterns/SKILL.md
- Fixed revision
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Sources and evidence
This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.
Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T15:01:43.001Z.
Categories are inferred from names, descriptions and paths. They do not establish compatibility.
License and attribution
MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.
Original license ↗Synchronization, copying and user-reported success do not mark a resource as runtime-tested.
Limitations and notes
- Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.