fastapi-patternslisted
Install: claude install-skill jjackkun/claude-harness-hermes
# FastAPI Patterns
Production FastAPI patterns with Pydantic v2 and async-first design.
## When to Activate
- Designing or editing FastAPI routes / routers
- Writing Pydantic models (request/response, validation)
- Dependency injection, background tasks, middleware
- Async database sessions, transaction scoping
- Error handling, exception handlers, status codes
- OpenAPI schema customization
## Project Layout
```
backend/
├── app/
│ ├── main.py # FastAPI() + router mounting
│ ├── config.py # Settings (pydantic-settings)
│ ├── deps.py # Shared Depends() — DB session, current_user
│ ├── api/
│ │ ├── users/
│ │ │ ├── router.py # APIRouter
│ │ │ ├── schemas.py # Pydantic models
│ │ │ └── service.py # Business logic (pure funcs, takes session)
│ │ └── ...
│ ├── db/
│ │ ├── base.py # engine, session factory
│ │ └── models.py # SQLAlchemy ORM
│ └── core/
│ ├── security.py # JWT, password hashing
│ └── errors.py # AppException hierarchy
└── tests/
```
Router per feature. Service layer takes an `AsyncSession` explicitly — no hidden globals.
## Pydantic v2 Schemas
```python
from pydantic import BaseModel, Field, EmailStr, ConfigDict
from datetime import datetime
class UserCreate(BaseModel):
model_config = ConfigDict(str_strip_whitespace=True)
email: EmailStr
name: str = Field(min_length=1, max_length=100)
password: str = Field(min_l