System Overview & Map
System overview, high-level architecture, principles, and directory map.
mailwart - Technical Documentation
Welcome to the comprehensive technical documentation for mailwart, a modern, cPanel-grade Stalwart Mail Server & Roundcube Webmail management console with an integrated AI Copilot.
mailwart is built with Next.js 16 (App Router), React 19, Tailwind CSS v4, TypeScript, and PostgreSQL, deployed via Docker Compose behind Traefik in Dokploy.
Documentation Structure
This documentation directory is organized into modular guides covering every layer of the system:
| Guide | Title | Description |
|---|---|---|
| Getting Started Guide | Getting Started Guide | Step-by-step setup, local development, domain provisioning, and webmail SSO. |
| System Architecture | System Architecture & Infrastructure | Complete topology, container networking, runtime isolation, data flow lifecycles, and mock vs. live dual runtime engine. |
| Pages, Navigation & UX | Frontend Pages, Navigation & UX | Exhaustive mapping of all 11 UI pages, AppShell chrome, navigation sidebar, modals, wizards, and interactive components. |
| HTTP REST API Reference | HTTP API Endpoints | Specifications for all Next.js API route handlers (/api/auth, /api/copilot, /api/deliverability, /api/diagnostics, /api/webmail/sso, etc.). |
| Server Actions Catalog | Server Actions Catalog | In-depth technical catalog of all 80+ server actions across mail, users, Cloudflare, copilot, deliverability, and auth. |
| Stalwart Mail Server & JMAP | Stalwart Mail Server Integration | JMAP protocol specification, method calls, data normalization, catch-all handling, app passwords, and mock engine. |
| Roundcube Webmail SSO | Roundcube Webmail & SSO | Custom em_sso PHP plugin, HMAC SHA-256 token minting, master impersonation protocol (user%impersonator), and Traefik routing. |
| Cloudflare DNS Automation | Cloudflare DNS Automation | Multi-account token pooling, automated zone discovery, 1-click DNS record provisioning (MX, SPF, DKIM, DMARC), and conflict detection. |
| Deliverability Suite | Email Deliverability Suite | 10-point deliverability audit engine, port & TLS probes, DNSBL blacklist monitoring, SMTP banner & EHLO checks, and mail-tester scoring. |
| AI Copilot & Tool Registry | AI Copilot & Tool Registry | Architecture with Vercel AI SDK, 10 supported LLM providers, 48 registered administrative tools, and human-in-the-loop approval workflows. |
| Database, Security & Deployment | Database, Security & Deployment | PostgreSQL 12-table schema, iron-session encryption, RBAC, operator impersonation, OTP recovery, audit logging, and Dokploy deployment. |
| Rav Webmail & Dual Engine | Rav Webmail & Dual-Engine Architecture | Next.js 16 + React 19 + Rust Axum webmail, Tantivy search, live WebSockets, and dual SSO. |
| Model Context Protocol (MCP) Server | Model Context Protocol (MCP) Server & Direct Mailbox Engine | External AI agent integration, direct JMAP mailbox access, 56 admin tools, HTTP SSE & Stdio CLI transports. |
High-Level System Architecture
Diagram
Core Product Principles
- Stalwart is the Source of Truth: Mailbox existence, domain states, catch-all configurations, and email routing are always verified against Stalwart JMAP. The local PostgreSQL database mirrors directory state to power RBAC domain ownership and cached analytics without desynchronizing from the server.
- Zero Plaintext Mailbox Passwords in Browser: User mailbox passwords are generated or reset in single-flight operations. When opening webmail, administrators never enter or view the mailbox password - short-lived signed HMAC tokens and Stalwart SASL PLAIN master impersonation handle authentication transparently.
- Graceful Fallback & Mock Runtime: If Stalwart or PostgreSQL credentials are unset (e.g. during local frontend development or automated testing), the application boots cleanly in
mockmode with a stateful in-memory directory store. - Strict Isolation & Safe Operations: Destructive actions (deleting domains, removing mailboxes, mass password resets) require explicit typed confirmations or operator approval modals in the AI Copilot.
- Intelligent Quotas & Archival Mirroring: Mailbox storage defaults to unmetered infinite capacity with dynamic 0.25 GB tier scaling on system overview meters. Catch-alls serve as active domain archives with automated Sieve postmaster/DMARC report filtering and retroactive JMAP cleanup abstractions.
Quick Reference Commands
bash
# Install dependencies
npm install
# Start development server
npm run dev
# Run type check
npm run typecheck
# Run linter
npm run lint
# Run test suite (Vitest)
npm test
# Build production bundle
npm run build