# stdevpavelmc/mailad architecture

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

- Interactive diagram: https://gitdiagram.com/stdevpavelmc/mailad
- Repository: https://github.com/stdevpavelmc/mailad

## Overview

##### Main Components
- Provisioning & Configuration Scripts – These reside mainly in the top-level directories (like scripts and utils) and include Makefile integration. They are responsible for automatically setting up, upgrading, and managing configurations.
- Mail Services – The “var” directory clearly contains configurations and templates for key mail server components:
- Postfix (mail routing, SMTP handling, aliasing, and relay configurations)
- Dovecot (IMAP/POP3 for mail retrieval with separate folders for different versions indicating legacy and new configuration setups)
- Amavis (email content scanning, virus and spam filtering, and integration with ClamAV or Spamassassin)
- Active Directory Integration – The README and AD_Requirements.md point to integration with AD for authentication and alias management, plus scripts that handle LDAP and RSAT configuration.
- Auxiliary Components – These include backup scripts, configuration upgrade tools, monitoring scripts (feedback, test scripts for localhost/mailadmin), and language specific documentation in the “i18n” directory.
- Supporting Files – These cover things like licensing, contributors, FAQ, and installation guidelines which help understand operational requirements.

##### Relationships & Interactions
- Provisioning process: At deployment the Makefile and setup scripts read from configuration files (e.g., common.conf, mailad.conf) to apply settings across the various services.
- AD Communication: There is a linkage between the mail server and AD (either Samba or Windows) to enforce user validation and to ensure email usernames meet AD constraints.
- Backup & Upgrade: Scripts facilitate config backups, restoration, and even dynamic configuration adjustments based on network storage (e.g., using NFS for /home/vmail).

##### Architectural Patterns & Design Principles
- Separation of Concerns: The configuration files, scripts, and service configurations are neatly separated into grouped directories (e.g., “var” for runtime mail components, “scripts” for provisioning tasks). This reflects a modular, loosely coupled design.
- Extensibility & Robustness: The design accommodates various layers of security (firewall, mail gateway recommendations) and integration patterns (AD and local user management, backup/restore routines).
- Use of Standard Technologies: The system leverages known, tested mail server applications (Postfix, Dovecot, Amavis) and standard security practices (encrypted LDAP, careful configuration of ports).

##### Relevant Technologies and Frameworks
- Mail Transmission Agents: Postfix for SMTP.
- Mail Retrieval & Storage: Dovecot and Vmail (configured in /home/vmail).
- Content Filtering: Amavis with its various configuration templates and ClamAV/Spamassassin integrations.
- AD Integration: LDAP/Samba/Windows AD connectivity and RSAT requirements.
- Scripting & Automation: Shell scripts (located under scripts/ and utils/) integrated into a Makefile process for provision automation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Provisioning & Configuration Layer
    subgraph "Provisioning & Configuration Layer"
        MF["Makefile"]:::provisioning
        SCR["Scripts"]:::provisioning
        UTL["Utils"]:::provisioning
        PENG["Provisioning Engine"]:::provisioning
        MF --> PENG
        SCR --> PENG
        UTL --> PENG
    end

    %% Mail Service Layer
    subgraph "Mail Service Layer"
        PP["Postfix"]:::service
        DV22["Dovecot 2.2"]:::service
        DV23["Dovecot 2.3"]:::service
        AM["Amavis"]:::service
        CL["ClamAV"]:::service
        SA["Spamassassin"]:::service
        PP -->|"configures"| DV22
        PP -->|"configures"| DV23
        AM -->|"integrates"| CL
        AM -->|"integrates"| SA
    end

    %% Active Directory Integration (External)
    AD["Active Directory (LDAP/AD)"]:::external
    AD_S["TestLDAPBinding"]:::external
    AD_U["ADUpgrade"]:::external
    AD_S --> AD
    AD_U --> AD

    %% Auxiliary Tools
    subgraph "Auxiliary Tools"
        BACK["Backup & Restore"]:::aux
        UPGR["Upgrade Scripts"]:::aux
        MON["Monitoring Scripts"]:::aux
        DISC["Disclaimer Management"]:::aux
    end

    %% Documentation and Internationalization
    DOC["Internationalization & Documentation"]:::docs

    %% Backend Storage
    BS["Backend Storage (/home/vmail)"]:::storage

    %% Connections between layers
    PENG -->|"configures"| PP
    PENG -->|"configures"| DV22
    PENG -->|"configures"| DV23
    PENG -->|"configures"| AM

    PP -->|"authenticates_with"| AD
    DV22 -->|"authenticates_with"| AD
    DV23 -->|"authenticates_with"| AD
    PENG -->|"sets_AD_params"| AD

    BACK -->|"stores_backup_in"| BS
    UPGR -->|"updates"| PP
    UPGR -->|"updates"| DV22
    UPGR -->|"updates"| DV23
    UPGR -->|"updates"| AM

    MON -->|"reports_to"| DOC

    %% Click Events for Provisioning & Configuration
    click MF "https://github.com/stdevpavelmc/mailad/tree/master/Makefile"
    click SCR "https://github.com/stdevpavelmc/mailad/blob/master/scripts/provision.sh"
    click UTL "https://github.com/stdevpavelmc/mailad/blob/master/utils/samba_scaffold.sh"

    %% Click Events for Mail Services
    click PP "https://github.com/stdevpavelmc/mailad/tree/master/var/postfix"
    click DV22 "https://github.com/stdevpavelmc/mailad/blob/master/var/dovecot-2.2"
    click DV23 "https://github.com/stdevpavelmc/mailad/blob/master/var/dovecot-2.3"
    click AM "https://github.com/stdevpavelmc/mailad/tree/master/var/amavis"

    %% Click Events for Active Directory Integration
    click AD "https://github.com/stdevpavelmc/mailad/blob/master/AD_Requirements.md"
    click AD_S "https://github.com/stdevpavelmc/mailad/blob/master/scripts/test_bind_dn.sh"
    click AD_U "https://github.com/stdevpavelmc/mailad/blob/master/utils/upgrade_simple_ad.sh"

    %% Click Events for Auxiliary Tools
    click BACK "https://github.com/stdevpavelmc/mailad/blob/master/scripts/backup.sh"
    click UPGR "https://github.com/stdevpavelmc/mailad/blob/master/scripts/confupgrade.sh"
    click MON "https://github.com/stdevpavelmc/mailad/blob/master/scripts/feedback.sh"
    click DISC "https://github.com/stdevpavelmc/mailad/tree/master/var/disclaimer_related"

    %% Click Event for Documentation & Internationalization
    click DOC "https://github.com/stdevpavelmc/mailad/tree/master/i18n/"

    %% Styles
    classDef provisioning fill:#fce94f,stroke:#555,stroke-width:2px;
    classDef service fill:#8ae234,stroke:#555,stroke-width:2px;
    classDef external fill:#729fcf,stroke:#555,stroke-width:2px;
    classDef aux fill:#ad7fa8,stroke:#555,stroke-width:2px;
    classDef docs fill:#ef2929,stroke:#555,stroke-width:2px;
    classDef storage fill:#f9c74f,stroke:#555,stroke-width:2px;
```
