# ecolistico/growgreens architecture

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

- Interactive diagram: https://gitdiagram.com/ecolistico/growgreens
- Repository: https://github.com/ecolistico/growgreens

## Overview

##### Project type and purpose
- From the README and file-tree, this is a full-stack IoT greenhouse control system (“GrowGreens for ECOLISTICO”).
- It includes embedded firmware (Arduino, ESP32), edge gateways (Raspberry Pi “Grower” and “Master” nodes), a cloud component (Python/Cloud), plus local web UIs served via Rasp-AP.

##### File structure
- **C++/**
- Arduino subfolders (multiple .ino projects for solutionMaker, generalControl, sMakerV2, accessControl, motorsGrower, etc.)
- ESP32 subfolders (staticSensors, AC-MideaIRMqtt with AutoConnect-Grow library and MQTT data files)
- libs/ (third-party and in-house C++ libraries: AutoConnect-Grow, GrowGreens core, AtlasScientific, etc.)
- **Python/**
- Cloud/ (MQTT clients, streamServer, GUI, sysCloud)
- Grower/ (Raspberry Pi script set for local grow node: APconfig, MQTT callbacks, BLE advertise, web front-end under html/)
- Master/ (Raspberry Pi central node: data-logger, irrigation control, reports, GUI, email/Telegram alerts, sysMaster)
- Tucan/ (likely a mobile or remote client node)
- utils/sysRasp (helper scripts to configure Raspbian service files, WiFi, camera streaming)
- **Rasp-AP/**
- Preconfigured hostapd, dnsmasq, rc.local, dhcpcd for hosting a WiFi AP on both Grower and Master nodes
- Static HTML/CSS/JS/PHP front-end served to browsers for local configuration & monitoring
- **Bash/** and **Test/** for helper scripts and hardware test code

##### README for additional insights
- Minimal description, but screenshot shows a GUI dashboard—confirming local and remote UIs.

a. Main components
1. Embedded layer:
– Arduino boards running C++ “solutionMaker,” “motorsGrower,” etc., controlling sensors, solenoids, motors
– ESP32 boards running AutoConnect-Grow + MQTT firmware for WiFi‐connected static sensors and remote IR control
2. Edge gateway layer (Raspberry Pi nodes):
– Grower node: local data aggregator, AP server, MQTT client, BLE advertiser
– Master node: central controller, data logger (log2DB), irrigation scheduler, alert dispatcher (email/Telegram), GUI server
3. Cloud layer:
– Python/Cloud service hosting MQTT broker (or client to public broker), stream server (video), blue_server, web dashboard GUI
4. User Interfaces:
– Local web UI served by Rasp-AP on Grower/Master (HTML/CSS/JS/PHP)
– Remote web UI / dashboards in Python/Cloud
b. Relationships and interactions
– Sensors → Arduino/ESP32 → serial or MQTT → Raspberry Pi (Grower/Master)
– Pis ↔ MQTT broker → Python/Cloud → persistent storage (JSON files or database)
– Web clients (browsers) → HTTP server on Pis (Rasp-AP) or Cloud UI → invoke Python scripts via HTTP or local APIs
– Alerts (email/Telegram) sent by Master via modules in Python/Master
– Camera streaming: Pi runs streamServer & client callbacks to Cloud
c. Architectural patterns & principles
– Layered separation: Firmware layer, edge processing layer, cloud services
– Microservices style: each Python subproject independently handles a domain (Cloud, Grower, Master, Tucan)
– Pub/Sub messaging: MQTT as central bus for sensor data and control commands
– Modular libraries: C++ libs for connectivity (AutoConnect-Grow), sensor drivers (AtlasScientific), control logic (GrowGreens)
d. Key technologies/frameworks/libraries
– Arduino SDK, ESP32 Arduino + AutoConnect-Grow library, MQTT protocol
– Python 3 with paho-mqtt, Flask or built-in HTTP server for streamServer & blue_server
– Hostapd/dnsmasq for Raspberry Pi access point
– Frontend: HTML/CSS/JavaScript, PHP for local API endpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Embedded Layer
    subgraph "Embedded Devices" 
        direction TB
        EM1["solutionMaker (Arduino)"]:::embedded
        EM2["motorsGrower (Arduino)"]:::embedded
        EM3["sMakerV2 (Arduino)"]:::embedded
        EM4["accessControl (Arduino)"]:::embedded
        EM5["generalControl (Arduino)"]:::embedded
        EM6["Spindle_aspersorDER (Arduino)"]:::embedded
        ES1["IR-Midea MQTT Ctrl (ESP32)"]:::embedded
        ES2["Static Sensors MQTT (ESP32)"]:::embedded
        ES3["ESP32 Access Control"]:::embedded
    end

    click EM1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/Arduino/solutionMaker/solutionMaker.ino"
    click EM2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/Arduino/motorsGrower/motorsGrower/motorsGrower.ino"
    click EM3 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/Arduino/sMakerV2/sMakerV2.ino"
    click EM4 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/Arduino/accessControl/accessControl.ino"
    click EM5 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/Arduino/generalControl/generalControl.ino"
    click EM6 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/Arduino/Spindle_aspersorDER/Spindle_aspersorDER.ino"
    click ES1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/ESP32/AC-MideaIRMqtt/ESP32-OTA_AutoConnect/ESP32-OTA_AutoConnect.ino"
    click ES2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/ESP32/staticSensors/ESP32-OTA_AutoConnect/ESP32-OTA_AutoConnect.ino"
    click ES3 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/C++/ESP32/accessControl/README.txt"

    %% Edge Gateway Layer
    subgraph "Grower Node (Raspberry Pi)" 
        direction TB
        G1["growGrower.py"]:::edge
        G2["mqttCallback.py"]:::edge
        G3["ble_advertise.py"]:::edge
        G4["APconfig.py"]:::edge
        G5["hostapdConfig.py"]:::edge
        G6["Local Web UI"]:::ui
    end

    subgraph "Master Node (Raspberry Pi)" 
        direction TB
        M1["sysMaster.py"]:::edge
        M2["log2DB.py"]:::edge
        M3["irrigationControl.py"]:::edge
        M4["Alert.py"]:::edge
        M5["smtp.py"]:::edge
        M6["gui.py"]:::edge
        M7["mqttCallback.py"]:::edge
        DB["Data Store (JSON/DB)"]:::storage
    end

    click G1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Grower/src/growGrower.py"
    click G2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Grower/src/mqttCallback.py"
    click G3 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Grower/src/ble_advertise.py"
    click G4 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Grower/src/APconfig.py"
    click G5 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Grower/src/hostapdConfig.py"
    click G6 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Grower/html/index.html"

    click M1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/src/sysMaster.py"
    click M2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/log2DB/log2DB.py"
    click M3 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/src/irrigationControl.py"
    click M4 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/src/Alert.py"
    click M5 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/src/smtp.py"
    click M6 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/src/gui.py"
    click M7 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Master/src/mqttCallback.py"

    %% Cloud Layer
    subgraph "Cloud Services"
        direction TB
        C1["blue_server.py"]:::cloud
        C2["streamCallback.py"]:::cloud
        C3["sysCloud.py"]:::cloud
        C4["growCloud.py"]:::cloud
        C5["gui.py"]:::cloud
        C6["dev/streamServer.py"]:::cloud
        C7["dev/mqttClient.py"]:::cloud
        BROKER["MQTT Broker"]:::cloud
    end

    click C1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/src/blue_server.py"
    click C2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/src/streamCallback.py"
    click C3 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/src/sysCloud.py"
    click C4 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/growCloud.py"
    click C5 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/src/gui.py"
    click C6 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/dev/streamServer.py"
    click C7 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/Cloud/dev/mqttClient.py"

    %% Local Web UIs via Rasp-AP
    subgraph "Local Web UIs (Rasp-AP)"
        direction TB
        UI1["Grower UI"]:::ui
        UI2["Master Setup UI"]:::ui
    end

    click UI1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Rasp-AP/Grower/html/index.html"
    click UI1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Rasp-AP/Grower/configFiles_AP/etc/hostapd/hostapd.conf.ap"
    click UI2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Rasp-AP/Master/Setup/index.html"

    %% SysRasp Utilities
    subgraph "System Utilities (sysRasp)" 
        direction TB
        U1["APconfig.py"]:::edge
        U2["WiFiconfig.py"]:::edge
        U3["startCamStreaming.py"]:::edge
        U4["stopCamStreaming.py"]:::edge
        U5["growgreens.service (Grower)"]:::edge
        U6["growgreens.service (Master)"]:::edge
    end

    click U1 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/utils/sysRasp/src/APconfig.py"
    click U2 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/utils/sysRasp/src/WiFiconfig.py"
    click U3 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/utils/sysRasp/src/startCamStreaming.py"
    click U4 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/utils/sysRasp/src/stopCamStreaming.py"
    click U5 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/utils/sysRasp/configFiles_GrowerService/growgreens.service"
    click U6 "https://github.com/ecolistico/growgreens/blob/MX-CANCUN/Python/utils/sysRasp/configFiles_MasterService/growgreens.service"

    %% Data Flows
    EM1 -->|"Serial/MQTT"| G1
    EM2 -->|"Serial/MQTT"| G1
    EM3 -->|"Serial/MQTT"| G1
    EM4 -->|"Serial/MQTT"| G1
    EM5 -->|"Serial/MQTT"| G1
    EM6 -->|"Serial/MQTT"| G1
    ES1 -->|"MQTT/TCP"| G2
    ES2 -->|"MQTT/TCP"| G2
    ES3 -->|"MQTT/TCP"| G2

    G2 -->|"MQTT"| BROKER
    M7 -->|"MQTT"| BROKER
    BROKER -->|"MQTT"| C1

    G6 -->|"HTTP"| UI1
    M6 -->|"HTTP"| UI2
    C5 -->|"HTTP"| UI2

    M1 -->|"Scheduler"| M3
    M1 -->|"Alerts"| M4
    M2 -->|"Writes"| DB

    %% Styles
    classDef embedded fill:#a8e6cf,stroke:#379683,color:#05386b
    classDef edge fill:#d0e1f9,stroke:#4a69bb,color:#1e272e
    classDef cloud fill:#ffd3b6,stroke:#f39c12,color:#6e2c00
    classDef ui fill:#f6cd61,stroke:#f39c12,color:#5d4037
    classDef storage fill:#dfe6e9,stroke:#636e72,color:#2d3436
```
