# processone/ejabberd architecture

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

- Interactive diagram: https://gitdiagram.com/processone/ejabberd
- Repository: https://github.com/processone/ejabberd

## Overview

##### Main Components
- Core Server Engine: Represent the heart of ejabberd, the ejabberd daemon (with its main application in src/ejabberd.erl). This is the supervisor that brings up various OTP processes.
- Protocol Handlers:
- XMPP Server – handling client-to-server (C2S) and server-to-server (S2S) communications (modules like ejabberd_c2s.erl, ejabberd_s2s.erl, etc.).
- MQTT Broker – indicated by modules such as src/mod_mqtt.erl and related MQTT bridge/session processes.
- SIP Service – with modules like ejabberd_sip.erl.
- Modular Extensions: Numerous modules (under src and plugins) manage various XMPP features like presence, roster, multi-user chat (MUC), pubsub, and more (for instance, mod_muc, mod_pubsub, mod_vcard, etc.).
- Administration & Web Interfaces: Include components for the web admin interface (ejabberd_web_admin.erl, ejabberd_web.erl) plus HTTP and websocket support.
- Authentication and Security: A collection of auth backends such as mod_auth and external auth modules (auth modules for anonymous, LDAP, SQL, PAM, etc.).
- Persistence Layer: Two primary stores are used:
- Mnesia (Erlang’s in-memory database) as seen in several _mnesia modules.
- SQL databases – there is a whole sql directory with scripts for MySQL, PostgreSQL, Microsoft SQL, and SQLite.
- Additional services like Redis integration (ejabberd_redis.erl, ejabberd_redis_sup.erl) can also be shown.
- Configuration & Logging:
- Dynamic config handling (many modules under lib/ejabberd/config and config files under config/).
- Dedicated logging modules (ejabberd_logger.erl, and the logger sub-directory in lib).
- Clustering and Supervision: Highlight modules for clusters, distributed supervision (e.g., ejabberd_cluster.erl and ejabberd_cluster_mnesia.erl) that allow horizontal scaling.
- Tools & Deployment:
- Containerization and build scripts (Dockerfiles in .devcontainer and .github/container, Makefile.in, autogen.sh).
- Developer utilities (scripts in tools/ for generating binaries, installers, etc.).

##### Out Interactions and Relationships
- Core server engine (ejabberd daemon) orchestrating various modules via OTP supervision trees.
- Data flow from messaging and presence between the protocol handlers and persistence layers (Mnesia, SQL, Redis).
- Encompass the clustering layer to show how multiple ejabberd instances can interact and synchronize state for scalability.

##### Architectural Patterns and Design Principles
- Modularity: Each XMPP feature is encapsulated as a separate module, facilitating extensibility.
- Use of OTP’s supervision trees for fault-tolerance and process monitoring.
- Separation of concerns: Different directories for configuration, core business logic (in src and lib), and external interfaces.
- Aspects of containerized deployment, reflecting the multiple Docker configuration files.

– Communication interfaces (network protocols)
– Backend processes and modules (Erlang/OTP components)
– External services and storage (databases, container orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        ext1["XMPP Client"]:::client
        ext2["MQTT Client"]:::client
        ext3["SIP Client"]:::client
    end

    %% Protocol Handlers
    subgraph "Protocol Handlers"
        p1["XMPP C2S"]:::protocol
        p2["XMPP S2S"]:::protocol
        p21["XMPP S2S In"]:::protocol
        p22["XMPP S2S Out"]:::protocol
        p3["MQTT Broker"]:::protocol
        p31["MQTT Bridge"]:::protocol
        p32["MQTT Session"]:::protocol
        p4["SIP Service (Core)"]:::protocol
        p41["SIP Module"]:::protocol
    end

    %% Core Processing
    subgraph "Core Processing"
        core["Core Server Engine"]:::core
    end

    %% Modular Extensions
    subgraph "Modular Extensions"
        mod1["MUC Module"]:::extension
        mod2["MUC Room"]:::extension
        mod3["PubSub Module"]:::extension
        mod4["VCard Module"]:::extension
        mod5["Other Modules & Plugins"]:::extension
    end

    %% Administration & Interfaces
    subgraph "Administration & Interfaces"
        admin1["Web Admin Interface"]:::admin
        admin2["Web Interface"]:::admin
    end

    %% Authentication & Security
    subgraph "Authentication"
        auth1["Core Auth"]:::auth
        auth2["Auth Anonymous"]:::auth
        auth3["Auth External"]:::auth
        auth4["Auth LDAP"]:::auth
        auth5["Auth Mnesia"]:::auth
        auth6["Auth PAM"]:::auth
        auth7["Auth SQL"]:::auth
        auth8["Auth Headers"]:::auth
    end

    %% Persistence Layer
    subgraph "Persistence"
        pers1["Mnesia Integration"]:::persistence
        pers2["SQL Integration"]:::persistence
        pers3["Redis Integration"]:::persistence
    end

    %% Configuration & Logging
    subgraph "Configuration & Logging"
        conf["Configuration"]:::config
        log["Logging"]:::config
    end

    %% Clustering & Supervision
    subgraph "Clustering & Supervision"
        cluster["Clustering"]:::cluster
        sup["Supervision"]:::cluster
    end

    %% Tools & Deployment
    subgraph "Tools & Deployment"
        cont["Containerization"]:::tools
        build["Build Scripts"]:::tools
        devtools["Developer Tools"]:::tools
    end

    %% Connections from External Clients to Protocol Handlers
    ext1 -->|"to"| p1
    ext1 -->|"to"| p2
    ext2 -->|"to"| p3
    ext3 -->|"to"| p4

    %% Connections from Protocol Handlers to Core Processing
    p1 -->|"invokes"| core
    p2 -->|"invokes"| core
    p21 -->|"partOf"| p2
    p22 -->|"partOf"| p2
    p3 -->|"invokes"| core
    p31 -->|"submodule"| p3
    p32 -->|"submodule"| p3
    p4 -->|"invokes"| core
    p41 -->|"submodule"| p4

    %% Core Processing to other subsystems
    core -->|"loads"| mod1
    core -->|"loads"| auth1
    core -->|"loads"| pers1
    core -->|"manages"| admin1
    core -->|"reads"| conf
    core -->|"coordinates"| cluster
    core -->|"triggers"| cont

    %% Internal flows
    mod1 -->|"extends"| mod2
    admin1 -->|"interfaces"| admin2
    auth1 -->|"integratesWith"| auth2
    auth1 -->|"integratesWith"| auth3
    auth1 -->|"integratesWith"| auth4
    auth1 -->|"integratesWith"| auth5
    auth1 -->|"integratesWith"| auth6
    auth1 -->|"integratesWith"| auth7
    auth1 -->|"integratesWith"| auth8
    pers1 -->|"syncsWith"| pers2
    pers1 -->|"syncsWith"| pers3
    cluster -->|"monitors"| sup

    %% Click Events
    click core "https://github.com/processone/ejabberd/blob/master/src/ejabberd.erl"
    click p1 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_c2s.erl"
    click p2 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_s2s.erl"
    click p21 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_s2s_in.erl"
    click p22 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_s2s_out.erl"
    click p3 "https://github.com/processone/ejabberd/blob/master/src/mod_mqtt.erl"
    click p31 "https://github.com/processone/ejabberd/blob/master/src/mod_mqtt_bridge.erl"
    click p32 "https://github.com/processone/ejabberd/blob/master/src/mod_mqtt_session.erl"
    click p4 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_sip.erl"
    click p41 "https://github.com/processone/ejabberd/blob/master/src/mod_sip.erl"
    click mod1 "https://github.com/processone/ejabberd/blob/master/src/mod_muc.erl"
    click mod2 "https://github.com/processone/ejabberd/blob/master/src/mod_muc_room.erl"
    click mod3 "https://github.com/processone/ejabberd/blob/master/src/mod_pubsub.erl"
    click mod4 "https://github.com/processone/ejabberd/blob/master/src/mod_vcard.erl"
    click mod5 "https://github.com/processone/ejabberd/tree/master/plugins/"
    click admin1 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_web_admin.erl"
    click admin2 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_web.erl"
    click auth1 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth.erl"
    click auth2 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth_anonymous.erl"
    click auth3 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth_external.erl"
    click auth4 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth_ldap.erl"
    click auth5 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth_mnesia.erl"
    click auth6 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth_pam.erl"
    click auth7 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_auth_sql.erl"
    click auth8 "https://github.com/processone/ejabberd/blob/master/include/ejabberd_auth.hrl"
    click pers1 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_mnesia.erl"
    click pers2 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_sql.erl"
    click pers2 "https://github.com/processone/ejabberd/tree/master/sql/"
    click pers3 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_redis.erl"
    click pers3 "https://github.com/processone/ejabberd/blob/master/src/ejabberd_redis_sup.erl"
    click conf "https://github.com/processone/ejabberd/tree/master/config/"
    click log "https://github.com/processone/ejabberd/blob/master/src/ejabberd_logger.erl"
    click cluster "https://github.com/processone/ejabberd/blob/master/src/ejabberd_cluster.erl"
    click sup "https://github.com/processone/ejabberd/blob/master/src/ejabberd_sup.erl"
    click cont "https://github.com/processone/ejabberd/tree/master/.devcontainer/"
    click build "https://github.com/processone/ejabberd/blob/master/Makefile.in"
    click devtools "https://github.com/processone/ejabberd/tree/master/tools/"

    %% Styles
    classDef client fill:#bbf,stroke:#333,stroke-width:2px;
    classDef protocol fill:#f96,stroke:#333,stroke-width:2px;
    classDef core fill:#fb8,stroke:#333,stroke-width:2px;
    classDef extension fill:#cfc,stroke:#333,stroke-width:2px;
    classDef admin fill:#ccf,stroke:#333,stroke-width:2px;
    classDef auth fill:#fc9,stroke:#333,stroke-width:2px;
    classDef persistence fill:#c9f,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;
    classDef cluster fill:#fcc,stroke:#333,stroke-width:2px;
    classDef tools fill:#ccc,stroke:#333,stroke-width:2px;
```
