# 10xrashed/kidneywashingunit architecture

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

- Interactive diagram: https://gitdiagram.com/10xrashed/kidneywashingunit
- Repository: https://github.com/10xrashed/kidneywashingunit

## Overview

##### Project Type and Purpose
- This is an embedded + web full-stack system: an ESP32-based hardware controller that monitors and controls a portable dialysis unit and a glass-morphism web dashboard for real-time visualization and remote control.

##### Analysis of File Structure
- Top-level source:
- dialysis-controller.cpp → the Arduino/C++ firmware for the ESP32
- dialysis-dashboard.html → the standalone HTML/CSS/JS UI
- Documentation:
- README.md → detailed overview, architecture, wiring
- manual.txt → likely quickstart or hardware notes
- PPTX & CAD files (.pptx, .3mf, .f3d) → hardware design / 3D models
- No dedicated “backend” service: the ESP32 acts as both data source and HTTP server/client.

##### Main Architectural Components
a. Hardware Controller (ESP32)
- Sensor Inputs: DS18B20 (temp), flow sensor (hall effect), analog pressure, analog conductivity
- Actuators/Safety: two solenoid valves, pump relay, heater relay, status LEDs, buzzer
- On-device UI: 16×2 I2C LCD, emergency-stop button
- Communication: WiFi ↔ HTTP/JSON
b. Web Dashboard
- Browser-based UI (HTML/CSS/JS) using Fetch API to poll or receive updates
- Visualization: circular progress indicators, alert notifications, start/stop controls
c. Optional Future Components (not in code but in README):
- SD-card data logger
- Cloud IoT broker (MQTT)
- User profile backend

##### Component Interactions and Data Flow
1. Sensors → ESP32 read & convert raw data
2. ESP32 safety logic → control relays, LEDs, buzzer, LCD
3. ESP32 packages JSON payload → sends via HTTPClient or serves via built-in web server
4. Browser UI fetches / polls JSON → updates dashboards & triggers notifications
5. UI commands (start/stop) → HTTP request → ESP32 changes state

##### Architectural Patterns and Principles
- Single-board microcontroller as edge device + lightweight HTTP/JSON API
- Event-driven sensor loop with interrupt for flow sensor
- Fail-safe design: threshold checks trigger immediate relay shutdown
- Separation of concerns: firmware handles real-time control; dashboard handles visualization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Elements
    subgraph "Hardware Elements" 
        direction TB
        TempSensor["DS18B20 Temp Sensor"]:::hardware
        FlowSensor["Hall Effect Flow Sensor"]:::hardware
        PressureSensor["Analog Pressure Sensor"]:::hardware
        ConductivitySensor["Analog Conductivity Sensor"]:::hardware
        SolenoidValves["Solenoid Valves"]:::hardware
        PumpRelay["Pump Relay"]:::hardware
        HeaterRelay["Heater Relay"]:::hardware
        LEDs["Status LEDs"]:::hardware
        Buzzer["Buzzer"]:::hardware
        EStopButton["Emergency-Stop Button"]:::hardware
        LCD["16×2 I2C LCD"]:::hardware
    end

    %% ESP32 Controller
    subgraph "ESP32 Controller" 
        direction TB
        SensorReader["Sensor Reader Module"]:::software
        SafetyModule["Safety Logic Module"]:::safety
        CommModule["Communication Module (HTTP/JSON)"]:::software
        LocalUI["Local UI Handler"]:::software
    end
    click ESP32Controller "https://github.com/10xrashed/kidneywashingunit/blob/main/dialysis-controller.cpp"

    %% Connectivity
    WiFiRouter["WiFi / HTTP Network"]:::hardware
    BrowserUI["Web Dashboard (HTML/CSS/JS)"]:::software
    click BrowserUI "https://github.com/10xrashed/kidneywashingunit/blob/main/dialysis-dashboard.html"

    %% Documentation
    subgraph "Documentation & Assets"
        direction TB
        README["System Architecture Overview"]:::documentation
        manual["Quickstart & Hardware Notes"]:::documentation
        pptx["Hardware Design Presentation"]:::documentation
        cad1["PI3MK3M_Part122.3mf"]:::documentation
        cad2["PI3MK3M_Part3.f3d"]:::documentation
        cad3["PI3MK3M_Part4.3mf"]:::documentation
        license["License Information"]:::documentation
    end
    click README "https://github.com/10xrashed/kidneywashingunit/blob/main/README.md"
    click manual "https://github.com/10xrashed/kidneywashingunit/blob/main/manual.txt"
    click pptx "https://github.com/10xrashed/kidneywashingunit/blob/main/Kidney-Washing-Unit-Portable-Smart-Dialysis.pptx"
    click cad1 "https://github.com/10xrashed/kidneywashingunit/blob/main/PI3MK3M_Part122.3mf"
    click cad2 "https://github.com/10xrashed/kidneywashingunit/blob/main/PI3MK3M_Part3.f3d"
    click cad3 "https://github.com/10xrashed/kidneywashingunit/blob/main/PI3MK3M_Part4.3mf"
    click license "https://github.com/10xrashed/kidneywashingunit/tree/main/LICENSE"

    %% Data Flows
    TempSensor -->|OneWire Data| SensorReader
    FlowSensor -->|Interrupt Event| SensorReader
    PressureSensor -->|Analog Read| SensorReader
    ConductivitySensor -->|Analog Read| SensorReader

    SensorReader -->|"Sensor Data"| SafetyModule
    SafetyModule -->|"Control Signals"| SolenoidValves
    SafetyModule -->|"Control Signals"| PumpRelay
    SafetyModule -->|"Control Signals"| HeaterRelay
    SafetyModule -->|"LED/Buzzer Alerts"| LEDs
    SafetyModule -->|"LED/Buzzer Alerts"| Buzzer
    SafetyModule -->|"Display Data"| LocalUI
    LocalUI -->|I2C| LCD
    LocalUI -->|Digital| EStopButton

    SafetyModule -->|"Emergency Shutdown"| SolenoidValves
    SafetyModule -->|"Emergency Shutdown"| PumpRelay
    SafetyModule -->|"Emergency Shutdown"| HeaterRelay

    SafetyModule -->|"JSON Payload"| CommModule
    CommModule -->|"HTTP Serve/Client"| WiFiRouter
    WiFiRouter -->|"HTTP/JSON Poll"| BrowserUI
    BrowserUI -->|"Start/Stop Requests"| WiFiRouter
    WiFiRouter -->|"Commands"| CommModule
    CommModule -->|"Actuator Commands"| SafetyModule

    %% Styles
    classDef hardware fill:#cce5ff,stroke:#004085
    classDef software fill:#d4edda,stroke:#155724
    classDef safety fill:#f8d7da,stroke:#721c24
    classDef documentation fill:#fff3cd,stroke:#856404

    class TempSensor,FlowSensor,PressureSensor,ConductivitySensor,SolenoidValves,PumpRelay,HeaterRelay,LEDs,Buzzer,EStopButton,LCD,WiFiRouter hardware
    class SensorReader,CommModule,LocalUI,BrowserUI software
    class SafetyModule safety
    class README,manual,pptx,cad1,cad2,cad3,license documentation
```
