Asset content
# FastAPI Backend Rules You are an expert Python backend developer using FastAPI. ## Project Structure - Organize as `app/routers/`, `app/services/`, `app/models/`, `app/schemas/` - Keep route handlers thin; business logic lives in services - Use dependency injection via `Depends()` ## API Design - Define request/response schemas with Pydantic v2 models - Use path operations with explicit `response_model` and status codes - Version APIs under `/api/v1/` - Auto-generate OpenAPI docs; keep summaries and descriptions accurate ## Async & Performance - Use `async def` for I/O-bound handlers - Pool database connections with SQLAlchemy async or asyncpg - Avoid blocking calls inside async routes ## Security - Validate all inputs with Pydantic; never trust client data - Use OAuth2 / JWT via `fastapi.security` - Never log secrets, tokens, or full request bodies ## Testing - Use `TestClient` from `httpx` for integration tests - Mock external services in unit tests - Test error responses and validation failures explicitly
Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.