What problem does it solve?
Concrete, copy-adaptable recipes for FastAPI services with Pydantic v2 and SQLAlchemy 2.0. The conventional guidelines in rules/fastapi.md establish the baseline; this skill adds deeper, idiom-specific patterns for DTOs, repositories, and error handling to speed up design and implementation.
Core Features & Use Cases
- DTOs (Pydantic v2): BaseDTO with ConfigDict, model_config flags for from_attributes, populate_by_name, and whitespace stripping.
- Create / Read / Update split: separate DTOs for create, read, and update semantics with per-field controls and patch semantics.
- Validation and computed fields: field_validator and model_validator usage; @computed_field to derive values at serialization.
- Repository pattern and endpoints wiring: generic BaseRepository with session injection via Depends; example domain-specific repos with eager loading strategies.
- Exception mapping: central AppError hierarchy and a single HTTP exception handler to decouple business logic from HTTP concerns.
Quick Start
Apply these patterns by creating DTOs, wiring a per-request session dependency, implementing a repository layer, and mapping AppError to HTTP responses in your FastAPI app.