# iot-projects/iot-home-temp-tracking architecture

> Architecture diagram of the GitHub repository iot-projects/iot-home-temp-tracking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iot-projects/iot-home-temp-tracking
- Repository: https://github.com/iot-projects/iot-home-temp-tracking

## Overview

##### Main Components
- ESP8266 Device: This is the hardware component that measures temperature using the DHT22 sensor. It sends a GET request with the measurement data.
- Central Server (API): The server side includes PHP files (api.php in both the root and “src” directories) that handle the incoming GET requests from the sensors. The README also mentions the use of PHP and SQLite for storing the data.
- Web Application Frontend:
- The “src” folder contains HTML (index.html, setup.html), JavaScript (including get-temp.js, main.js, and React components in the “src/react” folder) and style files (LESS and SCSS).
- The “dist” folder is the built output (compiled HTML, CSS, and JavaScript).
- External Service Integration: The README suggests integrating with openweathermap.org to fetch local weather data, which can be shown as an additional data source or external dependency.

##### Understand the Flow and Relationships
- Backend Data Processing: Illustrate how the API (PHP scripts) receives the data and then (presumably) writes it to a database (e.g., SQLite) even if the database isn’t explicitly seen in the file tree; it’s mentioned in the README.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Distinguish clearly between hardware (ESP8266), backend (PHP API server), and the frontend (React and traditional JavaScript UI).
- Build Process: Indicate the transformation from the “src” directory to the “dist” distribution directory via build tools (grunt, as indicated by gruntfile.js, and package.json). This shows the build/deployment pipeline.
- Modularity: Point out how the code is organized (e.g., separating React components, libraries under src/js/lib, and style components in src/less and src/scss), emphasizing extensibility and clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Hardware Layer
    subgraph "Hardware Layer"
        sensor("ESP8266 (Hardware Sensor) [DHT22]"):::hardware
        firmware("Sensor Firmware"):::hardware
    end

    %% Backend Layer
    subgraph "Backend Layer"
        apiRoot("API Root (api.php)"):::backend
        apiSrc("API Src (src/api.php)"):::backend
        db("SQLite Database"):::database
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        htmlIndex("HTML: index.html"):::frontend
        htmlSetup("HTML: setup.html"):::frontend
        jsMain("JS: main.js"):::frontend
        jsGet("JS: get-temp.js"):::frontend
        reactApp("React: app.jsx"):::frontend
        reactCard("React: card.jsx"):::frontend
        reactMain("React: main-content.jsx"):::frontend
        lessFiles("LESS Styles"):::frontend
        scssFiles("SCSS Styles"):::frontend
    end

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        process("Build Process"):::build
        grunt("Gruntfile"):::build
        pkg("Package.json"):::build
        dist("Distribution Build Output (dist)"):::build
    end

    %% External Service
    external("External Weather Service"):::external

    %% Connections between layers
    sensor -->|"GET_request"| apiRoot
    apiRoot -->|"stores_data"| db
    apiSrc -->|"stores_data"| db
    htmlIndex -->|"client_call"| apiRoot
    jsMain -->|"client_call"| apiRoot
    jsGet -->|"client_call"| apiRoot
    apiRoot -->|"weather_call"| external

    %% Build process connections
    htmlIndex -->|"build_trigger"| process
    jsMain -->|"build_trigger"| process
    reactApp -->|"build_trigger"| process
    lessFiles -->|"build_trigger"| process
    scssFiles -->|"build_trigger"| process
    process -->|"configured_by"| grunt
    process -->|"configured_by"| pkg
    process -->|"outputs"| dist

    %% Click Events for Hardware
    click firmware "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/esp8266/temp-web-IoT/temp-web-IoT.ino"

    %% Click Events for Backend
    click apiRoot "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/api.php"
    click apiSrc "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/api.php"

    %% Click Events for Frontend HTML
    click htmlIndex "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/index.html"
    click htmlSetup "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/setup.html"

    %% Click Events for Frontend JavaScript
    click jsMain "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/js/main.js"
    click jsGet "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/js/get-temp.js"

    %% Click Events for React Components
    click reactApp "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/react/app.jsx"
    click reactCard "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/react/card.jsx"
    click reactMain "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/src/react/main-content.jsx"

    %% Click Events for Frontend Styling
    click lessFiles "https://github.com/iot-projects/iot-home-temp-tracking/tree/master/src/less"
    click scssFiles "https://github.com/iot-projects/iot-home-temp-tracking/tree/master/src/scss"

    %% Click Events for Build & Deployment
    click grunt "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/gruntfile.js"
    click pkg "https://github.com/iot-projects/iot-home-temp-tracking/blob/master/package.json"
    click dist "https://github.com/iot-projects/iot-home-temp-tracking/tree/master/dist"

    %% Styles
    classDef hardware fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef database fill:#FFFACD,stroke:#000,stroke-width:1px;
    classDef frontend fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef build fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
