# mailserver2/mailserver architecture

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

- Interactive diagram: https://gitdiagram.com/mailserver2/mailserver
- Repository: https://github.com/mailserver2/mailserver

## Overview

##### Main Components Overview

**[External Email Servers] <---> [Traefik Reverse Proxy] <---> [Mail Server Container]**

- [Database] <-----------|
- [Redis] <--------------|

##### Detailed Component Architecture

**[Traefik Reverse Proxy]**

- > [Mail Server Container]

- > [Postfix] (SMTP Server)
- Handles incoming/outgoing email
- Port 25 (SMTP)
- Port 587 (Submission)
- Port 465 (SMTPS)

- > [Dovecot] (IMAP/POP3 Server)
- Handles email storage and retrieval
- Port 993 (IMAPS)
- Port 995 (POP3S)
- Port 4190 (ManageSieve)

- > [Rspamd] (Spam Filter)
- Anti-spam filtering
- DKIM/SPF/DMARC
- Web interface

- > [ClamAV] (Antivirus)
- Email virus scanning
- Auto-updates

- > [Unbound] (DNS Resolver)
- Local DNS resolution
- DNSSEC support

- > [Zeyple] (Email Encryption)
- GPG encryption

How email flows through the system:

**[Incoming Email] --> [Traefik] --> [Postfix]**

- v
- [Rspamd] --> [ClamAV]

- v
- [Dovecot] --> [Mail Storage]
- ^

**[IMAP Clients] -----------------> [Dovecot]**

##### Storage and Persistence

Persistent storage structure:

**[/mnt/docker/mail/]**

- > [postfix/] (Configuration and queues)
- > [dovecot/] (Email storage and config)
- > [clamav/] (Virus databases)
- > [rspamd/] (Spam filter data)
- > [ssl/] (SSL certificates)
- > [dkim/] (DKIM keys)
- > [vhosts/] (Virtual domains)

##### Authentication Flow

**[Email Client]**

- > [Dovecot Auth]

- v
- [Database/LDAP]

- v        v
**[Postfix] [Dovecot]**

- External services (blue)
- Internal components (green)
- Storage systems (yellow)
- Security components (red)

##### Ports and protocols
- SMTP (25, 465, 587)
- IMAP (143, 993)
- POP3 (110, 995)
- Management (4190)

##### Security layers
- SSL/TLS termination
- Spam filtering
- Virus scanning
- DKIM/SPF/DMARC verification

##### Data persistence
- Database connections
- Volume mounts
- Configuration storage

##### Monitoring and management interfaces
- Rspamd web interface
- Postfixadmin
- Rainloop webmail

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Environment"]
        ExtServers["External Email Servers"]
    end

    subgraph Proxy["Proxy Layer"]
        Traefik["Traefik Reverse Proxy"]
        SSL["SSL/TLS Certificates"]:::security
    end

    subgraph MailServer["Mail Server Container"]
        subgraph CoreServices["Core Mail Services"]
            Postfix["Postfix SMTP Server"]:::core
            Dovecot["Dovecot IMAP/POP3 Server"]:::core
        end

        subgraph SecurityServices["Security Services"]
            Rspamd["Rspamd Anti-spam"]:::security
            ClamAV["ClamAV Antivirus"]:::security
            Zeyple["Zeyple GPG Encryption"]:::security
        end

        subgraph FilteringServices["Filtering Services"]
            Sieve["Sieve Email Filtering"]:::filter
            Unbound["Unbound DNS Resolver"]:::filter
        end

        subgraph SystemServices["System Services"]
            S6["s6 Process Supervisor"]:::system
            Rsyslog["Rsyslog Logging"]:::system
        end
    end

    subgraph Storage["Storage Layer"]
        Database[(Database)]:::storage
        Redis[(Redis Cache)]:::storage
    end

    %% External Connections
    ExtServers <--> Traefik
    Traefik --> SSL
    
    %% Core Service Connections
    Traefik --> Postfix
    Postfix <--> Dovecot
    
    %% Security Service Connections
    Postfix --> Rspamd
    Postfix --> ClamAV
    Postfix --> Zeyple
    
    %% Filtering Service Connections
    Dovecot --> Sieve
    Postfix --> Unbound
    
    %% Storage Connections
    Postfix --> Database
    Dovecot --> Database
    Rspamd --> Redis
    
    %% System Service Connections
    S6 --> Postfix
    S6 --> Dovecot
    S6 --> Rspamd
    S6 --> ClamAV
    Rsyslog --> Postfix
    Rsyslog --> Dovecot

    %% Click Events
    click Postfix "https://github.com/mailserver2/mailserver/tree/master/rootfs/etc/postfix/"
    click Dovecot "https://github.com/mailserver2/mailserver/tree/master/rootfs/etc/dovecot/"
    click Rspamd "https://github.com/mailserver2/mailserver/tree/master/rootfs/etc/rspamd/"
    click ClamAV "https://github.com/mailserver2/mailserver/tree/master/rootfs/services/clamd/"
    click Zeyple "https://github.com/mailserver2/mailserver/blob/master/rootfs/usr/local/bin/zeyple.py"
    click Sieve "https://github.com/mailserver2/mailserver/tree/master/rootfs/etc/dovecot/sieve/"
    click Unbound "https://github.com/mailserver2/mailserver/tree/master/rootfs/etc/unbound/"
    click S6 "https://github.com/mailserver2/mailserver/tree/master/rootfs/services/"
    click Rsyslog "https://github.com/mailserver2/mailserver/tree/master/rootfs/etc/rsyslog/"
    click SSL "https://github.com/mailserver2/mailserver/tree/master/test/share/letsencrypt/"

    %% Styling
    classDef core fill:#2374ab
    classDef security fill:#ff7f50
    classDef filter fill:#ffd700
    classDef system fill:#98fb98
    classDef storage fill:#dda0dd

    %% Legend
    subgraph Legend
        CoreLegend["Core Services"]:::core
        SecurityLegend["Security Services"]:::security
        FilterLegend["Filtering Services"]:::filter
        SystemLegend["System Services"]:::system
        StorageLegend["Storage Services"]:::storage
    end
```
