Skip to content

feat: Cloud Sync (Hono + Neon) #69

@tomymaritano

Description

@tomymaritano

Overview

Add cloud synchronization with offline-first architecture for Pro tier monetization.

Stack: Hono (API) + Neon (Postgres) + Stripe/Lemon Squeezy (payments)

New Packages

@readied/sync-core

Pure TypeScript sync logic:

src/
  types.ts      # SyncableEntity, SyncChange, SyncConflict
  operations.ts # push(), pull(), merge()
  conflict.ts   # ConflictResolver (last-write-wins)
  queue.ts      # OfflineQueue

@readied/api

Hono backend:

src/
  index.ts
  routes/
    auth.ts           # Magic link authentication
    notes.ts          # GET/POST /sync
    subscription.ts   # Stripe webhooks
  middleware/auth.ts  # JWT verification
  db/schema.ts        # Drizzle schema

API Endpoints

Method Path Description
POST /auth/magic-link Send magic link email
POST /auth/verify Verify token, return JWT
GET /notes/sync?cursor=X Pull changes since cursor
POST /notes/sync Push local changes
POST /subscription/webhook Stripe/Lemon Squeezy

Local SQLite Migration

ALTER TABLE notes ADD COLUMN device_id TEXT;
ALTER TABLE notes ADD COLUMN sync_version INTEGER DEFAULT 0;
ALTER TABLE notes ADD COLUMN last_synced_at TEXT;

CREATE TABLE sync_queue (
  id INTEGER PRIMARY KEY,
  entity_type TEXT,
  entity_id TEXT,
  operation TEXT,
  data TEXT,
  timestamp TEXT,
  synced INTEGER DEFAULT 0
);

CREATE TABLE sync_metadata (key TEXT PRIMARY KEY, value TEXT);

Desktop UI Components

  • syncStore.ts - Zustand store for sync state
  • SyncStatusIndicator.tsx - Cloud icon with status
  • ConflictResolutionModal.tsx - Resolve conflicts
  • LoginModal.tsx - Auth flow

Dependencies

"hono": "^4.0.0",
"@hono/zod-validator": "^0.2.0",
"drizzle-orm": "^0.29.0",
"@neondatabase/serverless": "^0.7.0",
"jose": "^5.2.0"

Estimate

~90 hours (11-12 days)

Pre-requisites

  • Neon account (Postgres)
  • Stripe/Lemon Squeezy account
  • Domain for API (api.readied.app?)
  • Email provider (Resend/SendGrid)

Acceptance Criteria

  • Magic link authentication works
  • Notes sync across devices
  • Offline changes queue and sync later
  • Conflicts detected and resolvable
  • Pro subscription gates sync feature
  • Free tier works fully offline

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions