# gurux/gxdlmsdirector architecture

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

- Interactive diagram: https://gitdiagram.com/gurux/gxdlmsdirector
- Repository: https://github.com/gurux/gxdlmsdirector

## Overview

##### Project Type and Purpose
- This is a Windows desktop application (C#/.NET WinForms) named GXDLMSDirector.
- Purpose: provide a unified UI to read and control DLMS/COSEM-compatible electricity, gas, or water meters from different manufacturers.

##### File-Structure Analysis
- Top level:
- Development/ – contains all source code and submodules.
- Development/ConformanceTests/ – XML-based test definitions and a C# test runner.
- Development/Macro/ – macro engine code for recording and replaying meter actions.
- Resources/ and Development/Resources/ – bitmap and UI resource files.
- Properties/, app.config, packages.config – .NET configuration and NuGet dependencies.
- The ‘Development’ folder breaks down into UI forms (MainForm, various dialogs), business logic classes (GXDLMSDevice, GXDLMSCommunicator), protocol helpers (GXByteConverter, GXValueSerializer), test frameworks, and manufacturer settings.

##### README Insights
- Confirms it’s a desktop tool for DLMS/COSEM meter communication.
- References external XML files for “default meter settings” and a community website.
- Build prereq: Visual Studio + NuGet.

##### Main Components
a. User Interface Layer
- WinForms (MainForm, DLMSTranslatorForm, DevicePropertiesForm, etc.)
- Macro Editor UI and Conformance Test UI
b. Business Logic Layer
- GXDLMSDeviceCollection, GXDLMSDirector core classes
- Device models (GXDLMSDevice, GXDLMSModemConfiguration, etc.)
c. Communication Layer
- GXDLMSCommunicator
- Protocol submodules: HDLC (GXDLMSHdlcSetup), IEC optical, TCP/UDP, M-Bus, PrimePLC
d. Serialization & Conversion
- GXValueSerializer, GXByteConverter, GXDataConcentratorUI
e. Configuration & Settings
- XML test definitions under ConformanceTests/DLMS
- app.config, packages.config, ManufacturerSettings
f. Macro Engine
- GXMacro, GXMacroEditor, related dialogs
g. Conformance Test Engine
- GXConformanceTest runner, Settings/CttApplicationSettings
h. External Services & Devices
- Physical ports: Serial, TCP/IP, PLC, Optical
- External meters (DLMS/COSEM)

##### Relationships & Data Flows
- UI → Business Logic → Communicator → Physical Port → Meter → Communicator → Logic → UI
- From Conformance Test UI → Test Engine → Communicator → Meter
- Macro UI → Macro Engine → Business Logic → Communicator
- Configuration loaded once at startup (app.config, XML).

##### Architectural Patterns & Technologies
- Layered architecture (UI, business logic, communication, data/config).
- Event-driven WinForms controllers.
- XML-driven test definitions and default meter settings.
- Uses Gurux DLMS/COSEM protocol library (NuGet).
- No central database; configuration and tests are file-based.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface Layer"
        direction TB
        MainForm["MainForm"]:::ui
        DLMSTranslatorForm["DLMSTranslatorForm"]:::ui
        DevicePropertiesForm["DevicePropertiesForm"]:::ui
        MacroEditorUI["GXMacroEditor"]:::ui
        ConformanceTestUI["GXConformanceDlg"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        Program["Program.cs"]:::business
        DeviceCollection["GXDLMSDeviceCollection"]:::business
        DeviceModel["GXDLMSDevice"]:::business
        ExceptionModel["GXDLMSException"]:::business
    end

    %% Communication & Protocol
    subgraph "Communication Layer"
        direction TB
        Communicator["GXDLMSCommunicator"]:::comm
        HDLC["GXDLMSHdlcSetup"]:::comm
        IECOptical["GXDLMSIECOpticalPortSetup"]:::comm
        Ip4["GXDLMSIp4Setup"]:::comm
    end

    %% Serialization & Conversion
    subgraph "Serialization & Conversion"
        direction TB
        ValueSerializer["GXValueSerializer"]:::comm
        ByteConverter["GXByteConverter"]:::comm
        ObjectSerializer["GXDLMSObjectSerializer"]:::comm
    end

    %% Configuration & Settings
    subgraph "Configuration & Settings"
        direction TB
        AppConfig["app.config"]:::config
        PackagesConfig["packages.config"]:::config
        ManufacturerSettings["ManufacturerSettings (folder)"]:::config
        XMLStore["Test Definitions XML"]:::config
    end

    %% Macro Engine
    subgraph "Macro Engine"
        direction TB
        MacroCore["GXMacro"]:::business
    end

    %% Conformance Test Engine
    subgraph "Conformance Test Engine"
        direction TB
        TestRunner["GXConformanceTest"]:::business
        TestEditor["GXConformanceEditor"]:::ui
    end

    %% External Devices & Ports
    subgraph "External Media & Devices"
        direction TB
        SerialPort["Serial/TCP/PLC/Optical"]:::comm
        ExternalMeter["DLMS/COSEM Meter"]:::external
    end

    %% Flows
    MainForm -->|"user action"| Program
    DLMSTranslatorForm -->|"user action"| Program
    DevicePropertiesForm -->|"edit properties"| Program

    Program -->|"loads config"| AppConfig
    Program -->|"loads packages"| PackagesConfig
    Program -->|"loads settings"| ManufacturerSettings

    Program -->|"manages"| DeviceCollection
    DeviceCollection -->|"contains"| DeviceModel

    Program -->|"calls"| Communicator
    Communicator -->|"uses"| HDLC
    Communicator -->|"uses"| IECOptical
    Communicator -->|"uses"| Ip4

    Communicator -->|"serialize/deserialize"| ValueSerializer
    Communicator -->|"convert bytes"| ByteConverter
    Communicator -->|"object serialize"| ObjectSerializer

    Communicator -->|"open"| SerialPort
    SerialPort -->|"send/receive"| ExternalMeter
    ExternalMeter -->|"response"| Communicator

    Communicator -->|"returns data"| DeviceCollection
    DeviceCollection -->|"update UI"| MainForm

    ConformanceTestUI -->|"start tests"| TestRunner
    TestRunner -->|"reads definitions"| XMLStore
    TestRunner -->|"uses communicator"| Communicator

    MacroEditorUI -->|"create macros"| MacroCore
    MacroCore -->|"invoke"| Program

    %% Click events
    click MainForm "https://github.com/gurux/gxdlmsdirector/blob/master/Development/MainForm.cs"
    click DLMSTranslatorForm "https://github.com/gurux/gxdlmsdirector/blob/master/Development/DLMSTranslatorForm.cs"
    click DevicePropertiesForm "https://github.com/gurux/gxdlmsdirector/blob/master/Development/DevicePropertiesForm.cs"
    click MacroEditorUI "https://github.com/gurux/gxdlmsdirector/blob/master/Development/Macro/GXMacroEditor.cs"
    click ConformanceTestUI "https://github.com/gurux/gxdlmsdirector/blob/master/Development/ConformanceTests/GXConformanceDlg.cs"
    click Program "https://github.com/gurux/gxdlmsdirector/blob/master/Development/Program.cs"
    click DeviceModel "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSDevice.cs"
    click DeviceCollection "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSDeviceCollection.cs"
    click ExceptionModel "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSException.cs"
    click Communicator "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSCommunicator.cs"
    click HDLC "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSHdlcSetup.cs"
    click IECOptical "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSIECOpticalPortSetup.cs"
    click Ip4 "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSIp4Setup.cs"
    click ValueSerializer "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXValueSerializer.cs"
    click ByteConverter "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXByteConverter.cs"
    click ObjectSerializer "https://github.com/gurux/gxdlmsdirector/blob/master/Development/GXDLMSObjectSerializer.cs"
    click AppConfig "https://github.com/gurux/gxdlmsdirector/blob/master/Development/app.config"
    click PackagesConfig "https://github.com/gurux/gxdlmsdirector/blob/master/Development/packages.config"
    click ManufacturerSettings "https://github.com/gurux/gxdlmsdirector/tree/master/Development/ManufacturerSettings"
    click XMLStore "https://github.com/gurux/gxdlmsdirector/tree/master/Development/ConformanceTests/DLMS"
    click MacroCore "https://github.com/gurux/gxdlmsdirector/blob/master/Development/Macro/GXMacro.cs"
    click TestRunner "https://github.com/gurux/gxdlmsdirector/blob/master/Development/ConformanceTests/GXConformanceTest.cs"
    click TestEditor "https://github.com/gurux/gxdlmsdirector/blob/master/Development/ConformanceTests/GXConformanceEditor.cs"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef business fill:#E8F5E9,stroke:#2E7D32,color:#000
    classDef comm fill:#FFF3E0,stroke:#EF6C00,color:#000
    classDef config fill:#ECEFF1,stroke:#607D8B,color:#000
    classDef external fill:#CFD8DC,stroke:#455A64,color:#000
```
