# mitishraina/dewdrop architecture

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

- Interactive diagram: https://gitdiagram.com/mitishraina/dewdrop
- Repository: https://github.com/mitishraina/dewdrop

## Overview

##### Project type and purpose
- This is a full-stack IoT + AI data-visualization application (“DewDrop”) for harvesting and managing fog-condensed water.
- It integrates custom hardware sensors, a Node.js/Express real-time server, Python-based ML microservices (fog prediction & water-quality analysis), and a React.js frontend dashboard.

##### File structure
- Top-level “hardware” folder: Arduino (.ino) and a JavaScript serialReader to collect sensor data from pH, TDS, humidity, temperature sensors and ionizer hardware.
- “server” folder: Node.js/Express backend (index.js), REST/WebSocket routes under server/routes for deviceControl and real-time updates.
- “python models” folder: two separate ML services:
– fogpredictionmodel.h5 + main.py (likely a script or micro-service for fog density prediction)
– “water quality” subfolder with app.py serving potable water analysis, using an xgboost_model.joblib.
- “src” folder: React application (Vite config, CSS, components, pages, utility libraries).
- No formal database—data persistence currently via CSVs or in-memory; could be extended later.

##### README for additional insights
- Describes system workflow:
1. Hardware collects data
2. Ionized dehumidifier condenses water
3. Data flows to website for analysis, visualization, predictions
- Tech stack: React, Node.js/Express, AI/ML (Python).
- Emphasis on real-time analytics (WebSockets) and centralized management for multi-device deployment.

a. Main components
- Hardware Layer: Sensors + Ionizer + Arduino
- Edge Data Collector: serialReader.js (device gateway)
- Backend Server: Node.js/Express
- ML Microservices:
– Fog Prediction Service (Python main.py)
– Water Quality Service (Python app.py)
- Frontend Dashboard: React/Vite app
- Data Stores: CSV files (placeholder), potential future DB
- External Integrations (future): Solar power controller, Web3 registry

b. Relationships & interactions
1. Hardware → serialReader: sensor readings over serial/USB
2. serialReader → Backend: HTTP POST or WebSocket publish
3. Backend → ML Services: REST or child-process calls to Python endpoints
4. ML Services → Backend: JSON responses (predictions, analysis)
5. Backend → Frontend: real-time data via WebSocket; config and control via REST
6. Frontend → Backend: user actions (device control, config changes)

c. Architectural patterns & principles
- Layered architecture: Edge (hardware), Gateway, Application (server), AI microservices, Presentation (frontend)
- Microservice pattern: separate Python services for easy scaling
- Event-driven: WebSocket for live updates
- Component-based UI: React components per domain (device, admin, charts)

