# raushanraja/ec200ucn architecture

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

- Interactive diagram: https://gitdiagram.com/raushanraja/ec200ucn
- Repository: https://github.com/raushanraja/ec200ucn

## Overview

##### Project type and purpose
- This is an embedded IoT firmware project written in C++ using PlatformIO (configured via pyproject.toml and platformio.ini).
- The firmware runs on a microcontroller paired with a Quectel EC200UCN cellular modem. It publishes/subscribes to a remote MQTT broker over TLS.
- A Python helper (cert.py) plus the QFlash tool are used to upload the CA root certificate into the modem’s flash.

##### File structure
- Top-level config
– platformio.ini: build, upload and board settings
– pyproject.toml: Poetry environment for PlatformIO + cert.py
– .vscode, .gitignore
- Firmware code
– include/: public headers for application
– lib/mqtt/: AT-command-based MQTT client and helper modules
– src/main.cpp: entry point, orchestrates init, sensor read, MQTT calls
- Utilities & tests
– cert.py: Python script to push CA cert to modem via AT+QFUPL
– test/: (future) harness or unit tests
- README.md: developer onboarding, build & upload instructions, serial console notes, QFlash procedure

##### README for additional insights
- The architecture is implied: developer PC → build & upload → device → cloud.
- Dependencies: PlatformIO, Poetry, minicom (or any serial terminal), QFlash.

a. Main components
- Developer Workstation (IDE, Poetry, PlatformIO CLI, cert.py, QFlash UI)
- Build & Upload Path (PlatformIO toolchain + USB/serial)
- Target Hardware
– MCU (runs the firmware)
– Cellular Modem (EC200UCN) with CA store
- Firmware Modules
– Application logic (main.cpp)
– MQTT client library (lib/mqtt)
– Certificate helper (in-modem storage & usage)
- External Service
– MQTT Broker (cloud)
b. Relationships & data flows
- Dev PC → (PlatformIO via USB/serial) → MCU flash
- cert.py + QFlash UI → (AT+QFUPL over serial) → Modem CA storage
- MCU firmware → (AT commands over UART) → Modem → (cellular network) → MQTT Broker
c. Architectural patterns & principles
- Layered separation:
– Hardware abstraction (AT serial interface)
– Communication layer (MQTT client & helper)
– Application layer (main.cpp sensor read + publish logic)
- Single responsibility: cert.py solely handles certificate upload
- Modularity: independent lib/mqtt that could be reused/tested
d. Key technologies & libraries
- PlatformIO (gcc-arm toolchain, u-upload)
- Poetry (Python env for cert.py + PlatformIO plugin)
- C++17, AVR/ARM SDK (as per board)
- MQTT over AT commands
- Quectel EC200UCN, QFlash tool

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Workstation (Blue)
    subgraph "Developer Workstation"
        direction TB
        PIO["PlatformIO Configuration"]:::dev
        Poetry["Poetry Environment & Cert Push Script"]:::dev
        VSCode["VSCode Settings"]:::dev
    end

    click PIO "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/platformio.ini"
    click Poetry "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/pyproject.toml"
    click Poetry "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/cert.py"
    click VSCode "https://github.com/raushanraja/ec200ucn/tree/tasks_freertos/.vscode/"

    %% Firmware Modules (Green)
    subgraph "Firmware Code"
        direction TB
        subgraph "Application Layer"
            direction TB
            App["Application Logic (src/main.cpp)"]:::fw
        end
        subgraph "Communication Layer"
            direction TB
            subgraph "MQTT Client Library"
                direction TB
                ATS["atserial.h"]:::fw
                MQTTCPP["mqtt.cpp"]:::fw
                MQTTH["mqtt.h"]:::fw
            end
            subgraph "MQTT Helper Modules"
                direction TB
                HelperCPP["mqtt_helper.cpp"]:::fw
                HelperH["mqtt_helper.h"]:::fw
            end
        end
        PublicHdrs["Public Headers (include/)"]:::fw
    end

    click App "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/src/main.cpp"
    click ATS "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/lib/mqtt/atserial.h"
    click MQTTCPP "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/lib/mqtt/mqtt.cpp"
    click MQTTH "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/lib/mqtt/mqtt.h"
    click HelperCPP "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/lib/mqtt/mqtt_helper.cpp"
    click HelperH "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/lib/mqtt/mqtt_helper.h"
    click PublicHdrs "https://github.com/raushanraja/ec200ucn/tree/tasks_freertos/include/"

    %% Documentation (Gray)
    subgraph "Documentation"
        direction TB
        LibDoc["Library Documentation"]:::doc
        IncDoc["Include Directory Documentation"]:::doc
        TestDoc["Test Harness Placeholder"]:::doc
        ProjectDoc["Project README & Onboarding"]:::doc
    end

    click LibDoc "https://github.com/raushanraja/ec200ucn/tree/tasks_freertos/lib/README"
    click IncDoc "https://github.com/raushanraja/ec200ucn/tree/tasks_freertos/include/README"
    click TestDoc "https://github.com/raushanraja/ec200ucn/tree/tasks_freertos/test/README"
    click ProjectDoc "https://github.com/raushanraja/ec200ucn/blob/tasks_freertos/readme.md"

    %% Target Hardware (Gray)
    subgraph "Target Hardware"
        direction TB
        MCU["Microcontroller (MCU)"]:::hw
        Modem["Quectel EC200UCN Modem"]:::hw
    end

    %% External Service (Orange)
    Broker["MQTT Broker (Cloud)"]:::ext

    %% Build & Upload Paths
    PIO -->|"Build & Upload via USB/Serial"| MCU
    Poetry -->|"Upload CA Cert (AT+QFUPL)"| Modem

    %% Runtime Data Flow
    App -->|"calls MQTT functions"| MQTTH
    MQTTH -->|"uses AT serial API"| ATS
    ATS -->|"UART AT commands"| Modem
    Modem -->|"Cellular Network"| Broker
    Broker -->|"MQTT Subscribe/Publish"| Modem
    Modem -->|"UART AT responses"| ATS
    ATS -->|"feedback to client"| MQTTH
    MQTTH -->|"returns to app"| App

    %% Legend
    classDef dev fill:#ADD8E6,stroke:#000;
    classDef fw fill:#90EE90,stroke:#000;
    classDef hw fill:#D3D3D3,stroke:#000;
    classDef ext fill:#FFA500,stroke:#000;
    classDef doc fill:#F0F0F0,stroke:#000;

    class PIO,Poetry,VSCode dev;
    class App,ATS,MQTTCPP,MQTTH,HelperCPP,HelperH,PublicHdrs fw;
    class MCU,Modem hw;
    class Broker ext;
    class LibDoc,IncDoc,TestDoc,ProjectDoc doc;
```
