# opcua-lads/lads-client-py architecture

> Architecture diagram of the GitHub repository opcua-lads/lads-client-py, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/opcua-lads/lads-client-py
- Repository: https://github.com/opcua-lads/lads-client-py

## Overview

##### Project type and purpose
- This is an open-source Python tooling project composed of two related libraries:
- lads_opcua_client: a Pythonic client for interacting with a LADS OPC UA server
- lads_opcua_viewer: a Streamlit-based viewer/CLI that builds on the client library to present live data

##### File structure
- Top-level directories and files
- lads_opcua_client/…: client library sources, AFO CSV dictionary, `main.py` entry point
- lads_opcua_viewer/…: viewer library sources, CLI (`cli.py`), Streamlit `main.py`
- dev/: build & install scripts (PowerShell + Bash) for both packages
- tests/: unit tests (e.g., `test_main.py`)
- requirements.txt, README.md, LICENSE, presentation/ (PPTX)
- Patterns and architecture hints
- Two distinct Python packages, each with its own pyproject.toml
- Client library defines core domain logic (OPC UA connection + data models)
- Viewer library depends on client and adds a presentation layer (CLI + web UI)
- Dev scripts automate build/install for local editable or packaged installs

##### README for additional insights
- Confirms dual-package structure and install order (client → viewer)
- Highlights dependencies: Python 3.12+, python-build, Streamlit (for the viewer)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    subgraph "External Systems"
        OPCUA["OPC UA Server (LADS)"]:::external
    end

    %% Core Client Library
    subgraph "Core Client Library (lads_opcua_client)" 
        ClientPkg["lads_opcua_client library"]:::core
        API["OPC UA Connection Manager & API (main.py)"]:::core
        AFOmod["AFO Dictionary loader module (afo.py)"]:::core
        AFOcsv["AFO Dictionary CSV data file"]:::core
        BuildCfgClient["Client build config (pyproject.toml)"]:::core
    end

    %% Viewer Library
    subgraph "Presentation Layer (lads_opcua_viewer)"
        ViewerPkg["lads_opcua_viewer library"]:::presentation
        ViewerCLI["Viewer CLI adapter (cli.py)"]:::presentation
        ViewerUI["Streamlit UI adapter (main.py)"]:::presentation
        BuildCfgViewer["Viewer build config (pyproject.toml)"]:::presentation
    end

    %% Development Tooling
    subgraph "Development Tooling"
        PSBuild["build_and_install.ps1"]:::tooling
        SHBuild["build_and_install.sh"]:::tooling
        PSEdit["install_editable.ps1"]:::tooling
        SHEdit["install_editable.sh"]:::tooling
        DebugScript["debug_script.py"]:::tooling
    end

    %% Tests Suite
    subgraph "Tests Suite"
        Tests["Unit tests (test_main.py)"]:::tests
    end

    %% Data and Control Flows
    OPCUA -->|provides data| API
    API -->|loads dictionary| AFOmod
    AFOmod -->|reads CSV| AFOcsv
    ViewerCLI -->|calls client API| API
    ViewerUI -->|calls client API| API
    PSBuild -->|builds client| BuildCfgClient
    PSBuild -->|builds viewer| BuildCfgViewer
    SHBuild -->|builds client| BuildCfgClient
    SHBuild -->|builds viewer| BuildCfgViewer
    PSEdit -->|installs client| ClientPkg
    PSEdit -->|installs viewer| ViewerPkg
    SHEdit -->|installs client| ClientPkg
    SHEdit -->|installs viewer| ViewerPkg
    DebugScript -->|debug workflow| ClientPkg
    DebugScript -->|debug workflow| ViewerPkg
    Tests -->|tests client API| API

    %% Click Events
    click ClientPkg "https://github.com/opcua-lads/lads-client-py/tree/main/lads_opcua_client/src/lads_opcua_client"
    click API "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_client/src/lads_opcua_client/main.py"
    click AFOmod "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_client/src/lads_opcua_client/afo/afo.py"
    click AFOcsv "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_client/src/lads_opcua_client/afo/AFO_Dictionary-2025_03.csv"
    click BuildCfgClient "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_client/pyproject.toml"
    click ViewerPkg "https://github.com/opcua-lads/lads-client-py/tree/main/lads_opcua_viewer/src/lads_opcua_viewer"
    click ViewerCLI "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_viewer/src/lads_opcua_viewer/cli.py"
    click ViewerUI "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_viewer/src/lads_opcua_viewer/main.py"
    click BuildCfgViewer "https://github.com/opcua-lads/lads-client-py/blob/main/lads_opcua_viewer/pyproject.toml"
    click PSBuild "https://github.com/opcua-lads/lads-client-py/blob/main/dev/build_and_install.ps1"
    click SHBuild "https://github.com/opcua-lads/lads-client-py/blob/main/dev/build_and_install.sh"
    click PSEdit "https://github.com/opcua-lads/lads-client-py/blob/main/dev/install_editable.ps1"
    click SHEdit "https://github.com/opcua-lads/lads-client-py/blob/main/dev/install_editable.sh"
    click DebugScript "https://github.com/opcua-lads/lads-client-py/blob/main/dev/debug_script.py"
    click Tests "https://github.com/opcua-lads/lads-client-py/blob/main/tests/test_main.py"

    %% Styles
    classDef core fill:#cfe2f3,stroke:#6fa8dc,color:#073763;
    classDef presentation fill:#d9ead3,stroke:#93c47d,color:#274e13;
    classDef external fill:#f2f2f2,stroke:#999999,color:#555555;
    classDef tooling fill:#ffe599,stroke:#f1c232,color:#7f6000;
    classDef tests fill:#e6e6fa,stroke:#b4a7d6,color:#3d3d5c;
```
