# bambooww/iot-tree architecture

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

- Interactive diagram: https://gitdiagram.com/bambooww/iot-tree
- Repository: https://github.com/bambooww/iot-tree

## Overview

##### Project Type and Purpose
- This is a Java-based, Maven multi-module full-stack IoT middleware and SCADA system (“IOT-Tree Server”).
- It provides device/system connectivity (Modbus, OPC UA/DA, MQTT, HTTP, PLC protocols, etc.), a tree-structured device/tag management core, a message-flow engine (MsgNet) for control and data processing, pluggable storage backends (JDBC, InfluxDB, IoTDB, TSSDB), and web-based UIs (administration, HMI) plus a .NET desktop client.

##### File Structure Analysis
Top-level Maven modules:
- core – the heart of the system: communications layer, drivers interface, IOC & tree, message flow engine (msgnet), filter, router, service abstractions, plugins, storage adapters, online UI editor support.
- driver-parent – collection of protocol drivers (Modbus, OPC UA/DA, Siemens, Mitsubishi, BACnet, NB-IoT, etc.).
- ext-parent – extension modules (basic extensions for messaging, ROA, VO).
- server – Java service bootstrap, embedded web container or wrapper, server-side control handlers, REST/WebSocket endpoints.
- web – JSP-based HMI front-end (ROOT), administration panel (web/admin), documentation site (web/doc), custom web/main example app.
- win_panel – Windows .NET desktop client for HMI.

##### Architecture from README
- “Root Part of the tree”: device connectivity → communication access → channels → device drivers → tag model → tree‐structured organization → online UI nodes.
- “Upper Part of the tree”: MsgNet message-flow runtime → functional nodes (scheduling, alerts, data routing, storage, external services like MQTT/Kafka/Mail/Excel) → control logic.
- Web-based management UI and HMI delivered as standard Java Webapps and static assets, served by the server module.

##### Main Components & Interactions
A. Device Connectivity Layer
- Driver modules (driver-parent) and core/conn packages
- Protocol adapters: TCP/UDP/COM/HTTP/MQTT/OPCUA/OPCDA/Virtual/etc.
→ feed raw data into
B. Core Processing Engine (core module)
- IOC & tree model: Config, ConnManager, DevManager, UAManager, etc.
- MsgNet engine: MNManager, MNNode, modules, nodes, store sub-packages
- Plugin framework: PlugManager, AbstractPlugin, driver plugins
→ outputs processed data or control commands to
C. Storage Layer
- StoreManager with adapters: SourceJDBC, SourceInfluxDB, SourceTSSDB, etc.
- Historical & real-time storage APIs
D. Server & Service Layer (server module)
- Bootstrapping components: ServerBootCompMgr, ServiceWrapperMain
- REST endpoints, WebSocket (WSRoot, WSServer)
- Admin/control handlers, Tomcat integration
→ serves UIs and exposes APIs for UI and external systems
E. Web-based UIs (web module)
- HMI (web/ROOT): JSPs, JavaScript, iottree_hmi.js
- Admin panel (web/admin): JSPs, Vue router, AJAX endpoints (WSNetMsgDebug, WSHmiRT, etc.)
→ accessed by browser clients
F. Desktop Client (win_panel)
- .NET WinForms app uses WBBridge, Conf to connect via WebSocket/REST to server for kiosk UI.
G. External Systems
- MQTT broker, Kafka cluster, mail servers, databases (MySQL, Oracle, SQL Server), OPC servers, RESTful services

##### Architectural Patterns & Principles
- Layered Architecture:
1) Driver/Connector layer
2) Core engine (model + MsgNet processing)
3) Service/API layer
4) Presentation layer (web UI, desktop client)
- Plugin/Adapter pattern for drivers and storage backends
- Dependency Injection (IOC packages) for pluggable components
- Event-driven message flow (MsgNet) for control logic
- Maven multi-module for clear separation and reuse

