# mayankchetan/discon-wrapper architecture

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

- Interactive diagram: https://gitdiagram.com/mayankchetan/discon-wrapper
- Repository: https://github.com/mayankchetan/discon-wrapper

## Overview

##### Project type and purpose
- This is a full-stack, multi-service Go application (“DISCON-Wrapper”) for bridging 32-bit wind turbine Controller DLLs into 64-bit simulation applications (OpenFAST).
- It comprises three primary services:
- discon-client: a 64-bit shared‐library plugin (DLL) loaded by OpenFAST
- discon-server: a 32-bit server process that loads the legacy Controller DLL and proxies calls over WebSockets
- discon-manager: a browser-based admin web application to configure, monitor, and orchestrate server instances

##### File structure
- Top-level directories and files:
- discon-client/ (client.go)
- discon-server/ (server.go, websocket.go, load_shared_library.c)
- discon-manager/ (main.go, admin.go, config.go, docker.go, templates/, config/, db/)
- shared/ (shared/utils)
- Dockerfiles (for manager, server, rosco), docker-compose.yml
- docs/ (Sphinx-based documentation, including dedicated pages for each component)
- Patterns & configurations:
- discon-manager uses MVC (Go templates + controllers + JSON “database”)
- discon-server uses a WebSocket RPC pattern to marshal/unmarshal payloads (payload.go)
- Docker-compose orchestrates three containers: manager, server, rosco

##### README for additional insights
- discon-server listens on a configurable TCP/WebSocket port, loads the legacy Controller via a C shared-library loader, and waits for client connections.
- discon-client.dll is loaded by OpenFAST, reads environment variables (server address, controller path, entry proc), opens a WebSocket, and proxies function calls & file transfers.
- The wrapper is transparent to OpenFAST: it simply replaces the Controller DLL.
- discon-manager is mentioned in docs as a way to centrally configure server settings and controller deployments.

