# sagarrajak01/smart-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/sagarrajak01/smart-monitor
- Repository: https://github.com/sagarrajak01/smart-monitor

## Overview

1. **Overall shape**
   - Smart Monitor is split into three runtime layers: a native **C++ telemetry engine**, a **Node.js bridge/orchestrator**, and a **React dashboard**.  
   - The main architectural boundary is between **data collection/computation** in the native layer and **persistence/streaming/UI delivery** in the JavaScript layers.

2. **Telemetry source and host dependency**
   - The system is Linux-specific because the engine reads memory/process information from **`/proc` procfs**.
   - That means the lowest layer depends directly on host kernel-exposed process metrics rather than on an external agent or API.

3. **C++ engine responsibilities**
   - The `engine/` directory contains the high-performance telemetry collector.
   - `Parser.*` is the input boundary to procfs data, `Analyzer.*` is the statistical layer, and `main.cpp`/`leaker.cpp` are the executable entry points/supporting runtime pieces.
   - The engine’s output is a **JSON telemetry stream on stdout**, which makes it a producer-only process with no direct coupling to the UI or database.

4. **Statistical computation boundary**
   - The engine is where raw samples are turned into usable signals such as **OLS slope estimation** and **EMA-style smoothing**.
   - This keeps the expensive or latency-sensitive math close to the data source, reducing work in the bridge and frontend.

5. **Node.js bridge as orchestration layer**
   - The `bridge/` folder is the central control plane.
   - `server.js` is the top-level backend server, `logic/engine.js` manages the lifecycle and stream ingestion from the C++ binary, and `logic/metrics.js` handles derived metrics such as **time-to-failure projection** or similar runtime calculations.
   - This layer is also where raw telemetry becomes an application-level event stream.

6. **Persistence boundary**
   - `bridge/database.js` indicates a **SQLite** persistence layer for historical telemetry.
   - The bridge sits between live samples and durable storage, so it can both replay history and retain the time-series needed for the dashboard’s hydration and longer-term analysis.

7. **Real-time transport**
   - The bridge also exposes a **Socket.IO** channel to push updates to the client.
   - This is the live delivery path: engine stdout → bridge parsing/metrics → Socket.IO broadcast → dashboard components.

8. **React dashboard responsibilities**
   - The `dashboard/` app is a Vite-based React UI focused on visualization rather than computation.
   - `services/socket.js` connects to the bridge, while components like `TelemetryChart`, `StatCard`, `ProcessSidebar`, and `LoadingScreen` render the current monitoring state.
   - `useTheme.js` and `ThemeToggle.jsx` show that UI state is kept local to the frontend, separate from telemetry state.

9. **Client data flow**
   - The dashboard appears to consume both **live socket events** and **initial/historical data** from the backend so it can render immediately and then stay synchronized.
   - That makes the UI a read-only consumer of backend state, not a source of telemetry.

10. **Operational and deployment boundaries**
   - The repo is designed to run either **natively** or via **Docker Compose**.
   - `Dockerfile` and `docker-compose.yml` package the full stack for a single-host deployment, while `.github/workflows/ci.yml` suggests automated build/validation around the three project parts.

11. **Documentation and observability metadata**
   - `Documentation/telemetry-format.md`, `performance.md`, and the day-by-day notes capture the contract and evolution of the telemetry pipeline.
   - These docs are useful architectural artifacts because they define the shape of the stream and the intended behavior of the metrics pipeline.

12. **Primary architecture diagram takeaway**
   - The cleanest diagram is a **one-way telemetry pipeline**: Linux procfs feeds the C++ engine; the engine emits JSON to the Node bridge; the bridge computes/persists/broadcasts; the React dashboard renders and subscribes.
   - SQLite is the durable side store, while Socket.IO is the real-time edge of the system.

Main entry points: [`dashboard/src/App.jsx`](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/App.jsx) (Dashboard app), [`bridge/server.js`](https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/server.js) (Server), [`bridge/logic/engine.js`](https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/logic/engine.js) (Engine bridge), [`engine/src/main.cpp`](https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/main.cpp) (Engine main)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_engine["C++ telemetry engine"]
  node_node_procfs[("Linux procfs<br/>host metrics source")]
  node_node_parser["Parser<br/>procfs ingestion<br/>[Parser.cpp]"]
  node_node_analyzer["Analyzer<br/>signal math<br/>[Analyzer.cpp]"]
  node_node_engine_main["Engine main<br/>collector runtime<br/>[main.cpp]"]
  node_node_leaker["Leaker<br/>support binary<br/>[leaker.cpp]"]
  node_node_json_stream["JSON stream<br/>stdout telemetry"]
end

