# maillab/cloud-mail architecture

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

- Interactive diagram: https://gitdiagram.com/maillab/cloud-mail
- Repository: https://github.com/maillab/cloud-mail

## Overview

Cloud Mail is a Cloudflare-hosted email platform: users manage accounts and messages in a Vue web client, while a Worker handles API requests and incoming mail. Its domain spans account/authentication, mailbox and attachment handling, outbound delivery, administration, and analytics. The README documents additional capabilities such as OAuth, bulk/open API operations, Telegram or webhook forwarding, Turnstile, AI code recognition, and customizable settings. The graph includes those documented branches; source excerpts are selective, so unshown internal routes are not inferred.

Main entry points: [`mail-worker/src/service/email-service.js`](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/email-service.js) (Email service), [`mail-worker/src/service/user-service.js`](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/user-service.js) (User management), [`mail-worker/src/index.js`](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/index.js) (Worker entry), [`mail-vue/src`](https://github.com/maillab/cloud-mail/tree/main/mail-vue/src) (Vue application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_webapp["Vue application"]
  node_mailbox["Mailbox views"]
  node_composer["Message composer<br/>[index.vue]"]
  node_clientapi["API client"]
end

subgraph group_runtime["Worker runtime"]
  node_worker["Worker entry<br/>[index.js]"]
  node_api["HTTP API handlers"]
end

subgraph group_mail["Mail operations"]
  node_mailservice["Email service<br/>[email-service.js]"]
  node_inbound["Inbound mail<br/>[email.js]"]
  node_attachments["Attachment service<br/>[att-service.js]"]
end

subgraph group_admin["Accounts and policy"]
  node_auth["Login and OAuth<br/>[login-service.js]"]
  node_oauth["OAuth accounts<br/>[oauth-service.js]"]
  node_accounts["Mailbox accounts<br/>[account-service.js]"]
  node_users["User management<br/>[user-service.js]"]
  node_roles["Roles and permissions<br/>[role-service.js]"]
  node_settings["System settings<br/>[setting-service.js]"]
end

subgraph group_platform["Platform integrations"]
  node_delivery["Email delivery<br/>[resend-service.js]"]
  node_forwarding["Mail forwarding"]
  node_analytics["Mail analytics"]
  node_proxy["Image proxy<br/>[proxy-service.js]"]
  node_storage["R2 and S3 storage<br/>[r2-service.js]"]
  node_verification["Bot verification"]
  node_ai["Code recognition<br/>[ai-service.js]"]
  node_d1[("D1 database<br/>[orm.js]")]
end

node_user(("Mail user"))
node_cloudflare["Cloudflare services"]
node_resend["Resend"]
node_telegram["Telegram"]
node_webhook["Webhook provider"]

node_user -->|"uses"| node_webapp
node_webapp -->|"presents"| node_mailbox
node_webapp -->|"composes in"| node_composer
node_webapp -.->|"requests data"| node_clientapi
node_clientapi -.->|"calls API"| node_api
node_worker -->|"routes API"| node_api
node_worker -->|"registers mail"| node_inbound
node_worker -->|"dispatches images"| node_proxy
node_worker -->|"refreshes cache"| node_analytics
node_api -->|"invokes"| node_oauth
node_oauth -->|"looks up users"| node_users
node_oauth -->|"registers login"| node_auth
node_inbound -->|"uses mail operations"| node_mailservice
node_inbound -->|"resolves recipients"| node_accounts
node_mailservice -->|"saves attachments"| node_attachments
node_mailservice -->|"checks accounts"| node_accounts
node_mailservice -->|"checks users"| node_users
node_mailservice -->|"checks policy"| node_roles
node_mailservice -->|"reads settings"| node_settings
node_accounts -->|"queries users"| node_users
node_users -->|"queries roles"| node_roles
node_roles -->|"queries users"| node_users
node_settings -->|"uses storage"| node_storage
node_mailservice -->|"reads and writes"| node_d1
node_accounts -->|"reads and writes"| node_d1
node_users -->|"reads and writes"| node_d1
node_roles -->|"reads and writes"| node_d1
node_oauth -->|"reads and writes"| node_d1
node_mailservice -.->|"delivers mail"| node_delivery
node_mailservice -.->|"forwards mail"| node_forwarding
node_mailservice -.->|"recognizes codes"| node_ai
node_api -.->|"verifies registration"| node_verification
node_worker -->|"serves on"| node_cloudflare
node_delivery -->|"sends through"| node_resend
node_forwarding -->|"notifies"| node_telegram
node_forwarding -.->|"notifies"| node_webhook
node_storage -->|"uses R2"| node_cloudflare
node_analytics -->|"visualizes with ECharts"| node_webapp

click node_webapp "https://github.com/maillab/cloud-mail/tree/main/mail-vue/src"
click node_mailbox "https://github.com/maillab/cloud-mail/tree/main/mail-vue/src/views"
click node_composer "https://github.com/maillab/cloud-mail/blob/main/mail-vue/src/layout/write/index.vue"
click node_clientapi "https://github.com/maillab/cloud-mail/tree/main/mail-vue/src/request"
click node_worker "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/index.js"
click node_api "https://github.com/maillab/cloud-mail/tree/main/mail-worker/src/api"
click node_auth "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/login-service.js"
click node_oauth "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/oauth-service.js"
click node_accounts "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/account-service.js"
click node_users "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/user-service.js"
click node_roles "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/role-service.js"
click node_settings "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/setting-service.js"
click node_mailservice "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/email-service.js"
click node_inbound "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/email/email.js"
click node_attachments "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/att-service.js"
click node_delivery "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/resend-service.js"
click node_forwarding "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/telegram-service.js"
click node_analytics "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/analysis-service.js"
click node_proxy "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/proxy-service.js"
click node_storage "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/r2-service.js"
click node_verification "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/turnstile-service.js"
click node_ai "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/ai-service.js"
click node_d1 "https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/entity/orm.js"

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_webapp,node_mailbox,node_composer,node_clientapi,node_user toneBlue
class node_worker,node_api toneAmber
class node_mailservice,node_inbound,node_attachments,node_webhook toneMint
class node_auth,node_oauth,node_accounts,node_users,node_roles,node_settings toneRose
class node_delivery,node_forwarding,node_analytics,node_proxy,node_storage,node_verification,node_ai,node_d1,node_cloudflare,node_resend,node_telegram toneIndigo
```

## Components

### Web client

- [Vue application](https://github.com/maillab/cloud-mail/tree/main/mail-vue/src): `mail-vue/src`
- [Mailbox views](https://github.com/maillab/cloud-mail/tree/main/mail-vue/src/views): `mail-vue/src/views`
- [Message composer](https://github.com/maillab/cloud-mail/blob/main/mail-vue/src/layout/write/index.vue): `mail-vue/src/layout/write/index.vue`
- [API client](https://github.com/maillab/cloud-mail/tree/main/mail-vue/src/request): `mail-vue/src/request`

### Worker runtime

- [Worker entry](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/index.js): `mail-worker/src/index.js`
- [HTTP API handlers](https://github.com/maillab/cloud-mail/tree/main/mail-worker/src/api): `mail-worker/src/api`

### Mail operations

- [Email service](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/email-service.js): `mail-worker/src/service/email-service.js`
- [Inbound mail](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/email/email.js): `mail-worker/src/email/email.js`
- [Attachment service](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/att-service.js): `mail-worker/src/service/att-service.js`

### Accounts and policy

- [Login and OAuth](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/login-service.js): `mail-worker/src/service/login-service.js`
- [OAuth accounts](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/oauth-service.js): `mail-worker/src/service/oauth-service.js`
- [Mailbox accounts](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/account-service.js): `mail-worker/src/service/account-service.js`
- [User management](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/user-service.js): `mail-worker/src/service/user-service.js`
- [Roles and permissions](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/role-service.js): `mail-worker/src/service/role-service.js`
- [System settings](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/setting-service.js): `mail-worker/src/service/setting-service.js`

### Platform integrations

- [Email delivery](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/resend-service.js): `mail-worker/src/service/resend-service.js`
- [Mail forwarding](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/telegram-service.js): `mail-worker/src/service/telegram-service.js`
- [Mail analytics](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/analysis-service.js): `mail-worker/src/service/analysis-service.js`
- [Image proxy](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/proxy-service.js): `mail-worker/src/service/proxy-service.js`
- [R2 and S3 storage](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/r2-service.js): `mail-worker/src/service/r2-service.js`
- [Bot verification](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/turnstile-service.js): `mail-worker/src/service/turnstile-service.js`
- [Code recognition](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/service/ai-service.js): `mail-worker/src/service/ai-service.js`
- [D1 database](https://github.com/maillab/cloud-mail/blob/main/mail-worker/src/entity/orm.js): `mail-worker/src/entity/orm.js`

### Other components

- **Mail user**
- **Cloudflare services**
- **Resend**
- **Telegram**
- **Webhook provider**

## Connections

- Mail user → Vue application: uses (evidence: `README.md`)
- Vue application → Mailbox views: presents (evidence: `README.md`)
- Vue application → Message composer: composes in (evidence: `README.md`)
- Vue application → API client: requests data
- API client → HTTP API handlers: calls API
- Worker entry → HTTP API handlers: routes API (evidence: `mail-worker/src/index.js`)
- Worker entry → Inbound mail: registers mail (evidence: `mail-worker/src/index.js`)
- Worker entry → Image proxy: dispatches images (evidence: `mail-worker/src/index.js`)
- Worker entry → Mail analytics: refreshes cache (evidence: `mail-worker/src/index.js`)
- HTTP API handlers → OAuth accounts: invokes (evidence: `mail-worker/src/api/oauth-api.js`)
- OAuth accounts → User management: looks up users (evidence: `mail-worker/src/service/oauth-service.js`)
- OAuth accounts → Login and OAuth: registers login (evidence: `mail-worker/src/service/oauth-service.js`)
- Inbound mail → Email service: uses mail operations (evidence: `mail-worker/src/email/email.js`)
- Inbound mail → Mailbox accounts: resolves recipients (evidence: `mail-worker/src/email/email.js`)
- Email service → Attachment service: saves attachments (evidence: `mail-worker/src/service/email-service.js`)
- Email service → Mailbox accounts: checks accounts (evidence: `mail-worker/src/service/email-service.js`)
- Email service → User management: checks users (evidence: `mail-worker/src/service/email-service.js`)
- Email service → Roles and permissions: checks policy (evidence: `mail-worker/src/service/email-service.js`)
- Email service → System settings: reads settings (evidence: `mail-worker/src/service/email-service.js`)
- Mailbox accounts → User management: queries users (evidence: `mail-worker/src/service/account-service.js`)
- User management → Roles and permissions: queries roles (evidence: `mail-worker/src/service/user-service.js`)
- Roles and permissions → User management: queries users (evidence: `mail-worker/src/service/role-service.js`)
- System settings → R2 and S3 storage: uses storage (evidence: `mail-worker/src/service/setting-service.js`)
- Email service → D1 database: reads and writes (evidence: `mail-worker/src/service/email-service.js`)
- Mailbox accounts → D1 database: reads and writes (evidence: `mail-worker/src/service/account-service.js`)
- User management → D1 database: reads and writes (evidence: `mail-worker/src/service/user-service.js`)
- Roles and permissions → D1 database: reads and writes (evidence: `mail-worker/src/service/role-service.js`)
- OAuth accounts → D1 database: reads and writes (evidence: `mail-worker/src/service/oauth-service.js`)
- Email service → Email delivery: delivers mail
- Email service → Mail forwarding: forwards mail (evidence: `mail-worker/src/service/email-service.js`)
- Email service → Code recognition: recognizes codes
- HTTP API handlers → Bot verification: verifies registration
- Worker entry → Cloudflare services: serves on (evidence: `README.md`)
- Email delivery → Resend: sends through (evidence: `README.md`)
- Mail forwarding → Telegram: notifies (evidence: `README.md`)
- Mail forwarding → Webhook provider: notifies (evidence: `README.md`)
- R2 and S3 storage → Cloudflare services: uses R2 (evidence: `README.md`)
- Mail analytics → Vue application: visualizes with ECharts (evidence: `README.md`)