##### Elements
- Annotations for protocols (e.g., OPC UA, MQTT) and storage backends.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Driver/Connector Layer"
        ConnPkg["Core Connections Package"]:::internal 
        subgraph "Driver Plugins"
            D1["driver-common"]:::internal 
            D2["driver-opc"]:::internal 
        end
    end

    subgraph "Core Processing Engine"
        IOC["IOC & Tree Model"]:::internal
        MsgNet["MsgNet Message-Flow Engine"]:::internal
        PluginFW["Plugin Framework"]:::internal
    end

    subgraph "Storage Layer"
        Store["Storage Adapters & APIs"]:::internal
        MsgNetStore["MsgNet Store Sub-package"]:::internal
    end

    subgraph "Service Layer & Server"
        Server["Server Bootstrap & APIs"]:::internal
    end

    subgraph "Web-based UIs"  
        HMI["HMI Frontend (ROOT)"]:::ui
        Admin["Administration Panel"]:::ui
        Doc["Documentation Site"]:::ui
        MainApp["Custom Web App"]:::ui
    end

    Desktop["Desktop Client (.NET WinForms)"]:::ui

    subgraph "External Systems"
        MQTT["MQTT Broker"]:::service
        Kafka["Kafka Cluster"]:::service
        Mail["Mail Servers"]:::service
        DBs["Databases (MySQL/Oracle/SQL Server)"]:::service
        OPCServ["OPC Servers"]:::service
        RESTExt["RESTful Services"]:::service
    end

    %% Data and control flows
    D1 -->|raw data| ConnPkg
    D2 -->|raw data| ConnPkg
    ConnPkg -->|poll/tag update| IOC
    IOC -->|tree events| MsgNet
    PluginFW -->|pluggable drivers| IOC
    MsgNet -->|store messages| Store
    MsgNet -->|store events| MsgNetStore
    MsgNet -->|REST API calls| Server
    Server -->|serves| HMI
    Server -->|REST API| Admin
    Server -->|hosts| Doc
    Server -->|serves| MainApp
    Server -->|WebSocket push| Desktop
    MsgNet -->|publish/subscribe| MQTT
    MsgNet -->|produce/consume| Kafka
    MsgNet -->|send alerts| Mail
    MsgNet -->|write/read| DBs
    MsgNet -->|connect| OPCServ
    MsgNet -->|call| RESTExt

    %% Click Events
    click ConnPkg "https://github.com/bambooww/iot-tree/tree/main/core/src/main/java/org/iottree/core/conn"
    click D1 "https://github.com/bambooww/iot-tree/tree/main/driver-parent/driver-common"
    click D2 "https://github.com/bambooww/iot-tree/tree/main/driver-parent/driver-opc"
    click IOC "https://github.com/bambooww/iot-tree/tree/main/core/src/main/java/org/iottree/core"
    click MsgNet "https://github.com/bambooww/iot-tree/tree/main/core/src/main/java/org/iottree/core/msgnet"
    click PluginFW "https://github.com/bambooww/iot-tree/tree/main/core/src/main/java/org/iottree/core/plugin"
    click Store "https://github.com/bambooww/iot-tree/tree/main/core/src/main/java/org/iottree/core/store"
    click MsgNetStore "https://github.com/bambooww/iot-tree/tree/main/core/src/main/java/org/iottree/core/msgnet/store"
    click Server "https://github.com/bambooww/iot-tree/tree/main/server/src/main/java/org/iottree/server"
    click HMI "https://github.com/bambooww/iot-tree/tree/main/web/ROOT"
    click Admin "https://github.com/bambooww/iot-tree/tree/main/web/admin"
    click Doc "https://github.com/bambooww/iot-tree/tree/main/web/doc"
    click MainApp "https://github.com/bambooww/iot-tree/tree/main/web/main"
    click Desktop "https://github.com/bambooww/iot-tree/tree/main/win_panel/win_client"

    %% Styling
    classDef internal fill:#D0E4F5,stroke:#0B5394,stroke-width:1px,color:#0B5394;
    classDef service fill:#D9EAD3,stroke:#38761D,stroke-width:1px,color:#38761D;
    classDef ui fill:#FDE9D9,stroke:#E69138,stroke-width:1px,color:#E69138;
    classDef external fill:#F2F2F2,stroke:#999999,stroke-width:1px,color:#666666;
```
