maarcadetweet: initial commit

AT Protocol PDS + AppView + Tauri Desktop Client, 160-char post limit.

- PDS (Rust + axum + sqlx)
  - Auth: createAccount, createSession, refreshSession
  - Records: createRecord, deleteRecord (race-safe via SELECT FOR UPDATE)
  - Feed: feed.like.create, feed.repost.create
  - Sync: getRepo, getBlocks, getLatestCommit, getRecord (with MST proof), listRepos
  - Identity: resolveHandle
  - MST: spec-conformant (at-mst crate, 27 tests)
  - Repo: signed commits, TID counter (monotonic, 4096 wrap safe)

- AppView (Rust + axum + sqlx)
  - Jetstream consumer (WebSocket, exponential backoff, 38k+ events indexed)
  - REST API: timeline/home (graph-aware), profile, search, post (with thread hydration)
  - Handle-sync worker (did:plc + did:web)
  - JSONB embed storage + thread columns (migration 0003)
  - Like/repost counter cache (migration 0004)

- Tauri 2 + Svelte 5 Desktop Client
  - System tray (Show/Compose/Quit menu)
  - OS notifications (tauri-plugin-notification)
  - Auto-update (tauri-plugin-updater, placeholder endpoint)
  - Window-state (tauri-plugin-window-state)
  - 160-char compose with live counter
  - Image/Link embed rendering
  - LocalStorage-persisted like state
  - Timeline with poll (prepend new posts)
  - Custom TitleBar (transparent, no decorations)
  - Orange/IBM Plex Mono maarcade design

