# stepfunc/rodbus architecture

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

- Interactive diagram: https://gitdiagram.com/stepfunc/rodbus
- Repository: https://github.com/stepfunc/rodbus

## Overview

Rodbus is a commercial Modbus client/server library with TCP, RTU serial, TLS, retries, decoding controls, and C/Java-oriented FFI. The main client workflow is user or binding API -> channel setup -> transport/session -> Modbus request encoding and exchange -> callback or returned values. The server workflow is remote Modbus client -> transport listener -> session -> unit-ID handler -> application data. Sampled code strongly supports transport, TLS authorization, handler dispatch, FFI database access, and generated binding surfaces; some client internals are inferred only from module structure.

Main entry points: [`ffi/rodbus-ffi/src/client.rs`](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/client.rs) (Native FFI API), [`rodbus/src/client/channel.rs`](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/client/channel.rs) (Client Channel), [`rodbus/src/tcp/server.rs`](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/server.rs) (TCP Server), [`ffi/rodbus-ffi/src/server.rs`](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/server.rs) (FFI Server API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client API"]
  node_cli["CLI Client<br/>[main.rs]"]
  node_client_api["Client Channel<br/>[channel.rs]"]
  node_client_tasks["Request Tasks<br/>[task.rs]"]
end

subgraph group_protocol["Protocol Core"]
  node_request_codecs["Request Codecs"]
  node_frame["Frame Layer<br/>[frame.rs]"]
  node_decode["Decode Controls<br/>[decode.rs]"]
end

subgraph group_transport["Transports"]
  node_tcp_client["TCP Client<br/>[client.rs]"]
  node_serial_client["RTU Client<br/>[client.rs]"]
  node_tls_client["TLS Client<br/>[client.rs]"]
end

subgraph group_server["Server Runtime"]
  node_tcp_server["TCP Server<br/>[server.rs]"]
  node_serial_server["RTU Server<br/>[server.rs]"]
  node_tls_server["TLS Server<br/>[server.rs]"]
  node_sessions["Server Sessions<br/>[task.rs]"]
  node_handlers["Handler Map<br/>[handler.rs]"]
  node_address_filter["Address Filter<br/>[address_filter.rs]"]
end

subgraph group_ffi["FFI Surface"]
  node_ffi_api["Native FFI API<br/>[client.rs]"]
  node_ffi_runtime["FFI Runtime<br/>[runtime.rs]"]
  node_ffi_server["FFI Server API<br/>[server.rs]"]
  node_ffi_database[("FFI Database<br/>[database.rs]")]
  node_binding_schema["Binding Schema<br/>[client.rs]"]
end

node_user(("Application User"))
node_remote_client(("Modbus Client"))
node_remote_device(("Modbus Device"))

node_user -->|"invokes"| node_cli
node_user -.->|"invokes"| node_ffi_api
node_cli -->|"opens"| node_tcp_client
node_cli -->|"opens"| node_serial_client
node_ffi_api -->|"uses"| node_ffi_runtime
node_ffi_api -->|"creates"| node_tcp_client
node_ffi_api -->|"creates"| node_serial_client
node_ffi_api -.->|"creates"| node_tls_client
node_tcp_client -->|"returns channel"| node_client_api
node_serial_client -->|"returns channel"| node_client_api
node_tls_client -->|"returns channel"| node_client_api
node_client_api -->|"dispatches"| node_client_tasks
node_client_tasks -->|"encodes requests"| node_request_codecs
node_client_tasks -->|"frames traffic"| node_frame
node_client_api -->|"sets decoding"| node_decode
node_frame -->|"exchanges frames"| node_remote_device
node_remote_client -->|"connects"| node_tcp_server
node_remote_client -->|"connects"| node_serial_server
node_tcp_server -->|"filters peers"| node_address_filter
node_tcp_server -.->|"upgrades TLS"| node_tls_server
node_tcp_server -->|"starts sessions"| node_sessions
node_serial_server -->|"starts sessions"| node_sessions
node_tls_server -->|"authorizes sessions"| node_sessions
node_sessions -->|"dispatches requests"| node_handlers
node_handlers -->|"reads and writes"| node_ffi_database
node_ffi_server -->|"configures data"| node_ffi_database
node_ffi_server -->|"starts server"| node_tcp_server
node_ffi_server -->|"starts server"| node_serial_server
node_ffi_server -.->|"configures TLS"| node_tls_server
node_binding_schema -->|"defines bindings"| node_ffi_api
node_client_api -->|"returns results"| node_cli

click node_cli "https://github.com/stepfunc/rodbus/blob/main/rodbus-client/src/main.rs"
click node_client_api "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/client/channel.rs"
click node_client_tasks "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/client/task.rs"
click node_request_codecs "https://github.com/stepfunc/rodbus/tree/main/rodbus/src/client/requests"
click node_frame "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/common/frame.rs"
click node_decode "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/decode.rs"
click node_tcp_client "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/client.rs"
click node_serial_client "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/serial/client.rs"
click node_tls_client "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/tls/client.rs"
click node_tcp_server "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/server.rs"
click node_serial_server "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/serial/server.rs"
click node_tls_server "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/tls/server.rs"
click node_sessions "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/server/task.rs"
click node_handlers "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/server/handler.rs"
click node_address_filter "https://github.com/stepfunc/rodbus/blob/main/rodbus/src/server/address_filter.rs"
click node_ffi_api "https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/client.rs"
click node_ffi_runtime "https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/runtime.rs"
click node_ffi_server "https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/server.rs"
click node_ffi_database "https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/database.rs"
click node_binding_schema "https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-schema/src/client.rs"

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_cli,node_client_api,node_client_tasks,node_user,node_remote_client toneBlue
class node_request_codecs,node_frame,node_decode toneAmber
class node_tcp_client,node_serial_client,node_tls_client toneMint
class node_tcp_server,node_serial_server,node_tls_server,node_sessions,node_handlers,node_address_filter toneRose
class node_ffi_api,node_ffi_runtime,node_ffi_server,node_ffi_database,node_binding_schema,node_remote_device toneIndigo
```

## Components

### Client API

- [CLI Client](https://github.com/stepfunc/rodbus/blob/main/rodbus-client/src/main.rs): `rodbus-client/src/main.rs`
- [Client Channel](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/client/channel.rs): `rodbus/src/client/channel.rs`
- [Request Tasks](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/client/task.rs): `rodbus/src/client/task.rs`

### Protocol Core

- [Request Codecs](https://github.com/stepfunc/rodbus/tree/main/rodbus/src/client/requests): `rodbus/src/client/requests`
- [Frame Layer](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/common/frame.rs): `rodbus/src/common/frame.rs`
- [Decode Controls](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/decode.rs): `rodbus/src/decode.rs`

### Transports

- [TCP Client](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/client.rs): `rodbus/src/tcp/client.rs`
- [RTU Client](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/serial/client.rs): `rodbus/src/serial/client.rs`
- [TLS Client](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/tls/client.rs): `rodbus/src/tcp/tls/client.rs`

### Server Runtime

- [TCP Server](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/server.rs): `rodbus/src/tcp/server.rs`
- [RTU Server](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/serial/server.rs): `rodbus/src/serial/server.rs`
- [TLS Server](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/tcp/tls/server.rs): `rodbus/src/tcp/tls/server.rs`
- [Server Sessions](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/server/task.rs): `rodbus/src/server/task.rs`
- [Handler Map](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/server/handler.rs): `rodbus/src/server/handler.rs`
- [Address Filter](https://github.com/stepfunc/rodbus/blob/main/rodbus/src/server/address_filter.rs): `rodbus/src/server/address_filter.rs`

### FFI Surface

- [Native FFI API](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/client.rs): `ffi/rodbus-ffi/src/client.rs`
- [FFI Runtime](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/runtime.rs): `ffi/rodbus-ffi/src/runtime.rs`
- [FFI Server API](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/server.rs): `ffi/rodbus-ffi/src/server.rs`
- [FFI Database](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-ffi/src/database.rs): `ffi/rodbus-ffi/src/database.rs`
- [Binding Schema](https://github.com/stepfunc/rodbus/blob/main/ffi/rodbus-schema/src/client.rs): `ffi/rodbus-schema/src/client.rs`

### Other components

- **Application User**
- **Modbus Client**
- **Modbus Device**

## Connections

- Application User → CLI Client: invokes
- Application User → Native FFI API: invokes
- CLI Client → TCP Client: opens
- CLI Client → RTU Client: opens
- Native FFI API → FFI Runtime: uses
- Native FFI API → TCP Client: creates
- Native FFI API → RTU Client: creates
- Native FFI API → TLS Client: creates
- TCP Client → Client Channel: returns channel
- RTU Client → Client Channel: returns channel
- TLS Client → Client Channel: returns channel
- Client Channel → Request Tasks: dispatches
- Request Tasks → Request Codecs: encodes requests
- Request Tasks → Frame Layer: frames traffic
- Client Channel → Decode Controls: sets decoding
- Frame Layer → Modbus Device: exchanges frames
- Modbus Client → TCP Server: connects
- Modbus Client → RTU Server: connects
- TCP Server → Address Filter: filters peers
- TCP Server → TLS Server: upgrades TLS
- TCP Server → Server Sessions: starts sessions
- RTU Server → Server Sessions: starts sessions
- TLS Server → Server Sessions: authorizes sessions
- Server Sessions → Handler Map: dispatches requests
- Handler Map → FFI Database: reads and writes
- FFI Server API → FFI Database: configures data
- FFI Server API → TCP Server: starts server
- FFI Server API → RTU Server: starts server
- FFI Server API → TLS Server: configures TLS
- Binding Schema → Native FFI API: defines bindings
- Client Channel → CLI Client: returns results
