# salim-mrw/usb-rubber architecture

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

- Interactive diagram: https://gitdiagram.com/salim-mrw/usb-rubber
- Repository: https://github.com/salim-mrw/usb-rubber

## Overview

##### Project Type and Purpose
- This is an Arduino “library” (open-source tool) that wraps the native Arduino Keyboard/HID API.
- Purpose: expose simple functions (begin, print, press, end) to send USB keyboard HID reports from ATmega32u4-based boards to a host computer.

##### File Structure
- Top‐level files: LICENSE, README.md, library.properties (defines library metadata for Arduino IDE), keywords.txt (for syntax highlighting).
- examples/: Contains a single example (“open_POWERSHELL.ino”) showing how user code invokes the library.
- src/: Contains usbrubber.cpp/h – core implementation of the usbrubber class.

##### Pull Insights from README
- Target hardware: Arduino Leonardo, Micro, Nano (ATmega32u4).
- Dependency: Arduino core’s Keyboard.h (native USB HID driver).
- Core functionality: initialize HID, send text, press single keys, terminate HID session.

a. Hardware
- ATmega32u4-based Arduino board (Leonardo, Micro or Nano).
- USB physical connection to host.
b. Firmware Software Layers
- **User Sketch** (example .ino)
- **usbrubber Library** (src/usbrubber.cpp/h)
- **Arduino HID Core** (Keyboard.h, built into Arduino framework)
c. Host System
- USB HID Driver (OS kernel component)
- User shell/application (e.g., PowerShell on Windows)

##### Relationships & Data Flow
- User Sketch calls usbrubber.begin() → usbrubber wraps Keyboard.begin()
- Sketch calls usbrubber.print()/press() → usbrubber constructs HID reports → Keyboard.sendReport()
- USB controller on ATmega32u4 sends HID packets to Host
- OS HID Driver on the host interprets packets as keystrokes → routes to active application (PowerShell, text editor, etc.)
- usbrubber.end() calls Keyboard.end() to release HID interface

##### Architectural Patterns & Design Principles
- **Facade/Wrapper Pattern**: usbrubber abstracts the complexity of raw HID calls behind simple methods.
- **Layered Architecture**: clear separation between
- Application layer (user sketch)
- Library layer (usbrubber API)
- Framework layer (Arduino core)
- Hardware layer (USB controller & MCU)
- Host layer (OS HID stack)

##### Relevant Technologies & Frameworks
- C++ (Arduino flavor)
- Arduino IDE build system (via library.properties)
- ATmega32u4 USB-HID peripheral
- OS USB HID drivers (Windows, macOS, Linux)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "IDE Metadata"
        LP["library.properties"] 
        KT["keywords.txt"]
        RM["README.md"]
        LI["LICENSE"]
    end

    US["User Sketch\n(open_POWERSHELL.ino)"]:::arduino
    subgraph "usbrubber Library"
        UCPP["usbrubber.cpp"]:::arduino
        UHH["usbrubber.h"]:::arduino
    end
    ARD["Arduino Core HID\n(Keyboard.h)"]:::arduino
    HW["ATmega32u4 Board\n+ USB Controller"]:::hardware
    HD["OS USB HID Driver"]:::host
    APP["Host Application\n(PowerShell)"]:::host

    LP -->|"provides metadata"| US
    KT -->|"syntax highlighting"| US
    RM -->|"documentation for"| US
    LI -->|"license info for"| US

    US -->|"begin() call"| UCPP
    UCPP -->|"Keyboard.begin()"| ARD
    US -->|"print()/press() calls"| UCPP
    UCPP -->|"sendReport() HID Packet"| HW
    UCPP -->|"end() call"| ARD
    HW -->|"USB HID"| HD
    HD -->|"keystroke events"| APP

    click US "https://github.com/salim-mrw/usb-rubber/blob/main/examples/WIN/open_POWERSHELL/open_POWERSHELL.ino"
    click UCPP "https://github.com/salim-mrw/usb-rubber/blob/main/src/usbrubber.cpp"
    click UHH "https://github.com/salim-mrw/usb-rubber/blob/main/src/usbrubber.h"
    click LP "https://github.com/salim-mrw/usb-rubber/blob/main/library.properties"
    click KT "https://github.com/salim-mrw/usb-rubber/blob/main/keywords.txt"
    click RM "https://github.com/salim-mrw/usb-rubber/blob/main/README.md"
    click LI "https://github.com/salim-mrw/usb-rubber/tree/main/LICENSE"

    classDef arduino fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef hardware fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef host fill:#ffe0b3,stroke:#333,stroke-width:1px
    classDef metadata fill:#e5e5e5,stroke:#333,stroke-width:1px
```
