# simplex-chat/simplexmq architecture

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

- Interactive diagram: https://gitdiagram.com/simplex-chat/simplexmq
- Repository: https://github.com/simplex-chat/simplexmq

## Overview

##### Main Components Structure

a. Client Layer:
- SMP Client Library
- SMP Agent
- Applications (e.g., SimpleX Chat)
- Remote Control Components

b. Server Layer:
- SMP Server
- XFTP Server
- Notification Server

c. Infrastructure Layer:
- Message Store
- Queue Store
- Transport Layer (TLS/WebSocket)
- File System Storage

##### Core Components Relationships

a. Transport Protocols:
- HTTP/2 and WebSocket connections between clients and servers
- TLS encryption layer
- TCP port 5223 for SMP server
- TCP port 443 for XFTP server

b. Queue Management:
- Unidirectional message queues
- Queue rotation mechanisms
- Store log persistence
- Message delivery paths

##### Security Components

Security features:
- Certificate Authority chain
- TLS handshake process
- Server fingerprint verification
- Optional password protection
- Encryption layers

##### Specific Implementation Details

Specialized components:
- STM (Software Transactional Memory) queues
- Journal-based persistence
- In-memory message storage
- Queue rotation mechanism
- Push notification system

##### Component Interactions

Specific flows:
- Message creation and delivery
- Queue initialization
- File transfer operations
- Push notification delivery
- Agent-server communication

##### Technical Details

Annotations for:
- Protocol versions
- Port numbers
- Storage paths
- Configuration locations
- Certificate locations

##### Storage and persistence mechanisms

This system design should reflect the project's focus on privacy, security, and reliable message delivery while showing the clear separation of concerns between different components of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef client fill:#90EE90
    classDef server fill:#87CEEB
    classDef storage fill:#FFD700
    classDef security fill:#FF6B6B
    classDef transport fill:#DDA0DD
    classDef protocol fill:#98FB98

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        Client["SMP Client Library"]
        Agent["SMP Agent"]
        Apps["Applications"]
        RemoteCtrl["Remote Control"]
    end

    %% Server Layer
    subgraph ServerLayer["Server Layer"]
        SMPServer["SMP Server"]
        XFTPServer["XFTP Server"]
        NotifServer["Notification Server"]
    end

    %% Infrastructure Layer
    subgraph InfraLayer["Infrastructure Layer"]
        MsgStore["Message Store"]
        QStore["Queue Store"]
        Transport["Transport Layer"]
        FileStore["File System Storage"]
        Security["Security Components"]
        Protocol["Protocol Implementation"]
    end

    %% Relationships
    Client --> Agent
    Agent --> SMPServer
    Agent --> XFTPServer
    Agent --> NotifServer
    Apps --> Client
    RemoteCtrl --> Agent

    SMPServer --> MsgStore
    SMPServer --> QStore
    XFTPServer --> FileStore
    
    SMPServer & XFTPServer & NotifServer --> Transport
    Transport --> Security
    Security --> Protocol

    %% Component Classifications
    class Client,Agent,Apps,RemoteCtrl client
    class SMPServer,XFTPServer,NotifServer server
    class MsgStore,QStore,FileStore storage
    class Security security
    class Transport transport
    class Protocol protocol

    %% Click Events
    click Client "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/Messaging/Client/"
    click Agent "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/Messaging/Agent/"
    click RemoteCtrl "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/RemoteControl/"
    click SMPServer "https://github.com/simplex-chat/simplexmq/tree/stable/apps/smp-server/"
    click XFTPServer "https://github.com/simplex-chat/simplexmq/tree/stable/apps/xftp-server/"
    click NotifServer "https://github.com/simplex-chat/simplexmq/tree/stable/apps/ntf-server/"
    click MsgStore "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/Messaging/Server/MsgStore/"
    click QStore "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/Messaging/Server/QueueStore/"
    click Transport "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/Messaging/Transport/"
    click Security "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/Messaging/Crypto/"
    click Protocol "https://github.com/simplex-chat/simplexmq/blob/stable/src/Simplex/Messaging/Protocol.hs"
    click FileStore "https://github.com/simplex-chat/simplexmq/tree/stable/src/Simplex/FileTransfer/"

    %% Legend
    subgraph Legend
        C1["Client Component"]:::client
        S1["Server Component"]:::server
        ST1["Storage Component"]:::storage
        SEC1["Security Component"]:::security
        T1["Transport Component"]:::transport
        P1["Protocol Component"]:::protocol
    end
```
