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:
servemigrateconfig checkconfig print-defaultsowner createowner reset-passwordstorage gcstorage verifystorage exportstorage importjobs run-onceuser 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.rsaccount.rsfiles.rspastes.rsitems.rsbrowse.rsadmin.rsapi.rssystem.rsupload.rsoidc.rssupport.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.