# bytebeamio/rumqtt architecture

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

- Interactive diagram: https://gitdiagram.com/bytebeamio/rumqtt
- Repository: https://github.com/bytebeamio/rumqtt

## Overview

##### Main Components Identification

a) rumqttc (MQTT Client Library)
- Client implementation
- Protocol handlers (v4 and v5)
- Network/TLS layer
- Event loop system

b) rumqttd (MQTT Broker)
- Server implementation
- Router system
- Protocol handlers
- Link management
- Replication system

**┌─────────────────────────────────────┐    ┌─────────────────────────────────────┐**
- rumqttc                  │    │              rumqttd                 │
- ┌─────────────┐    ┌─────────────┐ │    │ ┌─────────────┐    ┌─────────────┐  │
- MQTT v4    │    │  MQTT v5    │ │    │ │   Router    │    │  Protocol   │  │
- ┘    └─────────────┘ │    │ └─────────────┘    └─────────────┘  │
- ┌─────────────┐    ┌─────────────┐ │    │ ┌─────────────┐    ┌─────────────┐  │
- Event Loop  │    │    TLS      │ │    │ │    Link     │    │ Replicator  │  │
- ┘    └─────────────┘ │    │ └─────────────┘    └─────────────┘  │
- ┘    └─────────────────────────────────────┘

##### Detailed Component Breakdown

For rumqttc:
**Client Implementation**
- Protocol Handlers (v4/v5)
- Connection Management
- Event Loop
- Transport Layer (TCP/TLS/WebSocket)

For rumqttd:
**Broker Implementation**
- Router System
- Connection Management
- Message Routing
- Subscription Handling
- Link Management
- Bridges
- Console
- Network
- Protocol Support
- Replication System

##### Connection Flows

- Client ↔ Broker connections
- Inter-broker communication
- Bridge connections
- WebSocket connections
- TLS handshakes

##### Additional Elements

Supporting components:
- Configuration management
- Metrics and monitoring
- Authentication/Authorization
- Storage systems for retained messages

##### Notes for Implementation

- Clear boundaries between client and broker components
- Async nature of the system
- Version support indicators
- Scalability aspects

- MQTT 3.1.1 and 5.0 support
- QoS levels
- TLS security
- WebSocket support
- High performance architecture
- Replication capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef broker fill:#99ff99,stroke:#333,stroke-width:2px
    classDef protocol fill:#ffcc99,stroke:#333,stroke-width:2px
    classDef network fill:#ffff99,stroke:#333,stroke-width:2px
    classDef security fill:#ff9999,stroke:#333,stroke-width:2px
    classDef system fill:#cc99ff,stroke:#333,stroke-width:2px

    subgraph Client["MQTT Client (rumqttc)"]
        C_IMPL["Client Implementation"]:::client
        C_V4["Protocol Handler v4"]:::protocol
        C_V5["Protocol Handler v5"]:::protocol
        C_EVENT["Event Loop"]:::system
        C_TLS["TLS Layer"]:::security
        C_WS["WebSocket Support"]:::network

        C_IMPL --> C_V4
        C_IMPL --> C_V5
        C_IMPL --> C_EVENT
        C_EVENT --> C_TLS
        C_EVENT --> C_WS
    end

    subgraph Broker["MQTT Broker (rumqttd)"]
        B_IMPL["Server Implementation"]:::broker
        B_ROUTER["Router System"]:::system
        B_CONN["Connection Management"]:::system
        B_V4["Protocol Handler v4"]:::protocol
        B_V5["Protocol Handler v5"]:::protocol
        B_LINK["Link Management"]:::system
        B_REP["Replication System"]:::system
        B_TLS["TLS Support"]:::security

        B_IMPL --> B_ROUTER
        B_IMPL --> B_CONN
        B_ROUTER --> B_V4
        B_ROUTER --> B_V5
        B_IMPL --> B_LINK
        B_IMPL --> B_REP
        B_IMPL --> B_TLS
    end

    %% Inter-component connections
    C_TLS -.-> B_TLS
    C_WS -.-> B_CONN
    C_V4 -.-> B_V4
    C_V5 -.-> B_V5

    %% Legend
    subgraph Legend
        L_CLIENT["Client Component"]:::client
        L_BROKER["Broker Component"]:::broker
        L_PROTO["Protocol Handler"]:::protocol
        L_NET["Network Layer"]:::network
        L_SEC["Security Component"]:::security
        L_SYS["System Component"]:::system
    end

    %% Click events
    click C_IMPL "https://github.com/bytebeamio/rumqtt/blob/main/rumqttc/src/client.rs"
    click C_V4 "https://github.com/bytebeamio/rumqtt/tree/main/rumqttc/src/mqttbytes/v4/"
    click C_V5 "https://github.com/bytebeamio/rumqtt/tree/main/rumqttc/src/v5/mqttbytes/v5/"
    click C_EVENT "https://github.com/bytebeamio/rumqtt/blob/main/rumqttc/src/eventloop.rs"
    click C_TLS "https://github.com/bytebeamio/rumqtt/blob/main/rumqttc/src/tls.rs"
    click C_WS "https://github.com/bytebeamio/rumqtt/blob/main/rumqttc/src/websockets.rs"
    click B_IMPL "https://github.com/bytebeamio/rumqtt/tree/main/rumqttd/src/server/"
    click B_ROUTER "https://github.com/bytebeamio/rumqtt/tree/main/rumqttd/src/router/"
    click B_V4 "https://github.com/bytebeamio/rumqtt/tree/main/rumqttd/src/protocol/v4/"
    click B_V5 "https://github.com/bytebeamio/rumqtt/tree/main/rumqttd/src/protocol/v5/"
    click B_LINK "https://github.com/bytebeamio/rumqtt/tree/main/rumqttd/src/link/"
    click B_REP "https://github.com/bytebeamio/rumqtt/tree/main/rumqttd/src/replicator/"
    click B_CONN "https://github.com/bytebeamio/rumqtt/blob/main/rumqttd/src/server/connection.rs"
    click B_TLS "https://github.com/bytebeamio/rumqtt/blob/main/rumqttd/src/server/tls.rs"
```
