# gitnonta/smartenergy architecture

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

- Interactive diagram: https://gitdiagram.com/gitnonta/smartenergy
- Repository: https://github.com/gitnonta/smartenergy

## Overview

Smart Energy Monitoring Dashboard receives AI205 meter telemetry through MQTT, processes and stores time-series data, then serves live updates and query results to a React dashboard. Users can inspect live electrical measurements, historical energy summaries and alerts; supporting branches cover authentication and administration, AI chat, device firmware, and customizable layouts. The README documents the MQTT-to-WebSocket flow; sampled source confirms several backend service and frontend context relationships. Some feature implementations were not sampled, so their internal links are omitted rather than inferred.

Main entry points: [`backend/src/routes/index.js`](https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/index.js) (Route registration), [`frontend/src/App.tsx`](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/App.tsx) (Application routing), [`backend/src/server.js`](https://github.com/gitnonta/smartenergy/blob/main/backend/src/server.js) (API and WebSocket server), [`backend/src/ingestor.js`](https://github.com/gitnonta/smartenergy/blob/main/backend/src/ingestor.js) (Telemetry ingestor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telemetry["Telemetry and storage"]
  node_ingestor["Telemetry ingestor<br/>[ingestor.js]"]
  node_influx[("Time-series store<br/>[influxdb.js]")]
  node_alerts["Alert processing<br/>[alertService.js]"]
  node_line["Line messaging"]
end

subgraph group_api["Backend API"]
  node_server["API and WebSocket server<br/>[server.js]"]
  node_routes["Route registration<br/>[index.js]"]
  node_energyapi["Energy endpoints<br/>[energyRoutes.js]"]
  node_energycalc["Energy calculations"]
end

subgraph group_identity["Identity and admin"]
  node_authroutes["Authentication endpoints<br/>[authRoutes.js]"]
  node_sessions["Session management<br/>[sessionService.js]"]
  node_activity["Activity audit<br/>[activityLogger.js]"]
  node_sqldb[("User and session database<br/>[db.js]")]
  node_userapi["User management API<br/>[userRoutes.js]"]
  node_login["Login view<br/>[LoginPage.tsx]"]
  node_adminui["User administration"]
end

subgraph group_dashboard["Dashboard experience"]
  node_app["Application routing<br/>[App.tsx]"]
  node_shell["Dashboard shell<br/>[AppShell.tsx]"]
  node_live["Live telemetry view<br/>[DashboardPage.tsx]"]
  node_wscontext["Live data context"]
  node_wsclient["WebSocket client<br/>[webSocketClient.ts]"]
  node_history["Historical data access<br/>[influxService.ts]"]
  node_alertspage["Alerts view<br/>[AlertsPage.tsx]"]
end

subgraph group_extensions["Product extensions"]
  node_chat["AI chat<br/>[aiChatService.js]"]
  node_chatwidget["Chat widget<br/>[ChatWidget.tsx]"]
  node_firmwareui["Firmware management"]
  node_firmware["Firmware operations<br/>[firmwareManager.js]"]
  node_layout["Dashboard layouts<br/>[layoutService.js]"]
  node_layoutapi["Layout endpoints<br/>[layoutRoutes.js]"]
end

node_meter(("AI205 meter"))
node_broker(("MQTT broker"))
node_user(("Dashboard user"))

node_meter -->|"publishes telemetry"| node_broker
node_broker -->|"delivers MQTT"| node_ingestor
node_ingestor -->|"writes measurements"| node_influx
node_ingestor -->|"checks alerts"| node_alerts
node_ingestor -->|"sends notifications"| node_line
node_server -->|"queries data"| node_influx
node_server -->|"mounts routes"| node_routes
node_routes -->|"registers route"| node_energyapi
node_energyapi -->|"uses calculations"| node_energycalc
node_routes -->|"registers route"| node_authroutes
node_authroutes -->|"creates sessions"| node_sessions
node_authroutes -->|"logs activity"| node_activity
node_sessions -->|"reads and updates"| node_sqldb
node_activity -->|"writes audit data"| node_sqldb
node_routes -->|"registers route"| node_userapi
node_server -->|"streams live data"| node_user
node_user -->|"uses dashboard"| node_app
node_app -->|"renders shell"| node_shell
node_app -->|"routes dashboard"| node_live
node_app -->|"routes alerts"| node_alertspage
node_app -->|"routes login"| node_login
node_app -->|"routes administration"| node_adminui
node_shell -->|"uses live context"| node_wscontext
node_wscontext -->|"connects client"| node_wsclient
node_wscontext -->|"receives WebSocket data"| node_server
node_history -->|"requests historical data"| node_server
node_routes -->|"registers chat service"| node_chat
node_shell -->|"renders widget"| node_chatwidget
node_firmwareui -.->|"requests firmware operations"| node_firmware
node_routes -->|"registers route"| node_layoutapi
node_layoutapi -.->|"uses layout service"| node_layout

click node_ingestor "https://github.com/gitnonta/smartenergy/blob/main/backend/src/ingestor.js"
click node_influx "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/influxdb.js"
click node_alerts "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/alertService.js"
click node_line "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/lineMessagingService.js"
click node_server "https://github.com/gitnonta/smartenergy/blob/main/backend/src/server.js"
click node_routes "https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/index.js"
click node_energyapi "https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/energyRoutes.js"
click node_energycalc "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/energyCalculation.js"
click node_authroutes "https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/authRoutes.js"
click node_sessions "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/sessionService.js"
click node_activity "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/activityLogger.js"
click node_sqldb "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/db.js"
click node_userapi "https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/userRoutes.js"
click node_app "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/App.tsx"
click node_shell "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/components/AppShell.tsx"
click node_live "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/dashboard/DashboardPage.tsx"
click node_wscontext "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/context/WebSocketContext.tsx"
click node_wsclient "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/services/webSocketClient.ts"
click node_history "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/services/influxService.ts"
click node_alertspage "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/alerts/AlertsPage.tsx"
click node_login "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/auth/LoginPage.tsx"
click node_adminui "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/admin/UserManagementPage.tsx"
click node_chat "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/aiChatService.js"
click node_chatwidget "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/components/ChatWidget.tsx"
click node_firmwareui "https://github.com/gitnonta/smartenergy/blob/main/frontend/src/components/DeviceFirmwareManager.tsx"
click node_firmware "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/firmwareManager.js"
click node_layout "https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/layoutService.js"
click node_layoutapi "https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/layoutRoutes.js"

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_ingestor,node_influx,node_alerts,node_line,node_user toneBlue
class node_server,node_routes,node_energyapi,node_energycalc toneAmber
class node_authroutes,node_sessions,node_activity,node_sqldb,node_userapi,node_login,node_adminui toneMint
class node_app,node_shell,node_live,node_wscontext,node_wsclient,node_history,node_alertspage toneRose
class node_chat,node_chatwidget,node_firmwareui,node_firmware,node_layout,node_layoutapi,node_meter,node_broker toneIndigo
```

## Components

### Telemetry and storage

- [Telemetry ingestor](https://github.com/gitnonta/smartenergy/blob/main/backend/src/ingestor.js): `backend/src/ingestor.js`
- [Time-series store](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/influxdb.js): `backend/src/services/influxdb.js`
- [Alert processing](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/alertService.js): `backend/src/services/alertService.js`
- [Line messaging](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/lineMessagingService.js): `backend/src/services/lineMessagingService.js`

### Backend API

- [API and WebSocket server](https://github.com/gitnonta/smartenergy/blob/main/backend/src/server.js): `backend/src/server.js`
- [Route registration](https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/index.js): `backend/src/routes/index.js`
- [Energy endpoints](https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/energyRoutes.js): `backend/src/routes/energyRoutes.js`
- [Energy calculations](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/energyCalculation.js): `backend/src/services/energyCalculation.js`

### Identity and admin

- [Authentication endpoints](https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/authRoutes.js): `backend/src/routes/authRoutes.js`
- [Session management](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/sessionService.js): `backend/src/services/sessionService.js`
- [Activity audit](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/activityLogger.js): `backend/src/services/activityLogger.js`
- [User and session database](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/db.js): `backend/src/services/db.js`
- [User management API](https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/userRoutes.js): `backend/src/routes/userRoutes.js`
- [Login view](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/auth/LoginPage.tsx): `frontend/src/features/auth/LoginPage.tsx`
- [User administration](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/admin/UserManagementPage.tsx): `frontend/src/features/admin/UserManagementPage.tsx`

### Dashboard experience

- [Application routing](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Dashboard shell](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/components/AppShell.tsx): `frontend/src/components/AppShell.tsx`
- [Live telemetry view](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/dashboard/DashboardPage.tsx): `frontend/src/features/dashboard/DashboardPage.tsx`
- [Live data context](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/context/WebSocketContext.tsx): `frontend/src/context/WebSocketContext.tsx`
- [WebSocket client](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/services/webSocketClient.ts): `frontend/src/services/webSocketClient.ts`
- [Historical data access](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/services/influxService.ts): `frontend/src/services/influxService.ts`
- [Alerts view](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/features/alerts/AlertsPage.tsx): `frontend/src/features/alerts/AlertsPage.tsx`

### Product extensions

- [AI chat](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/aiChatService.js): `backend/src/services/aiChatService.js`
- [Chat widget](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/components/ChatWidget.tsx): `frontend/src/components/ChatWidget.tsx`
- [Firmware management](https://github.com/gitnonta/smartenergy/blob/main/frontend/src/components/DeviceFirmwareManager.tsx): `frontend/src/components/DeviceFirmwareManager.tsx`
- [Firmware operations](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/firmwareManager.js): `backend/src/services/firmwareManager.js`
- [Dashboard layouts](https://github.com/gitnonta/smartenergy/blob/main/backend/src/services/layoutService.js): `backend/src/services/layoutService.js`
- [Layout endpoints](https://github.com/gitnonta/smartenergy/blob/main/backend/src/routes/layoutRoutes.js): `backend/src/routes/layoutRoutes.js`

### Other components

- **AI205 meter**
- **MQTT broker**
- **Dashboard user**

## Connections

- AI205 meter → MQTT broker: publishes telemetry (evidence: `README.md`)
- MQTT broker → Telemetry ingestor: delivers MQTT (evidence: `README.md`)
- Telemetry ingestor → Time-series store: writes measurements (evidence: `backend/src/ingestor.js`)
- Telemetry ingestor → Alert processing: checks alerts (evidence: `backend/src/ingestor.js`)
- Telemetry ingestor → Line messaging: sends notifications (evidence: `backend/src/ingestor.js`)
- API and WebSocket server → Time-series store: queries data (evidence: `backend/src/server.js`)
- API and WebSocket server → Route registration: mounts routes (evidence: `backend/src/server.js`)
- Route registration → Energy endpoints: registers route (evidence: `backend/src/routes/index.js`)
- Energy endpoints → Energy calculations: uses calculations (evidence: `backend/src/routes/energyRoutes.js`)
- Route registration → Authentication endpoints: registers route (evidence: `backend/src/routes/index.js`)
- Authentication endpoints → Session management: creates sessions (evidence: `backend/src/routes/authRoutes.js`)
- Authentication endpoints → Activity audit: logs activity (evidence: `backend/src/routes/authRoutes.js`)
- Session management → User and session database: reads and updates (evidence: `backend/src/services/sessionService.js`)
- Activity audit → User and session database: writes audit data (evidence: `backend/src/services/activityLogger.js`)
- Route registration → User management API: registers route (evidence: `backend/src/routes/index.js`)
- API and WebSocket server → Dashboard user: streams live data (evidence: `README.md`)
- Dashboard user → Application routing: uses dashboard (evidence: `README.md`)
- Application routing → Dashboard shell: renders shell (evidence: `frontend/src/App.tsx`)
- Application routing → Live telemetry view: routes dashboard (evidence: `frontend/src/App.tsx`)
- Application routing → Alerts view: routes alerts (evidence: `frontend/src/App.tsx`)
- Application routing → Login view: routes login (evidence: `frontend/src/App.tsx`)
- Application routing → User administration: routes administration (evidence: `frontend/src/App.tsx`)
- Dashboard shell → Live data context: uses live context (evidence: `frontend/src/components/AppShell.tsx`)
- Live data context → WebSocket client: connects client (evidence: `frontend/src/context/WebSocketContext.tsx`)
- Live data context → API and WebSocket server: receives WebSocket data (evidence: `README.md`)
- Historical data access → API and WebSocket server: requests historical data (evidence: `README.md`)
- Route registration → AI chat: registers chat service (evidence: `backend/src/routes/index.js`)
- Dashboard shell → Chat widget: renders widget (evidence: `frontend/src/components/AppShell.tsx`)
- Firmware management → Firmware operations: requests firmware operations
- Route registration → Layout endpoints: registers route (evidence: `backend/src/routes/index.js`)
- Layout endpoints → Dashboard layouts: uses layout service
