Client development guide¶
How each LibreRing client fits together and where to add code.
Shared concepts¶
| Concept | Web | iOS | Android |
|---|---|---|---|
| Local DB | Dexie (apps/web/src/lib/db.ts) | SQLite (LocalStore.swift) | Room (LibreRingDatabase.kt) |
| Auth port | @librering/sdk AuthService | Supabase Swift (future) / REST | Supabase Kotlin (future) |
| Sync port | SyncService + sync.ts | SyncRepository protocol | SyncRepository interface |
| Blob port | StorageService → Worker | Worker REST | Worker REST |
| BLE protocol | N/A (import only) | OuraProtocol.swift → librering-core | librering-core via UniFFI |
Web (apps/web)¶
Stack: Next.js 16 static export, Dexie, @librering/sdk
| Task | File |
|---|---|
| Add chart | src/app/dashboard/ |
| Import parser | src/lib/ingest*.ts |
| Cloud sync | src/lib/sync.ts |
| Auth | src/lib/auth.ts (wraps SDK) |
Deploys to GitHub Pages at /laughing-chainsaw base path.
iOS (apps/ios/LibreRing)¶
Stack: Swift 6, SwiftUI, CoreBluetooth, HealthKit, SQLite
| Task | Location |
|---|---|
| BLE session | BLE/BLEManager.swift |
| Protocol | BLE/OuraProtocol.swift → migrate to Rust |
| Local storage | Storage/LocalStore.swift |
| Cloud sync | Sync/SyncEngine.swift, Sync/SupabaseSyncRepository.swift |
| HealthKit | Health/HealthKitManager.swift |
Requires physical iPhone (BLE).
Android (apps/android)¶
Stack: Kotlin, Jetpack Compose, Room (scaffold)
TypeScript SDK (packages/sdk-ts)¶
Public API:
import { createLibreRingClient } from "@librering/sdk";
const client = createLibreRingClient({
supabaseUrl: "...",
supabaseAnonKey: "...",
workerUrl: "https://api.librering.dev",
});
await client.auth.signIn(email, password);
await client.sync.push({ deviceId, cursor, batches });
SOLID mapping:
AuthService— interface (Dependency Inversion)SupabaseAuthService— Single ResponsibilityLibreRingClient— Facade for app code
Rust core (core/librering-core)¶
Shared BLE packet parsing and constants. Ported from tools/oura_protocol.py.
UniFFI bindings (Phase 5 stub) will generate Swift/Kotlin bindings for mobile.
Python tools (tools/)¶
Reverse-engineering CLIs — not part of cloud sync. Use for protocol research and hardware testing.
Adding a new metric end-to-end¶
- Add column/table in
backend/supabase/migrations/ - Extend
push_sync_batch/pull_sync_delta - Add Dexie table +
sync.tsmapping - Add SQLite/Room schema on mobile
- Update
packages/api-spec/openapi.yamlschemas
Testing sync locally¶
- Apply Supabase migrations
- Set web
.env.local - Sign up in web app
- Import sample data → Settings → Sync Now
- Verify rows in Supabase Table Editor