# simondankelmann/bluetooth-le-spam architecture

> Architecture diagram of the GitHub repository simondankelmann/bluetooth-le-spam, 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/simondankelmann/bluetooth-le-spam
- Repository: https://github.com/simondankelmann/bluetooth-le-spam

## Overview

##### Project type and purpose
- This is a native Android mobile application (“Bluetooth LE Spam”) written in Kotlin.
- Purpose: generate and send phantom BLE advertisements (various protocols) and detect incoming BLE spam.
- It uses Android Jetpack (Room DB, ViewModel), Android BLE APIs, foreground/background services, and a local SQLite database.

##### File structure for architectural clues
- Top-level modules:
- app/ – the Android app module with source folders.
- fastlane/ – deployment pipeline (Appfile, Fastfile, metadata).
- Within app/src/main/java/de/simon/dankelmann/bluetoothlespam:
- ui/ + ViewModel packages → presentation layer (MVVM).
- Services/ + Callbacks/Interfaces → background BLE scanning & advertising services.
- AdvertisementSetGenerators/ → factory/strategy generators of protocol-specific BLE payloads.
- Database/Dao/Entities/Migrations → local persistence using Room.
- Handlers, Helpers, Constants, Enums → utility & business-logic support.
- MainActivity, SettingsActivity → entry points for UI.

##### Additional insights from README
- Key features: BLE advertisement spoofing (Apple, SwiftPair, Samsung, Lovespouse, etc.), iOS crash exploit, spam detector.
- Requires Android 8+ BLE APIs, runs entirely on the device, no external backend.

##### Main components
a. Presentation Layer
- Activities & Fragments
- ViewModels (Advertise, SpamDetector, Start)
b. Service Layer
- BluetoothLeScanService & BluetoothLeScanForegroundService
- BluetoothLeAdvertisementService & AdvertisementForegroundService
- LegacyAdvertisementService / ModernAdvertisementService (version forks)
- AdvertisementSetQueueHandler
c. Generators & Business Logic
- AdvertisementSetGenerators (strategy classes implementing IAdvertisementSetGenerator)
- Handlers (AdvertisementSetQueueHandler)
- Helpers & Constants (BluetoothHelpers, DatabaseHelpers, etc.)
d. Data Layer
- Room Database (AppDatabase)
- DAOs (AdvertiseDataDao, AdvertisementSetDao, …)
- Entities & Migrations
e. Android OS & BLE Subsystem
- Android BLE API (BluetoothLeAdvertiser, BluetoothLeScanner)
- Hardware radio
f. External Environment
- Target BLE-capable devices (phones, speakers, adult toys, etc.)

##### Relationships and data flows
- UI → ViewModel → calls Service (via Context.bindService or Intent).
- Service → AdvertisementSetQueueHandler → selects appropriate AdvertisementSetGenerator → builds BLE payload.
- Service → Android BluetoothLeAdvertiser → hardware radio → external device.
- Android BLE Scanner → BluetoothLeScanService → scan callbacks propagate to SpamDetector logic → ViewModel → UI notifications.
- Services & UI both read/write to Room database through DAOs.

##### Architectural patterns / design principles
- MVVM for UI separation (Fragments/Activities + ViewModels).
- Service pattern for long-running BLE tasks (foreground & background services).
- Repository-style access via Room (DAO + Entities + Migrations).
- Strategy pattern for AdvertisementSetGenerators.
- Callback/Observer pattern for BLE events.

##### Technologies & frameworks
- Kotlin, Android SDK (BLE, Services, Jetpack: ViewModel, Room)
- Gradle/KTS build scripts, ProGuard rules
- Fastlane for CI/CD and Play Store metadata
- GitHub Actions (build.yml)

