# iioter/iotgateway architecture

> Architecture diagram of the GitHub repository iioter/iotgateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iioter/iotgateway
- Repository: https://github.com/iioter/iotgateway

## Overview

##### Main System Components

a) Core Gateway Components:
- South-bound Interface (Device Connections)
- North-bound Interface (Cloud Platform Connections)
- Core Gateway Service
- Data Processing Engine

b) Protocol Support Layer:
- PLC Protocols (Siemens, Mitsubishi, Modbus, etc.)
- Industrial Protocols (OPC UA, OPC DA)
- IoT Protocols (MQTT)

c) Services:
- Built-in MQTT Broker (Port 1888)
- Built-in OPC UA Server (Port 62541)
- Built-in Modbus Slave (Port 503)

##### Architecture Patterns

Use these visual elements:

a) Layer Separation:
- Present a clear 3-tier architecture:
- UI Layer (Web Interface)
- Business Logic Layer (Gateway Core)
- Data Access Layer (Device Communication)

b) Communication Flows:
- Bidirectional data flow between components
- Real-time data paths
- Configuration paths

##### Specific Implementation Details

Technical aspects:

a) Database Components:
- SQLite storage (indicated by iotgateway.db)
- Configuration storage

b) Driver Framework:
- Plugin architecture for device drivers
- Driver management system

##### Key Integration Points

Interfaces:

a) External Systems:
- IoTSharp
- ThingsCloud
- ThingsBoard
- Huawei Cloud

b) Device Connections:
- PLCs
- CNCs
- Barcode Scanners
- Serial Devices

##### Additional Elements

Supporting components:

a) Security Layer:
- Authentication
- Authorization
- Device Security

b) Management Interface:
- Web Configuration
- Device Management
- Variable Management

Remember to emphasize the project's key features:
- Cross-platform capability
- Visual configuration
- Real-time data processing
- Edge computing capabilities
- Extensible driver system

This will create a clear, professional system design that accurately represents the IoT Gateway's architecture while maintaining readability and usefulness for technical stakeholders.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "UI Layer"
        WI[Web Interface]:::ui
        click WI "https://github.com/iioter/iotgateway/tree/master/IoTGateway/Areas/BasicData/Views"
        WC[Web Controllers]:::ui
        click WC "https://github.com/iioter/iotgateway/tree/master/IoTGateway/Areas/BasicData/Controllers"
    end

    subgraph "Business Logic Layer"
        CGS[Core Gateway Service]:::core
        click CGS "https://github.com/iioter/iotgateway/blob/master/IoTGateway/Plugin/IoTBackgroundService.cs"
        DMS[Device Management Service]:::core
        click DMS "https://github.com/iioter/iotgateway/blob/master/IoTGateway/Plugin/DeviceService.cs"
        DFS[Driver Framework Service]:::core
        click DFS "https://github.com/iioter/iotgateway/blob/master/IoTGateway/Plugin/DrvierService.cs"
    end

    subgraph "Protocol Support Layer"
        subgraph "PLC Protocols"
            SP[Siemens PLC]:::protocol
            click SP "https://github.com/iioter/iotgateway/blob/master/Plugins/Drivers/PLC.SiemensS7"
            MP[Mitsubishi PLC]:::protocol
            click MP "https://github.com/iioter/iotgateway/blob/master/Plugins/Drivers/PLC.MelsecMc"
            AB[Allen Bradley]:::protocol
            click AB "https://github.com/iioter/iotgateway/blob/master/Plugins/Drivers/PLC.AllenBradley"
            MB[Modbus Master]:::protocol
            click MB "https://github.com/iioter/iotgateway/blob/master/Plugins/Drivers/PLC.ModBusMaster"
        end

        subgraph "Industrial Protocols"
            OPCDA[OPC DA Client]:::protocol
            click OPCDA "https://github.com/iioter/iotgateway/blob/master/Plugins/Drivers/OPC.DaClient"
            OPCUA[OPC UA Client]:::protocol
            click OPCUA "https://github.com/iioter/iotgateway/blob/master/Plugins/Drivers/OPC.UaClient"
        end
    end

    subgraph "Built-in Services"
        MQTT[MQTT Broker :1888]:::service
        click MQTT "https://github.com/iioter/iotgateway/blob/master/IoTGateway/Plugin/MyMqttClient.cs"
        UAS["OPC UA Server :62541"]:::service
        click UAS "https://github.com/iioter/iotgateway/blob/master/IoTGateway/Plugin/UA.Server"
        MBS["Modbus Slave :503"]:::service
        click MBS "https://github.com/iioter/iotgateway/blob/master/IoTGateway/Plugin/ModbusSlaveService.cs"
    end

    subgraph "Data Layer"
        DB[(SQLite Database)]:::storage
        click DB "https://github.com/iioter/iotgateway/blob/master/IoTGateway/data/iotgateway.db"
        DAL[Data Access Layer]:::storage
        click DAL "https://github.com/iioter/iotgateway/blob/master/IoTGateway.DataAccess"
        
        subgraph "Configuration Models"
            DM[Device Model]:::model
            click DM "https://github.com/iioter/iotgateway/blob/master/IoTGateway.Model/Device.cs"
            VM[Variable Model]:::model
            click VM "https://github.com/iioter/iotgateway/blob/master/IoTGateway.Model/DeviceVariable.cs"
            CM[Config Model]:::model
            click CM "https://github.com/iioter/iotgateway/blob/master/IoTGateway.Model/DeviceConfig.cs"
        end
    end

    subgraph "External Systems"
        Cloud1[IoTSharp]:::external
        Cloud2[ThingsCloud]:::external
        Cloud3[ThingsBoard]:::external
        Cloud4[Huawei Cloud]:::external
    end

    subgraph "Connected Devices"
        PLC[PLCs]:::device
        CNC[CNCs]:::device
        BC[Barcode Scanners]:::device
        SD[Serial Devices]:::device
    end

    %% Connections
    WI --> WC
    WC --> CGS
    CGS --> DMS
    CGS --> DFS
    DFS --> SP & MP & AB & MB & OPCDA & OPCUA
    CGS --> MQTT & UAS & MBS
    CGS --> DAL
    DAL --> DB
    DMS --> DM
    DMS --> VM
    DMS --> CM
    
    MQTT --> Cloud1 & Cloud2 & Cloud3 & Cloud4
    
    SP & MP & AB & MB & OPCDA & OPCUA --> PLC & CNC & BC & SD

    %% Styles
    classDef ui fill:#E1F5FE,stroke:#01579B
    classDef core fill:#E8F5E9,stroke:#1B5E20
    classDef protocol fill:#FFF3E0,stroke:#E65100
    classDef service fill:#F3E5F5,stroke:#4A148C
    classDef storage fill:#EFEBE9,stroke:#3E2723
    classDef model fill:#E8EAF6,stroke:#1A237E
    classDef external fill:#FFE0B2,stroke:#E65100
    classDef device fill:#E0F2F1,stroke:#004D40
```
