04 — Crate-by-Crate Tour
This is your map of the Rust source. For each crate you will find:
- One-sentence purpose
- Key modules / entry points
- Who depends on it
- Rough size / complexity
Binary & Top-Level Orchestration
`chatmail` (main crate; builds the `madmail` binary)
Purpose: Process entry point, lifecycle, CLI, server supervision, boot, upgrade.
Key pieces:
main.rs— tiny dispatcher toboot::runorctl::dispatchboot.rs—initialize_state,run, hydrationsupervisor.rs—ServerSupervisor(the heart of the running server)servers.rs— listener wiring + HTTP router merging (admin + admin-web + www)ctl/— huge directory with ~25 submodules for every CLI command (accounts,blocklist,install,reload,tasks,federation, etc.)turn_boot.rs,iroh_boot.rs,ss_boot.rs— sidecar supervisorslogging.rs— tracing setup + No-Log support
Depends on: almost everything.
Who depends on it: only integration tests and the binary itself.
Core Infrastructure Crates
`chatmail-types`
Shared ChatmailError enum + domain helpers (domain_forms, validate_login_domain, etc.).
Tiny, foundational. Everything else depends on it.
`chatmail-config`
Purpose: All configuration parsing and effective value computation.
cli.rs— clap definition (global flags + many subcommands)parse.rs,maddy.rs,madmail_parse.rs— TOML + legacy maddy.conf AST parserinstall_cli.rs—madmail install --simple --ip ...client_mail.rs— dclogin links, effective listener addresses per servicecredential_policy.rs,data_size.rs,queue.rs, etc.db_path.rs— where the app DB and credentials DB live
Heavily used at boot and in ctl commands. The "effective_*" functions are the public API surface for "what port should I listen on?"
`chatmail-db`
Purpose: SQLx pool + all persistence for structured data (not mail bodies).
Modules:
pool.rs,schema.rs,migrations/settings.rs+settings_keys.rs— the dynamic config heartpasswords.rs,blocklist.rs,registration_tokens.rsquota_defaults.rs,account_info.rsfederation_policy.rs,endpoint_cache.rsmessage_stats.rs,maintenance.rs(dormant accounts),message_retention.rsinbound.rs— recipient validation helpers
Critical tables (from migrations): settings, passwords, quotas, blocked_users, registration_tokens, federation_stats, dns_overrides.
Also has Postgres migrations (for future or alternate deploys).
`chatmail-state`
Purpose: In-memory hot path state (the thing that must be fast).
AppStatestruct +hydratequota.rs(QuotaCache)policy.rs(FederationPolicyCache)tracker.rs(FederationTracker)flusher.rs— background task that persists statsevents.rs(EventBus for IDLE)silent_dismiss.rs,message_size.rs,listener_ports.rs
Almost every delivery path touches this crate under lock.
`chatmail-storage`
Purpose: Maildir abstraction + blob helpers + purge.
maildir.rs,maildir_message.rs— folder layout, flag parsing, expunge, move/copyblob.rs—write_blob,read_blob,deliver_local_messagesinbox.rs— listingpurge.rs— retention / cleanup jobs
Messages live under <state_dir>/mail/<user>/Maildir/ (with folders/DeltaChat/Maildir for the Delta Chat folder).
`chatmail-auth`
Purpose: Authentication + JIT registration.
jit.rs—authenticate(the main entry)hash.rs— password hashing/verification (importable hashes too)normalize.rs— PRECIS / unicode handlingvalidate.rs— localpart + password policy
Called from SMTP AUTH, IMAP LOGIN, and /new.
`chatmail-pgp`
Purpose: The encryption enforcement gate.
Single important function: enforce_encryption(raw: &[u8], opts).
Accepts:
multipart/encryptedwithapplication/pgp-encrypted- Certain
multipart/mixedSecure-Join handshakes (vc-request,vg-request) - Mailer-daemon
multipart/reportbounces
Rejects everything else. Used on SMTP DATA, IMAP APPEND, and /mxdeliv.
Protocol Server Crates
`chatmail-smtp`
Custom async SMTP (no external crate for the protocol loop).
server.rs— listenersession.rs— per-connection state machine (EHLO, AUTH, MAIL, RCPT, DATA)protocol.rs— low-level parsingdata_limit.rs
Two session configs: one for inbound port 25 (no auth required), one for submission (auth required).
`chatmail-imap`
Custom async IMAP.
server.rssession.rs— command dispatchconnection_stats.rs
Supports IDLE (push), METADATA (for TURN/Iroh discovery), QUOTA, CONDSTORE-ish bits, MOVE, etc.
`chatmail-fed`
HTTP server surface for federation.
server.rs— axum listenermxdeliv.rs— the POST handler (PGP gate + policy + storage)security.rs
`chatmail-delivery`
Outbound delivery engine.
queue/— persistent retry queue (store, worker, config)router.rs— decide HTTPS / HTTP / SMTP pathtransport.rs— the actual sendersfederation_http.rs
Started once at boot; workers pick up work from the queue.
Web & Admin Surface Crates
`chatmail-www`
Public-facing HTTP surface (the one normal users and Delta Chat clients hit).
Routes (see router.rs):
POST /new— registrationGET/POST /share— contact sharing/webimap/*+ WebSocket — browser-friendly IMAP subset/websmtp/send/docs/*(multi-language)/madmail— binary download/inv/*— invites- Static assets + catch-all
Also contains www-src/ (source) and www/ (built) for the classic web UI.
`chatmail-admin`
JSON-RPC style admin API (POST /api/admin or configurable path).
router.rs,handler.rsresources/— one module per domain (accounts, blocklist, federation, quota, settings, tokens, toggles, queue, dns, etc.)
All operations go through a single endpoint + Bearer token. Returns HTTP 200 with { "ok": ..., "error": ... } shape.
`chatmail-admin-web`
Serves the SvelteKit admin SPA.
build.rs— copies pre-built SPA fromexternal/madmail-admin-web/build(or env var) intoembed/at compile timeserve.rs— axum handler that serves the embedded assets + index.htmlassets.rs,patch.rs
When the SPA is not embedded, it serves a friendly placeholder.
The SPA itself lives in the external/ git submodule (Svelte + TS + Tailwind).
Sidecar / Optional Service Crates
`chatmail-turn`
In-process TURN/STUN server (based on webrtc-rs / turn-rs work in context/).
runner.rs,credentials.rsallocate_client.rs- Discovery info for IMAP METADATA
`chatmail-iroh`
Supervises an iroh-relay process (downloaded or built separately).
runner.rsdiscovery.rs
`chatmail-shadowsocks`
Optional port camouflage / proxy.
`chatmail-tasks`
Background maintenance scheduler.
scheduler.rs,jobs.rs- Retention, dormant account removal, etc.
`chatmail-metrics`
Prometheus/OpenMetrics exporter.
`chatmail-acme`
Let's Encrypt HTTP-01 + IP certificate issuance, self-signed fallback.
Used during madmail install --auto-ip-cert.
`chatmail-tls`
Tiny: load_server_config (rustls from PEM paths).
Test / Integration Crate
`tests` (workspace member `chatmail-integration`)
E2E tests that spin up real servers and talk SMTP/IMAP, do SecureJoin, exercise TURN, run the ctl binary, check OpenMetrics, etc.
Uses support helpers in tests/support/.
Dependency Rules of Thumb
- Low-level crates (
chatmail-types,chatmail-config,chatmail-db) have almost no async or protocol logic. chatmail-stateis the only place that should hold cross-cutting in-memory caches.- Protocol crates (
smtp,imap,fed) should not know about the admin API or web UI. - Anything that touches disk for mail belongs in or under
chatmail-storage. - CLI commands in
chatmail/ctl/are allowed to reach into many crates (they are operator tools).
How to Decide Where New Code Goes
- New protocol verb or extension → the relevant server crate (
smtp/imap). - New admin resource →
chatmail-admin/resources/. - New background job →
chatmail-tasks. - New hot-path cache →
chatmail-state. - New storage format or Maildir helper →
chatmail-storage. - New config knob →
chatmail-config+chatmail-dbsettings.
Next Steps
- See the runtime wiring in more detail: 05-boot-sequence-and-state.md
- See exact data flows for mail and federation in later docs.
- For deep protocol or security rationale, go to the matching
docs/TDD/NN-*.mdfile.
This crate map + the architecture diagram will let you answer "where does X live?" in seconds.