# aneazi/weatherpi architecture

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

- Interactive diagram: https://gitdiagram.com/aneazi/weatherpi
- Repository: https://github.com/aneazi/weatherpi

## Overview

##### Project type and purpose
- This is a small, two‐component full-stack IoT application (“WeatherPI”) designed for a Raspberry Pi.
- “pi-publisher” reads local sensors and publishes measurements.
- “weather-dashboard” subscribes to those measurements and provides a web dashboard.

##### File structure
Top‐level:
- config.yaml – global configuration (e.g., broker URL, topics)
- pi-publisher/ – Dockerized Python publisher
– Dockerfile, requirements.txt
– src/publisher.py, src/sensors.py, src/utils.py
- weather-dashboard/ – Python web subscriber + UI
– src/server.py (HTTP server), src/subscriber.py, src/utils.py
– static/ (CSS, JS for charting)
– templates/index.html

##### README insights
- Shows how to build/run the publisher container on a Pi.
- Implies use of a message broker (likely MQTT).
- No explicit mention of broker; assumed external.

##### Main components
a. Hardware & OS layer
- Raspberry Pi + physical sensors
b. Publisher component (Container)
- sensors.py: reads from GPIO/hardware
- publisher.py: publishes to broker (e.g., MQTT)
- utils.py: common helpers
c. Message broker (external service)
- MQTT Broker (could be local or cloud)
d. Subscriber component (Web server)
- subscriber.py: subscribes to broker topics, stores or buffers data
- server.py: runs a web server (Flask/HTTP) to serve HTML/JS
- utils.py: common code (e.g., config parsing)
e. Frontend (Browser)
- templates/index.html
- static/js/chart-setup.js (Chart.js or similar)
- static/css/styles.css

##### Relationships and interactions
1. sensors.py → publisher.py: raw readings passed to publisher
2. publisher.py → MQTT Broker: publishes messages on a topic (e.g., “weather/data”)
3. MQTT Broker → subscriber.py: subscriber receives live data
4. subscriber.py → server.py: passes or caches data for HTTP endpoints (e.g., /data)
5. server.py → Browser: serves index.html and exposes REST or WebSocket for live updates
6. Browser (chart-setup.js) → subscribes over HTTP/WebSocket to render charts

##### Architectural patterns and design principles
- Containerization (Docker) isolates the publisher on the Pi.
- Pub/Sub messaging decouples publisher and dashboard.
- Separation of concerns: sensor I/O vs. data transport vs. presentation.
- Single‐page dashboard client with static assets and dynamic charting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Raspberry Pi and Publisher
    subgraph "Raspberry Pi" 
        direction TB
        Config["config.yaml"]:::external
        subgraph "pi-publisher Container" 
            direction TB
            SENS["sensors.py"]:::backend
            PUB["publisher.py"]:::backend
            UTIL_PUB["utils.py"]:::backend
        end
    end

    %% External MQTT Broker
    MQTT["MQTT Broker"]:::external

    %% Weather Dashboard Service
    subgraph "weather-dashboard" 
        direction TB
        subgraph "Subscriber Service" 
            direction TB
            SUB["subscriber.py"]:::backend
            SERV["server.py"]:::backend
            UTIL_SUB["utils.py"]:::backend
        end
        subgraph "Frontend Assets" 
            direction TB
            HTML["index.html"]:::frontend
            CSS["styles.css"]:::frontend
            JS["chart-setup.js"]:::frontend
        end
    end

    %% Browser Client
    Browser["Browser (Client)"]:::frontend

    %% Data Flows and Relationships
    Config --> SENS
    Config --> SUB
    SENS -->|"raw readings"| PUB
    PUB -->|"MQTT publish(weather/data)"| MQTT
    MQTT -->|"MQTT subscribe(weather/data)"| SUB
    SUB -->|"passes data"| SERV
    SERV -->|"HTTP GET/WS"| Browser
    SERV -->|"serves"| HTML
    SERV -->|"serves"| CSS
    SERV -->|"serves"| JS
    Browser -->|"loads"| HTML
    Browser -->|"loads"| CSS
    Browser -->|"loads"| JS

    %% Click Events
    click Config "https://github.com/aneazi/weatherpi/blob/main/config.yaml"
    click SENS "https://github.com/aneazi/weatherpi/blob/main/pi-publisher/src/sensors.py"
    click PUB "https://github.com/aneazi/weatherpi/blob/main/pi-publisher/src/publisher.py"
    click UTIL_PUB "https://github.com/aneazi/weatherpi/blob/main/pi-publisher/src/utils.py"
    click MQTT "https://github.com/aneazi/weatherpi/tree/main/N/A"
    click SUB "https://github.com/aneazi/weatherpi/blob/main/weather-dashboard/src/subscriber.py"
    click SERV "https://github.com/aneazi/weatherpi/blob/main/weather-dashboard/src/server.py"
    click UTIL_SUB "https://github.com/aneazi/weatherpi/blob/main/weather-dashboard/src/utils.py"
    click HTML "https://github.com/aneazi/weatherpi/blob/main/weather-dashboard/templates/index.html"
    click CSS "https://github.com/aneazi/weatherpi/blob/main/weather-dashboard/static/css/styles.css"
    click JS "https://github.com/aneazi/weatherpi/blob/main/weather-dashboard/static/js/chart-setup.js"

    %% Styles
    classDef backend fill:#e3f2fd,stroke:#1976d2,color:#0d47a1
    classDef dataflow stroke:#43a047,stroke-width:2px
    classDef frontend fill:#fff3e0,stroke:#fb8c00,color:#e65100
    classDef external fill:#eeeeee,stroke:#9e9e9e,color:#424242
```
