# falleng0d/pi-remote architecture

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

- Interactive diagram: https://gitdiagram.com/falleng0d/pi-remote
- Repository: https://github.com/falleng0d/pi-remote

## Overview

##### Main Components

a) Client Layer:
- Remote Control App (external mobile application)
- This as the entry point for user interactions

b) Communication Layer:
- gRPC Server (represented by server.py)
- Protocol Buffers (input.proto and generated files)

c) Core Processing Layer:
- Input Service (input_service.py)
- Config Service (config_service.py)
- Text-to-HID Converter (text_to_hid.py)

d) Hardware Interface Layer:
- USB Gadget Implementation (otg directory)
- HID Protocol Handler (app/hid directory)

##### Component Relationships

**[Mobile App] → [gRPC Server] → [Input Service] → [HID Protocol Handler] → [USB Gadget] → [Target Device]**

##### Specific Implementation Details

Technical elements:
- Protocol Buffers for data serialization (input.proto)
- USB Gadget configuration scripts
- HID keycodes mapping
- System services (pi-remote.service)

##### Key Architectural Patterns to Highlight

- Client-Server architecture via gRPC
- Hardware abstraction layer for USB/HID
- Service-based architecture (input and config services)

##### Implementation-Specific Notes

Crucial elements:
- The USB gadget initialization flow
- HID protocol translation process
- Configuration management
- Service deployment

- Client Layer   | →   | Processing Layer | →   | Hardware Layer  |
- (Mobile App)   |     | (gRPC + Services)|     | (USB + HID)     |

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef client fill:#2196F3,stroke:#1565C0,color:white
    classDef grpc fill:#FDD835,stroke:#F9A825,color:black
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef hardware fill:#757575,stroke:#424242,color:white
    classDef config fill:#FF9800,stroke:#EF6C00,color:white

    %% Client Layer
    MobileApp["Remote Control App"]:::client

    %% Communication Layer
    subgraph Communication
        GRPC["gRPC Server"]:::grpc
        Proto["Protocol Buffers"]:::grpc
        ProtoGen["Generated Proto Code"]:::grpc
    end

    %% Core Processing Layer
    subgraph CoreProcessing
        InputSvc["Input Service"]:::core
        ConfigSvc["Config Service"]:::core
        TextHID["Text-to-HID Converter"]:::core
        KeyProc["Key Processing"]:::core
    end

    %% Hardware Interface Layer
    subgraph HardwareInterface
        HIDHandler["HID Protocol Handler"]:::hardware
        USBGadget["USB Gadget Implementation"]:::hardware
    end

    %% Configuration
    Config["Configuration Files"]:::config
    Services["System Services"]:::config

    %% Relationships
    MobileApp --> GRPC
    GRPC --> Proto
    Proto --> ProtoGen
    GRPC --> InputSvc
    InputSvc --> ConfigSvc
    ConfigSvc --> Config
    InputSvc --> TextHID
    TextHID --> KeyProc
    KeyProc --> HIDHandler
    HIDHandler --> USBGadget
    Services --> USBGadget

    %% Click events for component mapping
    click GRPC "https://github.com/falleng0d/pi-remote/blob/master/app/server.py"
    click Proto "https://github.com/falleng0d/pi-remote/blob/master/app/input.proto"
    click ProtoGen "https://github.com/falleng0d/pi-remote/blob/master/app/input_pb2.py"
    click InputSvc "https://github.com/falleng0d/pi-remote/blob/master/app/input_service.py"
    click ConfigSvc "https://github.com/falleng0d/pi-remote/blob/master/app/config_service.py"
    click TextHID "https://github.com/falleng0d/pi-remote/blob/master/app/text_to_hid.py"
    click HIDHandler "https://github.com/falleng0d/pi-remote/tree/master/app/hid"
    click USBGadget "https://github.com/falleng0d/pi-remote/tree/master/otg"
    click Services "https://github.com/falleng0d/pi-remote/blob/master/pi-remote.service"
    click Config "https://github.com/falleng0d/pi-remote/blob/master/remotecontrol.cfg"
    click KeyProc "https://github.com/falleng0d/pi-remote/blob/master/app/key.py"

    %% Legend
    subgraph Legend
        Client["Client Component"]:::client
        GRPCComp["Communication Component"]:::grpc
        CoreComp["Core Component"]:::core
        HWComp["Hardware Component"]:::hardware
        ConfigComp["Configuration Component"]:::config
    end
```
