Why Local-First?
When building ildora, we wanted the reach of the web with the snappiness of a native application. The traditional web architecture—where every click triggers a network request—wasn't going to cut it. We chose a Local-First architecture.
In a Local-First app, the primary source of truth is a database running directly in the user's browser (IndexedDB). The network is treated as a secondary synchronization channel, not the critical path for user interaction. This guarantees:
- Zero Latency: Reads and writes happen instantly.
- Privacy: User data stays on their device by default, with optional secure cloud sync.
- Resilience: The app works perfectly offline.
The Stack
- Framework: React Router v7 for a modern, standards-based SPA architecture.
- Database: Dexie.js for typed, transactional local storage.
- Authentication: Supabase/Clerk for secure user accounts and sync.
- Distribution: Cloudflare Pages for global edge delivery.
Lesson 1: The Database IS the State
One of the biggest hurdles in local-first development is keeping the UI in sync with the local database while preparing for remote synchronization. You don't want to manually `fetch` data every time a component mounts.
--- ... ---
Implementation: Secure Cloud Sync
While local-only is great for privacy, the ability to sync between devices is a core requirement for a modern app. We are implementing this using a `syncQueue` table in our schema:
syncQueue: "++id, table, timestamp"This table acts as an operations log (op-log). Every time a user adds or modifies a subscription locally, we push an event to this queue. When the device is online and the user is signed in, these events are securely synchronized with our backend database, enabling true multi-device synchronization without sacrificing the local-first speed.
Conclusion
Building ildora has reinforced that Local-First is about giving users the best of both worlds. By treating the browser's IndexedDB as the primary source of truth and using the cloud as a secure, optional synchronization layer, we've built an app that is fast, robust, and respects user privacy.