# sahiliot/nem_plant_monitoring architecture

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

- Interactive diagram: https://gitdiagram.com/sahiliot/nem_plant_monitoring
- Repository: https://github.com/sahiliot/nem_plant_monitoring

## Overview

NEM Plant Monitoring pairs a React dashboard with a FastAPI service. Users authenticate, configure assets, variables and monitoring rules, then submit readings or collect them read-only from OPC UA; the service evaluates conditions, records alerts/events and supports maintenance workflows. Dashboard configuration also covers documents, collections, backup/restore and account settings, with live updates and optional email delivery. The graph preserves these documented capabilities; some subsystem links are based on README descriptions because their implementation files were not sampled.

Main entry points: [`Nem_Backend/app/api/routes`](https://github.com/sahiliot/nem_plant_monitoring/tree/main/Nem_Backend/app/api/routes) (HTTP routes), [`Nem_Backend/app/services/monitoring_engine.py`](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/monitoring_engine.py) (Rule evaluation), [`Nem_Frontend/src/app/App.jsx`](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/app/App.jsx) (React dashboard), [`Nem_Backend/app/services/opcua_collector.py`](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/opcua_collector.py) (OPC UA collector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Dashboard"]
  node_dashboard["React dashboard<br/>[App.jsx]"]
  node_auth_ui["Sign-in state<br/>[AuthContext.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_live_ui["Live updates UI<br/>[liveUpdates.js]"]
end

subgraph group_api["API and access"]
  node_api_routes["HTTP routes"]
  node_auth["Accounts and roles<br/>[auth.py]"]
  node_access["Access scoping<br/>[access_scope.py]"]
end

subgraph group_monitoring["Plant monitoring"]
  node_assets_vars["Assets and variables<br/>[assets.py]"]
  node_readings["Reading ingestion"]
  node_opc_collector["OPC UA collector<br/>[opcua_collector.py]"]
  node_opc_client["OPC UA transport<br/>[opcua_client.py]"]
  node_rules["Rules and templates<br/>[rule.py]"]
  node_rule_engine["Rule evaluation"]
  node_alerts_events["Alerts and events<br/>[event_log.py]"]
end

subgraph group_operations["Operations"]
  node_maintenance["Maintenance workflows"]
  node_config_admin["Dashboard configuration<br/>[dashboard.py]"]
  node_email["Email delivery"]
  node_live_hub["Live event hub<br/>[main.py]"]
end

subgraph group_storage["Persistence"]
  node_db_session["Database sessions<br/>[session.py]"]
  node_db[("Application database<br/>[init_db.py]")]
end

node_operator(("Plant user"))
node_opc_server["OPC UA server"]
node_smtp["SMTP server"]

node_operator -->|"uses"| node_dashboard
node_dashboard -->|"routes through"| node_auth_ui
node_auth_ui -->|"requests session"| node_api_client
node_dashboard -->|"calls API"| node_api_client
node_api_client -->|"sends HTTP"| node_api_routes
node_api_routes -->|"registers routes"| node_auth
node_api_routes -->|"manages"| node_assets_vars
node_api_routes -->|"accepts readings"| node_readings
node_api_routes -->|"configures rules"| node_rules
node_api_routes -->|"manages work"| node_maintenance
node_api_routes -->|"manages configuration"| node_config_admin
node_api_routes -->|"checks access"| node_access
node_opc_server -->|"provides signals"| node_opc_collector
node_opc_collector -->|"reads and subscribes"| node_opc_client
node_opc_collector -->|"submits values"| node_readings
node_readings -->|"triggers evaluation"| node_rule_engine
node_rules -->|"defines conditions"| node_rule_engine
node_rule_engine -->|"records transitions"| node_alerts_events
node_rule_engine -->|"enqueues eligible jobs"| node_email
node_email -.->|"delivers mail"| node_smtp
node_dashboard -->|"subscribes"| node_live_ui
node_live_ui -->|"opens WebSocket"| node_live_hub
node_live_hub -->|"refreshes configuration"| node_opc_collector
node_api_routes -->|"uses sessions"| node_db_session
node_db_session -->|"reads and writes"| node_db
node_rule_engine -.->|"supports schedules"| node_maintenance
node_maintenance -.->|"creates warnings"| node_alerts_events

click node_dashboard "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/app/App.jsx"
click node_auth_ui "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/features/auth/AuthContext.jsx"
click node_api_client "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/services/api.js"
click node_live_ui "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/services/liveUpdates.js"
click node_api_routes "https://github.com/sahiliot/nem_plant_monitoring/tree/main/Nem_Backend/app/api/routes"
click node_auth "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/api/routes/auth.py"
click node_access "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/access_scope.py"
click node_assets_vars "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/api/routes/assets.py"
click node_readings "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/reading_ingestion.py"
click node_opc_collector "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/opcua_collector.py"
click node_opc_client "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/opcua_client.py"
click node_rules "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/schemas/rule.py"
click node_rule_engine "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/monitoring_engine.py"
click node_alerts_events "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/event_log.py"
click node_maintenance "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/maintenance_schedule.py"
click node_config_admin "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/api/routes/dashboard.py"
click node_email "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/email_notifications.py"
click node_live_hub "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/main.py"
click node_db_session "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/db/session.py"
click node_db "https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/db/init_db.py"

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_dashboard,node_auth_ui,node_api_client,node_live_ui,node_operator toneBlue
class node_api_routes,node_auth,node_access toneAmber
class node_assets_vars,node_readings,node_opc_collector,node_opc_client,node_rules,node_rule_engine,node_alerts_events,node_opc_server,node_smtp toneMint
class node_maintenance,node_config_admin,node_email,node_live_hub toneRose
class node_db_session,node_db toneIndigo
```

## Components

### Dashboard

- [React dashboard](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/app/App.jsx): `Nem_Frontend/src/app/App.jsx`
- [Sign-in state](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/features/auth/AuthContext.jsx): `Nem_Frontend/src/features/auth/AuthContext.jsx`
- [API client](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/services/api.js): `Nem_Frontend/src/services/api.js`
- [Live updates UI](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Frontend/src/services/liveUpdates.js): `Nem_Frontend/src/services/liveUpdates.js`

### API and access

- [HTTP routes](https://github.com/sahiliot/nem_plant_monitoring/tree/main/Nem_Backend/app/api/routes): `Nem_Backend/app/api/routes`
- [Accounts and roles](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/api/routes/auth.py): `Nem_Backend/app/api/routes/auth.py`
- [Access scoping](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/access_scope.py): `Nem_Backend/app/services/access_scope.py`

### Plant monitoring

- [Assets and variables](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/api/routes/assets.py): `Nem_Backend/app/api/routes/assets.py`
- [Reading ingestion](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/reading_ingestion.py): `Nem_Backend/app/services/reading_ingestion.py`
- [OPC UA collector](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/opcua_collector.py): `Nem_Backend/app/services/opcua_collector.py`
- [OPC UA transport](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/opcua_client.py): `Nem_Backend/app/services/opcua_client.py`
- [Rules and templates](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/schemas/rule.py): `Nem_Backend/app/schemas/rule.py`
- [Rule evaluation](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/monitoring_engine.py): `Nem_Backend/app/services/monitoring_engine.py`
- [Alerts and events](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/event_log.py): `Nem_Backend/app/services/event_log.py`

### Operations

- [Maintenance workflows](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/maintenance_schedule.py): `Nem_Backend/app/services/maintenance_schedule.py`
- [Dashboard configuration](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/api/routes/dashboard.py): `Nem_Backend/app/api/routes/dashboard.py`
- [Email delivery](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/services/email_notifications.py): `Nem_Backend/app/services/email_notifications.py`
- [Live event hub](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/main.py): `Nem_Backend/app/main.py`

### Persistence

- [Database sessions](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/db/session.py): `Nem_Backend/app/db/session.py`
- [Application database](https://github.com/sahiliot/nem_plant_monitoring/blob/main/Nem_Backend/app/db/init_db.py): `Nem_Backend/app/db/init_db.py`

### Other components

- **Plant user**
- **OPC UA server**
- **SMTP server**

## Connections

- Plant user → React dashboard: uses
- React dashboard → Sign-in state: routes through (evidence: `Nem_Frontend/src/app/App.jsx`)
- Sign-in state → API client: requests session (evidence: `Nem_Frontend/src/features/auth/AuthContext.jsx`)
- React dashboard → API client: calls API
- API client → HTTP routes: sends HTTP
- HTTP routes → Accounts and roles: registers routes (evidence: `Nem_Backend/app/main.py`)
- HTTP routes → Assets and variables: manages
- HTTP routes → Reading ingestion: accepts readings
- HTTP routes → Rules and templates: configures rules (evidence: `Nem_Backend/app/api/routes/frontend_compat.py`)
- HTTP routes → Maintenance workflows: manages work
- HTTP routes → Dashboard configuration: manages configuration (evidence: `Nem_Backend/app/api/routes/frontend_compat.py`)
- HTTP routes → Access scoping: checks access (evidence: `Nem_Backend/app/main.py`)
- OPC UA server → OPC UA collector: provides signals
- OPC UA collector → OPC UA transport: reads and subscribes
- OPC UA collector → Reading ingestion: submits values
- Reading ingestion → Rule evaluation: triggers evaluation (evidence: `Nem_Backend/app/services/reading_ingestion.py`)
- Rules and templates → Rule evaluation: defines conditions
- Rule evaluation → Alerts and events: records transitions (evidence: `Nem_Backend/app/services/monitoring_engine.py`)
- Rule evaluation → Email delivery: enqueues eligible jobs (evidence: `Nem_Backend/app/services/monitoring_engine.py`)
- Email delivery → SMTP server: delivers mail
- React dashboard → Live updates UI: subscribes
- Live updates UI → Live event hub: opens WebSocket
- Live event hub → OPC UA collector: refreshes configuration (evidence: `Nem_Backend/app/main.py`)
- HTTP routes → Database sessions: uses sessions (evidence: `Nem_Backend/app/db/session.py`)
- Database sessions → Application database: reads and writes (evidence: `Nem_Backend/app/db/session.py`)
- Rule evaluation → Maintenance workflows: supports schedules
- Maintenance workflows → Alerts and events: creates warnings
