Skip to content

Commit 40bbb6e

Browse files
committed
[Website] Update docs website and README to reflect all project features and BLE Zero-read protocol
1 parent 1ea8141 commit 40bbb6e

2 files changed

Lines changed: 173 additions & 139 deletions

File tree

README.md

Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,127 @@
11
# Off Chat: A Decentralized Digital Concierge
22
### Bachelor Thesis Project | CTU FEE, Prague
33

4-
**Off Chat** is an offline-first, peer-to-peer communication platform built with Flutter. It utilizes Bluetooth Low Energy (BLE) to enable device discovery, relative location tracking (Radar), and secure messaging without any reliance on internet or cellular connectivity.
4+
**Off Chat** is an offline-first, peer-to-peer decentralized communication platform built with Flutter. It utilizes Bluetooth Low Energy (BLE) to enable instant device discovery, relative location tracking (Radar), and secure messaging without any reliance on internet, cellular connectivity, or central infrastructure.
55

6-
This project was developed as part of a Bachelor Thesis at the **Czech Technical University in Prague (CTU), Faculty of Electrical Engineering (FEE)**.
6+
This project was developed as part of a Bachelor Thesis in Open Informatics at the **Czech Technical University in Prague (CTU), Faculty of Electrical Engineering (FEE)**.
77

88
---
99

1010
## 🌟 Key Features
1111

12-
- **The Nodes (Discovery):** Real-time scanning of nearby active devices. Displays user profiles (avatar, alias) and proximity metadata.
13-
- **The Radar (Location):** A custom-painted visualization showing the relative bearing and distance of peers using a combination of GPS coordinates and device compass data.
14-
- **Off-Grid Messaging:** Reliable text and media exchange (images up to 512x512) over BLE GATT characteristics.
15-
- **Identity Protocol:** Secure local profile management with automated image compression and background synchronization.
16-
- **Aurelian Noir Aesthetic:** A premium "Digital Concierge" design system featuring deep black surfaces, gold primary accents, and fluid geometry.
12+
### 📡 Zero-read Identification Protocol
13+
- **Instant Discovery:** Avoids the high overhead of establishing GATT connections for simple identification. Nearby active devices are discovered and verified immediately upon capturing a single advertisement packet.
14+
- **Cache-Hit Proximity:** If a peer's `stableId` is already cached locally and their `versionTag` hasn't changed, they are instantly visualized on the radar without any active radio transmission.
15+
16+
### 🗺️ Custom-Painted Location Radar
17+
- **Relative Proximity Canvas:** A gorgeous, custom-painted radar visualization showing the relative bearing and distance of peers in real-time.
18+
- **Sensor Fusion:** Merges high-precision GPS coordinates from the `geolocator` package with active compass data from `flutter_compass` to correctly rotate and render neighboring nodes relative to the user's orientation.
19+
20+
### ⚡ Dual-role Mesh Topography (Store & Forward)
21+
- **Central + Peripheral:** Each device runs simultaneous BLE Central (scanning/connecting) and BLE Peripheral (advertising/serving) roles using coordinated asynchronous timers.
22+
- **Background Persistence:** Utilizes a dedicated foreground service isolate on Android to ensure continuous mesh operations and location updates, even when the OS is under heavy memory pressure.
23+
24+
### 🛣️ Intelligent Mesh Routing Engines
25+
- **Directed Beam Routing (Geographic LAR):** When geographic locations are available, the app calculates a weighted *Forwarding Score* based on angular deviation (bearing via sférická trigonometrie) and RSSI signal strength. Messages are selectively routed towards the destination, reducing radio traffic by up to 65%.
26+
- **Starburst Routing (Flooding):** Used as a fallback when geographic data is unavailable. Floods the network with a strict 10-hop Time-To-Live (TTL) limit and duplicate message deduplication via local cache.
27+
- **Breadcrumb ACK Tracking:** ACKs travel back along the reversed paths of the messages, updating delivery states deterministically.
28+
29+
### 🛡️ End-to-End Cryptography (Security Level 4)
30+
- **Key Exchange:** Secure, local key exchange using **X25519 Diffie-Hellman** curves during first-contact synchronization.
31+
- **Symmetric Encryption:** All subsequent message payloads are encrypted end-to-end using **ChaCha20-Poly1305 AEAD** to ensure confidentiality, integrity, and authenticity.
32+
33+
### 📦 Chunked Transfer Engine
34+
- **Dynamic MTU Adaptation:** An abstract chunking protocol that dynamically resizes data chunks (from standard 23 bytes up to 512 bytes) based on MTU values negotiated during connection.
35+
- **Profile Synchronization:** Seamlessly streams and reconstructs larger data files, such as custom profile pictures, over BLE GATT characteristics.
36+
37+
### 🎨 Aurelian Noir Aesthetics
38+
- **Digital Concierge Style:** Premium dark UI designed to feel prestigious and elegant.
39+
- **Visual Palette:** Deep obsidian black background surfaces (`#131313`) with subtle textures, radiant gold accents (`#F2CA50`), fluid glassmorphic cards, custom typography (Plus Jakarta Sans/Outfit), and smooth bento-grid layouts.
1740

