# vial-kb/vial-gui architecture

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

- Interactive diagram: https://gitdiagram.com/vial-kb/vial-gui
- Repository: https://github.com/vial-kb/vial-gui

## Overview

##### Project Type and Purpose
- Vial-GUI is an open-source, cross-platform desktop application built in Python 3.6. It provides a graphical interface to configure mechanical keyboards in real time by interfacing with QMK firmware.
- The README highlights that the tool is aimed at keyboard configuration, and the file tree reinforces this with several components for keymaps, protocols, macros, and installers.

##### Main Components
- GUI/Frontend:
- This layer includes modules and widgets (found in src/main/python/widgets and main_window.py) along with support for editors (e.g., keymap_editor, layout_editor, macro_recorder) that provide the user interface.
- Application Core & Business Logic:
- Core functionality exists under modules like about_keyboard.py, constants.py, and util.py.
- The “editor” submodules (basic_editor, firmware_flasher, key_override, etc.) show a separation of concerns for different keyboard configuration operations.
- Communication & Protocol:
- The protocol directory (src/main/python/protocol) contains classes and modules that handle keyboard communications, including handling of keycodes, macro operations, and dynamic protocols.
- Keymap and Keycodes:
- There are several keymap files (located in src/main/python/keymap) and keycode definitions (under src/main/python/keycodes). Represent these as distinct modules that define how keyboard key mappings are managed.
- Build, Installer, and Platform-Specific Settings:
- The src/build and src/installer directories, along with the accompanying JSON settings files (e.g., base.json, linux.json, mac.json) imply a distinct build configuration module.
- The installers (like the NSIS installer for Windows) indicate platform-specific packaging components.
- Testing & Utilities:
- The test directory under src/main/python/test and util modules (build scripts and macro fuzzers in util/) show supporting components for automated testing, deployment, and developer utilities.

##### Interactions and Relationships
- The GUI interacts directly with the application core and business logic, passing user inputs to modules that then update configurations or communicate with the keyboard.
- The protocol components act as intermediaries between the high-level business logic (keymap and macro editor) and the low-level hardware communication (e.g., hidproxy, keyboard_comm).
- The build and installer modules encapsulate the configuration for packaging the application for different operating systems, feeding into the distribution pipeline.
- Testing utilities interact with almost every layer to validate both the UI and backend functions.

##### Architectural Patterns and Technologies
- The overall structure is modular, suggesting a separation of concerns that can be mapped with an MVC-inspired or layered architecture. The frontend (view) is clearly separated from the backend (model and controller) that handles keymap logic and hardware communications.
- Python is the main technology with the use of FBS for building the desktop GUI application.
- Platform-specific resources and configurations are neatly isolated (e.g., src/build/settings for JSON configurations and src/installer for installer scripts).

##### Specific Elements
- External dependencies and interactions, especially the integration points with QMK firmware and any external services or libraries employed by FBS.

- At the top, include the “User Interface” block showing the main window, editors, and widgets.
- Beneath that, have a “Business Logic” or “Application Core” block detailing keymap management, macros, and other logic.
- Parallel to this, include a block for “Protocol & Communication” to illustrate how the application sends/receives data to the keyboard.
- Optionally, add a “Testing & Utilities” section around the periphery to demonstrate supporting modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "GUI/Frontend"
        UI_Main("Main Window"):::frontend
        UI_Widgets("Widgets"):::frontend
        UI_Editors("Editors (GUI)"):::frontend
    end

    subgraph "Application Core & Business Logic"
        Core_About("About Keyboard"):::core
        Core_Constants("Constants"):::core
        Core_Util("Utilities"):::core
        Core_EditMods("Editor Modules (Business)"):::core
    end

    subgraph "Communication & Protocol"
        Comm_Protocol("Protocol Handler"):::protocol
        Comm_Keycodes("Keycodes"):::protocol
    end

    subgraph "Keymap & Keycodes Management"
        KM_KeymapFiles("Keymap Files"):::keymap
        KM_KeymapsIntegration("Keymaps Integration"):::keymap
    end

    subgraph "Build & Deployment"
        Build_Settings("Build Settings"):::deployment
        Build_Installer("Installer Builder"):::deployment
    end

    subgraph "Testing & Utilities"
        Test_Suite("Testing Suite"):::testing
        Test_Utilities("Utilities"):::testing
    end

    %% Connections between sections
    UI_Main -->|"user_input"| Core_About
    UI_Widgets -->|"widget_updates"| Core_Constants
    UI_Editors -->|"edit_actions"| Core_EditMods

    Core_EditMods -->|"send_commands"| Comm_Protocol
    Core_EditMods -->|"update_keymaps"| KM_KeymapFiles
    Core_Constants -->|"manage_layouts"| KM_KeymapsIntegration
    Core_Util -->|"configures"| Build_Settings

    Comm_Protocol -->|"uses"| Comm_Keycodes

    Build_Settings -->|"feeds"| Build_Installer

    Test_Suite -->|"validates"| Core_Util
    Test_Suite -->|"checks"| UI_Widgets
    Test_Utilities -->|"tests"| Core_EditMods

    %% Click Events for GUI/Frontend
    click UI_Main "https://github.com/vial-kb/vial-gui/blob/main/src/main/python/main_window.py"
    click UI_Widgets "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/widgets"
    click UI_Editors "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/editor"

    %% Click Events for Application Core & Business Logic
    click Core_About "https://github.com/vial-kb/vial-gui/blob/main/src/main/python/about_keyboard.py"
    click Core_Constants "https://github.com/vial-kb/vial-gui/blob/main/src/main/python/constants.py"
    click Core_Util "https://github.com/vial-kb/vial-gui/blob/main/src/main/python/util.py"
    click Core_EditMods "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/editor"

    %% Click Events for Communication & Protocol
    click Comm_Protocol "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/protocol"
    click Comm_Keycodes "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/keycodes"

    %% Click Events for Keymap & Keycodes Management
    click KM_KeymapFiles "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/keymap"
    click KM_KeymapsIntegration "https://github.com/vial-kb/vial-gui/blob/main/src/main/python/keymaps.py"

    %% Click Events for Build & Deployment
    click Build_Settings "https://github.com/vial-kb/vial-gui/tree/main/src/build/settings"
    click Build_Installer "https://github.com/vial-kb/vial-gui/tree/main/src/installer"

    %% Click Events for Testing & Utilities
    click Test_Suite "https://github.com/vial-kb/vial-gui/tree/main/src/main/python/test"
    click Test_Utilities "https://github.com/vial-kb/vial-gui/tree/main/util"

    %% Styles
    classDef frontend fill:#FFDDC1,stroke:#333,stroke-width:2px;
    classDef core fill:#C1FFD7,stroke:#333,stroke-width:2px;
    classDef protocol fill:#C1D4FF,stroke:#333,stroke-width:2px;
    classDef keymap fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef deployment fill:#DCD0FF,stroke:#333,stroke-width:2px;
    classDef testing fill:#FDE2FF,stroke:#333,stroke-width:2px;
```
