# pwr-solaar/solaar architecture

> Architecture diagram of the GitHub repository pwr-solaar/solaar, 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/pwr-solaar/solaar
- Repository: https://github.com/pwr-solaar/solaar

## Overview

##### Main Components Identification

The system should be represented with these key components:

a. Core Components:
- HID Interface Layer (lib/hidapi)
- Logitech Receiver Core (lib/logitech_receiver)
- Device Management System (lib/solaar)
- User Interface Components (lib/solaar/ui)
- Command Line Interface (lib/solaar/cli)

b. External Interfaces:
- Linux USB/HID System
- DBus Integration
- Desktop Notifications
- Udev Rules System

**┌─ User Interface Layer ─────────────────────┐**
- GTK UI (solaar/ui)                      │
- CLI Interface (solaar/cli)              │
- Desktop Notifications                    │
- Application Layer ──────────────────────┐ │
- Device Management                      │ │
- Configuration Management               │ │
- Rules Engine                          │ │
- Core Protocol Layer ───────────────────┐│ │
- HID++ 1.0 Protocol                   ││ │
- HID++ 2.0 Protocol                   ││ │
- Device Settings Templates            ││ │
- Hardware Interface Layer ─────────────┐││ │
- HID API                             ││││ │
- USB Communication                   ││││ │
- Bluetooth Communication             ││││ │
- ┘└┘└┘

##### Component Relationships

- Upward flow from hardware through protocol layers to UI
- Downward flow for commands from UI to devices

##### Additional Elements

- Test Framework (tests directory)
- Configuration Storage
- Device Profiles Repository
- System Integration Points (udev rules, desktop files)

##### Implementation Details

- MVC Pattern in UI (shown in ui/about structure)
- Plugin Architecture for Device Support
- Event-driven Communication System
- Multi-device Support Architecture

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        GTK["GTK UI"]:::ui
        CLI["CLI Interface"]:::ui
        TRAY["System Tray"]:::ui
        MAIN_WIN["Main Window"]:::ui
        PAIR_WIN["Pairing Window"]:::ui
        NOTIFY["Desktop Notifications"]:::ui
    end

    subgraph APP["Application Layer"]
        DEV_MGT["Device Management"]:::app
        CONFIG["Configuration System"]:::app
        RULES["Rules Engine"]:::app
        DBUS["DBus Integration"]:::app
        I18N["Internationalization"]:::app
    end

    subgraph CORE["Core Protocol Layer"]
        HID1["HID++ 1.0 Protocol"]:::protocol
        HID2["HID++ 2.0 Protocol"]:::protocol
        SETTINGS["Settings Management"]:::protocol
    end

    subgraph HW["Hardware Interface Layer"]
        HIDAPI["HID API"]:::hardware
        USB["USB Communication"]:::hardware
        BT["Bluetooth Communication"]:::hardware
    end

    %% Relationships
    GTK --> DEV_MGT
    CLI --> DEV_MGT
    TRAY --> DEV_MGT
    MAIN_WIN --> DEV_MGT
    PAIR_WIN --> DEV_MGT
    NOTIFY --> DEV_MGT

    DEV_MGT --> DBUS
    DEV_MGT --> CONFIG
    DEV_MGT --> RULES
    DEV_MGT --> I18N

    DEV_MGT --> HID1
    DEV_MGT --> HID2
    HID1 --> SETTINGS
    HID2 --> SETTINGS

    HID1 --> HIDAPI
    HID2 --> HIDAPI
    HIDAPI --> USB
    HIDAPI --> BT

    %% Click Events
    click GTK "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/gtk.py"
    click CLI "https://github.com/pwr-Solaar/Solaar/tree/master/lib/solaar/cli/"
    click TRAY "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/ui/tray.py"
    click MAIN_WIN "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/ui/window.py"
    click PAIR_WIN "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/ui/pair_window.py"
    click NOTIFY "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/ui/desktop_notifications.py"
    click DBUS "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/dbus.py"
    click CONFIG "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/configuration.py"
    click RULES "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/ui/rule_base.py"
    click I18N "https://github.com/pwr-Solaar/Solaar/blob/master/lib/solaar/i18n.py"
    click HID1 "https://github.com/pwr-Solaar/Solaar/blob/master/lib/logitech_receiver/hidpp10.py"
    click HID2 "https://github.com/pwr-Solaar/Solaar/blob/master/lib/logitech_receiver/hidpp20.py"
    click SETTINGS "https://github.com/pwr-Solaar/Solaar/blob/master/lib/logitech_receiver/settings.py"
    click HIDAPI "https://github.com/pwr-Solaar/Solaar/tree/master/lib/hidapi/"

    %% Styling
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef app fill:#e74c3c,stroke:#c0392b,color:white
    classDef protocol fill:#2ecc71,stroke:#27ae60,color:white
    classDef hardware fill:#f1c40f,stroke:#f39c12,color:black

    %% Legend
    subgraph Legend
        UI_LEG["UI Component"]:::ui
        APP_LEG["Application Component"]:::app
        PROT_LEG["Protocol Component"]:::protocol
        HW_LEG["Hardware Component"]:::hardware
    end
```
