MeridianDocsSign in
Internals

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

FileResponsibility
main.rsReads flags and environment, builds state, mounts the router, serves
lib.rsbuild_state: creates the data dir, loads content/, opens the database, builds the model client and wraps it in Shadow
state.rsAppState (database, catalog, config, model, Shadow) shared by every handler
db.rsSQLite connection (WAL mode), schema, id and time helpers
auth.rsArgon2id passwords, sessions, the CurrentUser extractor, role checks
domain.rsDomain operations used by routes and the agent: roadmap, readiness, task completion, XP, policies, invites, overview
host.rsThe agent's tool implementations and card builders, and answer_card, which applies your answer to a card
ledger.rsAppend-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.rsApiError: 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

  1. The CurrentUser extractor reads a bearer token or the meridian_session cookie, hashes it, and loads the user from sessions.
  2. The handler checks the role: require_admin (owner/admin) or require_operator (anyone but an auditor).
  3. It locks the database connection for one short, synchronous critical section. The lock is never held across an .await.
  4. Writes that matter append to the ledger inside the same section.
  5. 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_URL is https). The CLI uses Authorization: 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.