Skip to main content

Backend overview

FastAPI on Python 3.12+, SQLModel for models, Alembic for migrations, psycopg 3 as the Postgres driver.

apps/backend/
├── app/
│ ├── main.py FastAPI app, CORS, /health
│ ├── trips.py GET /trips, GET /trips/{id}
│ ├── core/config.py Settings (env vars, checked at startup)
│ ├── db/session.py Engine + get_session dependency
│ └── models/ One file per domain; __init__ exports every table
├── migrations/ Alembic env + versions/
├── scripts/seed.py Sample data for local dev
├── db/init/ Runs once when the Postgres volume is created (roles)
├── tests/ pytest, against the local database
├── requirements.txt Runtime deps
└── requirements-dev.txt + test deps

Settings​

app/core/config.py reads environment variables (and apps/backend/.env) with pydantic-settings. Secrets are wrapped in SecretStr so they don't leak into logs or tracebacks. A missing variable stops the app at startup rather than failing later.

VariablePurpose
ENVdevelopment, staging or production
DATABASE_URLWhat the API connects as (vesper_app role)
MIGRATOR_DATABASE_URLWhat Alembic connects as (vesper_migrator role)

Add every new variable to .env.example in the same PR.

Endpoints​

EndpointReturns
GET /tripsEvery trip, as the frontend's Trip type (no auth yet)
GET /trips/{id}One trip, or 404
GET /healthDatabase status

Responses use camelCase keys to match the frontend's TypeScript types. See Database for the field mapping.

Health check​

GET /health runs SELECT 1. It returns 200 {"status": "ok", "database": "ok"}, or 503 if Postgres is unreachable. Deploy tooling and uptime checks will use it.

Tests​

.\vesper test runs pytest against the local Postgres. The session fixture wraps each test in a transaction that is rolled back, so tests never leave data behind and can run against a seeded database. Use it for anything that touches the DB:

def test_something(session: Session) -> None:
session.add(...)
session.flush() # hits the DB and its constraints; rolled back afterwards

Planned structure​

As endpoints arrive, each domain gets domains/<name>/router.py (parse the request, call the service) and service.py (business logic and authorization). The planned AI agent's tools call the same services, so they inherit the same validation and per-trip permissions.