1841
---
1942

2043
## 🏗 Architecture
2144

22-
The project follows a **Feature-First Architecture**, ensuring high cohesion and low coupling between modules. Each feature is self-contained with its own Presentation, Domain, and Data layers.
45+
The project follows a rigorous **Domain-Driven Design (DDD) Feature-First Architecture**, keeping features modular, highly cohesive, and loosely coupled.
2346

2447
```text
2548
lib/src/
2649
├── features/
27-
│ ├── onboarding/ # Multi-step security & setup protocol
28-
│ ├── discovery/ # BLE Scanning & Peer management
29-
│ ├── location/ # Radar math, Compass, & UI Canvas
30-
│ ├── profile/ # Local identity & Settings
31-
│ └── chat/ # Messaging logic & Media chunking
50+
│ ├── onboarding/ # Multi-step onboarding, profile setup & key generation
51+
│ ├── discovery/ # BLE Discovery engine, scan loop, and Sync Queue
52+
│ ├── location/ # Radar math, Compass sensors, & CustomPaint Canvas
53+
│ ├── profile/ # Local identity, settings & System Health Bento Grid
54+
│ └── chat/ # Messaging handler, encryption, & ChunkedTransferManager
3255
├── core/
33-
│ ├── routing/ # Reactive GoRouter with Onboarding protection
34-
│ ├── theme/ # Centralized Aurelian Noir ThemeData
35-
│ ├── database/ # Isar local persistence layer
36-
│ └── notifications/# Local background alerts
56+
│ ├── routing/ # Reactive GoRouter with state guards
57+
│ ├── theme/ # Centralized Aurelian Noir ThemeData & app tokens
58+
│ ├── database/ # Isar local database collections (FoundDevice, Message, RelayTask)
59+
│ └── notifications/# Background local notification service
3760
└── app.dart # Root Material application
3861
```
3962

4063
---
4164

42-
## 🛰 The Off-Chat Protocol
65+
## 🛰 The Off-Chat BLE Protocol
66+
67+
To overcome BLE advertisement limits (31 bytes) and iOS background constraints, Off Chat splits data transmission between the primary packet and the scan response.
4368

44-
To overcome standard BLE advertisement limits (31 bytes) and iOS background restrictions, this project implements a **Hybrid Discovery Strategy**:
69+
### 1. Primary Advertisement Packet (Main Packet — Exactly 5 Bytes)
70+
Packs critical identity data tightly at the byte-level:
71+
- **Bytes 0-3:** `Stable Device ID` (32-bit big-endian unsigned integer).
72+
- **Byte 4:** Combined byte consisting of:
73+
- **Bits 7-2 (6 bits):** `Version Tag` (First 6 bits of the Profile Hash) to detect profile changes instantly.
74+
- **Bit 1 (1 bit):** Platform Flag (`1` for iOS, `0` for Android).
75+
- **Bit 0 (1 bit):** Online Status Flag (`1` if acting as an Internet Bridge, `0` if offline).
4576

