# fortiphyd/grficsv2 architecture

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

- Interactive diagram: https://gitdiagram.com/fortiphyd/grficsv2
- Repository: https://github.com/fortiphyd/grficsv2

## Overview

GRFICSv2 is an industrial-control training environment spanning a chemical-process simulation, remote I/O, an OpenPLC soft PLC, an operator HMI, and network isolation. The principal loop is process state → remote I/O over Modbus → PLC logic → remote-I/O commands → process state; operators monitor measurements and issue commands through the HMI. The repository also includes OpenPLC’s IEC 61131-3 compiler and runtime. The README documents system-level links; sampled source supports simulation and selected runtime/compiler internals, so unverified connections are omitted or marked dashed.

Main entry points: [`plc_vm/OpenPLC_v2-master/core/main.cpp`](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/main.cpp) (PLC scan loop), [`simulation_vm/simulation/remote_io/modbus`](https://github.com/fortiphyd/grficsv2/tree/master/simulation_vm/simulation/remote_io/modbus) (Remote I/O devices), [`simulation_vm/simulation/main.cc`](https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/main.cc) (Simulation JSON API), [`plc_vm/OpenPLC_v2-master/matiec_src/main.cc`](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/main.cc) (IEC compiler driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sim["Process simulation"]
  node_simulation["Chemical process<br/>[TE_process.cc]"]
  node_sim_api["Simulation JSON API<br/>[main.cc]"]
  node_remote_io["Remote I/O devices"]
  node_io_tank["Tank I/O<br/>[tank.py]"]
  node_io_product["Product I/O<br/>[product.py]"]
  node_io_feed["Feed I/O<br/>[feed2.py]"]
  node_visualization["3D visualization"]
end

subgraph group_plc["PLC runtime"]
  node_plc_runtime["PLC scan loop<br/>[main.cpp]"]
  node_io_image["PLC I/O image<br/>[ladder.h]"]
  node_modbus_server["Modbus server<br/>[server.cpp]"]
  node_persistent[("Persistent memory")]
end

subgraph group_compiler["IEC compiler"]
  node_iec_compiler["IEC compiler driver<br/>[main.cc]"]
  node_semantic["Semantic analysis"]
  node_c_codegen["C code generation<br/>[generate_c.cc]"]
end

subgraph group_network["Operator network"]
  node_workstation["Engineering workstation"]
  node_hmi["ScadaBR HMI"]
  node_firewall["pfSense router"]
end

node_operator(("Operator"))

node_simulation -->|"updates state"| node_sim_api
node_sim_api -->|"updates process"| node_simulation
node_sim_api -.->|"serves JSON API"| node_remote_io
node_remote_io -->|"reads and actuates"| node_simulation
node_plc_runtime -->|"Modbus I/O"| node_remote_io
node_hmi -->|"monitors and commands"| node_plc_runtime
node_operator -->|"operates"| node_hmi
node_workstation -->|"programs PLC"| node_iec_compiler
node_workstation -.->|"deploys logic"| node_plc_runtime
node_firewall -->|"routes DMZ traffic"| node_hmi
node_firewall -->|"routes ICS traffic"| node_plc_runtime
node_operator -->|"views process"| node_visualization
node_plc_runtime -->|"starts server"| node_modbus_server
node_modbus_server -.->|"maps protocol data"| node_io_image
node_plc_runtime -->|"scans I/O"| node_io_image
node_plc_runtime -.->|"persists state"| node_persistent
node_iec_compiler -->|"runs stage three"| node_semantic
node_iec_compiler -->|"runs stage four"| node_c_codegen
node_io_tank -.->|"implements device"| node_remote_io
node_io_product -.->|"implements device"| node_remote_io
node_io_feed -.->|"implements device"| node_remote_io

click node_simulation "https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/TE_process.cc"
click node_sim_api "https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/main.cc"
click node_remote_io "https://github.com/fortiphyd/grficsv2/tree/master/simulation_vm/simulation/remote_io/modbus"
click node_io_tank "https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/remote_io/modbus/tank.py"
click node_io_product "https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/remote_io/modbus/product.py"
click node_io_feed "https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/remote_io/modbus/feed2.py"
click node_visualization "https://github.com/fortiphyd/grficsv2/tree/master/simulation_vm/web_visualization"
click node_plc_runtime "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/main.cpp"
click node_io_image "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/ladder.h"
click node_modbus_server "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/server.cpp"
click node_persistent "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/persistent_storage.cpp"
click node_iec_compiler "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/main.cc"
click node_semantic "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/stage3/constant_folding.cc"
click node_c_codegen "https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/stage4/generate_c/generate_c.cc"

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_simulation,node_sim_api,node_remote_io,node_io_tank,node_io_product,node_io_feed,node_visualization toneBlue
class node_plc_runtime,node_io_image,node_modbus_server,node_persistent toneAmber
class node_iec_compiler,node_semantic,node_c_codegen toneMint
class node_workstation,node_hmi,node_firewall toneRose
class node_operator toneIndigo
```

## Components

### Process simulation

- [Chemical process](https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/TE_process.cc): `simulation_vm/simulation/TE_process.cc`
- [Simulation JSON API](https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/main.cc): `simulation_vm/simulation/main.cc`
- [Remote I/O devices](https://github.com/fortiphyd/grficsv2/tree/master/simulation_vm/simulation/remote_io/modbus): `simulation_vm/simulation/remote_io/modbus`
- [Tank I/O](https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/remote_io/modbus/tank.py): `simulation_vm/simulation/remote_io/modbus/tank.py`
- [Product I/O](https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/remote_io/modbus/product.py): `simulation_vm/simulation/remote_io/modbus/product.py`
- [Feed I/O](https://github.com/fortiphyd/grficsv2/blob/master/simulation_vm/simulation/remote_io/modbus/feed2.py): `simulation_vm/simulation/remote_io/modbus/feed2.py`
- [3D visualization](https://github.com/fortiphyd/grficsv2/tree/master/simulation_vm/web_visualization): `simulation_vm/web_visualization`

### PLC runtime

- [PLC scan loop](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/main.cpp): `plc_vm/OpenPLC_v2-master/core/main.cpp`
- [PLC I/O image](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/ladder.h): `plc_vm/OpenPLC_v2-master/core/ladder.h`
- [Modbus server](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/server.cpp): `plc_vm/OpenPLC_v2-master/core/server.cpp`
- [Persistent memory](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/core/persistent_storage.cpp): `plc_vm/OpenPLC_v2-master/core/persistent_storage.cpp`

### IEC compiler

- [IEC compiler driver](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/main.cc): `plc_vm/OpenPLC_v2-master/matiec_src/main.cc`
- [Semantic analysis](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/stage3/constant_folding.cc): `plc_vm/OpenPLC_v2-master/matiec_src/stage3/constant_folding.cc`
- [C code generation](https://github.com/fortiphyd/grficsv2/blob/master/plc_vm/OpenPLC_v2-master/matiec_src/stage4/generate_c/generate_c.cc): `plc_vm/OpenPLC_v2-master/matiec_src/stage4/generate_c/generate_c.cc`

### Operator network

- **Engineering workstation**
- **ScadaBR HMI**
- **pfSense router**

### Other components

- **Operator**

## Connections

- Chemical process → Simulation JSON API: updates state (evidence: `simulation_vm/simulation/main.cc`)
- Simulation JSON API → Chemical process: updates process (evidence: `simulation_vm/simulation/main.cc`)
- Simulation JSON API → Remote I/O devices: serves JSON API
- Remote I/O devices → Chemical process: reads and actuates
- PLC scan loop → Remote I/O devices: Modbus I/O
- ScadaBR HMI → PLC scan loop: monitors and commands
- Operator → ScadaBR HMI: operates
- Engineering workstation → IEC compiler driver: programs PLC
- Engineering workstation → PLC scan loop: deploys logic
- pfSense router → ScadaBR HMI: routes DMZ traffic
- pfSense router → PLC scan loop: routes ICS traffic
- Operator → 3D visualization: views process
- PLC scan loop → Modbus server: starts server (evidence: `plc_vm/OpenPLC_v2-master/core/main.cpp`)
- Modbus server → PLC I/O image: maps protocol data (evidence: `plc_vm/OpenPLC_v2-master/core/server.cpp`)
- PLC scan loop → PLC I/O image: scans I/O (evidence: `plc_vm/OpenPLC_v2-master/core/main.cpp`)
- PLC scan loop → Persistent memory: persists state
- IEC compiler driver → Semantic analysis: runs stage three (evidence: `plc_vm/OpenPLC_v2-master/matiec_src/main.cc`)
- IEC compiler driver → C code generation: runs stage four (evidence: `plc_vm/OpenPLC_v2-master/matiec_src/main.cc`)
- Tank I/O → Remote I/O devices: implements device
- Product I/O → Remote I/O devices: implements device
- Feed I/O → Remote I/O devices: implements device
