A production-grade, enterprise-ready Flutter architecture framework built for Bluetooth Low Energy (BLE) applications. This repository serves as a scalable, high-performance blueprint demonstrating mobile architecture best practices, native Swift/Kotlin platforms integration, robust telemetry logs, and test-driven development.
The codebase is built on Clean Architecture principles, decoupled by boundaries that ensure scalability, maintainability, and testability.
graph TD
UI[Presentation Layer: Widgets & Pages] -->|Dispatches Events| Bloc[State Management: BLoC]
Bloc -->|Requests Data / Operations| DomainRepo[Domain Layer: Repository Interfaces]
DomainRepo -.->|Implemented by| DataRepo[Data Layer: Repository Implementations]
DataRepo -->|Wraps Plugins / Local DB| NativeAPI[Native BLE / Local Storage]
- State Management: Orchestrated via
flutter_blocusing uni-directional data streams. - Navigation: Modern declarative routing powered by
go_router. - Theme: Custom Material 3 Dark/Light themes designed with visual tokens.
- Contains pure business contracts (Interfaces) and entities.
- Free from framework dependencies (e.g., UI or Bluetooth libraries).
- Concrete implementation of domain repository contracts.
- Maps third-party API events (e.g.,
flutter_blue_plusstreams) into standard domain models (BleDevice,BleConnectionStatus). - Manages local storage caching (Hive).
- Dynamic dependency injection managed via
get_itService Locator. - Bootstraps storage engines and logs handlers during initial zone startup.
To ensure system reliability during heavy BLE scans or GATT communication, this codebase implements a Hive-backed Telemetry Cache (BleLogsRepositoryImpl):
- No Code Generators: Structured log models serialized as JSON strings inside a standard
Box<String>, resolving conflicts with Dart 3 macro upgrades. - Log Capper: Limits stored telemetry events to 500 entries maximum. Old entries are automatically pruned on new writes to prevent performance degradation or out-of-memory crashes on device.
- Terminal GUI: Presentation logs screen styles messages with terminal-like monospaced typography and color codes representing message severity.
BLE operations require system-level permission authorizations. The app integrates permission_handler and prompts the user on startup:
The following permissions are configured in the manifest:
android.permission.BLUETOOTH_SCAN(withneverForLocationoptional flag)android.permission.BLUETOOTH_CONNECTandroid.permission.ACCESS_FINE_LOCATION(Required for legacy Android APIs)
The following usage descriptions are configured:
NSBluetoothAlwaysUsageDescription(Background/Foreground peripheral communications)NSBluetoothPeripheralUsageDescription(Legacy peripheral access)NSLocationWhenInUseUsageDescription(Service discovery requirements)
To demonstrate senior platform engineering, custom Kotlin and Swift BLE components have been designed as blueprints for native extensions when complex vendor SDKs or custom background daemon modes are needed:
- BleManager.kt: Master MethodChannel bridge.
- BleScanner.kt: Interfaces with
BluetoothLeScannerfor low-latency scanning. - BleConnectionManager.kt: Manages active GATT instances.
- GattCallbackHandler.kt: Inherits
BluetoothGattCallbackto track connection shifts.
- BLEManager.swift: Master CoreBluetooth MethodChannel bridge.
- BLEScanner.swift: Orchestrates peripheral scanning using
CBCentralManager. - BLEConnectionManager.swift: Wraps
CBPeripheralreferences and GATT delegate callbacks.
This project maintains unit tests covering presenter layers, events, and states using mocktail and bloc_test:
Run tests inside the repository using the Flutter CLI:
flutter test- BLoC Unit Tests:
BleScanBlocstates verification, event coverage, and stream subscription updates. - Widget Smoke Tests: Ensures basic MaterialApp routing, injection containers integration, and initial splash screens rendering.
Important
HIPAA Compliance Disclaimer
This repository is a clean, public-facing software architecture blueprint. It contains no proprietary medical device integrations, clinical data logic, or proprietary code. All core structures use standard public SDK APIs (flutter_blue_plus, hive, flutter_bloc). No Protected Health Information (PHI) is processed, collected, or transmitted.
- Prerequisites: Ensure Flutter SDK
3.35.4(or compatible 3.x) is installed. - Install Dependencies:
flutter pub get
- Run Code Analysis:
flutter analyze
- Launch Application:
flutter run
- Framework: Flutter 3.x (with null-safety)
- Language: Dart 3.x, Kotlin (Android), Swift (iOS)
- State Management: flutter_bloc & equatable
- Routing: go_router
- Local Storage: Hive (caching logs)
- BLE Core: flutter_blue_plus
- Secure Storage integration: Encrypt peripheral keys using keychain/keystore.
- Auto-reconnect logic: Implement automated reconnect policies inside BLoC handlers with exponential backoffs.
- Background daemon execution: Setup native services to perform background BLE data collection.
- Detailed architecture layers, state machine diagrams, and troubleshooting guidelines are located in the architecture.md documentation file.