← ClaudeAtlas

python-fastapi-stacklisted

FastAPI conventions for REST APIs: routers, Pydantic v2 schemas, dependency injection, error handling, pagination, and project structure. Trigger: When writing any router, endpoint, schema, or dependency in a FastAPI project.
lgzarturo/codeconductor · ★ 0 · API & Backend · score 76
Install: claude install-skill lgzarturo/codeconductor
## When to Use - Writing any new endpoint, router, or schema - Designing the structure of a new FastAPI feature - Adding error handling or validation - Implementing pagination or filtering - Configuring dependencies (DB session, auth, settings) ## Project Structure ``` src/ ├── main.py # App factory, lifespan, router inclusion ├── config.py # Settings via pydantic-settings ├── dependencies.py # Shared Depends() functions (db, auth) ├── routers/ │ ├── __init__.py │ ├── products.py │ └── orders.py ├── schemas/ │ ├── __init__.py │ ├── product.py # ProductCreate, ProductRead, ProductUpdate │ └── order.py ├── models/ # SQLAlchemy models (see sqlalchemy skill) │ ├── __init__.py │ └── product.py ├── services/ # Business logic — never in routers │ └── product.py └── tests/ ├── conftest.py └── test_products.py ``` **Rule**: Routers delegate to services. Services contain all business logic. Never write business logic directly in an endpoint function. ## Application Factory ```python # main.py from contextlib import asynccontextmanager from fastapi import FastAPI from src.routers import products, orders from src.config import settings @asynccontextmanager async def lifespan(app: FastAPI): # startup yield # shutdown def create_app() -> FastAPI: app = FastAPI( title=settings.app_name, version=settings.app_version, lifespan=lifespan, ) app.include_r