Backend
The Rust server — modules, request lifecycle, authentication, storage and the HTTP surface.
The backend is one binary, meridian-server, built from backend/server on top of three library crates. It's an axum app on Tokio with an embedded SQLite database.
Modules
| File | Responsibility |
|---|---|
main.rs | Reads flags and environment, builds state, mounts the router, serves |
lib.rs | build_state: creates the data dir, loads content/, opens the database, builds the model client and wraps it in Shadow |
state.rs | AppState (database, catalog, config, model, Shadow) shared by every handler |
db.rs | SQLite connection (WAL mode), schema, id and time helpers |
auth.rs | Argon2id passwords, sessions, the CurrentUser extractor, role checks |
domain.rs | Domain operations used by routes and the agent: roadmap, readiness, task completion, XP, policies, invites, overview |
host.rs | The agent's tool implementations and card builders, and answer_card, which applies your answer to a card |
ledger.rs | Append-only, hash-chained activity log and its verifier |
integrations/ | GitHub/GitLab clients (scm.rs), the background repository scan and how its findings fill the inventory, profile and evidence (scan.rs), token encryption (secrets.rs), the public homepage reader (website.rs) |
error.rs | ApiError: one place mapping errors to HTTP status codes and JSON |
routes/* | Thin HTTP handlers grouped by area |
Routes stay thin: they parse input, check the role, call domain and return JSON. Business rules live in domain.rs (stateful) and meridian-core (pure), so the agent and the API share exactly the same behaviour.
A request
- The
CurrentUserextractor reads a bearer token or themeridian_sessioncookie, hashes it, and loads the user fromsessions. - The handler checks the role:
require_admin(owner/admin) orrequire_operator(anyone but an auditor). - It locks the database connection for one short, synchronous critical section. The lock is never held across an
.await. - Writes that matter append to the ledger inside the same section.
- Errors become
{"error": "…"}with the right status code. Internal errors are logged and return a generic message.
Streaming chat
POST /api/threads/:id/messages returns Server-Sent Events. The handler does all synchronous work first: it applies any card answer, stores your message and builds the history. Then it spawns the agent turn and forwards events (delta, tool, card) as they happen. It ends with done, which carries the persisted message. See Agent internals.
Authentication & sessions
- Passwords are hashed with Argon2id. Sessions are 256-bit random tokens; only their SHA-256 is stored, and they expire after 30 days.
- The browser gets an HTTP-only, SameSite=Lax cookie (Secure when
MERIDIAN_PUBLIC_URLis https). The CLI usesAuthorization: Bearer. - The first signup creates the workspace and its owner; after that, signup is closed and people join by invitation.
Storage
One SQLite file in WAL mode, plus files on disk for evidence and logos. The schema is created idempotently on start. See Data model.
HTTP surface
Every endpoint, request and response is in the API reference. The frontend and the CLI use the same API.
