# eclipse-paho/paho.mqtt.android architecture

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

- Interactive diagram: https://gitdiagram.com/eclipse-paho/paho.mqtt.android
- Repository: https://github.com/eclipse-paho/paho.mqtt.android

## Overview

##### Project Type & Overview
- This is an Android service library for MQTT. Its purpose is to enable Android applications to communicate over MQTT (supporting MQTT 3.1 and 3.1.1, SSL/TLS, WebSocket, etc.).
- Besides the core service, the project offers sample applications (in directories like org.eclipse.paho.android.sample and paho.mqtt.android.example) which demonstrate how to use the service.

##### And Isolate the Main Components
- MQTT Android Service Library:
- Core internal components (e.g., MqttAndroidClient, MqttService, MqttConnection, MqttDeliveryTokenAndroid).
- Components handling persistence (Persistence, DatabaseMessageStore) and connectivity (AlarmPingSender, MqttTraceHandler).
- Internal package components that manage connections and message storage.
- Android Sample Applications:
- UI layers and activity components (e.g., MainActivity, various Fragments in the sample app).
- Adapters, view components, and layouts that interact with the service.
- Build and Configuration Tools:
- Gradle and Maven configuration files, wrappers and CI configurations (e.g., .travis.yml, build.gradle, settings.gradle).
- Testing Layers:
- Android tests included under src/androidTest and unit tests under src/test.
- External Services:
- The actual MQTT brokers that the service will connect to, using protocols like SSL/TLS and WebSocket.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Android Sample Applications Cluster
    subgraph "Android Sample Applications"
        SA1["MainActivity (Sample App)"]:::sample
        SA2["Sample UI Components"]:::sample
        SA3["PahoExampleActivity (Example App)"]:::sample
    end

    %% MQTT Android Service Library Cluster
    subgraph "MQTT Android Service Library"
        %% Core MQTT Components Subcluster
        subgraph "Core MQTT Components"
            MC1["MqttAndroidClient"]:::service
            MC2["MqttService"]:::service
            MC3["MqttConnection"]:::service
            MC4["MqttDeliveryTokenAndroid"]:::service
            MC5["MqttTokenAndroid"]:::service
            MC6["MqttTraceHandler"]:::service
        end
        %% Connectivity & Persistence Subcluster
        subgraph "Connectivity & Persistence"
            MP1["AlarmPingSender"]:::service
            MP2["DatabaseMessageStore"]:::service
            MP3["MessageStore"]:::service
        end
    end

    %% External MQTT Broker
    EB["MQTT Broker / External Server"]:::external

    %% Build & Configuration Tools Cluster
    subgraph "Build & Configuration Tools"
        BC1["build.gradle (Root)"]:::build
        BC2["build.gradle (Service)"]:::build
        BC3["build.gradle (Sample)"]:::build
        BC4["build.gradle (Example)"]:::build
        BC5["pom.xml"]:::build
        BC6[".travis.yml"]:::build
    end

    %% Testing Layers Cluster
    subgraph "Testing Layers"
        T1["Android Tests (Sample App)"]:::test
        T2["Android Tests (Service)"]:::test
        T3["Unit Tests (Example App)"]:::test
    end

    %% Connections between components
    SA1 -->|"serviceBinding"| MC2
    SA2 -->|"UIInteracts"| MC2
    SA3 -->|"serviceBinding"| MC2

    MC2 -->|"MQTTCommunication"| EB
    MC1 -->|"initConnection"| MC3
    MC2 -->|"schedulesPing"| MP1
    MC2 -->|"persistsMsg"| MP2

    %% Class Definitions for Colors
    classDef service fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef sample fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef build fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef test fill:#E0E0E0,stroke:#424242,stroke-width:2px;

    %% Click Events for Core MQTT Components
    click MC1 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java"
    click MC2 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java"
    click MC3 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttConnection.java"
    click MC4 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttDeliveryTokenAndroid.java"
    click MC5 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttTokenAndroid.java"
    click MC6 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttTraceHandler.java"

    %% Click Events for Connectivity & Persistence Components
    click MP1 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/AlarmPingSender.java"
    click MP2 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/DatabaseMessageStore.java"
    click MP3 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MessageStore.java"

    %% Click Events for Android Sample Applications
    click SA1 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.sample/src/main/java/org/eclipse/paho/android/sample/activity/MainActivity.java"
    click SA2 "https://github.com/eclipse-paho/paho.mqtt.android/tree/master/org.eclipse.paho.android.sample/src/main/java/org/eclipse/paho/android/sample/activity/"
    click SA3 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/paho.mqtt.android.example/src/main/java/paho/mqtt/java/example/PahoExampleActivity.java"

    %% Click Events for Build & Configuration Tools
    click BC1 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/build.gradle"
    click BC2 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/build.gradle"
    click BC3 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/org.eclipse.paho.android.sample/build.gradle"
    click BC4 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/paho.mqtt.android.example/build.gradle"
    click BC5 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/pom.xml"
    click BC6 "https://github.com/eclipse-paho/paho.mqtt.android/blob/master/.travis.yml"

    %% Click Events for Testing Layers
    click T1 "https://github.com/eclipse-paho/paho.mqtt.android/tree/master/org.eclipse.paho.android.sample/src/androidTest/"
    click T2 "https://github.com/eclipse-paho/paho.mqtt.android/tree/master/org.eclipse.paho.android.service/src/androidTest/"
    click T3 "https://github.com/eclipse-paho/paho.mqtt.android/tree/master/paho.mqtt.android.example/src/test/"
```