##### Main components & interactions
a. Components
- OpenFAST Simulator
- discon-client.dll (64-bit, loaded by OpenFAST)
- WebSocket Channel (TCP/ws:// or wss://)
- discon-server process (32-bit)
- Legacy Controller DLL (e.g., controller.dll)
- File Transfer sub-system (part of shared/utils)
- discon-manager Web UI
- Configuration storage (config.yaml, controllers.json)
- Manager’s embedded database
- Docker Engine / Orchestration (docker-compose)
b. Relationships & data flow
1. OpenFAST calls into discon-client.dll
2. Client marshals arguments → sends over WebSocket → Server
3. Server → unmarshals → invokes legacy Controller DLL via load_shared_library.c
4. Controller returns results → Server marshals → sends back over WebSocket → Client
5. Client returns result to OpenFAST
6. If Controller requests input files: Client checks local filesystem, transfers file to Server over WebSocket, updates path before invocation
7. discon-manager communicates with Docker Engine (via docker.go) to launch/stop discon-server instances, updates config and controllers.json
8. Browser ← HTTP ← discon-manager ← reads/writes Configuration database
c. Architectural patterns & principles
- Microservices: each component (client, server, manager) lives in its own process/container
- RPC over WebSockets for cross–address-space calls
- MVC for the manager (Go templates + handlers + JSON “DB”)
- Shared utility library for payload encoding, logging, and file-transfer logic
d. Key technologies & libraries
- Go for all three services
- C for load_shared_library.c in discon-server
- WebSockets (gorilla/websocket or stdlib)
- Sphinx/RST for documentation
- Docker & docker-compose for containerization
- Go templates for manager UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Simulation Environment
    subgraph "Simulation Environment"
        OF["OpenFAST Simulator"]:::external
        DC["discon-client.dll"]:::compute
    end

    %% RPC Transport Layer
    subgraph "RPC Transport"
        WS["WebSocket Transport\n(ws://)"]:::transport
    end

    %% Server Environment
    subgraph "Server Environment"
        DS["discon-server"]:::compute
        LD["Legacy Controller DLL"]:::external
        FL["File Transfer Sub-system"]:::compute
    end

    %% Admin Management
    subgraph "discon-manager"
        UI["Browser UI"]:::external
        API["Manager API\n(HTTP)"]:::compute
        DB["Embedded DB"]:::persistence
        CFG["Config Store\n(config.yaml, controllers.json)"]:::persistence
        DE["Docker Engine"]:::compute
    end

    %% Documentation & Orchestration
    subgraph "Deployment & Docs"
        DCmp["docker-compose.yml"]:::persistence
        DMgrDocker["Dockerfile.manager"]:::persistence
        DServDocker["Dockerfile.server"]:::persistence
        DRoscoDocker["Dockerfile.rosco"]:::persistence
        Docs["Sphinx Docs"]:::persistence
    end

    %% Data Flows
    OF -->|"Invoke(DISCON)"| DC
    DC -->|"Serialize & Send"| WS
    WS -->|"Receive & Unmarshal"| DS
    DS -->|"Invoke Controller"| LD
    LD -->|"Return Result"| DS
    DS -->|"Marshal & Send"| WS
    WS -->|"Receive & Deserialize"| DC
    DC -->|"Return to OpenFAST"| OF

    %% File Transfer
    DC -->|"File Transfer Request"| WS
    WS -->|"File Transfer Data"| FL
    FL -->|"Invoke Controller"| DS

    %% Admin Flows
    UI -->|"HTTP Request"| API
    API -->|"Read/Write"| DB
    API -->|"Read/Write"| CFG
    API -->|"Docker API"| DE
    DE -->|"Container Orchestration"| DCmp

    %% Click Events - discon-client
    click DC "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-client/client.go"

    %% Click Events - discon-server
    click DS "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-server/server.go"
    click WS "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-server/websocket.go"
    click LD "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-server/load_shared_library.c"

    %% Click Events - discon-manager
    click UI "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/main.go"
    click API "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/admin.go"
    click API "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/manager.go"
    click API "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/config.go"
    click API "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/docker.go"
    click DB "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/database.go"
    click CFG "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/config/config.yaml"
    click CFG "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/db/controllers.json"
    click UI "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/templates/admin.html"
    click UI "https://github.com/mayankchetan/discon-wrapper/blob/main/discon-manager/templates/login.html"

    %% Click Events - shared utils
    click FL "https://github.com/mayankchetan/discon-wrapper/blob/main/shared/utils/transfer.go"
    click FL "https://github.com/mayankchetan/discon-wrapper/blob/main/shared/utils/logging.go"
    click FL "https://github.com/mayankchetan/discon-wrapper/blob/main/shared/utils/file.go"

    %% Click Events - payload definitions
    click WS "https://github.com/mayankchetan/discon-wrapper/blob/main/payload.go"

    %% Click Events - Dockerfiles & Compose
    click DCmp "https://github.com/mayankchetan/discon-wrapper/blob/main/docker-compose.yml"
    click DMgrDocker "https://github.com/mayankchetan/discon-wrapper/blob/main/docker/Dockerfile.manager"
    click DServDocker "https://github.com/mayankchetan/discon-wrapper/blob/main/docker/Dockerfile.server"
    click DRoscoDocker "https://github.com/mayankchetan/discon-wrapper/blob/main/docker/Dockerfile.rosco"

    %% Click Events - Documentation
    click Docs "https://github.com/mayankchetan/discon-wrapper/blob/main/docs/source/components/discon-client.rst"
    click Docs "https://github.com/mayankchetan/discon-wrapper/blob/main/docs/source/components/discon-server.rst"
    click Docs "https://github.com/mayankchetan/discon-wrapper/blob/main/docs/source/components/discon-manager.rst"
    click Docs "https://github.com/mayankchetan/discon-wrapper/blob/main/docs/source/components/payload.rst"

    %% Styles
    classDef compute fill:#b6e7a9,stroke:#333;
    classDef external fill:#a8d0e6,stroke:#333;
    classDef transport fill:#f9bc86,stroke:#333;
    classDef persistence fill:#d3d3d3,stroke:#333;
```
