FastAPI
AGENTS.md for FastAPI + async SQLAlchemy
Nota: AAn AGENTS.md for a typed, fully-async FastAPI service: uv commands, router/service/model layering, and migration review rules.
# Atlas API (FastAPI) ## Project Overview FastAPI service on Python 3.12: Pydantic v2, async SQLAlchemy 2.0 + Postgres, Alembic migrations, uv for dependency management. OpenAPI docs served at /docs. ## Setup & Commands ```bash uv sync # install from uv.lock uv run uvicorn app.main:app --reload # dev server on :8000 uv run pytest # test suite uv run pytest tests/test_orders.py::test_create # single test uv run ruff check . && uv run ruff format --check . uv run mypy app # strict mode, gates CI uv run alembic upgrade head # apply migrations ``` ## Structure - `app/api/` - routers, one module per resource; thin, no business logic - `app/services/` - business logic; the only layer that opens a DB session - `app/models/` - SQLAlchemy models; `app/schemas/` - Pydantic request/response - `tests/` - mirrors `app/`; shared fixtures in `tests/conftest.py` ## Code Style - Type hints everywhere; mypy strict is a CI gate. - Request/response bodies are Pydantic schemas - never return ORM models directly. - Wire dependencies with `Depends()` (db session, auth, pagination); no module-level state. - Async end to end: `async def` routes, `AsyncSession`, no blocking IO in handlers. ## Testing - Tests drive the app through `httpx.AsyncClient` against a transactional test DB. - Every new endpoint covers: happy path, validation failure (422), auth failure (401). - Review autogenerated Alembic revisions by hand - autogenerate misses server defaults and enum renames. ## Security - Auth is JWT bearer via `app/core/security.py`; routers opt in with the `CurrentUser` dependency, never by parsing headers inline. - Settings come from the environment through `app/core/config.py`; no secrets in git. ## Boundaries - Dependency direction is one-way: `app.models` never imports `app.services`. - Routers don't touch the DB; go through a service function. - Never downgrade migrations in shared environments; roll forward.
Estes exemplos são publicados sob CC0. Use livremente, sem atribuição. São fornecidos como estão, sem garantia de qualquer tipo: revise e adapte ao seu projeto antes de usar, pois você é responsável pelo resultado de aplicá-los.
Leve o PromptArch para sua equipe
Implemente o PromptArch como ferramenta interna em todas as áreas da sua empresa. Obtenha contas de equipe com créditos pré-carregados compartilhados e domínios personalizados para sua organização.
Fale Conosco