Overview
Off Grid uses native modules to bridge React Native (JavaScript) to high-performance C++ and platform-specific inference engines.llama.rn (Text + Vision Inference)
Upstream: github.com/mybigday/llama.rnWraps: llama.cpp (Georgi Gerganov’s GGUF inference engine)
Platform Support
TypeScript API
Vision Inference (Multimodal)
Vision models require a mmproj file (multimodal projector) containing the CLIP vision encoder weights.Tool Calling Detection
llama.rn introspects the model’s jinja chat template to detect tool calling support.GPU Acceleration
Android: OpenCL (Adreno GPUs)iOS: Metal (Apple GPUs)
On devices with ≤4GB RAM, GPU layers are forced to 0 to prevent
abort() crashes during Metal/OpenCL buffer allocation (see src/services/llmHelpers.ts:getGpuLayersForDevice).whisper.rn (Speech Transcription)
Upstream: github.com/mybigday/whisper.rnWraps: whisper.cpp
Features
- Real-time audio recording and transcription
- Partial results (word-by-word streaming)
- Multiple model sizes: Tiny (39MB), Base (74MB), Small (244MB)
- No network required (100% on-device)
TypeScript API
LocalDreamModule (Android Stable Diffusion)
Path: android/app/src/main/java/ai/offgridmobile/localdream/LocalDreamModule.kt:32Wraps: local-dream C++ library (MNN/QNN backends)
Architecture
LocalDreamModule spawns a subprocess running an HTTP server onlocalhost:18081. The TypeScript layer sends POST requests to /generate, and the server responds with Server-Sent Events (SSE) for progress updates.
Backend Selection
Image Generation Flow
RGB → PNG Conversion
local-dream returns images as base64-encoded raw RGB bytes. LocalDreamModule decodes and converts to PNG:CoreMLDiffusionModule (iOS Stable Diffusion)
Path: ios/CoreMLDiffusionModule.swift:11Wraps: Apple’s
ml-stable-diffusion Swift library
Features
- Neural Engine (ANE) + CPU acceleration
- Supports SD 1.5, SD 2.1, and SDXL models
- DPM-Solver multistep scheduler
- Palettized (6-bit) and full-precision (fp16) models
Model Detection (SD vs SDXL)
SDXL models use a different text encoder (TextEncoder2.mlmodelc). CoreMLDiffusionModule auto-detects and loads the correct pipeline:
Image Generation
PDFExtractorModule
Android (PdfiumAndroid)
Path: android/app/src/main/java/ai/offgridmobile/pdf/PDFExtractorModule.kt:11iOS (PDFKit)
Path: ios/OffgridMobile/PDFExtractor/PDFExtractorModule.swift:4DownloadManagerModule (Android)
Path: android/app/src/main/java/ai/offgridmobile/download/DownloadManagerModule.kt:17Features
- Background downloads via Android’s native
DownloadManager - Progress polling (500ms intervals)
- Persistent download tracking via
SharedPreferences - Automatic cleanup of completed/stale downloads
- System notifications for download progress
Key Methods
DownloadComplete event. Fixed by tracking completedEventSent separately: