# ortuman/jackal architecture

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

- Interactive diagram: https://gitdiagram.com/ortuman/jackal
- Repository: https://github.com/ortuman/jackal

## Overview

##### Project Type and Purpose
- jackal is an XMPP server focused on high performance, stability, and low resource utilization.
- It supports core XMPP specifications (both client-to-server and server-to-server protocols) as well as advanced features like clustering with etcd, stream compression, TLS security, and extensibility via gRPC APIs.
- The project also includes deployment support (Docker, Docker Compose, Helm) and various configuration options for different storage backends (PostgreSQL, BoltDB) and caching (Redis).

##### Analyzing the File Structure
- Top-level directories:
– cmd: Contains main binaries for the core server (jackal) and control tool (jackalctl). This separation indicates dedicated entry points for service execution and administrative tasks.
– pkg: Houses the bulk of the server’s functionality. Look at packages like:
▸ pkg/jackal – Core XMPP server logic.
▸ pkg/auth – Authentication logic (with both standard and external interfaces).
▸ pkg/c2s – Implements client-to-server communication protocols.
▸ pkg/s2s – Deals with server-to-server interactions.
▸ pkg/cluster – Handles clustering, distributed state sharing (with etcd integration, memberlist management, component routing).
▸ pkg/module – Framework for extensibility, allowing third-party or additional internal modules via gRPC.
▸ pkg/storage – Abstractions and implementations for different storage backends (PostgreSQL, BoltDB, caching via Redis, and others).
▸ pkg/transport, pkg/router, pkg/util, etc. – Provide support functionality (compression, TLS, string matching, XMPP utilities).
– proto: Contains protocol buffer definitions for various interfaces (admin, c2s, cluster, and more), reinforcing the project’s modular and extensible design.
– helm, dockerfiles, config, and sql: Support deployment, configuration, and database initialization.

##### Key Components
A. Client Layer:
– XMPP Clients: Their connections flow into the server via standard ports (e.g., 5222 for client connections).
B. Core Server and Communication Components:
– Frontend Server (jackal binary running from cmd/jackal): Handles incoming XMPP streams.
– Authentication Module (pkg/auth): Validates and processes user credentials, integrates with external authentication if needed.
– Client-to-Server (c2s) and Server-to-Server (s2s) modules: Manage message routing and protocol adherence.
– Routing and Stream Management (pkg/router and pkg/s2s/router): Handle message delivery, presence, and related communications.
C. Distributed/Clustering Layer:
– Cluster Components (pkg/cluster): Illustrate components handling connection management, member list communication, key/value storage (with etcd integration), and stream management.
D. Storage and Persistence Layer:
– Persistent Storage: Represent both PostgreSQL and BoltDB (as configured), including caching via Redis.
– Storage Abstraction: Show that the server interacts with storage through the pkg/storage interfaces, with specific implementations for each storage technology.
E. Extensibility and Module Framework:
– External Modules (pkg/module): Indicate integration points for additional features (following XMPP component protocols and gRPC APIs, with proto definitions from the proto directory).
F. Administrative and Monitoring Tools:
– jackalctl: Acts as the command-line management tool.
– Monitoring: Include Prometheus metrics exposition and Grafana dashboards (monitoring/grafana-dashboards).
G. Deployment and Configuration:
– Docker Deployment: Illustrate the containerized deployment paths (Dockerfile and docker-compose setups).
– Helm Charts: Represent Kubernetes deployment and configuration management (helm directory).

##### Architectural Patterns & Design Principles
- Modularity: The clear separation of responsibilities into packages (auth, cluster, storage, module, etc.) supports a modular architecture.
- Extensibility: The plugin and module pattern allows new features or integrations to be added with minimal disturbance to core functionality.
- Distributed Systems: The design supports clustering via distributed key-value stores (etcd) and memberlist management which is crucial for fault tolerance and scalability.
- Configuration-Driven Deployment: Multiple configuration files and scripts indicate that the system’s behavior can be tuned via configuration (e.g., the config directory, Docker Compose, Helm values).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        CL["XMPP Client"]:::client
    end

    subgraph "Core Processing"
        S["jackal Server Core"]:::core
        A["Authentication Module"]:::module
        C2S["Client-to-Server Communication"]:::module
        S2S["Server-to-Server Communication"]:::module
        R["Routing & Stream Management"]:::module
    end

    subgraph "Distributed & Extensibility"
        CLUSTER["Clustering Manager"]:::cluster
        EXT["Extensibility Module"]:::module
        PROTO["Protocol Definitions"]:::proto
    end

    subgraph "Storage Layer"
        STORAGE["Storage Abstraction"]:::storage
        P["Persistent Storage (PostgreSQL/BoltDB)"]:::storage
        REDIS["Redis Cache"]:::storage
    end

    subgraph "Administrative & Monitoring"
        ADMIN["jackalctl Admin Tool"]:::admin
        subgraph "Deployment & Configuration"
            DOCK["Docker Deployment"]:::deployment
            HELM["Helm Charts"]:::deployment
        end
        MON["Monitoring & Grafana Dashboards"]:::monitoring
    end

    %% Connections
    CL -->|"connects"| S
    S -->|"calls"| A
    S -->|"handles"| C2S
    S -->|"handles"| S2S
    S -->|"routes"| R
    S -->|"syncs with"| CLUSTER
    S -->|"integrates"| EXT
    EXT -->|"uses"| PROTO

    A ---|"persists to"| STORAGE
    C2S ---|"persists to"| STORAGE
    S2S ---|"persists to"| STORAGE
    R ---|"persists to"| STORAGE
    CLUSTER ---|"persists to"| STORAGE
    EXT ---|"persists to"| STORAGE
    STORAGE -->|"stores in"| P
    STORAGE -->|"caches in"| REDIS

    ADMIN -->|"manages"| S
    DOCK -->|"deploys"| S
    HELM -->|"deploys"| S
    MON -->|"monitors"| S

    %% Click Events
    click S "https://github.com/ortuman/jackal/blob/main/cmd/jackal/main.go"
    click ADMIN "https://github.com/ortuman/jackal/blob/main/cmd/jackalctl/main.go"
    click A "https://github.com/ortuman/jackal/tree/main/pkg/auth"
    click C2S "https://github.com/ortuman/jackal/tree/main/pkg/c2s"
    click S2S "https://github.com/ortuman/jackal/tree/main/pkg/s2s"
    click R "https://github.com/ortuman/jackal/tree/main/pkg/router"
    click CLUSTER "https://github.com/ortuman/jackal/tree/main/pkg/cluster"
    click EXT "https://github.com/ortuman/jackal/tree/main/pkg/module"
    click STORAGE "https://github.com/ortuman/jackal/tree/main/pkg/storage"
    click PROTO "https://github.com/ortuman/jackal/tree/main/proto"
    click DOCK "https://github.com/ortuman/jackal/tree/main/dockerfiles/Dockerfile"
    click HELM "https://github.com/ortuman/jackal/tree/main/helm"
    click MON "https://github.com/ortuman/jackal/tree/main/monitoring/grafana-dashboards"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef core fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef module fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    classDef cluster fill:#FAD7A0,stroke:#BA4A00,stroke-width:2px;
    classDef storage fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef admin fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef deployment fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef monitoring fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
