Skip to main content

How it works, end to end

This page follows the moving parts in order: what .\vesper does, what a fresh database goes through, and what happens when the app asks for a trip. Each section links to the page that owns the detail.

1. The .\vesper task runner​

  • vesper.cmd is the entry point. In PowerShell, .\vesper finds vesper.cmd because there is no vesper.ps1 in the root. The .cmd file starts PowerShell with -ExecutionPolicy Bypass, so it works on machines where scripts are blocked.
  • scripts/vesper.ps1 does the work. The first argument picks the command, and everything after it is passed through untouched. So .\vesper test -k trips runs pytest -k trips, and .\vesper frontend -c runs expo start -c.
  • Every native command is checked. PowerShell 5.1 doesn't stop when docker, alembic or pytest fail, so the script checks each exit code and stops at the first failure. vesper.cmd passes the exit code on to your terminal.
  • Commands run in the right folder. Backend commands run in apps/backend, so Alembic finds alembic.ini. Expo runs in apps/frontend.

Daily development lists every command.

2. What .\vesper setup builds​

  • Roles are created once. Postgres runs apps/backend/db/init/ only when the data volume is new. If you change that script, run .\vesper db-destroy and then .\vesper setup.
  • The health check runs over TCP on purpose. During first-run init, Postgres listens only on its socket, so a TCP check can't pass until the roles exist.
  • The two roles have different rights. vesper_migrator owns the schema and is the only role that can run DDL. vesper_app can only read and write rows, and a test checks that it can't create tables. See Database → Roles.
  • Setup is safe to rerun. Existing .env files are kept, and a database that already has data isn't reseeded.

3. A request, from screen to row​

Status: proposal

The screens still read the sample data in apps/frontend/src/data/trips.ts. Steps 1 and 6 describe how they'll call the API once it's wired up. Steps 2 to 5 work today: try curl http://localhost:8000/trips.

  1. The app calls GET /trips on the URL in apps/frontend/.env. The right URL depends on where the app runs; see Daily development.
  2. FastAPI opens a database session as vesper_app through the get_session dependency. The session closes when the request ends.
  3. The API loads the trips, then the members of all of them in one query, so the number of queries doesn't grow with the number of trips.
  4. TripOut turns start_date into startDate, and so on, so the JSON matches the frontend's Trip type exactly. A test (test_get_trip_matches_frontend_shape) fails if the shape drifts.
  5. An unknown id returns 404, and an id that isn't a UUID returns 422.
  6. The app renders the same data it renders from the sample file today. The seed data matches that file, so nothing visible changes when the screens switch to the API.

4. Settings and startup​

uvicorn app.main:app reads apps/backend/.env from an absolute path, so it works from any folder. It checks the settings at startup, so a missing DATABASE_URL stops the server immediately instead of failing on the first request. GET /health runs SELECT 1 and returns 200, or 503 if Postgres is unreachable. See Backend overview.

5. Tests​

.\vesper test starts Postgres, applies migrations, then runs pytest. The tests use the real local database, not a mock:

  • The session fixture rolls back. It opens a transaction and rolls it back at the end of each test, so tests can run against your seeded data without changing it.
  • API tests share that session. They point get_session at the test's session, so the API sees the test's rows and the rollback removes them afterwards.
  • Schema tests run against Postgres itself. They check that the end_date >= start_date constraint holds, that vesper_app can't run DDL, and that /health returns 503 when the database is down.

6. Changing things​

You changeAlso doDetails
A model.\vesper makemigration "msg", read the file, .\vesper reset-dbDatabase → Changing the schema
An API responseKeep it matching the frontend type; update the shape testDatabase → How it maps
An env varAdd it to .env.example and the settings tableBackend overview
A .\vesper commandKeep it PowerShell 5.1-compatible; update the command tableDaily development
How or why something worksUpdate the page in the same PR; add an ADR for decisionsWriting docs

How these docs work​

This site is Docusaurus and lives in docs/ as its own npm project (see ADR 0002).

  • Pages are Markdown files in docs/docs/. Each folder is a sidebar section, ordered by its _category_.json, and sidebar_position orders the pages inside it.
  • Diagrams are Mermaid code blocks, so they're reviewed as text in PRs.
  • Broken links fail the build. Use relative .md links; .\vesper docs-build fails on any link that points nowhere.
  • Run it locally with .\vesper docs (http://localhost:3000). The page reloads as you save.
  • AI assistants read these pages. The root CLAUDE.md sends Claude Code here first, so keeping these pages current keeps the AI following the same conventions.