# ziyadinho/raadmailflare architecture

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

- Interactive diagram: https://gitdiagram.com/ziyadinho/raadmailflare
- Repository: https://github.com/ziyadinho/raadmailflare

## Overview

Mailflare is a self-hosted workspace for custom-domain email, calendar, booking, file storage, and AI-assisted workflows. A core email journey is configuring a domain and mailbox, receiving mail through an inbound provider, processing it into the application, and reading or sending it through the mail UI and APIs. The repository also exposes distinct calendar/booking, Drive, AI/MCP, and administration capabilities. Some links are documented in the README rather than shown in sampled implementation; those are identified by README evidence.

Main entry points: [`src/db/schema/index.ts`](https://github.com/ziyadinho/raadmailflare/blob/main/src/db/schema/index.ts) (Workspace database), [`src/app/api/mailboxes/route.ts`](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/mailboxes/route.ts) (Mailbox management), [`src/app/api/messages/route.ts`](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/messages/route.ts) (Message API), [`src/lib/domains/service.ts`](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/domains/service.ts) (Domain services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mail["Email and identity"]
  node_mail_ui["Mail interface<br/>[page.tsx]"]
  node_mail_api["Message API<br/>[route.ts]"]
  node_mailboxes["Mailbox management<br/>[route.ts]"]
  node_inbound_api["Inbound endpoint<br/>[route.ts]"]
  node_intake["Inbound intake<br/>[intake.ts]"]
  node_inbound_process["Inbound processing<br/>[inbound.ts]"]
  node_spam["Spam analysis<br/>[engine.ts]"]
  node_sending["Outbound sending<br/>[send.ts]"]
end

subgraph group_workspace["Workspace apps"]
  node_calendar["Calendar<br/>[page.tsx]"]
  node_booking["Public booking<br/>[route.ts]"]
  node_drive["Drive and sharing<br/>[page.tsx]"]
end

subgraph group_agent["AI and integrations"]
  node_agent_api["Agent API<br/>[route.ts]"]
  node_mcp["MCP tools<br/>[server.ts]"]
end

subgraph group_platform["Runtime and storage"]
  node_server["Runtime dispatcher<br/>[index.ts]"]
  node_db_config["Database selection<br/>[with-database.ts]"]
  node_database[("Workspace database<br/>[index.ts]")]
  node_storage["File storage<br/>[storage.ts]"]
end

subgraph group_admin["Administration"]
  node_admin_ui["Admin console<br/>[page.tsx]"]
  node_domains["Domain services<br/>[service.ts]"]
end

node_user(("Workspace user"))
node_email_provider{{"Mail providers"}}

node_user -->|"uses"| node_mail_ui
node_mail_ui -.->|"loads mail"| node_mail_api
node_user -->|"creates mailbox"| node_mailboxes
node_mailboxes -->|"reads and writes"| node_database
node_mailboxes -->|"configures routing"| node_domains
node_email_provider -->|"delivers mail"| node_inbound_api
node_inbound_api -->|"passes message"| node_intake
node_server -->|"dispatches inbound"| node_inbound_process
node_server -->|"dispatches outbound"| node_sending
node_mail_api -->|"queries messages"| node_database
node_user -->|"reads and manages"| node_mail_api
node_user -->|"sends mail"| node_sending
node_email_provider -->|"sends through"| node_sending
node_user -->|"manages events"| node_calendar
node_user -->|"books time"| node_booking
node_booking -.->|"reads availability"| node_calendar
node_user -->|"stores and shares"| node_drive
node_drive -->|"stores files"| node_storage
node_user -->|"uses agents"| node_agent_api
node_agent_api -.->|"exposes tools"| node_mcp
node_user -->|"connects tools"| node_mcp
node_admin_ui -.->|"manages domains"| node_domains
node_domains -->|"configures delivery"| node_email_provider
node_db_config -->|"selects backend"| node_database
node_spam -->|"reads trust data"| node_database

click node_mail_ui "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(dashboard)/inbox/page.tsx"
click node_mail_api "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/messages/route.ts"
click node_mailboxes "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/mailboxes/route.ts"
click node_inbound_api "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/inbound/route.ts"
click node_intake "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/email/intake.ts"
click node_inbound_process "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/email/inbound.ts"
click node_spam "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/spam/engine.ts"
click node_sending "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/email/send.ts"
click node_calendar "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(calendar)/calendar/page.tsx"
click node_booking "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/public/booking/route.ts"
click node_drive "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(drive)/drive/page.tsx"
click node_agent_api "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/agent/chat/route.ts"
click node_mcp "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/mcp/server.ts"
click node_admin_ui "https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(admin)/admin/page.tsx"
click node_domains "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/domains/service.ts"
click node_server "https://github.com/ziyadinho/raadmailflare/blob/main/server/index.ts"
click node_db_config "https://github.com/ziyadinho/raadmailflare/blob/main/src/db/with-database.ts"
click node_database "https://github.com/ziyadinho/raadmailflare/blob/main/src/db/schema/index.ts"
click node_storage "https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/drive/storage.ts"

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_mail_ui,node_mail_api,node_mailboxes,node_inbound_api,node_intake,node_inbound_process,node_spam,node_sending,node_user toneBlue
class node_calendar,node_booking,node_drive toneAmber
class node_agent_api,node_mcp toneMint
class node_server,node_db_config,node_database,node_storage toneRose
class node_admin_ui,node_domains,node_email_provider toneIndigo
```

## Components

### Email and identity

- [Mail interface](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(dashboard)/inbox/page.tsx): `src/app/(dashboard)/inbox/page.tsx`
- [Message API](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/messages/route.ts): `src/app/api/messages/route.ts`
- [Mailbox management](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/mailboxes/route.ts): `src/app/api/mailboxes/route.ts`
- [Inbound endpoint](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/inbound/route.ts): `src/app/api/inbound/route.ts`
- [Inbound intake](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/email/intake.ts): `src/lib/email/intake.ts`
- [Inbound processing](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/email/inbound.ts): `src/lib/email/inbound.ts`
- [Spam analysis](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/spam/engine.ts): `src/lib/spam/engine.ts`
- [Outbound sending](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/email/send.ts): `src/lib/email/send.ts`

### Workspace apps

- [Calendar](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(calendar)/calendar/page.tsx): `src/app/(calendar)/calendar/page.tsx`
- [Public booking](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/public/booking/route.ts): `src/app/api/public/booking/route.ts`
- [Drive and sharing](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(drive)/drive/page.tsx): `src/app/(drive)/drive/page.tsx`

### AI and integrations

- [Agent API](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/api/agent/chat/route.ts): `src/app/api/agent/chat/route.ts`
- [MCP tools](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/mcp/server.ts): `src/lib/mcp/server.ts`

### Runtime and storage

- [Runtime dispatcher](https://github.com/ziyadinho/raadmailflare/blob/main/server/index.ts): `server/index.ts`
- [Database selection](https://github.com/ziyadinho/raadmailflare/blob/main/src/db/with-database.ts): `src/db/with-database.ts`
- [Workspace database](https://github.com/ziyadinho/raadmailflare/blob/main/src/db/schema/index.ts): `src/db/schema/index.ts`
- [File storage](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/drive/storage.ts): `src/lib/drive/storage.ts`

### Administration

- [Admin console](https://github.com/ziyadinho/raadmailflare/blob/main/src/app/(admin)/admin/page.tsx): `src/app/(admin)/admin/page.tsx`
- [Domain services](https://github.com/ziyadinho/raadmailflare/blob/main/src/lib/domains/service.ts): `src/lib/domains/service.ts`

### Other components

- **Workspace user**
- **Mail providers**

## Connections

- Workspace user → Mail interface: uses (evidence: `README.md`)
- Mail interface → Message API: loads mail
- Workspace user → Mailbox management: creates mailbox (evidence: `README.md`)
- Mailbox management → Workspace database: reads and writes (evidence: `src/app/api/mailboxes/route.ts`)
- Mailbox management → Domain services: configures routing (evidence: `src/app/api/mailboxes/route.ts`)
- Mail providers → Inbound endpoint: delivers mail (evidence: `README.md`)
- Inbound endpoint → Inbound intake: passes message (evidence: `src/app/api/inbound/route.ts`)
- Runtime dispatcher → Inbound processing: dispatches inbound (evidence: `server/index.ts`)
- Runtime dispatcher → Outbound sending: dispatches outbound (evidence: `server/index.ts`)
- Message API → Workspace database: queries messages (evidence: `src/app/api/messages/route.ts`)
- Workspace user → Message API: reads and manages (evidence: `README.md`)
- Workspace user → Outbound sending: sends mail (evidence: `README.md`)
- Mail providers → Outbound sending: sends through (evidence: `README.md`)
- Workspace user → Calendar: manages events (evidence: `README.md`)
- Workspace user → Public booking: books time (evidence: `README.md`)
- Public booking → Calendar: reads availability
- Workspace user → Drive and sharing: stores and shares (evidence: `README.md`)
- Drive and sharing → File storage: stores files (evidence: `README.md`)
- Workspace user → Agent API: uses agents (evidence: `README.md`)
- Agent API → MCP tools: exposes tools
- Workspace user → MCP tools: connects tools (evidence: `README.md`)
- Admin console → Domain services: manages domains
- Domain services → Mail providers: configures delivery (evidence: `README.md`)
- Database selection → Workspace database: selects backend (evidence: `src/db/with-database.ts`)
- Spam analysis → Workspace database: reads trust data (evidence: `src/lib/spam/engine.ts`)
