# rufus800/energy-meter-monitoring- architecture

> Architecture diagram of the GitHub repository rufus800/energy-meter-monitoring-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rufus800/energy-meter-monitoring-
- Repository: https://github.com/rufus800/energy-meter-monitoring-

## Overview

This is a Flask-based power-quality and energy monitoring dashboard. Its main workflow is PLC polling, persistence of readings, and presentation of live values and historical analytics through two browser pages; an AI assistant can use live and historical context to answer questions. The README also documents deployment behind an existing Cloudflare tunnel. The backend excerpts support the database, history, and AI paths, but do not show every route or the HTML request details, so those connections are kept at the documented application level.

Main entry points: [`plc_reader.py`](https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py) (Flask Application), [`history.db`](https://github.com/rufus800/energy-meter-monitoring-/blob/main/history.db) (Readings Database), [`dashboard.html`](https://github.com/rufus800/energy-meter-monitoring-/blob/main/dashboard.html) (Live Dashboard), [`analytics.html`](https://github.com/rufus800/energy-meter-monitoring-/blob/main/analytics.html) (Analytics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Dashboard UI"]
  node_live_ui["Live Dashboard<br/>[dashboard.html]"]
  node_analytics_ui["Analytics<br/>[analytics.html]"]
end

subgraph group_backend["Monitoring Backend"]
  node_app["Flask Application<br/>[plc_reader.py]"]
  node_poller["PLC Polling<br/>[plc_reader.py]"]
  node_history_api["History API<br/>[plc_reader.py]"]
  node_history_stats["History Analysis<br/>[plc_reader.py]"]
  node_assistant["AI Assistant<br/>[plc_reader.py]"]
end

subgraph group_integrations["Data Integrations"]
  node_readings[("Readings Database<br/>[history.db]")]
  node_plc["Siemens PLC"]
  node_groq["Groq Chat API"]
  node_tunnel["Cloudflare Tunnel"]
end

node_operator(("Operator"))

node_operator -->|"views live data"| node_live_ui
node_operator -->|"views analytics"| node_analytics_ui
node_live_ui -->|"uses dashboard"| node_app
node_analytics_ui -->|"requests history"| node_app
node_app -->|"runs polling"| node_poller
node_poller -->|"reads measurements"| node_plc
node_poller -->|"stores readings"| node_readings
node_history_api -->|"queries history"| node_readings
node_history_stats -->|"reads statistics"| node_readings
node_assistant -->|"builds context"| node_history_stats
node_app -->|"serves history"| node_history_api
node_app -->|"serves chat"| node_assistant
node_assistant -->|"streams completion"| node_groq
node_tunnel -.->|"routes port 5002"| node_app

click node_live_ui "https://github.com/rufus800/energy-meter-monitoring-/blob/main/dashboard.html"
click node_analytics_ui "https://github.com/rufus800/energy-meter-monitoring-/blob/main/analytics.html"
click node_app "https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py"
click node_poller "https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py"
click node_history_api "https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py"
click node_history_stats "https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py"
click node_assistant "https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py"
click node_readings "https://github.com/rufus800/energy-meter-monitoring-/blob/main/history.db"
click node_tunnel "https://github.com/rufus800/energy-meter-monitoring-/blob/main/cloudflare-config-template.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_live_ui,node_analytics_ui toneBlue
class node_app,node_poller,node_history_api,node_history_stats,node_assistant toneAmber
class node_readings,node_plc,node_groq,node_tunnel toneMint
class node_operator toneIndigo
```

## Components

### Dashboard UI

- [Live Dashboard](https://github.com/rufus800/energy-meter-monitoring-/blob/main/dashboard.html): `dashboard.html`
- [Analytics](https://github.com/rufus800/energy-meter-monitoring-/blob/main/analytics.html): `analytics.html`

### Monitoring Backend

- [Flask Application](https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py): `plc_reader.py`
- [PLC Polling](https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py): `plc_reader.py`
- [History API](https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py): `plc_reader.py`
- [History Analysis](https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py): `plc_reader.py`
- [AI Assistant](https://github.com/rufus800/energy-meter-monitoring-/blob/main/plc_reader.py): `plc_reader.py`

### Data Integrations

- [Readings Database](https://github.com/rufus800/energy-meter-monitoring-/blob/main/history.db): `history.db`
- **Siemens PLC**
- **Groq Chat API**
- [Cloudflare Tunnel](https://github.com/rufus800/energy-meter-monitoring-/blob/main/cloudflare-config-template.yml): `cloudflare-config-template.yml`

### Other components

- **Operator**

## Connections

- Operator → Live Dashboard: views live data
- Operator → Analytics: views analytics
- Live Dashboard → Flask Application: uses dashboard
- Analytics → Flask Application: requests history
- Flask Application → PLC Polling: runs polling
- PLC Polling → Siemens PLC: reads measurements
- PLC Polling → Readings Database: stores readings
- History API → Readings Database: queries history
- History Analysis → Readings Database: reads statistics
- AI Assistant → History Analysis: builds context
- Flask Application → History API: serves history
- Flask Application → AI Assistant: serves chat
- AI Assistant → Groq Chat API: streams completion
- Cloudflare Tunnel → Flask Application: routes port 5002
