local-first

Local-first architecture decision framework for web applications. Covers when to go local-first vs server-based vs hybrid, sync engine selection (ElectricSQL, Zero, PowerSync, Replicache, LiveStore, Triplit), client-side storage options (IndexedDB, OPFS, SQLite WASM, PGlite), and conflict resolution strategies (LWW, CRDTs, server-wins, field-level merge). Use when deciding whether to adopt local-first architecture, choosing a sync engine, selecting client storage, or designing conflict resolution strategies.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "local-first" with this command: pnpm dlx skills add oakoss/agent-skills

Local-First

Overview

Local-first is an architecture where the application reads and writes to a local database, with changes syncing to the server in the background. The local database is the source of truth for the UI, providing instant reads, offline support, and optimistic writes by default.

When to use: Collaborative apps needing offline support, latency-sensitive UIs where instant response matters, apps with unreliable network conditions, real-time multiplayer features, mobile apps with intermittent connectivity.

When NOT to use: Simple CRUD apps with reliable connectivity, server-authoritative workflows (payments, inventory), content-heavy sites with minimal interactivity, apps where data freshness from the server is critical on every render.

Quick Reference

DecisionOptionsKey Consideration
Architecture modelServer-based, local-first, hybridOffline needs and latency tolerance drive the choice
Read pathServer fetch, local DB read, cache-then-networkLocal reads are instant; server reads block on network
Write pathServer mutation, optimistic update, local-first writeLocal writes never fail; sync handles delivery
Sync engineElectric, Zero, PowerSync, Replicache, LiveStorePostgres integration vs framework-agnostic
Client storageIndexedDB, OPFS, SQLite WASM, PGliteCapacity limits, query capability, browser support
Conflict resolutionLWW, CRDTs, server-wins, field-level mergeComplexity vs correctness tradeoff
Data modelNormalized tables, document store, CRDT documentsQuery patterns determine the best model
Partial replicationShapes, subscriptions, query-based syncSync only what the client needs
Progressive enhancementServer-first with local cache, full local-firstStart simple, add local-first incrementally
CQRS separationSeparate read/write models, unified modelLocal-first naturally separates reads from writes
Initial syncFull snapshot, incremental, progressive loadingFirst-load performance vs completeness
Auth integrationToken-based shape filtering, row-level securitySecurity lives at the sync layer, not the client
Schema evolutionAdditive migrations, versioned shapesLocal DB schema must evolve without data loss
State managementReplace React Query, coexist, hybrid approachLocal-first can replace or complement server state
Testing strategyMock sync engine, test offline scenarios, seed local DBTest both online and offline code paths

Common Mistakes

MistakeCorrect Approach
Going local-first for simple CRUD appsUse server-based architecture unless offline/latency is a real need
Choosing a sync engine before defining data modelDefine read/write patterns first, then pick the engine that fits
Ignoring conflict resolution until lateDesign conflict strategy alongside data model from the start
Syncing entire database to every clientUse partial replication (shapes, subscriptions) for relevant data
Treating local DB as a cacheLocal DB is the source of truth for the UI, not a cache layer
Using CRDTs for everythingLWW or server-wins is simpler and sufficient for most fields
Skipping progressive enhancementStart server-first, add local-first for high-value interactions
Not planning schema migrationsLocal databases need migration strategies just like server DBs

Delegation

If the electricsql skill is available, delegate ElectricSQL setup, shapes, auth, and write patterns to it. Otherwise, recommend: pnpm dlx skills add oakoss/agent-skills -s electricsql -a claude-code -y If the realtime-sync skill is available, delegate WebTransport, pub/sub, and CRDT implementation details to it. If the tanstack-db skill is available, delegate collection setup, live queries, and optimistic mutation patterns to it. Otherwise, recommend: pnpm dlx skills add oakoss/agent-skills -s tanstack-db -a claude-code -y If the tanstack-start skill is available, delegate server function proxies and SSR integration to it. Otherwise, recommend: pnpm dlx skills add oakoss/agent-skills -s tanstack-start -a claude-code -y

  • Architecture review: Use Plan agent to evaluate local-first vs server-based tradeoffs
  • Sync engine comparison: Use Explore agent to research current engine capabilities
  • Storage benchmarking: Use Task agent to test storage options for specific data patterns

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

github-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

tanstack-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

typescript-patterns

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

tanstack-devtools

No summary provided by upstream source.

Repository SourceNeeds Review