# luyenducmanh/mts5800_controller architecture

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

- Interactive diagram: https://gitdiagram.com/luyenducmanh/mts5800_controller
- Repository: https://github.com/luyenducmanh/mts5800_controller

## Overview

##### Main Components
- Electron Main Process – Located in files like src/index.ts, preload.ts, and webpack.main.config.ts. This part handles the application’s lifecycle, bootstrapping, and establishing communication channels.
- Preload Bridge – The preload.ts acts as the secure intermediary that bridges the Electron main process and the renderer process (UI), exposing APIs safely.
- Renderer Process (UI Layer) – Evident in src/renderer (and the file main_react.tsx). This directory holds a rich React-based UI with various components (Dashboard, Navbar, Cards, Charts, etc.). Include React components and specialized sub-components for theming (found in src/renderer/theme and customizations) and internal components for structured layout.
- SCPI Service Layer – Found in src/service/scpi with files like scpi_client.ts and scpi_service.ts. This layer likely handles requests and commands sent to the MTS5800 device using SCPI (Standard Commands for Programmable Instruments).
- Shared/Common Utilities – The src/common directory contains files like MTS5800_Common.ts, possibly holding shared types, constants, or helper functions used across the project.

##### Out the Interactions
- The UI (Renderer Process) sends user actions (e.g., pressing buttons on the Dashboard) via the exposed APIs in the Preload Bridge.
- The Main Process receives these actions, possibly forwarding them to the SCPI Service layer.
- The SCPI Service then constructs and sends commands to the actual instrument, handling responses which eventually propagate back to the UI.
- Additionally, the webpack configuration files indicate separate bundling and build processes for the main and renderer codebases, which is a key architectural aspect to note.

##### Architectural Patterns and Design Principles
- Separation of Concerns – Clear distinction between UI (renderer), core application logic (main process), and device communications (SCPI services).
- Modular and Component-based Structure – The renderer folder is organized into reusable React components, internal components, routing, and theming, all of which support maintainability and scalability.
- Secure API Exposure – The use of preload.ts indicates a careful approach to securely bridge the UI and backend processes.
- TypeScript & Webpack Usage – Indicates a strongly-typed codebase with a modern bundling strategy that further segregates responsibilities (main vs. renderer).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Electron Environment"
        MainProcess["Electron Main Process"] 
        Preload["Preload Bridge"]
    end

    subgraph "UI/Renderer"
        Renderer["Renderer Process (UI)"]
    end

    subgraph "SCPI Services"
        SCPI["SCPI Service Layer"]
    end

    CommonUtilities["Shared/Common Utilities"]
    WebpackConfig["Webpack Build Process"]
    Instrument["MTS5800 Instrument"]

    %% Data Flow Connections
    Renderer -->|"sendAction"| Preload
    Preload -->|"forwardCommand"| MainProcess
    MainProcess -->|"executeSCPI"| SCPI
    SCPI -->|"transmit"| Instrument
    Instrument -->|"response"| SCPI
    SCPI -->|"result"| MainProcess
    MainProcess -->|"update"| Renderer

    %% Utilization of Shared/Common Utilities
    MainProcess ---|"uses"| CommonUtilities
    SCPI ---|"uses"| CommonUtilities

    %% Webpack Bundling Connections
    WebpackConfig -->|"bundlesMain"| MainProcess
    WebpackConfig -->|"bundlesRenderer"| Renderer

    %% Click Events for Component Mapping
    click MainProcess "https://github.com/luyenducmanh/mts5800_controller/blob/main/src/index.ts"
    click MainProcess "https://github.com/luyenducmanh/mts5800_controller/blob/main/webpack.main.config.ts"
    click Preload "https://github.com/luyenducmanh/mts5800_controller/blob/main/src/preload.ts"
    click Renderer "https://github.com/luyenducmanh/mts5800_controller/tree/main/src/renderer"
    click Renderer "https://github.com/luyenducmanh/mts5800_controller/blob/main/src/main_react.tsx"
    click SCPI "https://github.com/luyenducmanh/mts5800_controller/blob/main/src/service/scpi/scpi_client.ts"
    click SCPI "https://github.com/luyenducmanh/mts5800_controller/blob/main/src/service/scpi/scpi_service.ts"
    click CommonUtilities "https://github.com/luyenducmanh/mts5800_controller/blob/main/src/common/MTS5800_Common.ts"
    click WebpackConfig "https://github.com/luyenducmanh/mts5800_controller/blob/main/webpack.main.config.ts"
    click WebpackConfig "https://github.com/luyenducmanh/mts5800_controller/blob/main/webpack.renderer.config.ts"
    click WebpackConfig "https://github.com/luyenducmanh/mts5800_controller/blob/main/webpack.plugins.ts"
    click WebpackConfig "https://github.com/luyenducmanh/mts5800_controller/blob/main/webpack.rules.ts"

    %% Styles
    classDef electron fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef ui fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef service fill:#abebc6,stroke:#333,stroke-width:2px;
    classDef common fill:#fef9e7,stroke:#333,stroke-width:2px;
    classDef config fill:#fadbd8,stroke:#333,stroke-width:2px;
    classDef external fill:#d5f5e3,stroke:#333,stroke-width:2px;

    class MainProcess,Preload electron;
    class Renderer ui;
    class SCPI service;
    class CommonUtilities common;
    class WebpackConfig config;
    class Instrument external;
```