Tests: 231 Rust + 9 vitest = 240 passed.
This commit is contained in:
tomdebone
2026-07-05 20:01:31 +02:00
commit c586fd39c9
134 changed files with 35279 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
-- AppView database schema (initial)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- =====================================================
-- posts
-- =====================================================
CREATE TABLE posts (
uri TEXT PRIMARY KEY, -- at://did/rkey/app.twi.post
did TEXT NOT NULL,
handle TEXT NOT NULL,
rkey TEXT NOT NULL,
collection TEXT NOT NULL, -- app.twi.post | app.bsky.feed.post
text TEXT NOT NULL,
cid TEXT NOT NULL,
parent_uri TEXT, -- reply parent
root_uri TEXT, -- thread root
langs TEXT[],
indexed_at TIMESTAMPTZ NOT NULL DEFAULT now(),
created_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX posts_did_idx ON posts (did);
CREATE INDEX posts_created_at_idx ON posts (created_at DESC);
CREATE INDEX posts_collection_idx ON posts (collection);
CREATE INDEX posts_parent_idx ON posts (parent_uri) WHERE parent_uri IS NOT NULL;
CREATE INDEX posts_root_idx ON posts (root_uri) WHERE root_uri IS NOT NULL;
-- =====================================================
-- likes
-- =====================================================
CREATE TABLE likes (
uri TEXT PRIMARY KEY,
did TEXT NOT NULL,
post_uri TEXT NOT NULL,
post_cid TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
indexed_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX likes_post_idx ON likes (post_uri);
CREATE INDEX likes_did_idx ON likes (did);
-- =====================================================
-- reposts
-- =====================================================
CREATE TABLE reposts (
uri TEXT PRIMARY KEY,
did TEXT NOT NULL,
post_uri TEXT NOT NULL,
post_cid TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
indexed_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX reposts_post_idx ON reposts (post_uri);
CREATE INDEX reposts_did_idx ON reposts (did);
-- =====================================================
-- follows
-- =====================================================
CREATE TABLE follows (
follower_did TEXT NOT NULL,
subject_did TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
indexed_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (follower_did, subject_did)
);
CREATE INDEX follows_subject_idx ON follows (subject_did);
-- =====================================================
-- timeline cache (materialized per-user timelines)
-- =====================================================
CREATE TABLE timeline_cache (
did TEXT NOT NULL,
post_uri TEXT NOT NULL,
score DOUBLE PRECISION NOT NULL,
ranked_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (did, post_uri)
);
CREATE INDEX timeline_did_score_idx ON timeline_cache (did, score DESC, ranked_at DESC);
-- =====================================================
-- search (simple trigram)
-- =====================================================
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX posts_text_trgm_idx ON posts USING GIN (text gin_trgm_ops);
-- =====================================================
-- jetstream cursor
-- =====================================================
CREATE TABLE jetstream_cursor (
id INTEGER PRIMARY KEY DEFAULT 1 CHECK (id = 1),
cursor BIGINT NOT NULL DEFAULT 0,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
INSERT INTO jetstream_cursor (id, cursor) VALUES (1, 0);
@@ -0,0 +1,15 @@
-- AppView database migration 0002
-- Adds pagination indexes that support the keyset `(indexed_at DESC, uri DESC)`
-- ordered queries used by /api/timeline/home and /api/profile. Without these,
-- every page request triggers a full table scan + sort.
--
-- Also fixes an UPSERT bug: re-indexing the same post rewrote `indexed_at`,
-- which shifted the row in the pagination order and caused mid-pagination
-- users to silently skip or duplicate posts.
CREATE INDEX IF NOT EXISTS posts_collection_indexed_at_uri_idx
ON posts (collection, indexed_at DESC, uri DESC);
CREATE INDEX IF NOT EXISTS posts_did_indexed_at_uri_idx
ON posts (did, indexed_at DESC, uri DESC)
WHERE collection IN ('app.twi.post','app.bsky.feed.post');
@@ -0,0 +1,38 @@
-- AppView database migration 0003
-- Adds embed + thread-context columns to `posts`.
--
-- Why
--
-- Phase 4 (indexer) only stored `text` + `parent_uri` + `root_uri`, which
-- was enough to render plain-text timelines. Phase 5 wants embeds (images,
-- link cards, quoted posts) and thread context visible in the UI.
--
-- Columns
-- embed JSONB, nullable — the full AT-Protocol embed
-- object as it appears in the record value. We
-- store the whole thing verbatim rather than
-- normalising into a separate `embeds` table so
-- the UI can decode it without a second round
-- trip, and so a future lexicon change doesn't
-- require a schema migration.
-- reply_parent_handle TEXT, nullable — display handle for
-- `parent_uri`'s author. Backfilled by the
-- handle-sync worker. Nullable because the
-- sync worker hasn't seen the row yet, OR
-- because the parent isn't in our index.
-- reply_root_handle TEXT, nullable — display handle for
-- `root_uri`'s author. Same semantics.
-- reply_root_uri TEXT, nullable — duplicate of `root_uri`
-- for the "show full thread" link target.
-- Kept as its own column so the index covers
-- it without having to special-case NULLs on
-- the existing `root_uri`.
--
-- All columns are nullable. Pre-existing rows will continue to render
-- correctly — old posts simply have `embed = NULL` and the UI omits the
-- embed block.
ALTER TABLE posts ADD COLUMN IF NOT EXISTS embed JSONB;
ALTER TABLE posts ADD COLUMN IF NOT EXISTS reply_parent_handle TEXT;
ALTER TABLE posts ADD COLUMN IF NOT EXISTS reply_root_handle TEXT;
ALTER TABLE posts ADD COLUMN IF NOT EXISTS reply_root_uri TEXT;
@@ -0,0 +1,45 @@
-- AppView migration 0004: like/repost counter cache + uniqueness
--
-- Phase 5b review identified two issues:
-- H3 — Users could spam `feed.like.create` against the same post because
-- the `likes` PK is just `uri` (the like's own rkey). Adding a
-- partial unique index lets us short-circuit "already liked" at the
-- DB layer instead of relying on caller discipline.
-- H6 — `SELECT COUNT(*) FROM likes WHERE post_uri = $1` on every post fetch
-- doesn't scale. We add a denormalized counter on `posts` that's
-- kept consistent by the AppView's own ingest path. Jetstream-driven
-- upserts touch this too. The PDS path goes through ingest-commit
-- which routes through the same code.
--
-- Idempotent: dedup likes/reposts first (real-world Jetstream replays can
-- leave duplicates). Keep only the oldest row per (did, post_uri).
-- dedup likes: keep only the lowest uri per (did, post_uri)
DELETE FROM likes a USING likes b
WHERE a.did = b.did
AND a.post_uri = b.post_uri
AND a.uri > b.uri;
-- dedup reposts: same approach
DELETE FROM reposts a USING reposts b
WHERE a.did = b.did
AND a.post_uri = b.post_uri
AND a.uri > b.uri;
CREATE UNIQUE INDEX IF NOT EXISTS likes_did_post_uri_idx
ON likes (did, post_uri);
CREATE UNIQUE INDEX IF NOT EXISTS reposts_did_post_uri_idx
ON reposts (did, post_uri);
ALTER TABLE posts ADD COLUMN IF NOT EXISTS like_count BIGINT NOT NULL DEFAULT 0;
ALTER TABLE posts ADD COLUMN IF NOT EXISTS repost_count BIGINT NOT NULL DEFAULT 0;
-- Backfill: compute current counts from the now-deduped rows so the
-- column matches reality on upgrade. Wrapped in a single statement so
-- it's fast even on 100k+ rows.
UPDATE posts p
SET like_count = COALESCE((SELECT COUNT(*) FROM likes WHERE post_uri = p.uri), 0),
repost_count = COALESCE((SELECT COUNT(*) FROM reposts WHERE post_uri = p.uri), 0);
CREATE INDEX IF NOT EXISTS posts_count_idx ON posts (like_count DESC, repost_count DESC);