# riclolsen/oshmi architecture

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

- Interactive diagram: https://gitdiagram.com/riclolsen/oshmi
- Repository: https://github.com/riclolsen/oshmi

## Overview

1. OSHMI is a substation/industrial HMI platform, not just a single app. The repo contains the core runtime, browser UI, protocol clients, database scripts, graphics authoring assets, and installation/OS integration for Windows and Linux deployments.

2. The central architecture is a data-acquisition-and-presentation pipeline: field protocols and helper clients feed point values, alarms, events, and histories into the backend; the backend persists selected data in SQLite/PostgreSQL; browser clients read it through HTTP/JSON/PHP endpoints and render SVG/HTML5 views, trends, tables, alarms, and events.

3. The main server-side engine lives in `webserver/`. This is the core native C++ application and its UI/dialog modules. It embeds a lightweight HTTP server, JSON handling, SQLite, Lua, and crypto helpers, and is responsible for serving the HMI services, historian access, event/alarm logic, and server-side automation hooks.

4. The `htdocs/` tree is the browser-facing application layer. It contains the HMI pages (`screen.html`, `trend.html`, `events.html`, `tabular.html`, etc.), PHP endpoints (`json.php`, `pntserver.php`, `eventserver.php`, `sqlite_oshmi.php`, `pgsql_*` scripts), and a large JavaScript/CSS library stack for SVG, jQuery UI, Flot, D3, Vega/Vega-Lite, Tableau WDC, and custom HMI widgets.

5. Data persistence is split by use case. The `db/` folder contains SQLite-oriented processing and maintenance scripts for dump/history/SOE tables, while `PostgreSQL/` and the `pgsql_*` endpoints support a PostgreSQL-backed variant for reporting and larger deployments. The repository also includes MongoDB helper scripts, showing that archival/export can be swapped or extended.

6. Protocol integration is decomposed into separate driver/client projects rather than a single monolith. Notable acquisition/control components are `DNP3/`, `modbus/`, `iec61850_client/`, `opc_client/`, `s7client/`, `qtester104/`, and `mon_proc/`. These are the boundaries where OSHMI talks to external automation systems and feeds the core HMI point model.

7. The `README` makes an important architectural distinction: OSHMI is an HMI and automation presentation system, not a protocol gateway by itself. In practice, external devices and protocol drivers supply data into OSHMI; OSHMI then visualizes, logs, correlates, alarms, and optionally issues commands or scripted actions.

8. Automation and business logic can be pushed into Lua. The `webserver/luasrc/` subtree and config templates like `conf_templates/script.lua` indicate a server-side scripting layer used for custom logic such as restoration sequences, tap control, point calculations, and other site-specific workflows.

9. Configuration is intentionally file-driven. The repo is full of templates and `.ini/.conf/.js/.txt` files under `conf_templates/`, plus protocol-specific configs in each client folder. That means most system wiring is done by deployment-time text configuration rather than hardcoded application state.

10. The graphics pipeline is a major subsystem. `inkscape_sage_src/` contains custom Inkscape/“SAGE” extensions for building animated SVG screens, while `svg/`, `icons/`, `charts/`, and the `htdocs` screen files support the runtime rendering side. This is the UX layer for lossless zooming, mimics, and live process visualization.

11. Operational control and shell replacement are handled separately from the HMI itself. `hmishell/` is a dedicated Windows shell application, and `bin/`, `etc/`, and `linux/` contain start/stop/reboot/logout scripts, service registration, and platform-specific launch automation. This is the boundary where OSHMI integrates with the host OS and kiosk-like deployments.

12. Reporting and analytics are first-class integrations. The repo includes a Power BI sample, Tableau WDC assets, OData/JSON endpoints, and Grafana packaging. These pieces let external BI tools query historian and point data without going through the live HMI UI.

13. Deployment is cross-platform but weighted toward Windows station/SCADA installations. There are Windows batch files, `.reg` files, and installer assets in `installer/`, plus Linux web stack assets in `linux/`, `nginx_php/`, and `conf_templates/`. The runtime is therefore a mix of native binaries, browser assets, and web middleware rather than a single server executable.

14. For an architecture diagram, the key boundaries are: field protocol clients on the left; core OSHMI backend in the center; SQLite/PostgreSQL/MongoDB/Grafana/BI/reporting on the right; and browser or shell-based operator clients on the top. The notable internal cross-cutting concerns are Lua scripting, configuration files, and SVG-based screen assets.

