# mailcow/mailcow-dockerized architecture

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

- Interactive diagram: https://gitdiagram.com/mailcow/mailcow-dockerized
- Repository: https://github.com/mailcow/mailcow-dockerized

## Overview

#### Purpose and Deployment Entry Points
mailcow: dockerized is a self-hosted mail-server stack packaged as coordinated Docker Compose services. Operational entry points are `docker-compose.yml`, initial environment/config generation via `generate_config.sh`, lifecycle/update automation in `update.sh`, and cold-standby provisioning through `create_cold_standby.sh`.

#### Compose-Orchestrated Service Boundary
`docker-compose.yml` is the system integration boundary: it wires separately built mail, web, storage, security, DNS, certificate, and operations containers. Service images are defined under `data/Dockerfiles/`; optional deployment topology/features are supplied as Compose overrides under `helper-scripts/docker-compose.override.yml.d/`, including HAProxy, external DNS/MySQL socket, and Prometheus exporter variants.

#### Mail Transport and Delivery Pipeline
Inbound/outbound SMTP traffic is handled by Postfix, with its container startup and transport behavior in `data/Dockerfiles/postfix/docker-entrypoint.sh` and `data/Dockerfiles/postfix/postfix.sh`; base MTA policy is in `data/conf/postfix/main.cf`. Mail passes through Rspamd-based filtering and ClamAV scanning before Dovecot mailbox storage/access. TLS-policy support is separated into `data/Dockerfiles/postfix-tlspol/`.

#### Mailbox, Groupware, and Data Services
Dovecot provides IMAP/mailbox functions, Sieve-related processing, quota/quarantine notifications, and maintenance jobs; its runtime boundary begins at `data/Dockerfiles/dovecot/docker-entrypoint.sh` and configuration is rooted at `data/conf/dovecot/dovecot.conf`. SOGo supplies groupware/webmail integration via `data/Dockerfiles/sogo/docker-entrypoint.sh` and `data/conf/sogo/sogo.conf`. MySQL configuration and initialization assets reside in `data/conf/mysql/my.cnf` and `data/assets/mysql/docker-entrypoint.sh`; Redis configuration is under `data/conf/redis/`.

#### Filtering, DNS, Certificates, and Network Enforcement
Rspamd is the central spam-policy engine, configured through `data/conf/rspamd/rspamd.conf.local` and rule fragments such as `data/conf/rspamd/local.d/actions.conf`; dynamic maps bridge filtering decisions to PHP-backed administrative data. Unbound provides internal DNS resolution (`data/Dockerfiles/unbound/docker-entrypoint.sh`, `data/conf/unbound/unbound.conf`). ACME certificate acquisition/renewal is encapsulated by `data/Dockerfiles/acme/obtain-certificate.sh`. Network enforcement is delegated to a privileged netfilter service supporting iptables/nftables in `data/Dockerfiles/netfilter/main.py`.

#### Web Administration and API Control Plane
Nginx fronts the PHP-FPM application; templated proxy configuration is in `data/conf/nginx/templates/nginx.conf.j2`, with container bootstrap at `data/Dockerfiles/nginx/bootstrap.py`. The PHP application serves administrator, domain-admin, and user interfaces from `data/web/`, with shared initialization/database access in `data/web/inc/init_db.inc.php`. Its primary machine interface is `data/web/json_api.php`, documented by `data/web/api/openapi.yaml`; OAuth endpoints are under `data/web/oauth/`.

#### Operations, Docker Control, and Extensibility
The Docker API service (`data/Dockerfiles/dockerapi/main.py`) exposes controlled container operations to the management plane, while Watchdog performs service/DNS/database health checks through `data/Dockerfiles/watchdog/watchdog.sh`. Backup is a dedicated container defined by `data/Dockerfiles/backup/Dockerfile`, with operator workflows in `helper-scripts/backup_and_restore.sh`. Administrators can inject runtime extensions through service-specific hook directories under `data/hooks/`, avoiding direct modification of container images or base configuration.

