# philipparndt/mqtt-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/philipparndt/mqtt-analyzer
- Repository: https://github.com/philipparndt/mqtt-analyzer

## Overview

##### Main Components
- iOS Frontend/UI: This is the presentation layer built using SwiftUI. It contains many view components (e.g., MQTTAnalyzer views, login screens, host forms, message details, topic lists, etc.) found under directories like “src/MQTTAnalyzer/views”, “src/MQTTAnalyzerIntentUI”, and “src/MQTTAnalyzer/Assets”.
- Business Logic & Domain Models: Located in “src/Common/model” and “src/MQTTAnalyzer/model”. These modules handle broker settings, message handling, topic trees, search, and timeseries functionalities. They encapsulate logic for grouping messages, full-text search, and more.
- MQTT Communication Layer: Found in “src/Common/mqtt” and in subdirectories such as “cocoamqtt” and “moscapsule”. This entire module covers the MQTT client implementations, delegates, and helper classes to send/receive messages from the broker. It even includes synchronous variants.
- Persistence and Storage: Files under “src/Common/model/persistence” indicate that the app uses mechanisms like SQLite and Core Data (via “MQTTAnalyzer.xcdatamodeld”) for storing configurations, broker settings, and potentially message histories.
- iCloud Sync: The “src/Common/icloud” folder contains modules that are responsible for syncing settings (like certificates and configurations) with a private iCloud database.
- Testing Framework: Note the presence of “MQTTAnalyzerTests”, “MQTTAnalyzerUITests”, and “MQTTAnalyzerIntegrationTests”. Although these are not part of the runtime architecture, they denote the separation of concerns and the extent of testing coverage.
- CI/CD and Build Systems: There are GitHub workflows (.github/workflows), CI scripts (in the “ci” and “src/ci_scripts” directories), and fastlane configuration (under “src/fastlane”) used to automate builds, tests, and releases.

##### Relationships & Interactions
- The UI components interact with the Business Logic layer using patterns consumed by SwiftUI (possibly adopting MVVM concepts). For example, forms related to broker connection are tied to models that validate and transform data (note the “HostFormModel” files).
- Business logic components interact with the MQTT Communication layer. For instance, an MQTT client instance (using CocoaMQTT or Moscapsule) is invoked to handle subscriptions, message publishing, and connection status updates.
- Persistence and iCloud Sync act as ancillary services that keep configuration data, broker settings, and historical message data available locally and on the cloud.
- The testing infrastructure isolates these components and simulates interactions with stub services (like the “mqtt-stub-service”) for automated testing.

##### Architectural Patterns & Technologies
- Separation of concerns: There is a clear separation between UI (SwiftUI views), business logic/domain models, network/MQTT communication, and persistence/iCloud syncing.
- Modularity: The source tree is modular, with “Common” libraries shared among different app targets (MQTTAnalyzer, intents, etc.).
- Dependency management: The use of CocoaPods (Podfile) and fastlane for build and deployment.
- Asynchronous communication: Given the nature of MQTT (and the existence of delegate and synchronous client implementations), asynchronous patterns are key.
- Testing as a first-class citizen, with dedicated UI and integration test suites.

##### Final Advice for the Principal Software Engineer
- Clearly differentiate internal modules from external interactions (the MQTT Broker).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% iOS Application Architecture
    subgraph "iOS Application"
        subgraph "UI Layer"
            UI1["SwiftUI Views"]:::uiLayer
            UI2["Intent UI Components"]:::uiLayer
        end
        subgraph "Business Logic & Domain Models"
            BL1["Common Domain Models"]:::businessLayer
            BL2["MQTTAnalyzer Models"]:::businessLayer
        end
        subgraph "MQTT Communication Layer"
            MC1["MQTT Client (CocoaMQTT & Moscapsule)"]:::communicationLayer
            MC2["MQTT Session Controller"]:::communicationLayer
        end
        subgraph "Persistence & Cloud Sync"
            P1["Local Persistence (SQLite/Core Data)"]:::persistenceLayer
            P2["iCloud Sync Manager"]:::persistenceLayer
        end
    end

    EX["External MQTT Broker"]:::external

    subgraph "Testing & CI/CD"
        T1["Unit Tests"]:::testingLayer
        T2["UI Tests"]:::testingLayer
        T3["Integration Tests"]:::testingLayer
        CI1["GitHub Workflows"]:::testingLayer
        CI2["CI Scripts"]:::testingLayer
        CI3["fastlane"]:::testingLayer
    end

    %% Connections between layers
    UI1 -->|"calls"| BL1
    UI2 -->|"calls"| BL2

    BL1 -->|"invokes"| MC1
    BL2 -->|"invokes"| MC2

    BL1 -->|"stores"| P1
    BL1 -->|"syncs"| P2

    MC1 <-->|"pub/sub"| EX
    MC2 <-->|"pub/sub"| EX

    %% Testing & CI/CD support connections (dashed)
    T1 ---|"supports"| UI1
    T1 ---|"supports"| BL1
    T1 ---|"supports"| MC1
    T1 ---|"supports"| P1

    T2 ---|"supports"| UI2
    T2 ---|"supports"| BL2
    T2 ---|"supports"| MC2

    T3 ---|"supports"| MC1
    T3 ---|"supports"| P1

    CI1 ---|"builds"| UI1
    CI1 ---|"builds"| BL1
    CI1 ---|"builds"| MC1

    CI2 ---|"runs"| P1

    CI3 ---|"deploys"| EX

    %% Click events
    click UI1 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzer/views"
    click UI2 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzerIntentUI"
    click BL1 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/Common/model"
    click BL2 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzer/model"
    click MC1 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/Common/mqtt"
    click MC2 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzer/mqtt"
    click P1 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/Common/model/persistence"
    click P2 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/Common/icloud"
    click T1 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzerTests"
    click T2 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzerUITests"
    click T3 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/MQTTAnalyzerIntegrationTests"
    click CI1 "https://github.com/philipparndt/mqtt-analyzer/tree/main/.github/workflows"
    click CI2 "https://github.com/philipparndt/mqtt-analyzer/tree/main/ci"
    click CI3 "https://github.com/philipparndt/mqtt-analyzer/tree/main/src/fastlane"

    %% Style definitions
    classDef uiLayer fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px,rx:5,ry:5;
    classDef businessLayer fill:#C9DAF8,stroke:#3C78D8,stroke-width:2px,rx:5,ry:5;
    classDef communicationLayer fill:#F9CB9C,stroke:#E69138,stroke-width:2px,rx:5,ry:5;
    classDef persistenceLayer fill:#FFF2CC,stroke:#BF9000,stroke-width:2px,rx:5,ry:5;
    classDef testingLayer fill:#EAD1DC,stroke:#B854A7,stroke-width:2px,rx:5,ry:5;
    classDef external fill:#F4CCCC,stroke:#DC143C,stroke-width:2px,rx:5,ry:5;
```
