# pouryaparsa/espressiot architecture

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

- Interactive diagram: https://gitdiagram.com/pouryaparsa/espressiot
- Repository: https://github.com/pouryaparsa/espressiot

## Overview

##### Main System Components

a) Hardware Layer
- ESP8266 Microcontroller (central component)
- TSIC 306 Temperature Sensor
- Solid State Relay (SSR)
- Espresso Machine Heater
- Physical Connections

b) Firmware Layer (on ESP8266)
- Core Control Logic
- PID Controller
- SPIFFS (for JSON config storage)

c) Communication Interfaces
- WiFi Connection
- MQTT Broker Connection
- Web Server
- Telnet Server
- OTA Update System

##### Component Relationships and Data Flow

a) Physical Control Flow:
**Temperature Sensor → ESP8266 → SSR → Heater**

b) Data Flow Paths:
**ESP8266 ←→ WiFi Router**
- ↓
**[Multiple Interfaces]**
- MQTT Broker
- Web Interface
- Telnet Console
- OTA Updates

##### Specific Implementation Details

Key software components (based on the .ino files):
- config.ino: Configuration management
- heater.ino: Heater control logic
- mqtt.ino: MQTT communication
- sensor_tsic.ino: Temperature sensing
- web.ino: Web interface
- tuning.ino: PID auto-tuning
- simulation.ino: System simulation

##### Key Features to Highlight

Critical aspects:
- PID Control Loop
- Configuration Storage (SPIFFS/JSON)
- Multiple Interface Options
- Safety Controls
- Tuning Capabilities

##### Architectural Patterns

Patterns:
- Event-driven architecture (for sensor readings and control)
- Publisher-Subscriber pattern (MQTT)
- RESTful interface (Web control)
- State management (heater control)

##### Technical Details

Annotations for:
- Temperature sampling rate
- Control loop frequency
- Communication protocols (MQTT, HTTP, Telnet)
- Storage requirements
- Safety thresholds

This approach will provide a clear visualization of how the ESPressIoT system integrates hardware control with IoT capabilities while maintaining precise temperature regulation for the espresso machine.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        ESP[ESP8266 Microcontroller]
        TSIC[TSIC 306 Temperature Sensor]
        SSR[Solid State Relay]
        HEAT[Espresso Machine Heater]
        TSIC -->|Temperature Data| ESP
        ESP -->|Control Signal| SSR
        SSR -->|Power Control| HEAT
    end

    subgraph Firmware
        MCL[Main Control Logic]:::code
        PID[PID Controller]
        SPIFFS[SPIFFS Storage]
        CONFIG[Configuration Management]:::code
        HEATER[Heater Control System]:::code
        TEMP[Temperature Sensor Interface]:::code
        UTILS[Utility Functions]:::code
        THERM[Thermostat Detection]:::code
        SIM[Simulation Module]:::code
        TUNE[PID Tuning System]:::code

        MCL <--> PID
        MCL <--> SPIFFS
        MCL <--> CONFIG
        MCL <--> HEATER
        MCL <--> TEMP
        MCL <--> UTILS
        MCL <--> THERM
        MCL <--> SIM
        PID <--> TUNE
    end

    subgraph Communication
        WIFI[WiFi Configuration]:::code
        MQTT[MQTT Interface]:::code
        WEB[Web Interface]:::code
        TELNET[Telnet Interface]:::code
        OTA[OTA Update System]

        ESP <--> WIFI
        WIFI --> MQTT
        WIFI --> WEB
        WIFI --> TELNET
        WIFI --> OTA
    end

    %% Hardware to Firmware Connections
    TSIC -.-> TEMP
    SSR -.-> HEATER
    HEAT -.-> THERM

    %% Firmware to Communication Connections
    MCL --> MQTT
    MCL --> WEB
    MCL --> TELNET

    classDef code fill:#f9f,stroke:#333,stroke-width:2px
    classDef hardware fill:#aaf,stroke:#333,stroke-width:2px
    classDef communication fill:#afa,stroke:#333,stroke-width:2px

    click MCL "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/espressiot.ino"
    click TEMP "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/sensor_tsic.ino"
    click HEATER "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/heater.ino"
    click CONFIG "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/config.ino"
    click MQTT "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/mqtt.ino"
    click WEB "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/web.ino"
    click TELNET "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/telnet.ino"
    click TUNE "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/tuning.ino"
    click SIM "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/simulation.ino"
    click WIFI "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/WiFiSecrets.h"
    click THERM "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/thermostatSwitchDetection.ino"
    click UTILS "https://github.com/PouryaParsa/ESPressIoT/blob/master-arduino/espressiot/helpers.ino"
```
