PromptArchPromptArch.ai
FastAPI

CLAUDE.md for FastAPI

Nota: A

A CLAUDE.md encoding the async-everywhere rule, layering direction, and the Alembic autogenerate review habit.

# CLAUDE.md - Atlas API (FastAPI)

## Commands
```bash
uv run uvicorn app.main:app --reload             # dev on :8000
uv run pytest -x                                 # stop at first failure
uv run pytest tests/test_orders.py::test_create  # single test
uv run ruff check . && uv run mypy app           # lint + types, both gate CI
uv run alembic revision --autogenerate -m "msg"  # new migration - review the diff
```

## Architecture
- Layering: `app/api` (routers) → `app/services` (logic + DB) → `app/models`.
  Routers stay thin; services own transactions; models never import upward.
- Pydantic schemas in `app/schemas/` are the API contract - ORM models never
  cross the HTTP boundary.
- Auth: `CurrentUser` dependency from `app/core/security.py`; use it, don't
  parse Authorization headers in routers.

## Conventions
- Everything async: `async def`, `AsyncSession`, `httpx` for outbound calls.
  Blocking IO in a handler will pass locally and stall under load.
- New endpoints follow `app/api/orders.py` as the reference implementation.
- Service functions take the session as their first argument; they never create it.

## Workflow
- Schema change: edit the model, autogenerate a revision, then hand-check the
  migration for missed server defaults before applying.
- Failing CI on mypy usually means a missing return type on a service function.

## Do not
- Do not return ORM objects from routes; map to a schema.
- Do not add module-level singletons; use dependencies so tests can override them.
- Do not write raw SQL in services when the ORM expresses it; if raw SQL is
  unavoidable, put it in the model layer with a comment naming the reason.

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