# hilscherautomation/netpi-openplc architecture

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

- Interactive diagram: https://gitdiagram.com/hilscherautomation/netpi-openplc
- Repository: https://github.com/hilscherautomation/netpi-openplc

## Overview

##### Project Type & Purpose
- Type: Embedded/edge-focused Docker image packaging an IEC 61131-3 PLC runtime.
- Purpose: Provide a ready-to-run OpenPLC V3 environment on netPI (Raspberry Pi 3B-based) with SSH, web GUI, Modbus TCP and a custom GPIO hardware layer.

##### File-Structure & README Analysis
– Top‐level files:
- Dockerfile / .dockerignore → container build.
- init.d/entrypoint.sh → container startup.
- hardware_layer/raspberrypi.cpp → custom GPIO interface.
- sample/… → test programs (.st, .xml).
– README highlights:
- Base: Debian + OpenPLC_v3 + SSH + custom hardware layer.
- Runtime exposes ports 22 (SSH), 8080 (GUI), 502 (Modbus TCP).
- Host requirements: privileged mode, /dev/gpiomem device mapping.
- External tools: Portainer UI, PLCOpen Editor, Modbus client.

##### Main Components
A. Host (netPI device)
– Docker Engine
– /dev/gpiomem (GPIO device)
B. Container (“hilschernetpi/netpi-openplc”)
1. Base OS (Debian)
2. init.d/entrypoint.sh (startup script)
3. SSH Daemon (port 22)
4. OpenPLC Runtime Core
- Webserver (port 8080)
- Modbus TCP server (port 502)
- Hardware Layer (modifiable GPIO interface via raspberrypi.cpp)
5. Sample programs (netPI_Test.st / .xml)
C. External Tools & Clients
– Portainer UI (manages container lifecycle)
– Web Browser (accesses OpenPLC GUI)
– SSH Client (remote shell)
– PLCOpen Editor (offline program authoring)
– Modbus Client Simulator (runtime testing)

##### Interactions & Data Flows
1. Operator uses Portainer → Docker Engine → starts container.
2. SSH Client ←→ SSH Daemon inside container.
3. Web Browser ←HTTP→ OpenPLC Webserver → OpenPLC Runtime.
4. PLCOpen Editor → uploads .st program via Web GUI.
5. Runtime ↔ Hardware Layer (raspberrypi.cpp) ↔ /dev/gpiomem → netPI GPIO.
6. Modbus Client Simulator ↔ Modbus TCP server in container.

##### Architectural Patterns & Principles
– Containerization: Isolation of services in one Docker image.
– Layered design: OS layer → init scripts → daemons → runtime core → hardware abstraction.
– Single‐process container (runs multiple daemons but you could split into microservices if desired).
– Hardware abstraction: custom GPIO layer isolates device-specific code.

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Host Tier"
    HostDocker["Docker Engine"]:::host
    GPIOMEM["/dev/gpiomem"]:::host
  end

  subgraph "Container Tier"
    BaseOS["Debian + OpenPLC + SSH (Ports:22,8080,502)"]:::container
    ConfigIgnore[".dockerignore"]:::script
    InitScript["init.d/entrypoint.sh"]:::script
    SSH["SSH Daemon (22)"]:::container
    subgraph "OpenPLC Runtime Core"
      WebGUI["OpenPLC Web GUI (8080)"]:::container
      Modbus["Modbus TCP Server (502)"]:::container
      HWLayer["Custom GPIO Layer"]:::container
    end
    SampleST["netPI_Test.st"]:::sample
    SampleXML["netPI_Test.xml"]:::sample
    Doc["README.md"]:::note
    Privilege["Privileged Mode"]:::note
  end

  subgraph "External Tools Tier"
    Portainer["Portainer UI"]:::external
    Browser["Web Browser"]:::external
    SSHClient["SSH Client"]:::external
    Editor["PLCOpen Editor"]:::external
    ModbusClient["Modbus Client Simulator"]:::external
  end

  %% Control Flow
  Portainer -- dashed --> HostDocker
  HostDocker -- dashed --> InitScript
  HostDocker -- dashed --> Privilege

  %% Service Interactions
  SSHClient <--> SSH
  Browser -->|"HTTP:8080"| WebGUI
  Editor -->|"Upload Program"| WebGUI
  ModbusClient <--> Modbus
  WebGUI -->|"Execute PLC"| HWLayer
  HWLayer -->|"/dev/gpiomem"| GPIOMEM

  %% Startup config files
  InitScript --> BaseOS
  InitScript --> SSH
  InitScript --> WebGUI
  InitScript --> Modbus

  %% Documentation
  Doc --- BaseOS

  %% Click Events
  click BaseOS "https://github.com/hilscherautomation/netpi-openplc/tree/master/Dockerfile"
  click ConfigIgnore "https://github.com/hilscherautomation/netpi-openplc/blob/master/.dockerignore"
  click InitScript "https://github.com/hilscherautomation/netpi-openplc/blob/master/init.d/entrypoint.sh"
  click HWLayer "https://github.com/hilscherautomation/netpi-openplc/blob/master/hardware_layer/raspberrypi.cpp"
  click SampleST "https://github.com/hilscherautomation/netpi-openplc/blob/master/sample/netPI_Test.st"
  click SampleXML "https://github.com/hilscherautomation/netpi-openplc/blob/master/sample/netPI_Test.xml"
  click Doc "https://github.com/hilscherautomation/netpi-openplc/blob/master/README.md"

  %% Styles
  classDef host fill:#EEEEEE,stroke:#333,stroke-width:1px
  classDef container fill:#BBDEFB,stroke:#333,stroke-width:1px
  classDef external fill:#C8E6C9,stroke:#333,stroke-width:1px
  classDef script fill:#FFE082,stroke:#333,stroke-width:1px
  classDef sample fill:#FFD54F,stroke:#333,stroke-width:1px
  classDef note fill:#FFCDD2,stroke:#333,stroke-width:1px
```
