# weliem/blessed-kotlin architecture

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

- Interactive diagram: https://gitdiagram.com/weliem/blessed-kotlin
- Repository: https://github.com/weliem/blessed-kotlin

## Overview

##### Main Components

a. Core Components:
- BluetoothCentralManager
- BluetoothPeripheral
- BluetoothPeripheralManager
- BluetoothCentral

b. Supporting Components:
- Utility Classes (BluetoothBytesParser, BluetoothBytesBuilder)
- Callback Interfaces
- Enums and Status Classes
- Android BLE Stack Integration

**┌─────────────────────────────────────────────────────────────┐**
- Application Layer                        │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Central   │  │  Peripheral │  │ Example Applications │ │
- Application │  │ Application │  │    (Sample Usage)    │ │
- ┘  └─────────────┘  └─────────────────────┘ │
- ┤
- BLESSED Library Core                      │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Central    │  │  Peripheral │  │   Utility Classes    │ │
- Manager    │◄─►│   Manager  │  │                     │ │
- ┘  └─────────────┘  │ - BytesParser       │ │
- ▲               ▲          │ - BytesBuilder       │ │
- ┘ │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Bluetooth  │  │  Bluetooth  │  │    Status Classes    │ │
- Peripheral │  │   Central   │  │ - GattStatus        │ │
- ┘  └─────────────┘  │ - HciStatus         │ │
- ┘ │
- ┤
- Android BLE Stack                        │
- ┘

##### Connection Flows

- Bidirectional communication between Central and Peripheral
- Callback flows from managers to applications
- Data flow through the BLE stack

##### Important Details

- MTU handling
- Bonding process flow
- Queue management for commands
- Notification/Indication paths
- Service discovery process
- PHY layer options (Bluetooth 5 support)

##### Notes for Implementation

- Use UML-style notation for classes and interfaces
- Clear separation between library and application code
- Thread handling (main thread callbacks)
- Public APIs vs internal components

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef application fill:#FFA500,stroke:#000
    classDef core fill:#4682B4,stroke:#000
    classDef utility fill:#FFD700,stroke:#000
    classDef status fill:#98FB98,stroke:#000
    classDef callback fill:#DDA0DD,stroke:#000
    classDef example fill:#F08080,stroke:#000
    classDef android fill:#A9A9A9,stroke:#000

    subgraph Application["Application Layer"]
        CentralApp["Central Application"]:::application
        PeripheralApp["Peripheral Application"]:::application
        MainApp["Main Application"]:::application
    end

    subgraph Core["BLESSED Library Core"]
        CentralManager["BluetoothCentralManager"]:::core
        PeripheralManager["BluetoothPeripheralManager"]:::core
        Peripheral["BluetoothPeripheral"]:::core
        Central["BluetoothCentral"]:::core

        subgraph Utilities["Utility Classes"]
            BytesParser["BluetoothBytesParser"]:::utility
            BytesBuilder["BluetoothBytesBuilder"]:::utility
        end

        subgraph Status["Status Classes"]
            GattStatus["GattStatus"]:::status
            HciStatus["HciStatus"]:::status
        end

        subgraph Callbacks["Callback Interfaces"]
            CentralCallback["BluetoothCentralManagerCallback"]:::callback
            PeripheralCallback["BluetoothPeripheralCallback"]:::callback
            PeripheralManagerCallback["BluetoothPeripheralManagerCallback"]:::callback
        end

        subgraph Examples["Example Services"]
            BaseService["BaseService"]:::example
            HeartRate["HeartRateService"]:::example
            CurrentTime["CurrentTimeService"]:::example
            DeviceInfo["DeviceInformationService"]:::example
        end
    end

    subgraph Android["Android BLE Stack"]
        BLEStack["Android Bluetooth Low Energy API"]:::android
    end

    %% Relationships
    CentralManager <--> Peripheral
    PeripheralManager <--> Central
    CentralManager --> CentralCallback
    Peripheral --> PeripheralCallback
    PeripheralManager --> PeripheralManagerCallback
    CentralManager <--> BLEStack
    PeripheralManager <--> BLEStack
    BaseService --> Examples
    HeartRate --> Examples
    CurrentTime --> Examples
    DeviceInfo --> Examples
    CentralApp --> CentralManager
    PeripheralApp --> PeripheralManager
    MainApp --> CentralManager

    %% Click Events
    click CentralManager "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothCentralManager.kt"
    click PeripheralManager "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothPeripheralManager.kt"
    click Peripheral "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothPeripheral.kt"
    click Central "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothCentral.kt"
    click BytesParser "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothBytesParser.kt"
    click BytesBuilder "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothBytesBuilder.kt"
    click GattStatus "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/GattStatus.kt"
    click HciStatus "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/HciStatus.kt"
    click CentralCallback "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothCentralManagerCallback.kt"
    click PeripheralCallback "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothPeripheralCallback.kt"
    click PeripheralManagerCallback "https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/java/com/welie/blessed/BluetoothPeripheralManagerCallback.kt"
    click BaseService "https://github.com/weliem/blessed-kotlin/blob/main/peripheral/src/main/java/com/welie/btserver/BaseService.kt"
    click HeartRate "https://github.com/weliem/blessed-kotlin/blob/main/peripheral/src/main/java/com/welie/btserver/HeartRateService.kt"
    click CurrentTime "https://github.com/weliem/blessed-kotlin/blob/main/peripheral/src/main/java/com/welie/btserver/CurrentTimeService.kt"
    click DeviceInfo "https://github.com/weliem/blessed-kotlin/blob/main/peripheral/src/main/java/com/welie/btserver/DeviceInformationService.kt"
    click PeripheralApp "https://github.com/weliem/blessed-kotlin/blob/main/peripheral/src/main/java/com/welie/btserver/BluetoothServer.kt"
    click MainApp "https://github.com/weliem/blessed-kotlin/blob/main/app/src/main/java/com/example/blessed3/MainActivity.kt"
```
