# s1t5/mail-archiver architecture

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

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

## Overview

Mail-Archiver is a multi-user email archiving system. Users configure mail accounts, scheduled provider sync imports messages into the archive, and users then search, preview, export, or restore archived mail. Distinct capabilities include authentication and account access, provider-specific synchronization and imports, archive storage, API/MCP access, invoice previews, retention, and monitoring. The graph follows README-documented capabilities and relationships named in the source index; unsampled implementation details are not inferred.

Main entry points: [`Controllers`](https://github.com/s1t5/mail-archiver/tree/main/Controllers) (Web controllers), [`Services/Core/EmailCoreService.cs`](https://github.com/s1t5/mail-archiver/blob/main/Services/Core/EmailCoreService.cs) (Email core), [`Services/Factories/ProviderEmailServiceFactory.cs`](https://github.com/s1t5/mail-archiver/blob/main/Services/Factories/ProviderEmailServiceFactory.cs) (Provider routing), [`Services/Providers/Imap/ImapMailSyncService.cs`](https://github.com/s1t5/mail-archiver/blob/main/Services/Providers/Imap/ImapMailSyncService.cs) (IMAP sync)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and users"]
  node_auth["Authentication"]
  node_user_services["User services<br/>[UserService.cs]"]
  node_account_access["Account permissions"]
end

subgraph group_archive["Archive and sync"]
  node_accounts["Mail accounts<br/>[MailAccount.cs]"]
  node_provider_factory["Provider routing"]
  node_imap["IMAP sync"]
  node_graph_provider["Graph provider"]
  node_imports["Archive imports"]
  node_email_core["Email core"]
  node_archive_models["Archive entities"]
  node_db[("Archive database")]
  node_raw_storage["Raw message storage"]
end

subgraph group_features["Archive features"]
  node_export_restore["Export and restore"]
  node_invoice["Invoice preview"]
  node_retention["Retention policies"]
  node_access_logs["Access logging"]
  node_monitoring["Monitoring and stats"]
end

subgraph group_interfaces["Application interfaces"]
  node_web["Web controllers"]
  node_search_api["REST API"]
  node_mcp["MCP tools"]
end

node_user(("User"))

node_user -->|"uses"| node_web
node_web -->|"authenticates"| node_auth
node_auth -->|"looks up users"| node_user_services
node_web -->|"checks access"| node_account_access
node_web -->|"manages accounts"| node_accounts
node_web -->|"selects provider"| node_provider_factory
node_provider_factory -->|"routes IMAP"| node_imap
node_provider_factory -->|"routes Graph"| node_graph_provider
node_user -->|"syncs mail"| node_imap
node_imap -->|"archives messages"| node_email_core
node_web -->|"starts imports"| node_imports
node_web -->|"searches mail"| node_email_core
node_email_core -->|"queries archive"| node_db
node_email_core -->|"uses raw store"| node_raw_storage
node_db -->|"maps entities"| node_archive_models
node_web -->|"exports and restores"| node_export_restore
node_search_api -->|"queries mail"| node_email_core
node_user -->|"accesses archive"| node_search_api
node_user -->|"uses tools"| node_mcp
node_web -->|"renders invoice"| node_invoice
node_invoice -->|"loads attachment"| node_db
node_web -->|"applies retention"| node_retention
node_web -->|"records activity"| node_access_logs
node_user -->|"views statistics"| node_monitoring

click node_web "https://github.com/s1t5/mail-archiver/tree/main/Controllers"
click node_auth "https://github.com/s1t5/mail-archiver/tree/main/Auth"
click node_user_services "https://github.com/s1t5/mail-archiver/blob/main/Services/UserService.cs"
click node_account_access "https://github.com/s1t5/mail-archiver/blob/main/Services/AccountAccessResolver.cs"
click node_accounts "https://github.com/s1t5/mail-archiver/blob/main/Models/MailAccount.cs"
click node_provider_factory "https://github.com/s1t5/mail-archiver/blob/main/Services/Factories/ProviderEmailServiceFactory.cs"
click node_imap "https://github.com/s1t5/mail-archiver/blob/main/Services/Providers/Imap/ImapMailSyncService.cs"
click node_graph_provider "https://github.com/s1t5/mail-archiver/tree/main/Services/Providers/Graph"
click node_imports "https://github.com/s1t5/mail-archiver/tree/main/Services/Providers"
click node_email_core "https://github.com/s1t5/mail-archiver/blob/main/Services/Core/EmailCoreService.cs"
click node_archive_models "https://github.com/s1t5/mail-archiver/tree/main/Models"
click node_db "https://github.com/s1t5/mail-archiver/blob/main/Data/MailArchiverDbContext.cs"
click node_raw_storage "https://github.com/s1t5/mail-archiver/tree/main/Services/Shared"
click node_search_api "https://github.com/s1t5/mail-archiver/blob/main/Controllers/Api/V1/EmailsApiController.cs"
click node_mcp "https://github.com/s1t5/mail-archiver/tree/main/Mcp/Tools"
click node_export_restore "https://github.com/s1t5/mail-archiver/tree/main/Services"
click node_invoice "https://github.com/s1t5/mail-archiver/blob/main/Services/EInvoicing/InvoicePdfService.cs"
click node_retention "https://github.com/s1t5/mail-archiver/blob/main/Services/EmailDeletionService.cs"
click node_access_logs "https://github.com/s1t5/mail-archiver/blob/main/Services/AccessLogService.cs"
click node_monitoring "https://github.com/s1t5/mail-archiver/tree/main/Services/Monitoring"

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_auth,node_user_services,node_account_access,node_user toneBlue
class node_accounts,node_provider_factory,node_imap,node_graph_provider,node_imports,node_email_core,node_archive_models,node_db,node_raw_storage toneAmber
class node_export_restore,node_invoice,node_retention,node_access_logs,node_monitoring toneMint
class node_web,node_search_api,node_mcp toneRose
```

## Components

### Access and users

- [Authentication](https://github.com/s1t5/mail-archiver/tree/main/Auth): `Auth`
- [User services](https://github.com/s1t5/mail-archiver/blob/main/Services/UserService.cs): `Services/UserService.cs`
- [Account permissions](https://github.com/s1t5/mail-archiver/blob/main/Services/AccountAccessResolver.cs): `Services/AccountAccessResolver.cs`

### Archive and sync

- [Mail accounts](https://github.com/s1t5/mail-archiver/blob/main/Models/MailAccount.cs): `Models/MailAccount.cs`
- [Provider routing](https://github.com/s1t5/mail-archiver/blob/main/Services/Factories/ProviderEmailServiceFactory.cs): `Services/Factories/ProviderEmailServiceFactory.cs`
- [IMAP sync](https://github.com/s1t5/mail-archiver/blob/main/Services/Providers/Imap/ImapMailSyncService.cs): `Services/Providers/Imap/ImapMailSyncService.cs`
- [Graph provider](https://github.com/s1t5/mail-archiver/tree/main/Services/Providers/Graph): `Services/Providers/Graph`
- [Archive imports](https://github.com/s1t5/mail-archiver/tree/main/Services/Providers): `Services/Providers`
- [Email core](https://github.com/s1t5/mail-archiver/blob/main/Services/Core/EmailCoreService.cs): `Services/Core/EmailCoreService.cs`
- [Archive entities](https://github.com/s1t5/mail-archiver/tree/main/Models): `Models`
- [Archive database](https://github.com/s1t5/mail-archiver/blob/main/Data/MailArchiverDbContext.cs): `Data/MailArchiverDbContext.cs`
- [Raw message storage](https://github.com/s1t5/mail-archiver/tree/main/Services/Shared): `Services/Shared`

### Archive features

- [Export and restore](https://github.com/s1t5/mail-archiver/tree/main/Services): `Services`
- [Invoice preview](https://github.com/s1t5/mail-archiver/blob/main/Services/EInvoicing/InvoicePdfService.cs): `Services/EInvoicing/InvoicePdfService.cs`
- [Retention policies](https://github.com/s1t5/mail-archiver/blob/main/Services/EmailDeletionService.cs): `Services/EmailDeletionService.cs`
- [Access logging](https://github.com/s1t5/mail-archiver/blob/main/Services/AccessLogService.cs): `Services/AccessLogService.cs`
- [Monitoring and stats](https://github.com/s1t5/mail-archiver/tree/main/Services/Monitoring): `Services/Monitoring`

### Application interfaces

- [Web controllers](https://github.com/s1t5/mail-archiver/tree/main/Controllers): `Controllers`
- [REST API](https://github.com/s1t5/mail-archiver/blob/main/Controllers/Api/V1/EmailsApiController.cs): `Controllers/Api/V1/EmailsApiController.cs`
- [MCP tools](https://github.com/s1t5/mail-archiver/tree/main/Mcp/Tools): `Mcp/Tools`

### Other components

- **User**

## Connections

- User → Web controllers: uses (evidence: `README.md`)
- Web controllers → Authentication: authenticates (evidence: `Auth/Handlers/AuthenticationHandler.cs`)
- Authentication → User services: looks up users (evidence: `Auth/Handlers/AuthenticationHandler.cs`)
- Web controllers → Account permissions: checks access (evidence: `Controllers/Api/ApiControllerBase.cs`)
- Web controllers → Mail accounts: manages accounts (evidence: `Controllers/MailAccountsController.cs`)
- Web controllers → Provider routing: selects provider (evidence: `Controllers/MailAccountsController.cs`)
- Provider routing → IMAP sync: routes IMAP (evidence: `Services/Factories/ProviderEmailServiceFactory.cs`)
- Provider routing → Graph provider: routes Graph (evidence: `Services/Factories/ProviderEmailServiceFactory.cs`)
- User → IMAP sync: syncs mail (evidence: `README.md`)
- IMAP sync → Email core: archives messages (evidence: `Services/Providers/Imap/ImapMailSyncService.cs`)
- Web controllers → Archive imports: starts imports (evidence: `Controllers/MailAccountsController.cs`)
- Web controllers → Email core: searches mail (evidence: `Controllers/EmailsController.cs`)
- Email core → Archive database: queries archive (evidence: `Services/Core/EmailCoreService.cs`)
- Email core → Raw message storage: uses raw store (evidence: `Services/Core/EmailCoreService.cs`)
- Archive database → Archive entities: maps entities (evidence: `Data/MailArchiverDbContext.cs`)
- Web controllers → Export and restore: exports and restores (evidence: `Controllers/EmailsController.cs`)
- REST API → Email core: queries mail (evidence: `Controllers/Api/V1/EmailsApiController.cs`)
- User → REST API: accesses archive (evidence: `README.md`)
- User → MCP tools: uses tools (evidence: `README.md`)
- Web controllers → Invoice preview: renders invoice (evidence: `Controllers/InvoicePreviewController.cs`)
- Invoice preview → Archive database: loads attachment (evidence: `Services/EInvoicing/InvoicePdfService.cs`)
- Web controllers → Retention policies: applies retention (evidence: `Controllers/EmailsController.cs`)
- Web controllers → Access logging: records activity (evidence: `README.md`)
- User → Monitoring and stats: views statistics (evidence: `README.md`)