Main entry points: [`docker-compose.yml`](https://github.com/mailcow/mailcow-dockerized/blob/master/docker-compose.yml) (Docker Compose), [`data/web/index.php`](https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/index.php) (PHP administration), [`data/Dockerfiles/postfix/docker-entrypoint.sh`](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/postfix/docker-entrypoint.sh) (Postfix), [`data/assets/mysql/docker-entrypoint.sh`](https://github.com/mailcow/mailcow-dockerized/blob/master/data/assets/mysql/docker-entrypoint.sh) (MySQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ops["Deployment &amp; Operations"]
  node_compose{{"Docker Compose<br/>service orchestration<br/>[docker-compose.yml]"}}
  node_config["Config generator<br/>bootstrap script<br/>[generate_config.sh]"]
  node_updates["Update automation<br/>lifecycle script<br/>[update.sh]"]
  node_standby["Cold standby<br/>provisioning script"]
  node_overrides["Compose overrides<br/>deployment variants"]
  node_watchdog["Watchdog<br/>health monitoring<br/>[watchdog.sh]"]
  node_backup["Backup service<br/>backup container"]
  node_hooks["Runtime hooks<br/>extension points<br/>[README.md]"]
end

subgraph group_mail["Mail Processing"]
  node_postfix["Postfix<br/>SMTP transport"]
  node_rspamd["Rspamd<br/>spam policy<br/>[rspamd.conf.local]"]
  node_clamav["ClamAV<br/>malware scanner<br/>[clamd.sh]"]
  node_tlspol["TLS policy"]
end

subgraph group_data["Mailbox &amp; Application Data"]
  node_dovecot["Dovecot<br/>IMAP and mailbox service"]
  node_sogo["SOGo<br/>groupware"]
  node_mysql[("MySQL<br/>relational database")]
  node_redis[("Redis<br/>cache datastore<br/>[redis-conf.sh]")]
end

subgraph group_control["Web Control Plane"]
  node_nginx["Nginx<br/>web proxy<br/>[bootstrap.py]"]
  node_phpapp["PHP administration<br/>management application<br/>[index.php]"]
  node_api["JSON API &amp; OAuth<br/>machine interface<br/>[json_api.php]"]
  node_dockerapi["Docker API<br/>container control<br/>[main.py]"]
end

subgraph group_infra["Network &amp; Trust Services"]
  node_unbound["Unbound<br/>internal DNS"]
  node_acme["ACME<br/>certificate automation"]
  node_netfilter["Netfilter<br/>network enforcement<br/>[main.py]"]
end

node_config -->|"generates environment for"| node_compose
node_updates -->|"updates"| node_compose
node_standby -->|"provisions"| node_compose
node_overrides -.->|"extends"| node_compose
node_compose -->|"orchestrates"| node_postfix
node_compose -->|"orchestrates"| node_dovecot
node_compose -->|"orchestrates"| node_nginx
node_compose -->|"orchestrates"| node_mysql
node_postfix -->|"filters mail through"| node_rspamd
node_rspamd -->|"scans with"| node_clamav
node_rspamd -->|"delivers filtered mail to"| node_dovecot
node_postfix -->|"uses"| node_tlspol
node_dovecot -->|"uses metadata"| node_mysql
node_sogo -->|"accesses mailboxes via"| node_dovecot
node_sogo -->|"uses"| node_mysql
node_nginx -->|"proxies to"| node_phpapp
node_phpapp -->|"exposes"| node_api
node_phpapp -->|"reads and writes"| node_mysql
node_phpapp -->|"uses"| node_redis
node_phpapp -->|"controls containers through"| node_dockerapi
node_postfix -->|"resolves through"| node_unbound
node_acme -->|"supplies certificates to"| node_nginx
node_netfilter -->|"enforces network policy for"| node_postfix
node_watchdog -.->|"monitors services"| node_compose
node_backup -->|"backs up"| node_mysql
node_hooks -.->|"extends service runtime"| node_compose

click node_compose "https://github.com/mailcow/mailcow-dockerized/blob/master/docker-compose.yml"
click node_config "https://github.com/mailcow/mailcow-dockerized/blob/master/generate_config.sh"
click node_updates "https://github.com/mailcow/mailcow-dockerized/blob/master/update.sh"
click node_standby "https://github.com/mailcow/mailcow-dockerized/blob/master/create_cold_standby.sh"
click node_overrides "https://github.com/mailcow/mailcow-dockerized/blob/master/helper-scripts/docker-compose.override.yml.d/BUILD_FLAGS/docker-compose.override.yml"
click node_postfix "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/postfix/docker-entrypoint.sh"
click node_rspamd "https://github.com/mailcow/mailcow-dockerized/blob/master/data/conf/rspamd/rspamd.conf.local"
click node_clamav "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/clamd/clamd.sh"
click node_tlspol "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/postfix-tlspol/docker-entrypoint.sh"
click node_dovecot "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/dovecot/docker-entrypoint.sh"
click node_sogo "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/sogo/docker-entrypoint.sh"
click node_mysql "https://github.com/mailcow/mailcow-dockerized/blob/master/data/assets/mysql/docker-entrypoint.sh"
click node_redis "https://github.com/mailcow/mailcow-dockerized/blob/master/data/conf/redis/redis-conf.sh"
click node_nginx "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/nginx/bootstrap.py"
click node_phpapp "https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/index.php"
click node_api "https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/json_api.php"
click node_dockerapi "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/dockerapi/main.py"
click node_unbound "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/unbound/docker-entrypoint.sh"
click node_acme "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/acme/obtain-certificate.sh"
click node_netfilter "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/netfilter/main.py"
click node_watchdog "https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/watchdog/watchdog.sh"
click node_backup "https://github.com/mailcow/mailcow-dockerized/tree/master/data/Dockerfiles/backup/Dockerfile"
click node_hooks "https://github.com/mailcow/mailcow-dockerized/blob/master/data/hooks/README.md"

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_compose,node_config,node_updates,node_standby,node_overrides,node_watchdog,node_backup,node_hooks toneBlue
class node_postfix,node_rspamd,node_clamav,node_tlspol toneAmber
class node_dovecot,node_sogo,node_mysql,node_redis toneMint
class node_nginx,node_phpapp,node_api,node_dockerapi toneRose
class node_unbound,node_acme,node_netfilter toneIndigo
```

## Components

### Deployment & Operations

- [Docker Compose](https://github.com/mailcow/mailcow-dockerized/blob/master/docker-compose.yml): service orchestration · Integration boundary for all stack containers. · `docker-compose.yml`
- [Config generator](https://github.com/mailcow/mailcow-dockerized/blob/master/generate_config.sh): bootstrap script · `generate_config.sh`
- [Update automation](https://github.com/mailcow/mailcow-dockerized/blob/master/update.sh): lifecycle script · `update.sh`
- [Cold standby](https://github.com/mailcow/mailcow-dockerized/blob/master/create_cold_standby.sh): provisioning script · `create_cold_standby.sh`
- [Compose overrides](https://github.com/mailcow/mailcow-dockerized/blob/master/helper-scripts/docker-compose.override.yml.d/BUILD_FLAGS/docker-compose.override.yml): deployment variants · Optional HAProxy, external-service, and Prometheus topologies. · `helper-scripts/docker-compose.override.yml.d/BUILD_FLAGS/docker-compose.override.yml`
- [Watchdog](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/watchdog/watchdog.sh): health monitoring · Checks service, DNS, and database health. · `data/Dockerfiles/watchdog/watchdog.sh`
- [Backup service](https://github.com/mailcow/mailcow-dockerized/tree/master/data/Dockerfiles/backup/Dockerfile): backup container · `data/Dockerfiles/backup/Dockerfile`
- [Runtime hooks](https://github.com/mailcow/mailcow-dockerized/blob/master/data/hooks/README.md): extension points · Service-specific operator extensions without image changes. · `data/hooks/README.md`

### Mail Processing

- [Postfix](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/postfix/docker-entrypoint.sh): SMTP transport · Handles inbound and outbound SMTP transport. · `data/Dockerfiles/postfix/docker-entrypoint.sh`
- [Rspamd](https://github.com/mailcow/mailcow-dockerized/blob/master/data/conf/rspamd/rspamd.conf.local): spam policy · Applies filtering policy and administrative data-backed maps. · `data/conf/rspamd/rspamd.conf.local`
- [ClamAV](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/clamd/clamd.sh): malware scanner · `data/Dockerfiles/clamd/clamd.sh`
- [TLS policy](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/postfix-tlspol/docker-entrypoint.sh): MTA TLS policy · `data/Dockerfiles/postfix-tlspol/docker-entrypoint.sh`

### Mailbox & Application Data

- [Dovecot](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/dovecot/docker-entrypoint.sh): IMAP and mailbox service · Provides mailbox access, Sieve processing, and maintenance jobs. · `data/Dockerfiles/dovecot/docker-entrypoint.sh`
- [SOGo](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/sogo/docker-entrypoint.sh): groupware · Provides webmail and groupware integration. · `data/Dockerfiles/sogo/docker-entrypoint.sh`
- [MySQL](https://github.com/mailcow/mailcow-dockerized/blob/master/data/assets/mysql/docker-entrypoint.sh): relational database · `data/assets/mysql/docker-entrypoint.sh`
- [Redis](https://github.com/mailcow/mailcow-dockerized/blob/master/data/conf/redis/redis-conf.sh): cache datastore · `data/conf/redis/redis-conf.sh`

### Web Control Plane

- [Nginx](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/nginx/bootstrap.py): web proxy · Fronts the PHP administration application. · `data/Dockerfiles/nginx/bootstrap.py`
- [PHP administration](https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/index.php): management application · Serves administrator, domain-admin, and user interfaces. · `data/web/index.php`
- [JSON API & OAuth](https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/json_api.php): machine interface · Programmatic management and OAuth endpoints. · `data/web/json_api.php`
- [Docker API](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/dockerapi/main.py): container control · Provides controlled container operations to management services. · `data/Dockerfiles/dockerapi/main.py`

### Network & Trust Services

- [Unbound](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/unbound/docker-entrypoint.sh): internal DNS · `data/Dockerfiles/unbound/docker-entrypoint.sh`
- [ACME](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/acme/obtain-certificate.sh): certificate automation · Obtains and renews certificates. · `data/Dockerfiles/acme/obtain-certificate.sh`
- [Netfilter](https://github.com/mailcow/mailcow-dockerized/blob/master/data/Dockerfiles/netfilter/main.py): network enforcement · Privileged iptables/nftables enforcement service. · `data/Dockerfiles/netfilter/main.py`

## Connections

- Config generator → Docker Compose: generates environment for
- Update automation → Docker Compose: updates
- Cold standby → Docker Compose: provisions
- Compose overrides → Docker Compose: extends
- Docker Compose → Postfix: orchestrates
- Docker Compose → Dovecot: orchestrates
- Docker Compose → Nginx: orchestrates
- Docker Compose → MySQL: orchestrates
- Postfix → Rspamd: filters mail through
- Rspamd → ClamAV: scans with
- Rspamd → Dovecot: delivers filtered mail to
- Postfix → TLS policy: uses
- Dovecot → MySQL: uses metadata
- SOGo → Dovecot: accesses mailboxes via
- SOGo → MySQL: uses
- Nginx → PHP administration: proxies to
- PHP administration → JSON API & OAuth: exposes
- PHP administration → MySQL: reads and writes
- PHP administration → Redis: uses
- PHP administration → Docker API: controls containers through
- Postfix → Unbound: resolves through
- ACME → Nginx: supplies certificates to
- Netfilter → Postfix: enforces network policy for
- Watchdog → Docker Compose: monitors services
- Backup service → MySQL: backs up
- Runtime hooks → Docker Compose: extends service runtime
