# instein125/mqtt_ec200u architecture

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

- Interactive diagram: https://gitdiagram.com/instein125/mqtt_ec200u
- Repository: https://github.com/instein125/mqtt_ec200u

## Overview

##### Project type and purpose
- This is an embedded IoT demo for a Quectel EC200U module, written in MicroPython.
- It uses an event-driven, publish/subscribe architecture to power a simple GUI (LVGL), network management, and MQTT messaging.

##### File structure
- Top-level “usr/” folder contains all source code.
- Subdirectories:
- extensions/ – Hardware abstraction layer (battery, buttons, LCD init, MQTT client wrapper, network manager)
- services/ – Business logic services (button, network, MQTT, time)
- screens/ – LVGL UI screens (Welcome, Connecting, Message)
- Core modules at root of usr/: config.py, demo.py (entry point), Eventstore.py (event bus), ui.py (UI manager).
- Assets and firmware files live under usr/assets and usr/comb_firmware.

##### README for additional insights
- Confirms an event-driven pub/sub pattern, clear separation of hardware drivers, services, UI, and orchestration in demo.py.
- README describes component roles and flow: startup → network init → MQTT connect → UI updates → button handling.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "External Services"
        cell["Cellular Network Provider"]:::cloud
        mqtt["MQTT Broker (SSL/TLS)"]:::cloud
    end

    demo["demo.py\n(entry point)"]:::orchestrator
    click demo "https://github.com/instein125/mqtt_ec200u/blob/main/usr/demo.py"

    config["config_demo.py"]:::config
    click config "https://github.com/instein125/mqtt_ec200u/blob/main/usr/config_demo.py"

    event["Eventstore"]:::eventbus
    click event "https://github.com/instein125/mqtt_ec200u/blob/main/usr/Eventstore.py"

    subgraph "Services"
        ns["network_service"]:::service
        click ns "https://github.com/instein125/mqtt_ec200u/blob/main/usr/services/network_service.py"
        ms["mqtt_service"]:::service
        click ms "https://github.com/instein125/mqtt_ec200u/blob/main/usr/services/mqtt_service.py"
        bs["button_service"]:::service
        click bs "https://github.com/instein125/mqtt_ec200u/blob/main/usr/services/button_service.py"
        ts["time_service"]:::service
        click ts "https://github.com/instein125/mqtt_ec200u/blob/main/usr/services/time_service.py"
    end

    subgraph "Extensions (HAL)"
        bat["MyBattery"]:::extension
        click bat "https://github.com/instein125/mqtt_ec200u/blob/main/usr/extensions/my_battery.py"
        btn["MyButton"]:::extension
        click btn "https://github.com/instein125/mqtt_ec200u/blob/main/usr/extensions/my_button.py"
        lcd["LcdLvglInit"]:::extension
        click lcd "https://github.com/instein125/mqtt_ec200u/blob/main/usr/extensions/Lcd_lvgl_init.py"
        nm["MyNetManager"]:::extension
        click nm "https://github.com/instein125/mqtt_ec200u/blob/main/usr/extensions/my_netmanager.py"
        mqttc["MyMqttClient"]:::extension
        click mqttc "https://github.com/instein125/mqtt_ec200u/blob/main/usr/extensions/my_mqtts.py"
    end

    subgraph "Hardware Layer"
        module["EC200U Module"]:::hardware
        sim["SIM Card"]:::hardware
        batt_ph["Battery"]:::hardware
        buttons["Physical Buttons"]:::hardware
        lcd_hw["LCD Display"]:::hardware
    end

    subgraph "UI Layer"
        ui["ui.py\n(UI Manager)"]:::ui
        click ui "https://github.com/instein125/mqtt_ec200u/blob/main/usr/ui.py"
        base["Screen (Base)"]:::ui
        click base "https://github.com/instein125/mqtt_ec200u/blob/main/usr/screens/screen.py"
        ws["WelcomeScreen"]:::ui
        click ws "https://github.com/instein125/mqtt_ec200u/blob/main/usr/screens/WelcomeScreen.py"
        cs["ConnectingScreen"]:::ui
        click cs "https://github.com/instein125/mqtt_ec200u/blob/main/usr/screens/ConnectingScreen.py"
        mscr["MessageScreen"]:::ui
        click mscr "https://github.com/instein125/mqtt_ec200u/blob/main/usr/screens/MessageScreen.py"
    end

    assets["assets/"]:::assets
    click assets "https://github.com/instein125/mqtt_ec200u/tree/main/usr/assets"
    firmware["comb_firmware/8915DM_cat1_open_FW_LV_AUDIO_merge_20250617-1511.pac"]:::assets
    click firmware "https://github.com/instein125/mqtt_ec200u/blob/main/usr/comb_firmware/8915DM_cat1_open_FW_LV_AUDIO_merge_20250617-1511.pac"
    cert["mqtt_ca.crt"]:::assets
    click cert "https://github.com/instein125/mqtt_ec200u/blob/main/usr/mqtt_ca.crt"

    %% Orchestration
    demo --> config
    demo --> event
    demo --> bat
    demo --> btn
    demo --> lcd
    demo --> nm
    demo --> mqttc
    demo --> ns
    demo --> ms
    demo --> bs
    demo --> ts
    demo --> ui

    %% Hardware to Extensions
    module --> bat
    buttons --> btn
    lcd_hw --> lcd
    module --> nm
    module --> mqttc

    %% Extensions to Services
    btn --> bs
    nm --> ns
    mqttc --> ms
    bat --> ts
    lcd --> ts

    %% Services publish to Eventstore
    ns -->|"publish('network.status')"| event
    ms -->|"publish('mqtt.status')"| event
    bs -->|"publish('button.event')"| event
    ts -->|"publish('time.update')"| event

    %% UI subscribes and publishes
    event --> ws
    event --> cs
    event --> mscr
    event --> ui
    ws -->|"UI event"| event
    cs -->|"UI event"| event
    mscr -->|"UI event"| event

    %% Services to External
    ns -->|"connect()"| cell
    ms -->|"publish()/subscribe()"| mqtt

    classDef hardware fill:#e0f7fa,stroke:#006064,color:#006064
    classDef extension fill:#e1f5fe,stroke:#0d47a1,color:#0d47a1
    classDef service fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20
    classDef eventbus fill:#f3e5f5,stroke:#4a148c,color:#4a148c
    classDef ui fill:#fff3e0,stroke:#e65100,color:#e65100
    classDef orchestrator fill:#eceff1,stroke:#546e7a,color:#546e7a
    classDef cloud fill:#e3f2fd,stroke:#0277bd,color:#0277bd
    classDef config fill:#fce4ec,stroke:#880e4f,color:#880e4f
    classDef assets fill:#f9fbe7,stroke:#827717,color:#827717
```
