# ckyb63/ppe_gui_package architecture

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

- Interactive diagram: https://gitdiagram.com/ckyb63/ppe_gui_package
- Repository: https://github.com/ckyb63/ppe_gui_package

## Overview

##### Main Components
- GUI Frontend: Built using PyQt5 under the “gui_package/main_gui_modules” folder. This includes the main window, widget components (buttons, help dialogs, settings panels), and utility modules (e.g., logger, settings_handler).
- ROS2 Integration Layer: ROS2 nodes from “launch” files (e.g., main_ppe_gui.launch.py, dummy_nodes.launch.py) and scripts such as “ros_node.py” in main_gui_modules. This layer handles communication over topics like “ppe_status”, “pleaseDispense”, “ppeInventoryStatus”, etc.
- Hardware Control Modules: The “gui_package/gate” directory features the ESP32 Bluetooth communications and the safety_gate_controller that manages the physical safety gate.
- Avend API Connector: Located within “gui_package/avend” (avend_connector.py and logger.py), this module interacts with the AVend API for inventory management, dispensing requests, and logging.
- Simulation/Dummy Nodes: Found in “gui_package/dummy_test” (dummy_inventory_publisher.py and dummy_ppe_status.py) to simulate PPE detection and inventory changes.

##### Out Relationships and Interactions
- The PyQt5 GUI serves as the user interface where users interact (touchscreen-friendly design, settings, override commands).
- The GUI node, once launched, publishes or subscribes to various ROS2 topics (e.g., receiving live PPE status and inventory updates, sending dispense commands).
- Hardware events are managed via the safety_gate_controller and the ESP32 Bluetooth module. These modules communicate with the ROS2 backend, sending status updates (e.g., “gate” topic) that affect GUI behavior.
- The dummy nodes simulate real hardware and sensor data, allowing for testing and demonstration without needing the physical devices.
- The Avend connector integrates the external AVend API for retrieving or updating inventory and dispensing logs.

##### Architectural Patterns and Design Principals
- Separation of Concerns:
- The GUI is decoupled from the ROS2 backend, and hardware-specific logic is isolated in dedicated modules (gate, avend).
- Modularity:
- The file tree clearly separates simulation (dummy_test), actual hardware control (gate), and the main GUI modules. This modular design simplifies maintenance and future extensions.
- ROS2 Pub/Sub Model:
- The nodes interact via well-defined topics, ensuring that data flow (e.g., PPE status updates, dispense commands) is managed in a loosely coupled manner.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% GUI Layer
    subgraph "GUI Layer"
        A["GUI: Main Window & Widgets"]:::gui
    end

    %% ROS2 Integration Layer
    subgraph "ROS2 Integration"
        C["ROS2 Launch Files"]:::ros
        D["ROS2 Node"]:::ros
    end

    %% Central Communication Hub
    subgraph "Central Bus"
        B["ROS2 Network Bus"]:::ros
    end

    %% Hardware Control
    subgraph "Hardware Control"
        E["Safety Gate Controller (ESP32)"]:::hardware
    end

    %% Simulation Nodes
    subgraph "Simulation Nodes"
        F["Dummy Inventory Publisher"]:::ros
        G["Dummy PPE Status"]:::ros
    end

    %% API Integration
    subgraph "API Integration"
        H["Avend API Connector"]:::api
        I["External AVend API"]:::api
    end

    %% Connections among layers
    A -->|"publishes_pleaseDispense"| B
    B -->|"status_updates"| A

    C -->|"initiates"| B
    D -->|"communicates"| B

    F -->|"publishes_ppeInventoryStatus"| B
    G -->|"publishes_ppe_status"| B

    E -->|"subscribes_gate"| B

    B -->|"inventory_updates"| H
    H <-->|"API_calls"| I

    %% Click Events
    click A "https://github.com/ckyb63/ppe_gui_package/tree/main/gui_package/main_gui_modules"
    click C "https://github.com/ckyb63/ppe_gui_package/tree/main/launch"
    click D "https://github.com/ckyb63/ppe_gui_package/blob/main/gui_package/main_gui_modules/ros_node.py"
    click E "https://github.com/ckyb63/ppe_gui_package/tree/main/gui_package/gate"
    click H "https://github.com/ckyb63/ppe_gui_package/tree/main/gui_package/avend"
    click F "https://github.com/ckyb63/ppe_gui_package/tree/main/gui_package/dummy_test"
    click G "https://github.com/ckyb63/ppe_gui_package/tree/main/gui_package/dummy_test"
    
    %% Styles
    classDef gui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef ros fill:#ffe0b3,stroke:#b35900,stroke-width:2px;
    classDef hardware fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef api fill:#e2d6f3,stroke:#6f42c1,stroke-width:2px;
```