d. Key technologies
- Hardware: Arduino C++ (.ino)
- Edge code: Node.js serialport (serialReader.js)
- Server: Node.js, Express.js, ws or socket.io
- ML: TensorFlow/Keras (.h5), XGBoost (.joblib), Flask or FastAPI (app.py)
- Frontend: React.js, Vite, Tailwind CSS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        Sensors["Sensors (pH, TDS, Temperature, Humidity)"]:::hardware
        Ionizer["Ionizer Condenser"]:::hardware
        Arduino["Arduino Firmware"]:::hardware
    end
    click Arduino "https://github.com/mitishraina/dewdrop/blob/main/hardware/sensors/sensors.ino"

    %% Edge Gateway Layer
    subgraph "Edge Gateway"
        direction TB
        SR_HW["serialReader.js (Edge Collector)"]:::nodejs
        SR_SRV["serialReader.js (Server Gateway)"]:::nodejs
    end
    click SR_HW "https://github.com/mitishraina/dewdrop/blob/main/hardware/sensors/serialReader.js"
    click SR_SRV "https://github.com/mitishraina/dewdrop/blob/main/server/hardware/serialReader.js"

    %% Backend Server
    subgraph "Backend Server"
        direction TB
        API_Server["index.js (Entry Point)"]:::nodejs
        subgraph "REST & WebSocket Modules"
            DeviceControl["Device Control API"]:::nodejs
            WebSocket["WebSocket Module"]:::nodejs
        end
    end
    click API_Server "https://github.com/mitishraina/dewdrop/blob/main/server/index.js"
    click DeviceControl "https://github.com/mitishraina/dewdrop/blob/main/server/routes/deviceControl.js"
    click WebSocket "https://github.com/mitishraina/dewdrop/blob/main/server/routes/websocket.js"

    %% ML Microservices
    subgraph "ML Microservices"
        direction TB
        FogService["Fog Prediction Service"]:::python
        FogModel["Model: fogpredictionmodel.h5"]:::datastore
        WaterService["Water Quality Service"]:::python
        WaterModel["Model: xgboost_model.joblib"]:::datastore
    end
    click FogService "https://github.com/mitishraina/dewdrop/blob/main/python models/main.py"
    click FogModel "https://github.com/mitishraina/dewdrop/blob/main/python models/fogpredictionmodel.h5"
    click WaterService "https://github.com/mitishraina/dewdrop/blob/main/python models/water quality/app.py"
    click WaterModel "https://github.com/mitishraina/dewdrop/blob/main/python models/water quality/xgboost_model.joblib"

    %% Data Store
    CSV["CSV Files (Data Persistence)"]:::datastore

    %% Frontend Dashboard
    subgraph "Frontend Dashboard"
        direction TB
        FE_Entry["main.jsx (Entry Point)"]:::frontend
        AppComp["App.jsx"]:::frontend
        Layout["Layout.jsx"]:::frontend
        subgraph "Pages"
            HomePage["HomePage.jsx"]:::frontend
            UserDashboard["UserDashboard.jsx"]:::frontend
            DevicePage["DevicePage.jsx"]:::frontend
            AdminPanel["AdminPanel.jsx"]:::frontend
            NotFound["NotFound.jsx"]:::frontend
        end
        subgraph "Components"
            SensorDash["SensorDashboard.jsx"]:::frontend
            AdminMap["AdminMap.jsx"]:::frontend
            DeviceSummary["DeviceSummary.jsx"]:::frontend
            WaterChart["WaterUsageChart.jsx"]:::frontend
        end
        Utils["utils.js"]:::frontend
    end
    click FE_Entry "https://github.com/mitishraina/dewdrop/blob/main/src/main.jsx"
    click AppComp "https://github.com/mitishraina/dewdrop/blob/main/src/App.jsx"
    click Layout "https://github.com/mitishraina/dewdrop/blob/main/src/components/Layout.jsx"
    click SensorDash "https://github.com/mitishraina/dewdrop/blob/main/src/components/SensorDashboard.jsx"
    click AdminMap "https://github.com/mitishraina/dewdrop/blob/main/src/components/admin/AdminMap.jsx"
    click DeviceSummary "https://github.com/mitishraina/dewdrop/blob/main/src/components/device/DeviceSummary.jsx"
    click WaterChart "https://github.com/mitishraina/dewdrop/blob/main/src/components/charts/WaterUsageChart.jsx"
    click Utils "https://github.com/mitishraina/dewdrop/blob/main/src/lib/utils.js"
    click HomePage "https://github.com/mitishraina/dewdrop/blob/main/src/pages/HomePage.jsx"
    click UserDashboard "https://github.com/mitishraina/dewdrop/blob/main/src/pages/UserDashboard.jsx"
    click DevicePage "https://github.com/mitishraina/dewdrop/blob/main/src/pages/DevicePage.jsx"
    click AdminPanel "https://github.com/mitishraina/dewdrop/blob/main/src/pages/AdminPanel.jsx"
    click NotFound "https://github.com/mitishraina/dewdrop/blob/main/src/pages/NotFound.jsx"

    %% Connections
    Sensors --> Arduino
    Ionizer --> Arduino
    Arduino --> SR_HW
    SR_HW --> SR_SRV
    SR_SRV --> API_Server
    API_Server --> DeviceControl
    API_Server --> WebSocket
    API_Server --> FogService
    API_Server --> WaterService
    FogService --> FogModel
    WaterService --> WaterModel
    FogService --> API_Server
    WaterService --> API_Server
    API_Server --> CSV
    CSV --> API_Server
    API_Server --> WebSocket
    WebSocket --> AppComp
    DeviceControl --> AppComp
    AppComp --> Layout
    Layout --> HomePage
    Layout --> UserDashboard
    Layout --> DevicePage
    Layout --> AdminPanel
    Layout --> NotFound
    HomePage --> SensorDash
    UserDashboard --> WaterChart
    DevicePage --> DeviceSummary
    AdminPanel --> AdminMap
    AppComp --> Utils

    %% Styles
    classDef hardware fill:#dddddd,stroke:#888888,stroke-width:1px
    classDef nodejs fill:#bbe1fa,stroke:#3282b8,stroke-width:1px
    classDef python fill:#d0f0c0,stroke:#3a5f0b,stroke-width:1px
    classDef frontend fill:#e2c6ff,stroke:#9b59b6,stroke-width:1px
    classDef datastore fill:#ffe6a7,stroke:#e67e22,stroke-width:1px
```