subgraph group_group_bridge["Node bridge"]
  node_node_server["Server<br/>backend entry<br/>[server.js]"]
  node_node_engine_bridge["Engine bridge<br/>process orchestration<br/>[engine.js]"]
  node_node_metrics["Metrics<br/>derived calculations<br/>[metrics.js]"]
  node_node_db[("SQLite store<br/>durable telemetry store<br/>[database.js]")]
  node_node_socket(("Socket.IO<br/>live transport"))
end

subgraph group_group_dashboard["React dashboard"]
  node_node_dashboard_app["Dashboard app<br/>React UI<br/>[App.jsx]"]
  node_node_socket_client["Socket client<br/>client transport<br/>[socket.js]"]
  node_node_chart["Telemetry chart<br/>visualization<br/>[TelemetryChart.jsx]"]
  node_node_statcard["Stat cards<br/>status widgets<br/>[StatCard.jsx]"]
  node_node_sidebar["Process sidebar<br/>process view<br/>[ProcessSidebar.jsx]"]
  node_node_theme["Theme UI<br/>local UI state<br/>[ThemeToggle.jsx]"]
end

subgraph group_group_ops["Ops and docs"]
  node_node_docs["Docs"]
  node_node_deploy["Deploy stack<br/>packaging<br/>[docker-compose.yml]"]
end

node_node_procfs -->|"raw samples"| node_node_parser
node_node_parser -->|"normalized telemetry"| node_node_analyzer
node_node_analyzer -->|"derived signals"| node_node_json_stream
node_node_engine_main -->|"starts"| node_node_parser
node_node_engine_main -->|"drives"| node_node_analyzer
node_node_leaker -.->|"runtime support"| node_node_engine_main
node_node_json_stream -->|"stdout ingest"| node_node_engine_bridge
node_node_server -->|"orchestrates"| node_node_engine_bridge
node_node_engine_bridge -->|"event stream"| node_node_metrics
node_node_engine_bridge -->|"persist history"| node_node_db
node_node_db -->|"historical data"| node_node_server
node_node_engine_bridge -->|"broadcast"| node_node_socket
node_node_socket -->|"subscribe"| node_node_socket_client
node_node_server -->|"exposes"| node_node_socket
node_node_socket_client -->|"feeds UI"| node_node_dashboard_app
node_node_server -->|"bootstrap data"| node_node_dashboard_app
node_node_dashboard_app -->|"renders"| node_node_chart
node_node_dashboard_app -->|"renders"| node_node_statcard
node_node_dashboard_app -->|"renders"| node_node_sidebar
node_node_dashboard_app -->|"ui state"| node_node_theme
node_node_server -.->|"contracts"| node_node_docs
node_node_deploy -.->|"packages"| node_node_engine_main
node_node_deploy -.->|"packages"| node_node_server
node_node_deploy -.->|"packages"| node_node_dashboard_app

