# tinnci/flutter_ble_hid_peripheral architecture

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

- Interactive diagram: https://gitdiagram.com/tinnci/flutter_ble_hid_peripheral
- Repository: https://github.com/tinnci/flutter_ble_hid_peripheral

## Overview

##### Project type and purpose
- This is a Flutter plugin (an open-source tool) whose purpose is to let a Flutter app emulate a BLE Human Interface Device (keyboard/mouse) on Android.
- Key indicators:
- Top-level lib/ directory with Dart code and platform‐interface abstractions.
- android/ directory containing Kotlin source for BLE HID peripheral logic.
- example/ directory showing a sample Flutter app integrating the plugin.

##### File structure
- Top‐level directories:
- lib/ – Dart API entrypoints, platform interface, MethodChannel implementation.
- android/ – native Android plugin code (Kotlin), BLE HID peripheral classes.
- example/ – sample Flutter app using the plugin.
- test/ – Dart unit tests for plugin APIs and MethodChannel.
- Patterns:
- Plugin architecture: separation between platform‐agnostic interface (flutter_ble_hid_peripheral_platform_interface.dart), MethodChannel bridge (flutter_ble_hid_peripheral_method_channel.dart), and platform implementation (FlutterBleHidPeripheralPlugin.kt).
- Native code implements BLE HID via Kotlin: HidPeripheral, KeyboardPeripheral, MousePeripheral, and utility classes under jp.kshoji.
- Config & Build:
- pubspec.yaml – declares Dart package & dependencies.
- build.gradle / settings.gradle – Android plugin module configuration.

##### README for architecture clues
- Describes plugin usage flow: Dart → permission checks → API calls (startKeyboard, sendKeys, etc.) → native BLE HID operations.
- Notes lack of iOS implementation (so only Android path is drawn).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Flutter Application"
        App["example/lib/main.dart"]:::dart
    end

    subgraph "Plugin API Layer (Dart)"
        API["lib/flutter_ble_hid_peripheral.dart"]:::dart
        Interface["lib/flutter_ble_hid_peripheral_platform_interface.dart"]:::dart
    end

    subgraph "MethodChannel Bridge"
        MC["lib/flutter_ble_hid_peripheral_method_channel.dart"]:::method
    end

    subgraph "Android Native Implementation"
        Plugin["FlutterBleHidPeripheralPlugin.kt"]:::native
        subgraph "BLE HID Classes"
            Base["HidPeripheral.kt"]:::native
            KB["KeyboardPeripheral.kt"]:::native
            Mouse["MousePeripheral.kt"]:::native
        end
        subgraph "Utilities"
            U1["BleUtils.kt"]:::native
            U2["BleUuidUtils.kt"]:::native
            U3["CoroutineUtils.kt"]:::native
        end
    end

    subgraph "Android BLE Stack & OS"
        Stack["BluetoothAdapter / BluetoothLeAdvertiser / GATT Server APIs"]:::stack
    end

    Hardware["Physical Bluetooth Controller"]:::hw

    App -->|"startKeyboard()/sendMouseMovement() etc"| API
    API -->|"invokePlatformInterface"| Interface
    Interface -->|"MethodChannel.invokeMethod"| MC
    MC -->|"onMethodCall"| Plugin
    Plugin -->|"uses"| Base
    Plugin -->|"uses"| KB
    Plugin -->|"uses"| Mouse
    Plugin -->|"uses"| U1
    Plugin -->|"uses"| U2
    Plugin -->|"uses"| U3
    Base -->|"calls"| Stack
    KB -->|"reports"| Stack
    Mouse -->|"reports"| Stack
    Stack -->|"sends/receives via"| Hardware
    Hardware -->|"event callbacks"| Stack
    Stack -->|"BLE events"| Base
    Base -->|"onStateChange"| Plugin
    Plugin -->|"reply via MethodChannel"| MC
    MC -->|"MethodChannel callback"| Interface
    Interface -->|"Dart callback"| API

    click App "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/example/lib/main.dart"
    click API "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/lib/flutter_ble_hid_peripheral.dart"
    click Interface "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/lib/flutter_ble_hid_peripheral_platform_interface.dart"
    click MC "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/lib/flutter_ble_hid_peripheral_method_channel.dart"
    click Plugin "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/kotlin/com/example/flutter_ble_hid_peripheral/FlutterBleHidPeripheralPlugin.kt"
    click Base "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/java/jp/kshoji/blehid/HidPeripheral.kt"
    click KB "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/java/jp/kshoji/blehid/KeyboardPeripheral.kt"
    click Mouse "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/java/jp/kshoji/blehid/MousePeripheral.kt"
    click U1 "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/java/jp/kshoji/blehid/util/BleUtils.kt"
    click U2 "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/java/jp/kshoji/blehid/util/BleUuidUtils.kt"
    click U3 "https://github.com/tinnci/flutter_ble_hid_peripheral/blob/main/android/src/main/java/jp/kshoji/blehid/util/CoroutineUtils.kt"

    classDef dart fill:#CCF,stroke:#339,stroke-width:1px
    classDef method fill:#CFC,stroke:#393,stroke-width:1px
    classDef native fill:#FCC,stroke:#933,stroke-width:1px
    classDef stack fill:#FCF,stroke:#939,stroke-width:1px
    classDef hw fill:#FFC,stroke:#993,stroke-width:1px
```
