An open API service indexing awesome lists of open source software.

https://github.com/edycutjong/beacon

๐Ÿ“ก Offline P2P field assistant โ€” delegates heavy AI inference from a phone to a nearby laptop via QVAC's peer-to-peer compute mesh. No cloud, no internet, just local Wi-Fi Direct.
https://github.com/edycutjong/beacon

edge-computing expo local-ai offline-first p2p qvac react-native

Last synced: about 1 month ago
JSON representation

๐Ÿ“ก Offline P2P field assistant โ€” delegates heavy AI inference from a phone to a nearby laptop via QVAC's peer-to-peer compute mesh. No cloud, no internet, just local Wi-Fi Direct.

Awesome Lists containing this project

README

          

## ๐Ÿง‘โ€โš–๏ธ For Judges โ€” Review in 5 Steps

> Offline P2P field assistant on `@qvac/sdk`: delegates heavy AI inference from a phone to a nearby laptop via QVAC's peer-to-peer compute mesh. No cloud, no internet, just local Wi-Fi Direct.

1. **The idea** โ€” [The Problem](#-the-problem) & [The Solution](#-the-solution) ยท [Why ONLY QVAC](#-why-only-qvac): **P2P compute delegation** (offload heavy LLM/Vision/RAG to a trusted local peer) + local fallback via `@qvac/sdk`.
2. **Run it** (Native Build Required):
> โš ๏ธ **Expo Go is NOT supported** because `@qvac/sdk` uses custom C++ native modules.
```bash
npm install && python3 scripts/seed.py # install packages and seed the manual
npm run provider # Start laptop provider
npm run ios # Build and launch the real native iOS app
```
Pair phone and laptop natively via QR/NFC โ†’ ask a complex medical or vision query โ†’ watch the inference correctly route to the heavy-compute peer. Real-time UI animations visualize the mesh traffic.
3. **Verify offline:** `python3 scripts/verify_offline.py` (disconnect network first) โ€” cloud-import scan + network isolation.
4. **Tests & metrics:** `npm run ci` โ€” typecheck + **265 unit tests** at 100% coverage (local-vs-delegate router, P2P pairing, RAG citations, multimodal routing, on-device audit log) + **3 E2E suites**. `python3 scripts/bench.py` โ€” inference latency and RAM usage.
5. **No remote APIs** ([docs/REMOTE_APIS.md](docs/REMOTE_APIS.md)) โ€” completion, RAG, TTS, vision, and P2P networking all run locally via `@qvac/sdk`; data never leaves the local mesh.

> โš ๏ธ **Austere Environment Design** โ€” Built for disaster zones and combat triage. The zero-internet P2P delegation, strict network timeouts (preventing UI freeze on packet drop), and fallback routing logic are real and unit-tested.

---


Beacon

Beacon ๐Ÿ“ก


Offline P2P field assistant โ€” delegates heavy AI inference from a phone to a nearby laptop via QVAC's peer-to-peer compute mesh. No cloud, no internet, just local Wi-Fi Direct.


Beacon: Privacy-First AI Mesh for Austere Environments

[![Built for QVAC Hackathon](https://img.shields.io/badge/DoraHacks-QVAC%20Edge%20AI-8b5cf6?style=for-the-badge)](https://dorahacks.io)
[![Track](https://img.shields.io/badge/Track-Mobile-06b6d4?style=for-the-badge)](https://dorahacks.io/hackathon/qvac-unleach-edge-ai-i/tracks/#mobile)
[![Demo Video](https://img.shields.io/badge/Demo-Video_YouTube-FF0000?style=for-the-badge&logo=youtube)](https://youtu.be/148A6cm2VDM)
[![Track](https://img.shields.io/badge/Track-Psy_Models_(MedPsy)-ef4444?style=for-the-badge)](https://dorahacks.io/hackathon/qvac-unleach-edge-ai-i/tracks/#psy-models-medpsy)
[![Download APK](https://img.shields.io/badge/Download-APK%20(Latest_Build)-22c55e?style=for-the-badge&logo=android)](https://nightly.link/edycutjong/beacon/workflows/ci/main/beacon-release-apk.zip)

---

### โš ๏ธ The Problem

In disaster zones, combat triage, and air-gapped enterprises, internet access is dead. Cloud AI is unreachable. First responders need complex AI, but running heavy Local LLMs and Vision Models on a mobile phone drains the battery in 20 minutes and causes severe thermal throttling.

### ๐Ÿ’ก The Solution

Beacon is an offline, peer-to-peer AI mesh. It allows lightweight frontline mobile devices to intelligently **delegate** heavy AI inference (Voice, RAG, Vision) to a high-compute local hub (e.g., a rugged laptop in a medic's backpack) over a local P2P network.

### โšก Key Innovations

* **Zero-Internet P2P Delegation:** Devices discover and pair locally, routing complex LLM queries to a heavy-compute node. Real-time UI animations visualize the mesh traffic.
* **Battle-Tested Fallbacks:** Built for chaotic environments with 90dB noise resilience (automatic high-value triage injection if Whisper STT fails) and strict P2P network timeouts.
* **Grounded RAG:** Hallucinations cost lives. Every response includes verifiable citations from offline databases.

### ๐Ÿ› ๏ธ Technical Complexity

* Custom network routing with `Promise.race()` 5s/10s hard timeouts to prevent UI freezing on packet drop.
* Implemented Out-of-Band (OOB) NFC secure pairing and QR fallbacks.
* 100% Test Coverage across statements, lines, branches, and functions in our CI pipeline.

### ๐Ÿ“ธ Screenshots


Multimodal Photo Analysis
RAG Citations

## ๐Ÿ—๏ธ Architecture & Tech Stack

```mermaid
graph TD
classDef phone fill:#06b6d4,stroke:#0891b2,stroke-width:2px,color:#fff,rx:8,ry:8;
classDef laptop fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#fff,rx:8,ry:8;
classDef sdk fill:#1e293b,stroke:#334155,stroke-width:1px,color:#cbd5e1,rx:5,ry:5;
classDef fallback fill:#22c55e,stroke:#16a34a,stroke-width:2px,color:#fff,rx:5,ry:5;
classDef heavy fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff,rx:5,ry:5;

Phone["๐Ÿ“ฑ Phone App"]:::phone
Laptop["๐Ÿ’ป Laptop Provider"]:::laptop

QvacSmall["@qvac/sdk
(small model)"]:::sdk
QvacLarge["@qvac/sdk
(large model)"]:::sdk

LocalFallback["๐ŸŸข Local fallback"]:::fallback
HeavyInference["๐ŸŸก Heavy inference
(delegate)"]:::heavy

Phone <-->|"Wi-Fi Direct"| Laptop
Phone --> QvacSmall
Laptop --> QvacLarge
QvacSmall --> LocalFallback
QvacLarge --> HeavyInference
```

| Layer | Technology |
|---|---|
| **Mobile App** | Expo 56, React Native 0.85, React 19 |
| **AI Engine** | @qvac/sdk (completion, RAG, TTS, vision, P2P) |
| **Models** | Llama-3.2-1B (general), MedPsy-1.7B (medical triage), SmolVLM2-500M (vision) |
| **Pairing** | QR (expo-camera) ยท NFC (react-native-nfc-manager) ยท `beacon://` deeplink (expo-linking) |
| **Provider** | Node.js daemon (laptop-side) |

## ๐Ÿ† Why ONLY QVAC?

| QVAC SDK Method | Beacon Usage | Cloud Alternative You'd Need |
|---|---|---|
| `startQVACProvider()` | Laptop hosts model for phone peers | AWS Lambda + API Gateway |
| `loadModel({ delegate })` | Phone offloads to laptop provider | OpenAI API + network |
| `completion()` | Local inference on both devices | OpenAI ChatCompletion |
| `ragSearch()` | Context-aware field answers | Pinecone + OpenAI |
| `unloadModel()` | Free RAM after query (critical on phone) | N/A |

**Take QVAC out and you'd need 4 separate cloud services** (OpenAI + Pinecone + AWS + a VPN), plus a stable internet connection โ€” exactly what you don't have in the field.

## ๐Ÿš€ Getting Started

**Prerequisites for iOS (macOS only):**
Because Beacon uses custom native C++ modules (`@qvac/sdk` and `BareKit`), you must have a modern version of CocoaPods (โ‰ฅ 1.14.0) installed to compile the app.
```bash
# If using Homebrew (Recommended)
brew upgrade cocoapods
# OR if using RubyGems
sudo gem install cocoapods
```

**Installation & Run:**
```bash
git clone https://github.com/edycutjong/beacon.git
cd beacon
npm install
python3 scripts/seed.py

# Start laptop provider
npm run provider

# Compile and start the custom native iOS app
npm run ios
```

## ๐Ÿ“Š Benchmarks

Real-world telemetry captured from a physical Android device delegating heavy inference to a laptop provider over local Wi-Fi:

| Metric | Local Fallback | Delegated (P2P) | Improvement |
|---|---|---|---|
| Inference Latency | 215,947ms | ~100,000ms | **2.15ร— Faster** |
| Fallback Switch | 30.5ms | โ€” | <500ms |
| Peak RAM | 17.8 MB | โ€” | <2,048MB |

> *Note: On-device inference on physical mobile hardware is taxing, taking over 3.5 minutes (215s) for a heavy query. P2P delegation successfully offloads the compute to the laptop peer, cutting the latency by more than half and preserving critical mobile battery life in the field.*

## ๐Ÿงช Testing & CI

**265 unit tests (Vitest) at 100% coverage** (statements ยท branches ยท functions ยท lines) covering the local-vs-delegate router, multimodal vision routing, Ed25519 P2P pairing, QR/NFC/deeplink key parsing, the auto-fallback path, the on-device audit log (model loads/unloads ยท TTFT ยท tokens/sec), and the UI components, plus **3 E2E suites (Playwright)** and the offline-verification checks.

## ๐Ÿ” Verification & Compliance

| Gate | Where | How / status |
|---|---|---|
| **No remote APIs** โ€” zero cloud | [`docs/REMOTE_APIS.md`](docs/REMOTE_APIS.md) | `python3 scripts/verify_offline.py` scans for cloud SDKs |
| **Offline proof** โ€” 0 outbound | `scripts/verify_offline.py` | unplug Wi-Fi, then run |
| **Tests** | `npm run ci` ยท `npx playwright test` | 265 unit (100% coverage) + 3 E2E |
| **Benchmarks** | `scripts/bench.py` | โœ… Real ยท reproducible (see `data/bench_results.json`) |
| **Audit log** (model loads/unloads ยท TTFT/tokens/sec) | `src/core/audit.ts` | โœ… auto-captured on every inference; shown in-app + `getAuditSummary()` |

**7-stage pipeline:** Quality โ†’ Security โ†’ Build โ†’ E2E โ†’ Performance โ†’ Offline Verify โ†’ Deploy

```bash
# โ”€โ”€ Evidence Bundle โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
python3 scripts/verify_offline.py
python3 scripts/bench.py
python3 scripts/check_submission_readiness.py

# โ”€โ”€ Advanced Testing โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
npm run e2e # Playwright E2E tests
npm run lighthouse # Lighthouse CI audit
```

| Layer | Tool | Status |
|---|---|---|
| Code Quality | TypeScript strict ยท expo lint | โœ… |
| Unit Testing | Vitest (265 tests ยท 100% coverage) | โœ… |
| E2E Testing | Playwright (3 suites) | โœ… |
| Security (SAST) | CodeQL | โœ… |
| Security (SCA) | Dependabot + npm audit | โœ… |
| Secret Scanning | TruffleHog | โœ… |
| Performance | Lighthouse CI | โœ… |
| Offline Verification | verify_offline.py | โœ… |

## ๐Ÿ“ Project Structure
```
beacon/
โ”œโ”€โ”€ docs/ # README assets
โ”œโ”€โ”€ e2e/ # Playwright E2E specs
โ”œโ”€โ”€ scripts/ # seed, bench, verify, readiness
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ core/
โ”‚ โ”‚ โ”œโ”€โ”€ domain.ts # Medical-query classifier
โ”‚ โ”‚ โ”œโ”€โ”€ manual.ts # Bundled offline field manual (RAG corpus)
โ”‚ โ”‚ โ”œโ”€โ”€ rag.ts # ragSearch + lexical fallback
โ”‚ โ”‚ โ”œโ”€โ”€ qvac.ts # @qvac/sdk wrapper (completion, vision, RAG, TTS, P2P)
โ”‚ โ”‚ โ”œโ”€โ”€ p2p.ts # P2P host/pair lifecycle
โ”‚ โ”‚ โ”œโ”€โ”€ pairingLink.ts # QR/NFC/deeplink key parsing
โ”‚ โ”‚ โ”œโ”€โ”€ nfc.ts # NFC tap-to-pair reader (platform-guarded)
โ”‚ โ”‚ โ”œโ”€โ”€ audit.ts # On-device audit log (loads/unloads ยท TTFT ยท tok/s)
โ”‚ โ”‚ โ””โ”€โ”€ router.ts # Local vs delegate routing (text + vision)
โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”‚ โ”œโ”€โ”€ QRScanner.tsx # Camera QR pairing
โ”‚ โ”‚ โ”œโ”€โ”€ NfcPairModal.tsx # NFC tap-to-pair
โ”‚ โ”‚ โ”œโ”€โ”€ CameraCapture.tsx # Multimodal field-photo capture
โ”‚ โ”‚ โ””โ”€โ”€ Markdown.tsx # Dependency-free markdown renderer
โ”‚ โ””โ”€โ”€ node/
โ”‚ โ””โ”€โ”€ provider.ts # Laptop-side daemon
โ”œโ”€โ”€ App.tsx # Expo UI (pairing ยท query ยท multimodal ยท markdown)
โ”œโ”€โ”€ .github/ # CI/CD + CodeQL + Dependabot
โ””โ”€โ”€ README.md
```

## โœ… Proof Status โ€” Real vs. Simulated

> We draw the line between *proven* and *pending* ourselves, so you don't have to guess. Nothing here is faked โ€” the ๐Ÿ”ถ rows are precisely the parts that need physical phone-plus-laptop hardware we couldn't fully capture in the hackathon window. The orchestration that makes Beacon *Beacon* โ€” the routing, fallback, pairing, RAG and offline guarantee โ€” is real and exhaustively tested.

| Capability | Status | Evidence |
|---|---|---|
| Local-vs-delegate routing + auto-fallback | โœ… Real ยท unit-tested | `src/core/router.ts` โ€” 265 tests, 100% coverage |
| Ed25519 pairing (QR ยท NFC ยท `beacon://` deeplink) | โœ… Real ยท unit-tested | `p2p.ts` ยท `pairingLink.ts` ยท `nfc.ts` |
| Offline RAG citations (bundled field manual) | โœ… Real ยท unit-tested | `rag.ts` ยท `manual.ts` |
| On-device audit log (TTFT ยท tok/s ยท load/unload) | โœ… Real ยท auto-captured | `audit.ts` |
| **100%-offline guarantee** (zero cloud SDKs) | โœ… Real ยท verifiable | `scripts/verify_offline.py` |
| `@qvac/sdk` integration (loadModel ยท completion ยท RAG ยท TTS ยท P2P) | โœ… Real code, to the SDK's documented API | `src/core/qvac.ts` |
| **Delegated-inference token stream** (`loadModel` โ†’ provider โ†’ `completion`) over QVAC P2P/DHT | โœ… Real ยท reproducible | `node scripts/verify_delegation.mjs` โ€” two live `@qvac/sdk` peers, `fallbackToLocal:false`; transcript in [`docs/evidence/`](docs/evidence/delegated-inference.md) |
| Same flow on a **physical phone โ†” laptop over Wi-Fi** (+ real device timings) | โœ… Real ยท verified on-device | Successfully executed full P2P pipeline between a physical Android device and a laptop provider over local Wi-Fi |
| Benchmark timings (latency ยท fallback ยท RAM) | โœ… Real ยท verifiable | run `scripts/bench.py` on-device to reproduce |
| Web preview (Playwright E2E) | ๐Ÿ”ถ Uses a mock `@qvac/sdk` shim | the native bare-kit worker can't run in a browser โ€” **the mobile app loads the real SDK**; `metro.config.js` aliases the mock for `web` only |

### Limitations & Known Constraints
1. Peers must share a local network (Wi-Fi Direct / hotspot) โ€” by design; there is no internet relay.
2. NFC tap-to-pair and camera/vision need a physical device (no simulator); iOS NFC also needs a paid Apple Developer account to sign the entitlement.

## ๐Ÿ“„ License
[MIT](LICENSE) ยฉ 2026 Edy Cu

## ๐Ÿ™ Acknowledgments
Built for **QVAC Hackathon I โ€” Unleash Edge AI** (DoraHacks). Edge AI isn't about one device โ€” it's about a mesh. QVAC makes that possible.