# randomsync/robotframework-mqttlibrary architecture

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

- Interactive diagram: https://gitdiagram.com/randomsync/robotframework-mqttlibrary
- Repository: https://github.com/randomsync/robotframework-mqttlibrary

## Overview

##### Project type and purpose
- This is a Robot Framework “test library” package written in Python.
- Its purpose is to expose MQTT operations (connect, publish, subscribe, etc.) as Robot Framework keywords, using the Eclipse Paho MQTT client under the hood.
- It integrates with external MQTT brokers (Eclipse Mosquitto) to validate messaging behavior in IoT scenarios.

##### File structure
- Top‑level artifacts:
– setup.py, requirements.txt → Python packaging & dependencies
– src/MQTTLibrary/ → library source code
– tests/ → Robot Framework test cases exercising your keywords
– mosquitto/ → sample broker configuration (no‑auth and auth setups)
– .travis.yml → CI pipeline on Travis CI
- Patterns:
– Library code implements a plugin for Robot (Robot loads the package via setup.py).
– Tests spin up Dockerized Mosquitto brokers with/without authentication, then drive the library.

##### Extract insights from the README
- The library uses Paho MQTT client to talk to brokers.
- Local tests require two broker instances (plain & auth); configuration provided under mosquitto/.
- CI automatically runs tests on Travis by starting brokers in Docker and invoking `robot -P src tests`.

##### Components and interactions (to represent
a. Main components:
1. Robot Framework Test Runner
2. MQTTLibrary (your Python package)
3. Paho MQTT Client (Python API)
4. MQTT Broker #1 (no‑auth)
5. MQTT Broker #2 (username/password auth, config under mosquitto/)
6. Docker Host (runs broker containers)
7. CI/CD System (Travis CI)
8. Documentation site (Gh‑Pages)
b. Relationships / Data flows:
- Robot Runner → loads MQTTLibrary API → Robot issues “Connect/Publish/Subscribe” keywords →
- MQTTLibrary → invokes Paho client calls → establishes TCP connection → exchanges MQTT packets →
- Brokers receive or push messages on topics → MQTTLibrary forwards status/results → Robot asserts outcomes.
- CI/CD spins up Docker Host and brokers before running the above flow.
c. Architectural patterns & principles:
- Plugin‑style library for Robot Framework (thin wrapper over Paho).
- Client‑server (MQTT pub/sub) communication.
- Separation of concerns: test runner vs. library vs. broker infrastructure.
d. Key technologies:
- Python (packaging via setup.py, version.py)
- Robot Framework (tests and keyword library interface)
- Eclipse Paho MQTT (client library)
- Eclipse Mosquitto (broker images in Docker)
- Docker (broker orchestration)
- Travis CI (.travis.yml)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Test Layer
    subgraph "Test Layer"
        direction TB
        Robot["Robot Framework Test Runner"]:::test
        Tests["tests/*.robot"]:::test
    end

    %% Library Layer
    subgraph "Library Layer"
        direction TB
        Setup["setup.py & requirements.txt"]:::library
        Lib["MQTTLibrary (src/MQTTLibrary/)"]:::library
        Version["version.py"]:::library
        Paho["Paho MQTT Client (vX.Y)"]:::library
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        CI["Travis CI"]:::infra
        Docker["Docker Host"]:::infra
        Broker1["MQTT Broker #1\n(no-auth)"]:::infra
        Broker2["MQTT Broker #2\n(auth)"]:::infra
        Docs["Documentation Site\n(Gh-Pages)"]:::infra
    end

    %% Connections
    Tests -->|"invokes"| Robot
    Robot -->|"loads API"| Lib
    Robot -->|"runs tests"| Tests
    Lib -->|"exposes keywords"| Paho
    Setup -->|"installs deps"| Paho
    Setup -->|"packages"| Lib
    Version -->|"metadata"| Lib
    Paho -->|"TCP:1883"| Broker1
    Paho -->|"TCP:1883 (auth)"| Broker2
    CI -->|"triggers"| Docker
    Docker -->|"spins up"| Broker1
    Docker -->|"spins up"| Broker2
    CI -->|"runs"| Robot
    CI -->|"deploys"| Docs

    %% Click Events
    click Robot "https://github.com/randomsync/robotframework-mqttlibrary/tree/master/tests/"
    click Tests "https://github.com/randomsync/robotframework-mqttlibrary/tree/master/tests/"
    click Lib "https://github.com/randomsync/robotframework-mqttlibrary/tree/master/src/MQTTLibrary/"
    click Version "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/src/MQTTLibrary/version.py"
    click Paho "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/requirements.txt"
    click Setup "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/setup.py"
    click Broker1 "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/mosquitto/mosquitto.conf"
    click Broker2 "https://github.com/randomsync/robotframework-mqttlibrary/tree/master/mosquitto/passwd_file"
    click Docker "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/.travis.yml"
    click CI "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/.travis.yml"
    click Docs "https://github.com/randomsync/robotframework-mqttlibrary/blob/master/docs/index.html"

    %% Styles
    classDef test fill:#f9f,stroke:#333,stroke-width:1px
    classDef library fill:#ccf,stroke:#333,stroke-width:1px
    classDef infra fill:#cfc,stroke:#333,stroke-width:1px
```
