# openstuder/openstuder-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/openstuder/openstuder-gateway
- Repository: https://github.com/openstuder/openstuder-gateway

## Overview

##### Project type and purpose
- This is a native C++ “gateway” daemon plus companion CLI tool, designed to bridge Studer Innotec energy devices to external clients via WebSocket or Bluetooth.
- The README confirms: “Gateway enabling access to Studer Innotec devices from Web or via Bluetooth.”

##### File structure
- Top-level:
- CMakeLists.txt and cmake/ → build system
- config/ → runtime configuration (drivers, extensions, users, datalog, gateway settings)
- src/api/ → core API library defining abstractions (authorize, device access, extension, storage)
- src/drivers/ → plugin implementations for each API:
– deviceaccess (e.g., demo, XCOM485i)
– extension (webstorage, usermanagement, wificonfig)
– storage (sqlite)
- src/sigatewayd/ → the gateway daemon’s components: initialization, Bluetooth protocol, WebSocket protocol, datalog, device-access operations, extension manager, main, settings
- src/sigwctl/ → command-line control tool reusing the same API
- Patterns:
- Layered architecture (API layer vs. drivers vs. daemon vs. CLI)
- Plugin/registry pattern for drivers and extensions
- Modular subsystems in the daemon (bluetooth, websocket, datalog, device operations, extension)

##### README for additional insights
- Mentions broader OpenStuder documentation online but no architecture detail here.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    WebClient["Web Client"]:::external
    BluetoothClient["Bluetooth Client"]:::external
    CLITool["CLI Tool (sigwctl)"]:::external

    %% Gateway Daemon Boundary
    subgraph "Gateway Daemon" 
        direction TB
        DaemonCore["Main & Daemon Lifecycle"]:::core
        ConfigLoader["Configuration Loader"]:::core
        subgraph "Protocol Adapters"
            direction TB
            WebSocketMgr["WebSocket Manager"]:::core
            BluetoothMgr["Bluetooth Manager"]:::core
        end
        DeviceAccessMgr["DeviceAccess Manager"]:::core
        ExtensionMgr["Extension Manager"]:::core
        SessionCtx["Session Context"]:::core
        DatalogMgr["Datalog Manager"]:::core
        APILayer["API Layer"]:::apilayer
    end

    %% Plugin Drivers
    subgraph "Plugin Drivers" 
        direction TB
        subgraph "DeviceAccess Plugins"
            DemoDriver["Demo Driver"]:::plugins
            XCOMDriver["XCOM485i Driver"]:::plugins
        end
        subgraph "Extension Plugins"
            UserMgmt["User Management"]:::plugins
            WebStorage["Web Storage"]:::plugins
            WiFiConfig["WiFi Config"]:::plugins
        end
        subgraph "Storage Plugins"
            SQLiteDriver["SQLite Storage Driver"]:::plugins
        end
    end

    %% Storage Backend and Hardware
    StorageFile["SQLite Database File"]:::storage
    Hardware["Studer Innotec Devices"]:::hardware

    %% Connections
    WebClient -->|"WebSocket"| WebSocketMgr
    BluetoothClient -->|"Bluetooth"| BluetoothMgr
    CLITool -->|"CLI API Calls"| APILayer

    WebSocketMgr -->|"handleRequest()"| DeviceAccessMgr
    BluetoothMgr -->|"handleRequest()"| DeviceAccessMgr
    DeviceAccessMgr -->|"uses API"| APILayer
    ExtensionMgr -->|"uses API"| APILayer
    DatalogMgr -->|"uses API"| APILayer

    APILayer -->|"DeviceAccess Interface"| DemoDriver
    APILayer -->|"DeviceAccess Interface"| XCOMDriver
    APILayer -->|"Extension Interface"| UserMgmt
    APILayer -->|"Extension Interface"| WebStorage
    APILayer -->|"Extension Interface"| WiFiConfig
    APILayer -->|"Storage Interface"| SQLiteDriver

    DemoDriver -->|"communicates"| Hardware
    XCOMDriver -->|"communicates"| Hardware
    SQLiteDriver -->|"writes/reads"| StorageFile
    DatalogMgr -->|"logEntry()"| SQLiteDriver

    %% Click Events for component mappings
    click CLITool "https://github.com/openstuder/openstuder-gateway/tree/main/src/sigwctl"
    click DaemonCore "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/main.cpp"
    click ConfigLoader "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/sisettings.cpp"
    click DeviceAccessMgr "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/deviceaccess/sideviceaccessmanager.cpp"
    click ExtensionMgr "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/extension/siextensionmanager.cpp"
    click SessionCtx "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/extension/sisessioncontext.h"
    click DatalogMgr "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/datalog/sidatalogmanager.cpp"
    click WebSocketMgr "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/websocket/siwebsocketmanager.cpp"
    click BluetoothMgr "https://github.com/openstuder/openstuder-gateway/blob/main/src/sigatewayd/bluetooth/sibluetoothmanager.cpp"
    click DemoDriver "https://github.com/openstuder/openstuder-gateway/tree/main/src/drivers/deviceaccess/demo"
    click XCOMDriver "https://github.com/openstuder/openstuder-gateway/tree/main/src/drivers/deviceaccess/xcom485i"
    click UserMgmt "https://github.com/openstuder/openstuder-gateway/tree/main/src/drivers/extension/usermanagement"
    click WebStorage "https://github.com/openstuder/openstuder-gateway/tree/main/src/drivers/extension/webstorage"
    click WiFiConfig "https://github.com/openstuder/openstuder-gateway/tree/main/src/drivers/extension/wificonfig"
    click SQLiteDriver "https://github.com/openstuder/openstuder-gateway/blob/main/src/drivers/storage/sqlite/sqlitestorage.cpp"

    %% Styles
    classDef external fill:#BBDEFB,stroke:#1976D2,color:#0D47A1
    classDef core fill:#C8E6C9,stroke:#388E3C,color:#1B5E20
    classDef apilayer fill:#FFF9C4,stroke:#FBC02D,color:#F57F17
    classDef plugins fill:#E1BEE7,stroke:#7B1FA2,color:#4A148C
    classDef storage fill:#FFCCBC,stroke:#E64A19,color:#BF360C
    classDef hardware fill:#CFD8DC,stroke:#455A64,color:#263238
```
