Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

Midden is a single Rust binary with focused modules around configuration, state, storage, database access, processing, web routing, jobs, metrics, and mail.

Entry Point

src/main.rs defines the CLI:

  • serve
  • migrate
  • config check
  • config print-defaults
  • owner create
  • owner reset-password
  • storage gc
  • storage verify
  • storage export
  • storage import
  • jobs run-once
  • user set-role

serve builds AppState, runs migrations, starts background jobs, builds the router, and listens with graceful shutdown.

App State

src/app.rs builds shared state:

  • Parsed AppConfig.
  • Database.
  • BlobStorage.
  • Built-in or disk templates.
  • Mailer.
  • Metrics registry.
  • Rate limiter.
  • Upload quota lock.

Handlers call state.settings().await to load runtime settings merged from config and the database.

Web Layer

src/web.rs owns router registration and cross-cutting middleware. Handler modules live under src/web/:

  • auth.rs
  • account.rs
  • files.rs
  • pastes.rs
  • items.rs
  • browse.rs
  • admin.rs
  • api.rs
  • system.rs
  • upload.rs
  • oidc.rs
  • support.rs

Keep route registration centralized unless there is a clear reason to split it further. The /{slug} file route is a catch-all and must remain after more specific routes.

Persistence

src/db.rs and src/db/ contain schema, models, auth, item, moderation, search, and settings methods. The schema string creates tables for settings, users, sessions, API tokens, auth flows, blobs, files, pastes, revisions, reports, scanner results, audit events, rate-limit buckets, and moderation notes.