# bkorzh/dbay architecture

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

- Interactive diagram: https://gitdiagram.com/bkorzh/dbay
- Repository: https://github.com/bkorzh/dbay

## Overview

##### Main System Components

a) Frontend Layer
- Built with Svelte/TypeScript (evident from /software/frontend structure)
- Tauri-based desktop application (src-tauri folder presence)
- Contains multiple UI modules and components

b) Backend Layer
- Python-based server (/software/backend)
- REST API endpoints (server_api.py)
- UDP control capabilities (udp_control.py)

c) Firmware Layer
- Microcontroller firmware (AD7124 and other components)
- Hardware control implementations
- Device drivers for various components (AD5684, PCA9557, etc.)

d) Hardware Layer
- Physical electronic components
- DAC modules (16-channel and 4-channel differential)

##### Component Relationships

**[Frontend UI] ←→ [Tauri Bridge] ←→ [Backend Server] ←→ [Firmware] ←→ [Hardware]**

##### Detailed Component Breakdown

Frontend Section:
- UI Components (/src/lib/)
- Module Controls (modules_dbay)
- State Management (state/)
- API Interface (api.ts)

Backend Section:
- Server API
- Device Control Modules
- Addons (vsense, vsource)
- Serial Communication
- UDP Control

Firmware Section:
- Components for:
- AD7124 Driver
- DAC Controllers
- I/O Expanders
- Device-specific implementations

Hardware Section:
- Include:
- DAC Modules (16D and 4D)
- Physical interfaces
- Communication buses

##### Additional Elements

Supplementary information:
- Technology stack labels
- Communication protocols
- Module initialization flow
- Error handling paths
- Configuration management

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef backend fill:#e8f5e9,stroke:#1b5e20
    classDef firmware fill:#fff3e0,stroke:#e65100
    classDef hardware fill:#ffebee,stroke:#b71c1c
    classDef communication fill:#f3e5f5,stroke:#4a148c

    %% Frontend Layer
    subgraph Frontend
        UI["UI Components"]:::frontend
        ModCtrl["Module Controls"]:::frontend
        State["State Management"]:::frontend
        API["API Interface"]:::frontend
        Tauri["Tauri Bridge"]:::frontend
    end

    %% Backend Layer
    subgraph Backend
        ServerAPI["Server API"]:::backend
        DevControl["Device Control"]:::backend
        Addons["Addons (VSense/VSource)"]:::backend
        Serial["Serial Communication"]:::backend
        UDP["UDP Control"]:::backend
        ModImpl["Module Implementations"]:::backend
    end

    %% Firmware Layer
    subgraph Firmware
        AD7124["AD7124 Driver"]:::firmware
        DACCtrl["DAC Controller"]:::firmware
        IOExp["I/O Expander"]:::firmware
    end

    %% Hardware Layer
    subgraph Hardware
        DAC16["16-Channel DAC"]:::hardware
        DAC4["4-Channel Differential DAC"]:::hardware
        PhysInt["Physical Interfaces"]:::hardware
        CommBus["Communication Buses"]:::hardware
    end

    %% Connections
    UI --> ModCtrl
    UI --> State
    ModCtrl --> API
    State --> API
    API --> Tauri
    Tauri --> ServerAPI
    ServerAPI --> DevControl
    ServerAPI --> UDP
    ServerAPI --> Serial
    DevControl --> ModImpl
    DevControl --> Addons
    Serial --> AD7124
    Serial --> DACCtrl
    Serial --> IOExp
    AD7124 --> CommBus
    DACCtrl --> DAC16
    DACCtrl --> DAC4
    IOExp --> PhysInt
    CommBus --> PhysInt

    %% Click Events
    click UI "https://github.com/bkorzh/dbay/tree/main/software/frontend/src/lib/"
    click ModCtrl "https://github.com/bkorzh/dbay/tree/main/software/frontend/src/lib/modules_dbay/"
    click State "https://github.com/bkorzh/dbay/tree/main/software/frontend/src/state/"
    click API "https://github.com/bkorzh/dbay/blob/main/software/frontend/src/api.ts"
    click Tauri "https://github.com/bkorzh/dbay/tree/main/software/frontend/src-tauri/"
    click ServerAPI "https://github.com/bkorzh/dbay/blob/main/software/backend/backend/server_api.py"
    click DevControl "https://github.com/bkorzh/dbay/tree/main/software/backend/backend/dbay_control/"
    click Addons "https://github.com/bkorzh/dbay/tree/main/software/backend/backend/addons/"
    click UDP "https://github.com/bkorzh/dbay/blob/main/software/backend/backend/udp_control.py"
    click Serial "https://github.com/bkorzh/dbay/blob/main/software/backend/backend/serialInstDbay.py"
    click ModImpl "https://github.com/bkorzh/dbay/tree/main/software/backend/backend/modules/"
    click AD7124 "https://github.com/bkorzh/dbay/blob/main/firmware/dbay_ctrlFW/ad7124.h"
    click DACCtrl "https://github.com/bkorzh/dbay/blob/main/firmware/dbay_ctrlFW/dbay_32DAC.cpp"
    click IOExp "https://github.com/bkorzh/dbay/blob/main/firmware/dbay_ctrlFW/PCA9557.h"
    click DAC16 "https://github.com/bkorzh/dbay/tree/main/docs/content/Modules/"
    click DAC4 "https://github.com/bkorzh/dbay/tree/main/docs/content/Modules/"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        Backend_L["Backend Component"]:::backend
        Firmware_L["Firmware Component"]:::firmware
        Hardware_L["Hardware Component"]:::hardware
    end
```