##### Diagramming recommendations
- Labels: annotate arrowheads with method calls or intents, e.g., “startScan()”, “startAdvertising()”, “onScanResult()”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        MainActivity["MainActivity"]:::frontend
        SettingsActivity["SettingsActivity"]:::frontend
        subgraph "Fragments"
            direction TB
            AdvertisementFragment["AdvertisementFragment"]:::frontend
            AdvertisementCollectionFragment["AdvertisementCollectionFragment"]:::frontend
            SpamDetectorFragment["SpamDetectorFragment"]:::frontend
            StartFragment["StartFragment"]:::frontend
            PreferencesFragment["PreferencesFragment"]:::frontend
        end
        subgraph "ViewModels"
            direction TB
            AdvertisementViewModel["AdvertisementViewModel"]:::frontend
            SpamDetectorViewModel["SpamDetectorViewModel"]:::frontend
            StartViewModel["StartViewModel"]:::frontend
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        BluetoothLeScanService["BluetoothLeScanService"]:::service
        BluetoothLeScanForegroundService["BluetoothLeScanForegroundService"]:::service
        BluetoothLeAdvertisementService["BluetoothLeAdvertisementService"]:::service
        AdvertisementForegroundService["AdvertisementForegroundService"]:::service
        LegacyAdvertisementService["LegacyAdvertisementService"]:::service
        ModernAdvertisementService["ModernAdvertisementService"]:::service
        AdvertisementSetQueueHandler["AdvertisementSetQueueHandler"]:::service
    end

    %% Business Logic
    subgraph "Business Logic"
        direction TB
        AdvertisementSetGenerator["AdvertisementSetGenerators\n(implements IAdvertisementSetGenerator)"]:::logic
        IAdvertisementSetGenerator["IAdvertisementSetGenerator"]:::logic
        Helpers["Helpers\n(BluetoothHelpers, DatabaseHelpers, etc.)"]:::logic
        Constants["Constants"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["Room DB\n(AppDatabase + DAOs + Entities)"]:::data
    end

    %% OS & Hardware
    subgraph "Android OS & BLE Subsystem"
        direction TB
        BLEAPI["Android BLE APIs\n(BluetoothLeAdvertiser, BluetoothLeScanner)"]:::os
        Radio["Hardware Radio"]:::os
    end

    %% External Environment
    ExternalDevices["Target BLE Devices"]:::external

    %% Connections - UI to ViewModel
    MainActivity -->|"binds to / interacts"| AdvertisementViewModel
    MainActivity -->|"binds to / interacts"| SpamDetectorViewModel
    SettingsActivity -->|"binds to / interacts"| StartViewModel
    AdvertisementFragment -->|"observes"| AdvertisementViewModel
    AdvertisementCollectionFragment -->|"observes"| StartViewModel
    SpamDetectorFragment -->|"observes"| SpamDetectorViewModel
    StartFragment -->|"observes"| StartViewModel
    PreferencesFragment -->|"observes"| StartViewModel

    %% ViewModel to Services
    AdvertisementViewModel -->|"startAdvertising() via Intent"| BluetoothLeAdvertisementService
    SpamDetectorViewModel -->|"startScan() via Intent"| BluetoothLeScanService
    StartViewModel -->|"startServices()"| BluetoothLeAdvertisementService
    StartViewModel -->|"startServices()"| BluetoothLeScanService

    %% Services to Business Logic
    BluetoothLeAdvertisementService -->|"enqueue()"| AdvertisementSetQueueHandler
    AdvertisementForegroundService -->|"enqueue()"| AdvertisementSetQueueHandler
    LegacyAdvertisementService -->|"enqueue()"| AdvertisementSetQueueHandler
    ModernAdvertisementService -->|"enqueue()"| AdvertisementSetQueueHandler
    AdvertisementSetQueueHandler -->|"select()"| AdvertisementSetGenerator
    AdvertisementSetGenerator -->|"generatePayload()"| BLEAPI

    BluetoothLeScanService -->|"onScanResult()"| SpamDetectorViewModel
    BluetoothLeScanForegroundService -->|"onScanResult()"| SpamDetectorViewModel

    %% Services & UI to DB
    BluetoothLeAdvertisementService -.->|"read/write"| DB
    BluetoothLeScanService -.->|"read/write"| DB
    AdvertisementViewModel -.->|"read/write"| DB
    SpamDetectorViewModel -.->|"read/write"| DB
    StartViewModel -.->|"read/write"| DB

    %% DB connections
    DB -->|DAOs| AdvertisementSetGenerator
    DB -->|DAOs| SpamDetectorViewModel

    %% BLE API to Hardware & External
    BLEAPI -->|"advertise() / scan()"| Radio
    Radio -->|"BLE Packets"| ExternalDevices
    ExternalDevices -->|"BLE Responses"| Radio
    Radio -->|"scan results"| BLEAPI
    BLEAPI -->|"callbacks"| BluetoothLeScanService

    %% Click Events
    click MainActivity "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/MainActivity.kt"
    click SettingsActivity "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/SettingsActivity.kt"
    click AdvertisementFragment "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisement/AdvertisementFragment.kt"
    click AdvertisementCollectionFragment "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisementcollection/AdvertisementCollectionFragment.kt"
    click SpamDetectorFragment "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/spamDetector/SpamDetectorFragment.kt"
    click StartFragment "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/start/StartFragment.kt"
    click PreferencesFragment "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/preferences/PreferencesFragment.kt"
    click AdvertisementViewModel "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisement/AdvertisementViewModel.kt"
    click SpamDetectorViewModel "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/spamDetector/SpamDetectorViewModel.kt"
    click StartViewModel "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/start/StartViewModel.kt"
    click BluetoothLeScanService "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeScanService.kt"
    click BluetoothLeScanForegroundService "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeScanForegroundService.kt"
    click BluetoothLeAdvertisementService "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeAdvertisementService.kt"
    click AdvertisementForegroundService "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/AdvertisementForegroundService.kt"
    click LegacyAdvertisementService "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/LegacyAdvertisementService.kt"
    click ModernAdvertisementService "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/ModernAdvertisementService.kt"
    click AdvertisementSetQueueHandler "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Handlers/AdvertisementSetQueueHandler.kt"
    click AdvertisementSetGenerator "https://github.com/simondankelmann/bluetooth-le-spam/tree/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/AdvertisementSetGenerators/"
    click IAdvertisementSetGenerator "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/AdvertisementSetGenerators/IAdvertisementSetGenerator.kt"
    click Helpers "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Helpers/BluetoothHelpers.kt"
    click Constants "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Constants/Constants.kt"
    click DB "https://github.com/simondankelmann/bluetooth-le-spam/blob/main/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Database/AppDatabase.kt"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef service fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20
    classDef logic fill:#fffde7,stroke:#f9a825,color:#f57f17
    classDef data fill:#fff3e0,stroke:#ef6c00,color:#e65100
    classDef os fill:#eceff1,stroke:#607d8b,color:#455a64
    classDef external fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
```