46-
### 1. The 13-Byte Payload
47-
We pack essential metadata into a byte-level structure to fit within Manufacturer Data:
48-
- **Byte 0:** Flags (Platform: Android/iOS, Visibility: Enabled/Disabled).
49-
- **Bytes 1-4:** Profile Hash (Deterministic CRC32 of username/avatar).
50-
- **Bytes 5-8:** Latitude (Float32).
51-
- **Bytes 9-12:** Longitude (Float32).
77+
### 2. Scan Response Packet (12 Bytes)
78+
Dispatched only when requested by active scanners to conserve battery:
79+
- **Bytes 0-2 (24 bits):** `Latitude` compressed to a 24-bit fixed-point integer.
80+
- **Bytes 3-5 (24 bits):** `Longitude` compressed to a 24-bit fixed-point integer.
81+
- **Bytes 6-11 (6 bytes):** `Full Profile Hash` for cryptographically verifying user identity.
5282

53-
### 2. Hybrid Strategy
54-
- **Primary Advertisement:** Broadcasts only the Service UUID and essential flags to minimize packet size and maximize discovery reliability (especially for iOS background).
55-
- **Scan Response:** The 13-byte custom metadata is moved to the Scan Response packet.
56-
- **Local Name:** Disabled to free up primary advertisement bandwidth.
57-
- **Background (iOS):** When Scan Response data is stripped by the OS, the app initiates a **silent GATT connection** to read the "Identity Characteristic," fetching the 13-byte payload before disconnecting.
83+
### 3. iOS Background Fallback
84+
iOS strips Manufacturer Data from advertisement packets when in the background. Off Chat handles this gracefully:
85+
- When a background node is detected without manufacturer data, the Central node initiates a **silent GATT connection** to read the designated `identityCharUuid` characteristic.
86+
- It extracts the same 5-byte and 12-byte metadata blocks and disconnects immediately, preserving battery.
5887

59-
### 3. Intelligent Motion (Flight Mode)
60-
To ensure stability in high-speed environments (airplanes, fast trains), the protocol implements **Adaptive Throttling**:
61-
- **Normal Mode (< 72 km/h):** Updates location and restarts advertising every **10 meters**.
62-
- **High-Speed Mode (≥ 72 km/h):** Switches to a stable **2-minute timer**, ignoring distance changes. This prevents rapid Bluetooth stack resets and allows peers a reliable window to connect.
63-
- **Heartbeat:** Forced update every **5 minutes** even if the device is stationary.
88+
### 4. Throttled Heartbeat (Energy Conservation)
89+
Continuous scanning and advertising is resource-heavy. Off Chat utilizes **Adaptive Throttling**:
90+
- **Stationary State:** If the user is sitting still, the advertiser sleeps and restarts advertising only every **300 seconds** (Heartbeat) to maintain connection tables.
91+
- **Motion State:** When a change of **111 meters** or movement from physical sensors is detected, advertising rates instantly spike to maximum frequency to facilitate rapid handshake loops.
6492

6593
---
6694

6795
## 🛠 Tech Stack & Dependencies
6896

6997
- **Framework:** Flutter (Dart)
70-
- **State Management:** Riverpod (Generator & Annotation)
71-
- **Navigation:** GoRouter
72-
- **Database:** Isar (NoSQL)
73-
- **Communication:** `flutter_blue_plus` (Client) & `ble_peripheral` (Server)
74-
- **Permissions:** `permission_handler` (Runtime Android 12+ BLE/Location support)
75-
- **Logging:** `logging` (Structured output for debugging)
76-
- **Sensors:** `geolocator` (GPS) & `flutter_compass`
77-
- **Design:** Google Fonts (Plus Jakarta Sans)
98+
- **State Management:** Riverpod (Generator, Annotations, and AsyncNotifiers)
99+
- **Database:** Isar (High-performance, asynchronous NoSQL database)
100+
- **BLE Communication:** `flutter_blue_plus` (Central scanner) & `ble_peripheral` (Peripheral server)
101+
- **Security:** `cryptography` (X25519 for key exchange, ChaCha20-Poly1305 for AEAD encryption)
102+
- **Sensors:** `geolocator` (GPS coordinates) & `flutter_compass` (Compass heading)
103+
- **Aesthetics:** Google Fonts (Outfit & Plus Jakarta Sans)
78104

