mailwartDocs
Docs/Getting Started4 min read

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:

GuideTitleDescription
Getting Started GuideGetting Started GuideStep-by-step setup, local development, domain provisioning, and webmail SSO.
System ArchitectureSystem Architecture & InfrastructureComplete topology, container networking, runtime isolation, data flow lifecycles, and mock vs. live dual runtime engine.
Pages, Navigation & UXFrontend Pages, Navigation & UXExhaustive mapping of all 11 UI pages, AppShell chrome, navigation sidebar, modals, wizards, and interactive components.
HTTP REST API ReferenceHTTP API EndpointsSpecifications for all Next.js API route handlers (/api/auth, /api/copilot, /api/deliverability, /api/diagnostics, /api/webmail/sso, etc.).
Server Actions CatalogServer Actions CatalogIn-depth technical catalog of all 80+ server actions across mail, users, Cloudflare, copilot, deliverability, and auth.
Stalwart Mail Server & JMAPStalwart Mail Server IntegrationJMAP protocol specification, method calls, data normalization, catch-all handling, app passwords, and mock engine.
Roundcube Webmail SSORoundcube Webmail & SSOCustom em_sso PHP plugin, HMAC SHA-256 token minting, master impersonation protocol (user%impersonator), and Traefik routing.
Cloudflare DNS AutomationCloudflare DNS AutomationMulti-account token pooling, automated zone discovery, 1-click DNS record provisioning (MX, SPF, DKIM, DMARC), and conflict detection.
Deliverability SuiteEmail Deliverability Suite10-point deliverability audit engine, port & TLS probes, DNSBL blacklist monitoring, SMTP banner & EHLO checks, and mail-tester scoring.
AI Copilot & Tool RegistryAI Copilot & Tool RegistryArchitecture with Vercel AI SDK, 10 supported LLM providers, 48 registered administrative tools, and human-in-the-loop approval workflows.
Database, Security & DeploymentDatabase, Security & DeploymentPostgreSQL 12-table schema, iron-session encryption, RBAC, operator impersonation, OTP recovery, audit logging, and Dokploy deployment.
Rav Webmail & Dual EngineRav Webmail & Dual-Engine ArchitectureNext.js 16 + React 19 + Rust Axum webmail, Tantivy search, live WebSockets, and dual SSO.
Model Context Protocol (MCP) ServerModel Context Protocol (MCP) Server & Direct Mailbox EngineExternal AI agent integration, direct JMAP mailbox access, 56 admin tools, HTTP SSE & Stdio CLI transports.

High-Level System Architecture

Diagram
Rendering diagram...

Core Product Principles

  1. 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.
  2. 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.
  3. 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 mock mode with a stateful in-memory directory store.
  4. 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.
  5. 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