# berenebot-agent/mm-dirty-wip architecture

> Architecture diagram of the GitHub repository berenebot-agent/mm-dirty-wip, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/berenebot-agent/mm-dirty-wip
- Repository: https://github.com/berenebot-agent/mm-dirty-wip

## Overview

MailMoose is self-hosted email infrastructure for AI agents: users configure domains and inboxes, agents access scoped mailboxes through the API or connectors, inbound mail is stored and emitted as replayable events, and outbound mail is delivered through configured providers. The graph preserves documented webhook, Direct MX, standalone IMAP/SMTP, Web UI, Hermes, OpenClaw, and event-replay capabilities. Several subsystem implementations were not sampled; those nodes use exact directories from the tree, and relationships are included only where the README or cited source supports them.

Main entry points: [`internal/app/service.go`](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/service.go) (Mailbox core), [`internal/events/hub.go`](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/events/hub.go) (Replayable events), [`internal/httpapp`](https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/httpapp) (API and Web UI), [`internal/store`](https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/store) (SQLite state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and mailbox"]
  node_http["API and Web UI"]
  node_auth["Scoped authentication<br/>[auth.go]"]
  node_mailbox["Mailbox core<br/>[service.go]"]
  node_standalone["Standalone mailbox<br/>[remote_mailbox.go]"]
end

subgraph group_mail["Mail processing"]
  node_remote_watch["IMAP watcher<br/>[remote_worker.go]"]
  node_webhooks["Inbound webhooks<br/>[webhook_worker.go]"]
  node_parser["MIME parsing<br/>[mailparse.go]"]
  node_outbox["Outbound worker<br/>[worker.go]"]
  node_transports["Mail transports"]
end

subgraph group_state["Durable state"]
  node_store[("SQLite state")]
  node_mime[("Raw MIME files<br/>[storage.go]")]
end

subgraph group_delivery["Events and connectors"]
  node_events["Replayable events<br/>[hub.go]"]
  node_realtime["SSE and REST"]
  node_hermes["Hermes Relay<br/>[server.go]"]
  node_openclaw["OpenClaw connector<br/>[relay.ts]"]
end

subgraph group_mx["MX receiving edge"]
  node_mx_server["MX receiver<br/>[server.go]"]
  node_mx_runtime["Receiver runtime<br/>[runtime.go]"]
  node_mx_delivery["MX core handoff<br/>[runtime.go]"]
end

node_operator(("Administrator"))
node_agent(("Agents and services"))
node_internet(("Internet email"))

node_operator -->|"configures"| node_http
node_agent -->|"uses API"| node_http
node_internet -->|"sends mail"| node_webhooks
node_internet -->|"sends mail"| node_mx_server
node_http -->|"authenticates"| node_auth
node_http -->|"routes requests"| node_mailbox
node_auth -->|"scopes access"| node_mailbox
node_mailbox -->|"persists state"| node_store
node_mailbox -->|"publishes events"| node_events
node_webhooks -->|"parses mail"| node_parser
node_webhooks -->|"deduplicates delivery"| node_store
node_parser -->|"ingests mail"| node_mailbox
node_outbox -->|"delivers queued mail"| node_mailbox
node_mailbox -->|"sends through"| node_transports
node_standalone -->|"watches inboxes"| node_remote_watch
node_remote_watch -->|"publishes arrivals"| node_events
node_events -->|"replays durable history"| node_store
node_events -->|"fans out"| node_realtime
node_events -->|"delivers events"| node_hermes
node_events -.->|"delivers events"| node_openclaw
node_realtime -->|"serves updates"| node_agent
node_hermes -->|"connects agents"| node_agent
node_openclaw -->|"connects agents"| node_agent
node_mx_server -->|"runs receiver"| node_mx_runtime
node_mx_runtime -->|"serves SMTP"| node_mx_server
node_mailbox -->|"opens MX session"| node_mx_delivery
node_mx_delivery -->|"hands off mail"| node_mx_server
node_store -->|"stores raw MIME"| node_mime
node_standalone -->|"uses IMAP and SMTP"| node_transports

click node_http "https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/httpapp"
click node_auth "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/auth/auth.go"
click node_mailbox "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/service.go"
click node_standalone "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/remote_mailbox.go"
click node_remote_watch "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/remote_worker.go"
click node_webhooks "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/webhook_worker.go"
click node_parser "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/mailparse/mailparse.go"
click node_outbox "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/worker.go"
click node_transports "https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/transport"
click node_store "https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/store"
click node_mime "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/store/storage.go"
click node_events "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/events/hub.go"
click node_realtime "https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/httpapp"
click node_hermes "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/hermesrelay/server.go"
click node_openclaw "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/plugins/openclaw/openclaw-plugin/src/relay.ts"
click node_mx_server "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/mxagent/server.go"
click node_mx_runtime "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/dialmx/runtime/runtime.go"
click node_mx_delivery "https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/transport/mxdial/runtime.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http,node_auth,node_mailbox,node_standalone toneBlue
class node_remote_watch,node_webhooks,node_parser,node_outbox,node_transports toneAmber
class node_store,node_mime toneMint
class node_events,node_realtime,node_hermes,node_openclaw toneRose
class node_mx_server,node_mx_runtime,node_mx_delivery,node_operator,node_agent,node_internet toneIndigo
```

## Components

### Access and mailbox

- [API and Web UI](https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/httpapp): `internal/httpapp`
- [Scoped authentication](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/auth/auth.go): `internal/auth/auth.go`
- [Mailbox core](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/service.go): `internal/app/service.go`
- [Standalone mailbox](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/remote_mailbox.go): `internal/app/remote_mailbox.go`

### Mail processing

- [IMAP watcher](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/remote_worker.go): `internal/app/remote_worker.go`
- [Inbound webhooks](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/webhook_worker.go): `internal/app/webhook_worker.go`
- [MIME parsing](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/mailparse/mailparse.go): `internal/mailparse/mailparse.go`
- [Outbound worker](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/app/worker.go): `internal/app/worker.go`
- [Mail transports](https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/transport): `internal/transport`

### Durable state

- [SQLite state](https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/store): `internal/store`
- [Raw MIME files](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/store/storage.go): `internal/store/storage.go`

### Events and connectors

- [Replayable events](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/events/hub.go): `internal/events/hub.go`
- [SSE and REST](https://github.com/berenebot-agent/mm-dirty-wip/tree/main/internal/httpapp): `internal/httpapp`
- [Hermes Relay](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/hermesrelay/server.go): `internal/hermesrelay/server.go`
- [OpenClaw connector](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/plugins/openclaw/openclaw-plugin/src/relay.ts): `plugins/openclaw/openclaw-plugin/src/relay.ts`

### MX receiving edge

- [MX receiver](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/mxagent/server.go): `internal/mxagent/server.go`
- [Receiver runtime](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/dialmx/runtime/runtime.go): `dialmx/runtime/runtime.go`
- [MX core handoff](https://github.com/berenebot-agent/mm-dirty-wip/blob/main/internal/transport/mxdial/runtime.go): `internal/transport/mxdial/runtime.go`

### Other components

- **Administrator**
- **Agents and services**
- **Internet email**

## Connections

- Administrator → API and Web UI: configures (evidence: `README.md`)
- Agents and services → API and Web UI: uses API (evidence: `README.md`)
- Internet email → Inbound webhooks: sends mail (evidence: `README.md`)
- Internet email → MX receiver: sends mail (evidence: `README.md`)
- API and Web UI → Scoped authentication: authenticates (evidence: `internal/httpapp/server.go`)
- API and Web UI → Mailbox core: routes requests (evidence: `internal/httpapp/server.go`)
- Scoped authentication → Mailbox core: scopes access (evidence: `README.md`)
- Mailbox core → SQLite state: persists state (evidence: `internal/app/service.go`)
- Mailbox core → Replayable events: publishes events (evidence: `README.md`)
- Inbound webhooks → MIME parsing: parses mail (evidence: `README.md`)
- Inbound webhooks → SQLite state: deduplicates delivery (evidence: `README.md`)
- MIME parsing → Mailbox core: ingests mail (evidence: `README.md`)
- Outbound worker → Mailbox core: delivers queued mail (evidence: `internal/app/worker.go`)
- Mailbox core → Mail transports: sends through (evidence: `internal/app/service.go`)
- Standalone mailbox → IMAP watcher: watches inboxes (evidence: `internal/app/remote_worker.go`)
- IMAP watcher → Replayable events: publishes arrivals (evidence: `internal/app/remote_worker.go`)
- Replayable events → SQLite state: replays durable history (evidence: `README.md`)
- Replayable events → SSE and REST: fans out (evidence: `README.md`)
- Replayable events → Hermes Relay: delivers events (evidence: `README.md`)
- Replayable events → OpenClaw connector: delivers events (evidence: `README.md`)
- SSE and REST → Agents and services: serves updates (evidence: `README.md`)
- Hermes Relay → Agents and services: connects agents (evidence: `README.md`)
- OpenClaw connector → Agents and services: connects agents (evidence: `README.md`)
- MX receiver → Receiver runtime: runs receiver
- Receiver runtime → MX receiver: serves SMTP (evidence: `dialmx/runtime/runtime.go`)
- Mailbox core → MX core handoff: opens MX session (evidence: `README.md`)
- MX core handoff → MX receiver: hands off mail (evidence: `README.md`)
- SQLite state → Raw MIME files: stores raw MIME (evidence: `README.md`)
- Standalone mailbox → Mail transports: uses IMAP and SMTP (evidence: `README.md`)
