# jjjsmit/bluetoothbleclient architecture

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

- Interactive diagram: https://gitdiagram.com/jjjsmit/bluetoothbleclient
- Repository: https://github.com/jjjsmit/bluetoothbleclient

## Overview

##### Project type and purpose
- This is a small, Linux-based Bluetooth Low Energy (BLE) central‐client tool written in C.
- It leverages the BlueZ 5.49 Bluetooth stack via D‐Bus and a GLib main loop to connect to a known BLE peripheral and interact with specific GATT characteristics.

##### File structure
- Top-level files:
- README.md – describes purpose, setup, dependencies
- Makefile – builds your client plus unmodified BlueZ sources
- ble.c – your main entry point (initializes, parses args)
- bleClient.c / bleClient.h – implementation of BLE/D‐Bus interactions
- External sources (not shown in tree) are pulled in from the BlueZ 5.49 directory: examples and headers for D‐Bus, GLib, and GATT support.

##### README for additional insights
- Dependencies: BlueZ ≥ 5.49, libdbus-1, libglib2.0
- Execution environment: Linux (e.g., Raspbian Stretch), interacts with system bluetoothd via D‐Bus
- Core functionality: minimal, low-priority thread, known device/service/characteristics

##### Main components
a. Application (ble executable)
– ble.c: startup, argument parsing
– bleClient.{c,h}: BLE connection management, GATT read/notify
b. BlueZ daemon (bluetoothd)
– exposes D-Bus API for BLE operations
– manages HCI interface to the Bluetooth adapter
c. Linux Bluetooth HCI layer
– Kernel driver + hardware interface (USB or built-in)
d. BLE peripheral device
– GATT server with known service UUIDs and characteristics you target
e. External libraries
– D-Bus library (libdbus-1)
– GLib (main event loop)

##### Relationships and interactions
- Your ble client binds to the GLib main loop → schedules GATT operations
- bleClient calls D-Bus methods (AcquireNotify, ReadValue) on bluetoothd
- bluetoothd drives HCI commands down to the kernel driver
- BLE radio on the adapter communicates wirelessly with the peripheral’s GATT server
- Notifications from peripheral propagate back up through HCI → bluetoothd → your client’s callback

##### Architectural patterns / design principles
- Layered architecture:
1. Application layer (ble client)
2. IPC layer (D-Bus)
3. Bluetooth stack (BlueZ daemon + kernel HCI)
4. Hardware / radio
5. Remote GATT server
- Event-driven: GLib main loop dispatches asynchronous notifications
- Minimalism: only uses necessary BlueZ files, no heavyweight abstractions

##### Detail to capture
- D-Bus AcquireNotify and ReadValue methods
- GLib main loop for event dispatch
- Exact flow of BLE notifications

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Layer
    subgraph "Application Layer"
        direction TB
        ble_main(("ble")):::app
        ble_client["bleClient.c / bleClient.h"]:::app
        g_loop["GLib Main Loop"]:::external
    end

    %% IPC Layer
    dbus["D-Bus IPC"]:::external

    %% System Service Layer
    bluetoothd["bluetoothd (BlueZ Daemon)"]:::service

    %% Hardware Layer
    subgraph "Bluetooth Hardware"
        direction TB
        driver["Kernel HCI Driver"]:::hardware
        adapter["Bluetooth Adapter"]:::hardware
    end

    radio["Radio Wireless Link"]:::hardware

    %% Peripheral
    peripheral["BLE Peripheral\nGATT Server"]:::hardware

    %% Project Files
    subgraph "Project Files"
        direction TB
        mk["Makefile"]:::external
        rm["README.md"]:::external
        lic["LICENSE"]:::external
    end

    %% Connections
    ble_main -->|"initializes & parses args"| ble_client
    ble_client -->|"schedules on"| g_loop
    ble_client -->|"AcquireNotify / ReadValue"| dbus
    dbus -->|"method calls"| bluetoothd
    bluetoothd -->|"HCI commands"| driver
    driver -->|"USB / driver interface"| adapter
    adapter -->|"wireless RF"| radio
    radio -->|"GATT operations"| peripheral
    peripheral -->|"notifications"| radio
    radio --> driver
    driver --> bluetoothd
    bluetoothd -->|"D-Bus signals"| dbus
    dbus -->|"callbacks"| ble_client

    %% Click Events
    click ble_main "https://github.com/jjjsmit/bluetoothbleclient/blob/master/ble.c"
    click ble_client "https://github.com/jjjsmit/bluetoothbleclient/blob/master/bleClient.c"
    click ble_client "https://github.com/jjjsmit/bluetoothbleclient/blob/master/bleClient.h"
    click mk "https://github.com/jjjsmit/bluetoothbleclient/tree/master/Makefile"
    click rm "https://github.com/jjjsmit/bluetoothbleclient/blob/master/README.md"
    click lic "https://github.com/jjjsmit/bluetoothbleclient/tree/master/LICENSE"

    %% Styles
    classDef app fill:#e0f7e9,stroke:#2e7d32,stroke-width:1px;
    classDef service fill:#e3f2fd,stroke:#1e88e5,stroke-width:1px;
    classDef hardware fill:#eeeeee,stroke:#757575,stroke-width:1px;
    classDef external fill:#fff3e0,stroke:#fb8c00,stroke-width:1px,stroke-dasharray: 5 5;
```
