# flectar/mail architecture

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

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

## Overview

Flectar Mail is a native, local-first client for email, calendars, contacts, and files. The main path is account setup and provider synchronization into local storage, followed by inbox presentation; message composition and native HTML rendering are related user-facing workflows. The tree and README support the product boundaries and several integrations, while sampled source confirms selected sync, database, and file-service relationships. Many UI-to-core connections and calendar/contact internals were not excerpted, so those links are omitted or marked unverified.

Main entry points: [`crates/flectar-mail-core/src/sync/engine.rs`](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/sync/engine.rs) (Account sync), [`src/mail.rs`](https://github.com/flectar/mail/blob/main/src/mail.rs) (Inbox workspace), [`crates/flectar-mail-core/src/files/service.rs`](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/files/service.rs) (Files service), [`crates/flectar-mail-core/src/db/mod.rs`](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/db/mod.rs) (SQLite database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Native app"]
  node_desktop["Desktop entry<br/>[desktop.rs]"]
  node_mailui["Inbox workspace<br/>[mail.rs]"]
  node_setup["Account setup<br/>[mail_setup.rs]"]
  node_filesui["Files workspace"]
  node_attachments["Attachment preview"]
  node_pdf["PDF preview<br/>[pdf_preview.rs]"]
end

subgraph group_mail["Mail workflows"]
  node_compose["Message composer"]
end

subgraph group_core["Core services"]
  node_sync["Account sync<br/>[engine.rs]"]
  node_gmail["Gmail sync<br/>[gmail.rs]"]
  node_jmapsync["JMAP sync<br/>[sync.rs]"]
  node_imap["IMAP service<br/>[mod.rs]"]
  node_smtp["SMTP service<br/>[mod.rs]"]
  node_calendar["Calendar sync<br/>[sync.rs]"]
  node_contacts["Contacts sync<br/>[sync.rs]"]
  node_fileservice["Files service<br/>[service.rs]"]
  node_fileclient["File protocols<br/>[jmap.rs]"]
end

subgraph group_data["Local data"]
  node_database[("SQLite database<br/>[mod.rs]")]
  node_repos["Data repositories<br/>[messages.rs]"]
end

subgraph group_render["Native rendering"]
  node_renderer["Email renderer<br/>[renderer.rs]"]
  node_dom["HTML and CSS DOM<br/>[document.rs]"]
  node_layout["Document layout<br/>[construct.rs]"]
  node_paint["Scene painter<br/>[render.rs]"]
  node_text["Text shaping<br/>[mod.rs]"]
end

node_user(("Mail user"))
node_providers(("Mail providers"))
node_dav(("CalDAV and CardDAV"))
node_fileserver(("JMAP and WebDAV"))

node_user -->|"opens"| node_desktop
node_desktop -.->|"shows workspace"| node_mailui
node_user -->|"connects accounts"| node_setup
node_setup -.->|"starts sync"| node_sync
node_providers -->|"provides mail"| node_sync
node_sync -->|"dispatches"| node_gmail
node_sync -->|"dispatches"| node_jmapsync
node_sync -->|"uses connections"| node_imap
node_sync -->|"reads and writes"| node_repos
node_repos -->|"queries"| node_database
node_mailui -.->|"reads local mail"| node_database
node_user -.->|"composes message"| node_compose
node_compose -.->|"submits mail"| node_smtp
node_dav -->|"syncs events"| node_calendar
node_dav -->|"syncs contacts"| node_contacts
node_user -->|"browses files"| node_filesui
node_filesui -->|"requests operations"| node_fileservice
node_fileservice -->|"uses protocol client"| node_fileclient
node_fileserver -->|"serves files"| node_fileclient
node_fileservice -->|"persists file state"| node_database
node_user -.->|"opens attachment"| node_attachments
node_attachments -->|"opens PDF preview"| node_pdf
node_mailui -->|"renders messages"| node_renderer
node_renderer -->|"parses email markup"| node_dom
node_dom -->|"constructs layout"| node_layout
node_layout -->|"provides paint tree"| node_paint
node_paint -->|"draws shaped text"| node_text

click node_desktop "https://github.com/flectar/mail/blob/main/src/desktop.rs"
click node_mailui "https://github.com/flectar/mail/blob/main/src/mail.rs"
click node_setup "https://github.com/flectar/mail/blob/main/src/mail_setup.rs"
click node_compose "https://github.com/flectar/mail/blob/main/src/compose_controller.rs"
click node_sync "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/sync/engine.rs"
click node_gmail "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/sync/gmail.rs"
click node_jmapsync "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/jmap/sync.rs"
click node_imap "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/imap/mod.rs"
click node_smtp "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/smtp/mod.rs"
click node_calendar "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/caldav/sync.rs"
click node_contacts "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/carddav/sync.rs"
click node_filesui "https://github.com/flectar/mail/blob/main/src/files_controller.rs"
click node_fileservice "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/files/service.rs"
click node_fileclient "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/files/jmap.rs"
click node_database "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/db/mod.rs"
click node_repos "https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/db/repo/messages.rs"
click node_attachments "https://github.com/flectar/mail/blob/main/src/attachment_controller.rs"
click node_pdf "https://github.com/flectar/mail/blob/main/src/pdf_preview.rs"
click node_renderer "https://github.com/flectar/mail/blob/main/src/renderer.rs"
click node_dom "https://github.com/flectar/mail/blob/main/crates/blitz-dom/src/document.rs"
click node_layout "https://github.com/flectar/mail/blob/main/crates/blitz-dom/src/layout/construct.rs"
click node_paint "https://github.com/flectar/mail/blob/main/crates/blitz-paint/src/render.rs"
click node_text "https://github.com/flectar/mail/blob/main/crates/parley/src/shape/mod.rs"

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_desktop,node_mailui,node_setup,node_filesui,node_attachments,node_pdf,node_user toneBlue
class node_compose toneAmber
class node_sync,node_gmail,node_jmapsync,node_imap,node_smtp,node_calendar,node_contacts,node_fileservice,node_fileclient toneMint
class node_database,node_repos toneRose
class node_renderer,node_dom,node_layout,node_paint,node_text,node_providers,node_dav,node_fileserver toneIndigo
```

## Components

### Native app

- [Desktop entry](https://github.com/flectar/mail/blob/main/src/desktop.rs): `src/desktop.rs`
- [Inbox workspace](https://github.com/flectar/mail/blob/main/src/mail.rs): `src/mail.rs`
- [Account setup](https://github.com/flectar/mail/blob/main/src/mail_setup.rs): `src/mail_setup.rs`
- [Files workspace](https://github.com/flectar/mail/blob/main/src/files_controller.rs): `src/files_controller.rs`
- [Attachment preview](https://github.com/flectar/mail/blob/main/src/attachment_controller.rs): `src/attachment_controller.rs`
- [PDF preview](https://github.com/flectar/mail/blob/main/src/pdf_preview.rs): `src/pdf_preview.rs`

### Mail workflows

- [Message composer](https://github.com/flectar/mail/blob/main/src/compose_controller.rs): `src/compose_controller.rs`

### Core services

- [Account sync](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/sync/engine.rs): `crates/flectar-mail-core/src/sync/engine.rs`
- [Gmail sync](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/sync/gmail.rs): `crates/flectar-mail-core/src/sync/gmail.rs`
- [JMAP sync](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/jmap/sync.rs): `crates/flectar-mail-core/src/jmap/sync.rs`
- [IMAP service](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/imap/mod.rs): `crates/flectar-mail-core/src/imap/mod.rs`
- [SMTP service](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/smtp/mod.rs): `crates/flectar-mail-core/src/smtp/mod.rs`
- [Calendar sync](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/caldav/sync.rs): `crates/flectar-mail-core/src/caldav/sync.rs`
- [Contacts sync](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/carddav/sync.rs): `crates/flectar-mail-core/src/carddav/sync.rs`
- [Files service](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/files/service.rs): `crates/flectar-mail-core/src/files/service.rs`
- [File protocols](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/files/jmap.rs): `crates/flectar-mail-core/src/files/jmap.rs`

### Local data

- [SQLite database](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/db/mod.rs): `crates/flectar-mail-core/src/db/mod.rs`
- [Data repositories](https://github.com/flectar/mail/blob/main/crates/flectar-mail-core/src/db/repo/messages.rs): `crates/flectar-mail-core/src/db/repo/messages.rs`

### Native rendering

- [Email renderer](https://github.com/flectar/mail/blob/main/src/renderer.rs): `src/renderer.rs`
- [HTML and CSS DOM](https://github.com/flectar/mail/blob/main/crates/blitz-dom/src/document.rs): `crates/blitz-dom/src/document.rs`
- [Document layout](https://github.com/flectar/mail/blob/main/crates/blitz-dom/src/layout/construct.rs): `crates/blitz-dom/src/layout/construct.rs`
- [Scene painter](https://github.com/flectar/mail/blob/main/crates/blitz-paint/src/render.rs): `crates/blitz-paint/src/render.rs`
- [Text shaping](https://github.com/flectar/mail/blob/main/crates/parley/src/shape/mod.rs): `crates/parley/src/shape/mod.rs`

### Other components

- **Mail user**
- **Mail providers**
- **CalDAV and CardDAV**
- **JMAP and WebDAV**

## Connections

- Mail user → Desktop entry: opens (evidence: `README.md`)
- Desktop entry → Inbox workspace: shows workspace
- Mail user → Account setup: connects accounts (evidence: `README.md`)
- Account setup → Account sync: starts sync
- Mail providers → Account sync: provides mail (evidence: `README.md`)
- Account sync → Gmail sync: dispatches (evidence: `crates/flectar-mail-core/src/sync/engine.rs`)
- Account sync → JMAP sync: dispatches (evidence: `crates/flectar-mail-core/src/sync/engine.rs`)
- Account sync → IMAP service: uses connections (evidence: `crates/flectar-mail-core/src/sync/engine.rs`)
- Account sync → Data repositories: reads and writes (evidence: `crates/flectar-mail-core/src/sync/engine.rs`)
- Data repositories → SQLite database: queries (evidence: `crates/flectar-mail-core/src/db/mod.rs`)
- Inbox workspace → SQLite database: reads local mail
- Mail user → Message composer: composes message
- Message composer → SMTP service: submits mail
- CalDAV and CardDAV → Calendar sync: syncs events (evidence: `README.md`)
- CalDAV and CardDAV → Contacts sync: syncs contacts (evidence: `README.md`)
- Mail user → Files workspace: browses files (evidence: `README.md`)
- Files workspace → Files service: requests operations (evidence: `src/files_controller.rs`)
- Files service → File protocols: uses protocol client (evidence: `crates/flectar-mail-core/src/files/service.rs`)
- JMAP and WebDAV → File protocols: serves files (evidence: `README.md`)
- Files service → SQLite database: persists file state
- Mail user → Attachment preview: opens attachment
- Attachment preview → PDF preview: opens PDF preview (evidence: `src/attachment_controller.rs`)
- Inbox workspace → Email renderer: renders messages (evidence: `README.md`)
- Email renderer → HTML and CSS DOM: parses email markup (evidence: `README.md`)
- HTML and CSS DOM → Document layout: constructs layout (evidence: `crates/blitz-dom/src/document.rs`)
- Document layout → Scene painter: provides paint tree
- Scene painter → Text shaping: draws shaped text (evidence: `crates/blitz-paint/src/render.rs`)
