<One sentence: what this API does.>
Stack
- Python <3.12+>, FastAPI, Pydantic v2
- DB: <PostgreSQL + SQLAlchemy 2.x (async) + Alembic>
- Package manager:
(`uv.lock` is the source of truth) - Tests: pytest (+ httpx
AsyncClientfor API tests)
Commands
- Install:
uv sync - Run:
uv run fastapi dev app/main.py(oruv run uvicorn app.main:app --reload) - Tests:
uv run pytest -q(one test:uv run pytest tests/test_users.py::test_create_user -q) - Lint + format:
uv run ruff check --fix . && uv run ruff format . - Types:
uv run mypy app - New migration:
uv run alembic revision --autogenerate -m "<message>"then review the generated file; apply withuv run alembic upgrade head
Layout
app/api/routers (thin),app/services/business logic,app/models/SQLAlchemy models,app/schemas/Pydantic models,app/core/config and securitytests/with fixtures inconftest.py(test DB per session, transaction rollback per test)
Rules
- Request and response bodies are Pydantic schemas; never return ORM objects directly.
- Use dependency injection (
Depends) for DB sessions, current user and settings. - Do not block the event loop in async endpoints: no sync DB drivers,
requestsortime.sleepinasync def. Use async libraries or run blocking work in a threadpool. - Settings via
pydantic-settings; secrets only from the environment. - Always review autogenerated Alembic migrations: autogenerate misses some changes (for example renames show up as drop + add).
- Every endpoint: auth dependency, input validation, tests for 2xx, 4xx and permission failures.
Definition of done
ruff, type checks andpytestpass; migrations reviewed; OpenAPI docs (/docs) render the new endpoints correctly.