# e9ctrl/vd architecture

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

- Interactive diagram: https://gitdiagram.com/e9ctrl/vd
- Repository: https://github.com/e9ctrl/vd

## Overview

Primary Flows:
- Client Applications → TCP Server → Protocol Handler → Device Simulator ↔ Parameter Manager
- HTTP Clients → HTTP API → Parameter Manager
- Configuration File → Config Parser → Device Simulator

##### Component Relationships

Create these distinct sections:

a. External Interface Layer:
- TCP Server (Device Communication)
- HTTP API Server (Control Interface)

b. Core Processing Layer:
- Protocol Handler (with Modbus support)
- Stream Processing (Lexer/Parser)
- Command Processing

c. State Management Layer:
- Parameter Storage
- Device State Management

##### Key Technical Elements to Highlight

Use annotations or callouts to show:
- Protocol support (especially Modbus)
- Stream processing capabilities
- Parameter types (int64, float64, string, bool)
- Command handling patterns
- Delay simulation features

##### Specific Implementation Details

Key features:
- Message parsing flow
- Response generation path
- Delay handling mechanism
- Trigger system for autonomous responses
- Parameter validation and constraints

##### Additional Elements

Include:
- Configuration file format examples
- API endpoints listing
- Supported protocol details
- Error handling paths

##### Clean separation between
- Network interfaces (TCP/HTTP)
- Protocol handling
- State management
- Configuration management

##### Modular nature of
- Protocol support
- Command processing
- Parameter management

##### Extensibility points
- Protocol additions
- Command types
- Parameter types

Remember to:
- Keep the main flow clear and centered
- Related components visually
- Version information and key constraints
- Document all external interfaces

This design should reflect the tool's primary purpose of device simulation while showing its flexibility in handling different protocols and command patterns.

##### Configuration Layer

Each layer should clearly show its interactions with adjacent layers while maintaining clear boundaries of responsibility.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef external fill:#2374AB,color:white
    classDef core fill:#57A773,color:white
    classDef state fill:#FF8C42,color:white
    classDef config fill:#9B6B9E,color:white
    classDef stream fill:#4B296B,color:white

    %% Legend
    subgraph Legend
        E[External Interface]:::external
        C[Core Component]:::core
        S[State Management]:::state
        CF[Configuration]:::config
        ST[Stream Processing]:::stream
    end

    %% Client Interface Layer
    subgraph "External Interface Layer"
        TCP["TCP Server\n(Port :9999)"]:::external
        HTTP["HTTP API Server\n(Port :8080)"]:::external
        Client["Client Interface"]:::external
    end

    %% Protocol Processing Layer
    subgraph "Protocol Layer"
        PH["Protocol Handler"]:::core
        MB["Modbus Protocol"]:::core
        SP["Stream Processor"]:::stream
        Lexer["Lexer"]:::stream
        Parser["Parser"]:::stream
    end

    %% Core Simulation Layer
    subgraph "Core Layer"
        DS["Device Simulator"]:::core
        CP["Command Processor"]:::core
        RT["Response Trigger"]:::core
    end

    %% State Management Layer
    subgraph "State Layer"
        PM["Parameter Manager"]:::state
        PS["Parameter Storage"]:::state
    end

    %% Configuration Layer
    subgraph "Configuration Layer"
        CFP["Configuration Parser"]:::config
        CM["Configuration Management"]:::config
        LS["Logging System"]:::config
    end

    %% Relationships
    TCP --> PH
    HTTP --> PM
    Client --> HTTP
    
    PH --> MB
    PH --> SP
    SP --> Lexer
    SP --> Parser
    
    MB --> DS
    Parser --> CP
    CP --> DS
    DS --> RT
    DS <--> PM
    
    PM --> PS
    CFP --> CM
    CM --> DS
    
    %% Click events
    click TCP "https://github.com/e9ctrl/vd/blob/main/server/server.go"
    click HTTP "https://github.com/e9ctrl/vd/blob/main/api/api.go"
    click Client "https://github.com/e9ctrl/vd/blob/main/api/client.go"
    click PH "https://github.com/e9ctrl/vd/blob/main/protocol/protocol.go"
    click MB "https://github.com/e9ctrl/vd/tree/main/protocol/modbus/"
    click SP "https://github.com/e9ctrl/vd/tree/main/protocol/stream/"
    click Lexer "https://github.com/e9ctrl/vd/blob/main/protocol/stream/lexer.go"
    click Parser "https://github.com/e9ctrl/vd/blob/main/protocol/stream/parser.go"
    click DS "https://github.com/e9ctrl/vd/blob/main/device/device.go"
    click CP "https://github.com/e9ctrl/vd/blob/main/command/command.go"
    click RT "https://github.com/e9ctrl/vd/blob/main/cmd/trigger.go"
    click PM "https://github.com/e9ctrl/vd/blob/main/parameter/parameter.go"
    click PS "https://github.com/e9ctrl/vd/blob/main/parameter/parameter.go"
    click CFP "https://github.com/e9ctrl/vd/blob/main/vdfile/vdfile.go"
    click CM "https://github.com/e9ctrl/vd/tree/main/vdfile/"
    click LS "https://github.com/e9ctrl/vd/blob/main/log/log.go"
```
