# thamidu-nadun/iot-green-house architecture

> Architecture diagram of the GitHub repository thamidu-nadun/iot-green-house, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thamidu-nadun/iot-green-house
- Repository: https://github.com/thamidu-nadun/iot-green-house

## Overview

##### Main Components

a. Hardware Layer:
- Sensors (DHT22, Soil Moisture Sensor) to the ESP32
- Actuators (Relay Module controlling fans, pumps) connected to ESP32
- Power supply connections (5V USB, 12V)

b. Communication Layer:
- WiFi connection from ESP32 to the network
- HTTP/WebSocket protocols for data transmission

c. Software Stack:
- Frontend (React Application):
- Main components structure (Dashboard, Charts, Sensors)
- Asset management (SCSS/CSS)
- Component hierarchy

d. Backend Layer:
- Python server (app.py)
- API endpoints for data handling

##### Component Relationships

- Bidirectional data flow between ESP32 and Python backend
- REST/WebSocket communication between backend and frontend
- Data flow between React components
- Sensor data paths to visualization components

##### Specific Implementation Details

Frontend Structure:
**Dashboard**
- Main Display (Dashboard.jsx)
- Monitoring Components
- TemperatureSection
- Charts (Bar, Circular, Line)
- Sensor Cards
- Control Interface

##### Additional Elements

Supporting elements:
- System requirements and dependencies
- Data flow direction indicators
- Component version information

##### Critical Aspects to Highlight

- Real-time data flow paths
- Security implementations
- Error handling routes
- Scalability points
- Backup/failover systems

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        ESP32[ESP32 Microcontroller]
        DHT22[DHT22 Temperature Sensor]
        SOIL[Soil Moisture Sensor]
        RELAY[Relay Module]
        FAN[Fans]
        PUMP[Water Pump]
        PS1[5V USB Power]
        PS2[12V Power Supply]
    end

    subgraph Communication
        WIFI[WiFi Connection]
        WS[WebSocket Protocol]
        HTTP[HTTP Protocol]
    end

    subgraph "Backend Services"
        SERVER[Python Server]
        API[API Endpoints]
    end

    subgraph "Frontend Application"
        APP[React App]
        DASH[Dashboard]
        TEMP[Temperature Section]
        SENS[Sensor Display]
        CARD[Sensor Cards]
        
        subgraph "Charts"
            BAR[Bar Chart]
            CIRC[Circular Chart]
            LINE[Line Chart]
        end
        
        subgraph "Navigation"
            SIDE[Sidebar]
            TOP[Topbar]
        end
        
        subgraph "Styles"
            MAIN_CSS[Main Styles]
            CHART_CSS[Chart Styles]
            DASH_CSS[Dashboard Styles]
        end
    end

    %% Hardware Connections
    PS1 --> ESP32
    PS2 --> RELAY
    ESP32 --> DHT22
    ESP32 --> SOIL
    ESP32 --> RELAY
    RELAY --> FAN
    RELAY --> PUMP

    %% Communication Flow
    ESP32 --> WIFI
    WIFI --> WS
    WIFI --> HTTP
    WS --> SERVER
    HTTP --> SERVER

    %% Backend Connections
    SERVER --> API
    API --> APP

    %% Frontend Structure
    APP --> DASH
    DASH --> TEMP
    DASH --> SENS
    SENS --> CARD
    DASH --> BAR
    DASH --> CIRC
    DASH --> LINE
    APP --> SIDE
    APP --> TOP

    %% Style Applications
    MAIN_CSS -.-> APP
    CHART_CSS -.-> BAR
    CHART_CSS -.-> CIRC
    CHART_CSS -.-> LINE
    DASH_CSS -.-> DASH

    %% Click Events
    click ESP32 "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/server/main.ino"
    click SERVER "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/server/app.py"
    click DASH "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Dashboard/Dashboard.jsx"
    click TEMP "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Dashboard/sections/TemperatureSection.jsx"
    click SENS "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Main/components/Sensor.jsx"
    click CARD "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Main/components/SensorCard.jsx"
    click BAR "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Charts/BarChart.jsx"
    click CIRC "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Charts/CircularChart.jsx"
    click LINE "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Charts/LineChart.jsx"
    click SIDE "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/SideBar/SideBar.jsx"
    click TOP "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/components/Topbar/Topbar.jsx"
    click MAIN_CSS "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/assets/scss/sb-admin-2.scss"
    click CHART_CSS "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/assets/scss/_charts.scss"
    click DASH_CSS "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/assets/dashboard.css"
    click APP "https://github.com/Thamidu-Nadun/IOT-Green-House/blob/main/client/src/App.jsx"

    %% Styling
    classDef hardware fill:#a8d5ff,stroke:#333,stroke-width:2px
    classDef communication fill:#fff59d,stroke:#333,stroke-width:2px
    classDef backend fill:#80cbc4,stroke:#333,stroke-width:2px
    classDef frontend fill:#c5e1a5,stroke:#333,stroke-width:2px
    classDef styles fill:#e1bee7,stroke:#333,stroke-width:2px

    class ESP32,DHT22,SOIL,RELAY,FAN,PUMP,PS1,PS2 hardware
    class WIFI,WS,HTTP communication
    class SERVER,API backend
    class APP,DASH,TEMP,SENS,CARD,BAR,CIRC,LINE,SIDE,TOP frontend
    class MAIN_CSS,CHART_CSS,DASH_CSS styles
```