79105
---
80106

81107
## 🚀 Getting Started
82108

83109
### Prerequisites
84-
- Flutter SDK (Latest Stable)
85-
- Two physical devices **OR** Android Emulators with **Netsim** enabled.
86-
- Android 12+ (API 31) for full BLE Advertising/Scanning support.
110+
- Flutter SDK (version 3.11.1 or newer stable)
111+
- Two physical Android/iOS devices (ideal for BLE testing) **OR** Android Emulators with **Netsim** configured.
112+
- Android 12+ (API 31) for required Nearby Devices runtime permissions.
87113

88114
### Installation
89-
1. Clone the repository.
90-
2. Install dependencies:
115+
1. Clone this repository.
116+
2. Fetch Dart packages:
91117
```bash
92118
flutter pub get
93119
```
94-
3. Run code generation (required for Riverpod and Isar):
120+
3. Generate required database schemas and Riverpod annotations:
95121
```bash
96122
dart run build_runner build --delete-conflicting-outputs
97123
```
98-
4. Deploy to a device:
124+
4. Run the application:
99125
```bash
100126
flutter run
101127
```
@@ -104,27 +130,20 @@ To ensure stability in high-speed environments (airplanes, fast trains), the pro
104130

105131
## 🧪 Testing & Verification
106132

107-
### Developer Terminal (In-App)
108-
A hidden debug console is available for real-time monitoring of BLE status and system logs:
109-
1. Navigate to the **Discovery (Home)** screen.
110-
2. **Triple-tap** the "OFFCHAT" logo in the header.
111-
3. The terminal displays the last 200 logs with color-coded severity levels.
112-
113-
### Multi-Emulator Testing (Netsim)
114-
You can test BLE discovery and GATT sync locally using **Netsim** (Android Network Simulator):
115-
1. Launch two Android emulators (API 31+).
116-
2. Ensure Netsim is enabled in emulator settings.
117-
3. Open the Netsim GUI: `http://localhost:7681/gui` to manage device proximity and signal strength.
118-
119-
### Continuous Integration
120-
A GitHub Action is configured to build release artifacts on every push to `master`.
121-
- **APK:** `off-chat-release.apk`
122-
- **App Bundle:** `off-chat-release.aab`
123-
Builds are pushed automatically to the `android` branch for deployment.
124-
125-
### Automated Checks
126-
The project strictly follows Dart style guidelines (lowerCamelCase constants, no `print` in production).
127-
Verify code quality and run tests:
133+
### 💻 Developer Console (In-App Terminal)
134+
A hidden debug console is built directly into the UI for real-time mesh monitoring:
135+
1. Navigate to the **Discovery (Home)** screen.
136+
2. **Triple-tap** the `OFFCHAT` logo in the top AppBar.
137+
3. A developer terminal overlay opens, showing the last 200 console logs with color-coded severity levels (Severe, Info, Warning).
138+
139+
### 🌐 Proximity Simulation (Netsim)
140+
Test mesh routing and discovery on a single machine:
141+
1. Launch two Android Emulators (API 31+).
142+
2. Open the **Netsim GUI** in your browser: `http://localhost:7681/gui`
143+
3. Drag the virtual devices closer or further apart to simulate RSSI changes, range limits, and connection handshakes.
144+
145+
### 🧹 Quality Checks & Verification
146+
The project maintains absolute style guidelines. Check for linting issues and run tests:
128147
```bash
129148
flutter analyze
130149
flutter test

0 commit comments

Comments
 (0)