Main entry points: [`webserver`](https://github.com/riclolsen/oshmi/tree/master/webserver) (Webserver), [`htdocs`](https://github.com/riclolsen/oshmi/tree/master/htdocs) (Browser app), [`htdocs/json.php`](https://github.com/riclolsen/oshmi/blob/master/htdocs/json.php) (Data endpoints), [`installer`](https://github.com/riclolsen/oshmi/tree/master/installer) (Installer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_field["Field clients"]
  node_n_dnp3["DNP3<br/>protocol client"]
  node_n_modbus["Modbus<br/>protocol client"]
  node_n_iec61850["IEC 61850<br/>protocol client"]
  node_n_opc["OPC client<br/>protocol client"]
  node_n_s7["S7 client<br/>protocol client"]
  node_n_monproc["Mon proc<br/>monitor client"]
end

subgraph group_g_core["Core runtime"]
  node_n_webserver["Webserver<br/>core backend"]
  node_n_httpd["HTTP/JSON<br/>service layer<br/>[httpd_u.cpp]"]
  node_n_hist_alarm["Hist & alarms<br/>domain logic<br/>[historico_u.cpp]"]
  node_n_lua["Lua hooks<br/>automation scripting"]
  node_n_screens["Screen runtime<br/>screen model<br/>[screen_list_u.cpp]"]
end

subgraph group_g_ui["Operator UI"]
  node_n_htdocs["Browser app<br/>web hmi"]
  node_n_endpoints["Data endpoints<br/>api layer<br/>[json.php]"]
  node_n_widgets["UI libraries<br/>frontend stack"]
end

subgraph group_g_data["Persistence & analytics"]
  node_n_db[("SQLite scripts<br/>persistence scripts")]
  node_n_pg[("PostgreSQL<br/>reporting store")]
  node_n_mongo[("Mongo helpers<br/>archive export")]
  node_n_bi["BI exports<br/>analytics integration"]
end

subgraph group_g_deploy["Deployment"]
  node_n_shell["HMI shell<br/>os shell"]
  node_n_scripts["OS scripts<br/>deployment scripts"]
  node_n_installer["Installer<br/>packaging"]
  node_n_linux["Linux stack<br/>platform package"]
end

subgraph group_g_graphics["Graphics pipeline"]
  node_n_graphics["SVG assets<br/>graphics authoring"]
end

node_n_dnp3 -->|"points/SOE"| node_n_webserver
node_n_modbus -->|"points"| node_n_webserver
node_n_iec61850 -->|"points"| node_n_webserver
node_n_opc -->|"points"| node_n_webserver
node_n_s7 -->|"points"| node_n_webserver
node_n_monproc -->|"monitoring"| node_n_webserver
node_n_webserver -->|"serves"| node_n_httpd
node_n_webserver -->|"coordinates"| node_n_hist_alarm
node_n_webserver -->|"hooks"| node_n_lua
node_n_webserver -->|"screen model"| node_n_screens
node_n_httpd -->|"delivers"| node_n_htdocs
node_n_htdocs -->|"calls"| node_n_endpoints
node_n_htdocs -->|"renders with"| node_n_widgets
node_n_endpoints -->|"reads/writes"| node_n_db
node_n_endpoints -->|"reports"| node_n_pg
node_n_endpoints -.->|"exports"| node_n_mongo
node_n_endpoints -->|"feeds"| node_n_bi
node_n_graphics -->|"screens"| node_n_htdocs
node_n_scripts -->|"launches"| node_n_webserver
node_n_shell -->|"hosts UI"| node_n_htdocs
node_n_linux -->|"web stack"| node_n_htdocs
node_n_installer -->|"packages"| node_n_webserver
node_n_installer -->|"packages"| node_n_htdocs

click node_n_dnp3 "https://github.com/riclolsen/oshmi/tree/master/DNP3"
click node_n_modbus "https://github.com/riclolsen/oshmi/tree/master/modbus"
click node_n_iec61850 "https://github.com/riclolsen/oshmi/tree/master/iec61850_client"
click node_n_opc "https://github.com/riclolsen/oshmi/tree/master/opc_client"
click node_n_s7 "https://github.com/riclolsen/oshmi/tree/master/s7client"
click node_n_monproc "https://github.com/riclolsen/oshmi/tree/master/mon_proc"
click node_n_webserver "https://github.com/riclolsen/oshmi/tree/master/webserver"
click node_n_httpd "https://github.com/riclolsen/oshmi/blob/master/webserver/httpd_u.cpp"
click node_n_hist_alarm "https://github.com/riclolsen/oshmi/blob/master/webserver/historico_u.cpp"
click node_n_lua "https://github.com/riclolsen/oshmi/tree/master/webserver/luasrc"
click node_n_screens "https://github.com/riclolsen/oshmi/blob/master/webserver/screen_list_u.cpp"
click node_n_htdocs "https://github.com/riclolsen/oshmi/tree/master/htdocs"
click node_n_endpoints "https://github.com/riclolsen/oshmi/blob/master/htdocs/json.php"
click node_n_widgets "https://github.com/riclolsen/oshmi/tree/master/htdocs/lib"
click node_n_db "https://github.com/riclolsen/oshmi/tree/master/db"
click node_n_pg "https://github.com/riclolsen/oshmi/tree/master/PostgreSQL"
click node_n_mongo "https://github.com/riclolsen/oshmi/tree/master/mongodb"
click node_n_bi "https://github.com/riclolsen/oshmi/tree/master/PowerBI"
click node_n_shell "https://github.com/riclolsen/oshmi/tree/master/hmishell"
click node_n_scripts "https://github.com/riclolsen/oshmi/tree/master/bin"
click node_n_installer "https://github.com/riclolsen/oshmi/tree/master/installer"
click node_n_linux "https://github.com/riclolsen/oshmi/tree/master/linux"
click node_n_graphics "https://github.com/riclolsen/oshmi/tree/master/inkscape_sage_src"

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_n_dnp3,node_n_modbus,node_n_iec61850,node_n_opc,node_n_s7,node_n_monproc toneBlue
class node_n_webserver,node_n_httpd,node_n_hist_alarm,node_n_lua,node_n_screens toneAmber
class node_n_htdocs,node_n_endpoints,node_n_widgets toneMint
class node_n_db,node_n_pg,node_n_mongo,node_n_bi toneRose
class node_n_shell,node_n_scripts,node_n_installer,node_n_linux toneIndigo
class node_n_graphics toneTeal
```

## Components

### Field clients

Protocol adapters and helper clients that acquire process data from external automation systems.

- [DNP3](https://github.com/riclolsen/oshmi/tree/master/DNP3): protocol client · C++ acquisition client for DNP3 field data and SOE handling. · `DNP3`
- [Modbus](https://github.com/riclolsen/oshmi/tree/master/modbus): protocol client · Modbus helper client for polling and point acquisition. · `modbus`
- [IEC 61850](https://github.com/riclolsen/oshmi/tree/master/iec61850_client): protocol client · .NET client for IEC 61850 integration. · `iec61850_client`
- [OPC client](https://github.com/riclolsen/oshmi/tree/master/opc_client): protocol client · OPC client integration for external automation systems. · `opc_client`
- [S7 client](https://github.com/riclolsen/oshmi/tree/master/s7client): protocol client · Siemens S7 acquisition client and helper logic. · `s7client`
- [Mon proc](https://github.com/riclolsen/oshmi/tree/master/mon_proc): monitor client · Process monitoring helper used to feed or supervise point data. · `mon_proc`

### Core runtime

Native backend engine, embedded HTTP, JSON, historian, alarms, and scripting.

- [Webserver](https://github.com/riclolsen/oshmi/tree/master/webserver): core backend · Native runtime that serves HMI services, historian access, alarms, events, JSON, and scripting. · `webserver`
- [HTTP/JSON](https://github.com/riclolsen/oshmi/blob/master/webserver/httpd_u.cpp): service layer · Embedded web server and request handling exposed by the backend. · `webserver/httpd_u.cpp`
- [Hist & alarms](https://github.com/riclolsen/oshmi/blob/master/webserver/historico_u.cpp): domain logic · Historian, event, alarm, SOE, and point-processing logic. · `webserver/historico_u.cpp`
- [Lua hooks](https://github.com/riclolsen/oshmi/tree/master/webserver/luasrc): automation scripting · Server-side scripting and site-specific automation hooks. · `webserver/luasrc`
- [Screen runtime](https://github.com/riclolsen/oshmi/blob/master/webserver/screen_list_u.cpp): screen model · Server-side screen list and HMI presentation model used by the backend. · `webserver/screen_list_u.cpp`

### Operator UI

Browser-facing HMI pages, endpoints, and client-side visualization stack.

- [Browser app](https://github.com/riclolsen/oshmi/tree/master/htdocs): web hmi · Browser-facing HTML, PHP, JavaScript, and CSS application layer. · `htdocs`
- [Data endpoints](https://github.com/riclolsen/oshmi/blob/master/htdocs/json.php): api layer · PHP endpoints for JSON, point, event, tabular, trend, and OData access. · `htdocs/json.php`
- [UI libraries](https://github.com/riclolsen/oshmi/tree/master/htdocs/lib): frontend stack · JavaScript and CSS libraries for charts, dialogs, tables, and SVG widgets. · `htdocs/lib`

### Persistence & analytics

Local databases, reporting integrations, and archival/export helpers.

- [SQLite scripts](https://github.com/riclolsen/oshmi/tree/master/db): persistence scripts · SQLite-oriented dump, historian, SOE, and maintenance scripts. · `db`
- [PostgreSQL](https://github.com/riclolsen/oshmi/tree/master/PostgreSQL): reporting store · PostgreSQL-backed reporting and archival variant. · `PostgreSQL`
- [Mongo helpers](https://github.com/riclolsen/oshmi/tree/master/mongodb): archive export · MongoDB helper scripts for alternate archival or export workflows. · `mongodb`
- [BI exports](https://github.com/riclolsen/oshmi/tree/master/PowerBI): analytics integration · Power BI, Tableau WDC, OData, and Grafana integration assets. · `PowerBI`

### Deployment

OS integration, launch scripts, installers, and platform-specific packaging.

- [HMI shell](https://github.com/riclolsen/oshmi/tree/master/hmishell): os shell · Dedicated operator shell and kiosk-style Windows shell application. · `hmishell`
- [OS scripts](https://github.com/riclolsen/oshmi/tree/master/bin): deployment scripts · Start/stop, service registration, reboot/logout, and platform launch scripts. · `bin`
- [Installer](https://github.com/riclolsen/oshmi/tree/master/installer): packaging · Windows installer and packaging assets for deployment. · `installer`
- [Linux stack](https://github.com/riclolsen/oshmi/tree/master/linux): platform package · Linux web stack, PHP, nginx, and autostart/service integration. · `linux`

### Graphics pipeline

Authoring and runtime assets for SVG-based process screens and mimics.

- [SVG assets](https://github.com/riclolsen/oshmi/tree/master/inkscape_sage_src): graphics authoring · Inkscape SAGE extensions, screen authoring assets, icons, charts, and SVG runtime support. · `inkscape_sage_src`

## Connections

- DNP3 → Webserver: points/SOE · Protocol data flows into the core backend point model.
- Modbus → Webserver: points · Modbus values are ingested by the backend.
- IEC 61850 → Webserver: points · IEC 61850 data feeds the backend.
- OPC client → Webserver: points · OPC data feeds the backend.
- S7 client → Webserver: points · S7 data feeds the backend.
- Mon proc → Webserver: monitoring · Monitoring helper supplies process-related data.
- Webserver → HTTP/JSON: serves · The backend exposes its services over embedded HTTP.
- Webserver → Hist & alarms: coordinates · Core runtime manages historian, alarms, events, and point processing.
- Webserver → Lua hooks: hooks · Automation logic is extended through Lua scripting.
- Webserver → Screen runtime: screen model · Backend maintains the screen list and presentation model.
- HTTP/JSON → Browser app: delivers · Browser application assets are served to clients.
- Browser app → Data endpoints: calls · Web pages consume PHP and JSON endpoints.
- Browser app → UI libraries: renders with · The HMI UI is built on client-side libraries and widgets.
- Data endpoints → SQLite scripts: reads/writes · Endpoints access SQLite-backed historian and point data.
- Data endpoints → PostgreSQL: reports · PostgreSQL endpoints support larger reporting deployments.
- Data endpoints → Mongo helpers: exports · Alternate archival/export paths can target MongoDB helpers.
- Data endpoints → BI exports: feeds · BI tools consume historian data through reporting integrations.
- SVG assets → Browser app: screens · Authoring assets support browser-rendered HMI graphics.
- OS scripts → Webserver: launches · Scripts start and stop the core runtime and services.
- HMI shell → Browser app: hosts UI · The shell provides an operator-facing desktop wrapper for the HMI.
- Linux stack → Browser app: web stack · Linux packaging supports the browser application deployment.
- Installer → Webserver: packages · Installer bundles backend and deployment components.
- Installer → Browser app: packages · Installer bundles browser assets and supporting files.