click node_node_parser "https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/Parser.cpp"
click node_node_analyzer "https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/Analyzer.cpp"
click node_node_engine_main "https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/main.cpp"
click node_node_leaker "https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/leaker.cpp"
click node_node_server "https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/server.js"
click node_node_engine_bridge "https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/logic/engine.js"
click node_node_metrics "https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/logic/metrics.js"
click node_node_db "https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/database.js"
click node_node_dashboard_app "https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/App.jsx"
click node_node_socket_client "https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/services/socket.js"
click node_node_chart "https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/TelemetryChart.jsx"
click node_node_statcard "https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/StatCard.jsx"
click node_node_sidebar "https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/ProcessSidebar.jsx"
click node_node_theme "https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/ThemeToggle.jsx"
click node_node_docs "https://github.com/sagarrajak01/smart-monitor/blob/main/Documentation/telemetry-format.md"
click node_node_deploy "https://github.com/sagarrajak01/smart-monitor/blob/main/docker-compose.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_node_procfs,node_node_parser,node_node_analyzer,node_node_engine_main,node_node_leaker,node_node_json_stream toneBlue
class node_node_server,node_node_engine_bridge,node_node_metrics,node_node_db,node_node_socket toneAmber
class node_node_dashboard_app,node_node_socket_client,node_node_chart,node_node_statcard,node_node_sidebar,node_node_theme toneMint
class node_node_docs,node_node_deploy toneRose
```

## Components

### C++ telemetry engine

Linux procfs collector and statistical processing runtime.

- **Linux procfs**: host metrics source · Kernel-exposed process and memory data read by the engine.
- [Parser](https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/Parser.cpp): procfs ingestion · Reads and normalizes raw /proc telemetry into samples. · `engine/src/Parser.cpp`
- [Analyzer](https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/Analyzer.cpp): signal math · Computes derived signals such as slope and smoothing. · `engine/src/Analyzer.cpp`
- [Engine main](https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/main.cpp): collector runtime · Executable entry point for the native telemetry process. · `engine/src/main.cpp`
- [Leaker](https://github.com/sagarrajak01/smart-monitor/blob/main/engine/src/leaker.cpp): support binary · Supporting runtime component in the native engine package. · `engine/src/leaker.cpp`
- **JSON stream**: stdout telemetry · One-way telemetry output emitted by the engine on stdout.

### Node bridge

Backend orchestration, persistence, and live streaming.

- [Server](https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/server.js): backend entry · Top-level Node.js server for the bridge layer. · `bridge/server.js`
- [Engine bridge](https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/logic/engine.js): process orchestration · Starts the native binary and ingests its output stream. · `bridge/logic/engine.js`
- [Metrics](https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/logic/metrics.js): derived calculations · Builds application-level metrics and projections from telemetry. · `bridge/logic/metrics.js`
- [SQLite store](https://github.com/sagarrajak01/smart-monitor/blob/main/bridge/database.js): durable telemetry store · Persists historical telemetry for replay and hydration. · `bridge/database.js`
- **Socket.IO**: live transport · Pushes telemetry updates to connected clients.

### React dashboard

Client UI for live and historical telemetry.

- [Dashboard app](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/App.jsx): React UI · Vite-based frontend shell for telemetry visualization. · `dashboard/src/App.jsx`
- [Socket client](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/services/socket.js): client transport · Connects the dashboard to the backend live stream. · `dashboard/src/services/socket.js`
- [Telemetry chart](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/TelemetryChart.jsx): visualization · Plots live and historical telemetry signals. · `dashboard/src/components/TelemetryChart.jsx`
- [Stat cards](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/StatCard.jsx): status widgets · Shows current summary metrics and alerts. · `dashboard/src/components/StatCard.jsx`
- [Process sidebar](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/ProcessSidebar.jsx): process view · Displays monitored process context and selection state. · `dashboard/src/components/ProcessSidebar.jsx`
- [Theme UI](https://github.com/sagarrajak01/smart-monitor/blob/main/dashboard/src/components/ThemeToggle.jsx): local UI state · Frontend-only theme toggle and theme hook. · `dashboard/src/components/ThemeToggle.jsx`

### Ops and docs

Deployment, packaging, and repository documentation.

- [Docs](https://github.com/sagarrajak01/smart-monitor/blob/main/Documentation/telemetry-format.md): architecture docs · Telemetry format, performance notes, and design history. · `Documentation/telemetry-format.md`
- [Deploy stack](https://github.com/sagarrajak01/smart-monitor/blob/main/docker-compose.yml): packaging · Docker and CI packaging for the full repository. · `docker-compose.yml`

## Connections

- Linux procfs → Parser: raw samples · The engine reads Linux procfs data and parses it into structured samples.
- Parser → Analyzer: normalized telemetry · Parsed samples flow into statistical analysis.
- Analyzer → JSON stream: derived signals · Computed metrics are serialized as JSON telemetry.
- Engine main → Parser: starts · Main runtime coordinates collection and parsing.
- Engine main → Analyzer: drives · Main runtime invokes the analysis pipeline.
- Leaker → Engine main: runtime support · Support component belongs to the native engine package.
- JSON stream → Engine bridge: stdout ingest · Bridge reads the engine's JSON stream.
- Server → Engine bridge: orchestrates · Backend entrypoint delegates engine lifecycle management.
- Engine bridge → Metrics: event stream · Streamed telemetry is converted into application-level metrics.
- Engine bridge → SQLite store: persist history · Telemetry is written to the SQLite store.
- SQLite store → Server: historical data · Server can serve stored telemetry for hydration and replay.
- Engine bridge → Socket.IO: broadcast · Live updates are pushed to Socket.IO clients.
- Socket.IO → Socket client: subscribe · Dashboard listens for backend telemetry events.
- Server → Socket.IO: exposes · Server hosts the real-time transport endpoint.
- Socket client → Dashboard app: feeds UI · Client service delivers live telemetry into the React app.
- Server → Dashboard app: bootstrap data · Dashboard also consumes initial or historical backend state.
- Dashboard app → Telemetry chart: renders · Main UI renders telemetry charts.
- Dashboard app → Stat cards: renders · Main UI renders summary cards.
- Dashboard app → Process sidebar: renders · Main UI renders process context.
- Dashboard app → Theme UI: ui state · Theme controls remain local to the frontend.
- Server → Docs: contracts · Documentation defines telemetry format and expected behavior.
- Deploy stack → Engine main: packages · Docker/CI build and ship the native engine.
- Deploy stack → Server: packages · Docker/CI build and ship the bridge service.
- Deploy stack → Dashboard app: packages · Docker/CI build and ship the frontend.
