Skip to content
Back to skills

Local First Architecture

ASecurity

Use when Local-first architecture guidance for instant-feeling web & desktop apps, optimistic updates, IndexedDB sync engines, offline operation, and Conflict-free Replicated Data Types (CRDTs).

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
ai-agentsbashsqlreactnextjsdatabase

Works with

  • cursor
  • cli

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add Harmitx7/tribunal-kit --skill local-first-architecture --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Local First Architecture?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Local First Architecture
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/harmitx7-local-first-architecture-tribunal-kit/badge)](https://www.skillsdirectory.com/skills/harmitx7-local-first-architecture-tribunal-kit)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: local-first-architecture
description: "Use when Local-first architecture guidance for instant-feeling web & desktop apps, optimistic updates, IndexedDB sync engines, offline operation, and Conflict-free Replicated Data Types (CRDTs)."
version: 5.0.0
last-updated: 2026-09-13
skills:
  - react-specialist
  - nextjs-react-expert
  - baseline-ui
tools: Read, Grep, Glob, Bash, Edit, Write
scripts-binding:
  - .agent/scripts/lint_runner.js
  - .agent/scripts/verify_all.js
---

# Local-First Architecture β€” Instant UI & Sync Engines

---

## πŸ› οΈ Technical Architecture & Reference Recipes

---

## 2026 Local-First Architecture & Sync Invariants

1. **OPFS (Origin Private File System) for WASM SQLite**:
   Always prefer OPFS sync access handles for SQLite in web workers. It delivers native near-SSD read/write speeds that dwarf standard IndexedDB overhead.
2. **Idempotency Key Protocol**:
   Every local mutation must generate an `idempotencyKey` (UUID v7). The server stores processed keys for 24h, discarding replays during network flushes.
3. **Delta Sync over Full Sync**:
   Never download entire tables. Use incremental sync cursors (`last_synced_version_id`) and stream compact binary deltas via WebSockets or SSE.

## Hallucination Traps (Read First)

- ❌ Blocking UI render on a remote fetch in a local-first app β†’ βœ… Render local cache immediately; reconcile in background
- ❌ Mutating server state without an idempotency key β†’ βœ… Flushed network retries will duplicate records
- ❌ Putting heavy SQLite WASM operations on the browser main thread β†’ βœ… Always run local DB queries inside a Dedicated Web Worker
- ❌ Storing unindexed large blobs inside IndexedDB β†’ βœ… Store blobs in OPFS; keep metadata in local SQLite/IndexedDB

---

## 4 Pillars of Local-First Architecture

### 1. Read & Write Local First

- **Zero Network Latency**: UI queries (`select * from tasks`) run synchronously or near-instantaneously against in-memory or IndexedDB caches.
- Mutations update the local cache immediately (_optimistic write_), appending a mutation log item to an outbound sync queue.

### 2. Outbound Mutation Queue & Idempotency

- Store mutation logs in a persistent local queue (`IndexedDB` / `SQLite`).
- Assign every client mutation a unique UUID (`idempotencyKey`).
- When network connection is restored, flush queue items sequentially with automatic retry on 5xx failures.

### 3. Conflict Resolution (CRDTs & LWW)

- **Last-Write-Wins (LWW)**: Timestamp + Client ID ordering for simple fields.
- **CRDTs (Yjs / Automerge)**: Conflict-free Replicated Data Types for collaborative text editing and array state.

### 4. Background Delta Streaming

- Receive database updates via WebSockets or Server-Sent Events (SSE) as thin binary deltas (`sync_version > client_version`), applying changes to local storage without re-fetching full datasets.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…