From 964f5db60414e737b774584e597d66ba5038490b Mon Sep 17 00:00:00 2001 From: Steve Purves Date: Sun, 12 Apr 2026 10:55:20 +0000 Subject: [PATCH 1/2] fix: show About link on mobile https://claude.ai/code/session_01C5w4RGRwK9tB9DNmtaUwfc --- web/app/routes/home.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/routes/home.tsx b/web/app/routes/home.tsx index 3a58fba..5b391f5 100644 --- a/web/app/routes/home.tsx +++ b/web/app/routes/home.tsx @@ -300,7 +300,7 @@ export default function Home() { About -- knotmirror 0.0.1 From c256a8fbe323c6d8d037dd6271499005a13edaa1 Mon Sep 17 00:00:00 2001 From: Steve Purves Date: Sun, 12 Apr 2026 12:36:59 +0000 Subject: [PATCH 2/2] docs: add blog/at-tracker-technical-context.md with architecture diagram https://claude.ai/code/session_01C5w4RGRwK9tB9DNmtaUwfc --- blog/at-tracker-technical-context.md | 224 +++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 blog/at-tracker-technical-context.md diff --git a/blog/at-tracker-technical-context.md b/blog/at-tracker-technical-context.md new file mode 100644 index 0000000..3229959 --- /dev/null +++ b/blog/at-tracker-technical-context.md @@ -0,0 +1,224 @@ +# AT Proto Collection Tracker — Technical Context + +## What it is + +AT Proto Collection Tracker is a live, bottom-up discovery dashboard for the +AT Protocol (ATmosphere) network. Rather than starting from a curated list of +known apps, it watches every record written to the network in real time and +counts what it sees — surfacing activity by collection type (called NSIDs), +grouped by namespace. + +The core insight: on AT Protocol, every record has a fully-qualified type name +(e.g. `social.attic.post`, `app.bsky.feed.like`). These names are reverse-domain +NSIDs — the domain owner controls the namespace. By aggregating these names from +the live firehose, you get a ground-truth picture of what applications exist and +how active they actually are, including apps that have never been publicly +announced. + +Live at: **https://at-tracker.opensci.dev** + +--- + +## Architecture + +```mermaid +flowchart TD + JS[Jetstream WebSocket\nfirehose] -->|commit events| HP + + subgraph relay["Relay (Node.js)"] + HP[Hot path\nin-memory Maps & Sets] + HP -->|every 5s| FW[Flush worker\nbatched upsert] + HP -->|enqueue DID| RQ[Resolution queue\nSet of DIDs] + RQ -->|every 2s, 100 DIDs| PR[PDS resolver\n10 concurrent fetches] + end + + PR -->|did:web| INF[Infer from DID string] + PR -->|did:plc| PLC[plc.directory\nW3C DID document] + INF --> DC + PLC --> DC + + FW -->|INSERT ON CONFLICT| PG[(PostgreSQL)] + DC[DID → PDS host] -->|cache write| PG + + subgraph web["Web (React Router v7 SSR)"] + LDR[Loader\nCTE + window functions] + UI[SSR page\nURL-driven state] + LDR --> UI + end + + PG -->|queries| LDR + + subgraph infra["Infrastructure"] + CD[Caddy\nreverse proxy + TLS] + DC2[Docker Compose] + HZ[Hetzner CX22\n~€5/mo] + end + + UI --> CD + CD -->|HTTPS| USR[User] + + GH[GitHub Actions\npush to main] -->|build & push| DH[Docker Hub\nimage] + DH -->|docker compose pull| DC2 + DC2 --> HZ +``` + +--- + +## Key features + +### Live namespace directory +- Domains (two-segment NSID prefixes, e.g. `social.attic`) shown as cards with + record counts, collection counts, PDS distribution, and first/last seen timestamps +- Grid (default) and list views +- Sort by first seen (default), last seen, or record count +- Filter/search by collection name +- Toggle to hide `app.bsky.*` to see the rest of the ecosystem clearly +- Counts update continuously — the page reflects the database state at load time + +### Domain detail pages +Each namespace card links to a detail page (`/domain/:domain`) showing: +- All collection types within the namespace with individual record counts and + relative bar charts +- Per-collection PDS (Personal Data Server) host distribution — how many records + of each type came from each hosting provider, shown as badges linking to pdsls.dev +- First/last seen timestamps per collection +- A "sample record" link to the most recently seen record of each type + +### AT record viewer +`/at/*` accepts any AT URI (`at://did.../collection/rkey`) and: +- Resolves the DID to its PDS host (via local cache or plc.directory) +- Fetches the record live from the PDS using `com.atproto.repo.getRecord` +- Renders it as interactive syntax-highlighted JSON with AT URIs and https URLs + linkified +- Falls back gracefully with a pdsls.dev link if the PDS is unreachable + +### About page with live system stats +Real-time counts from the database and relay process: +- Total records seen, collection types, namespaces, PDSs observed +- DID cache size (in-memory), DID resolution queue depth +- Cumulative resolved/failed DID counts for the current relay run + +### SEO +- Meta tags and Open Graph tags on all routes +- Dynamic `sitemap.xml` with every known domain URL (up to 5,000 entries) + +--- + +## How the relay works + +### Non-blocking hot path + +The WebSocket message handler does zero I/O. It only touches in-memory +structures: a `Map` for collection stats, a `Map` +for the DID cache, and a `Set` for the resolution queue. It returns +immediately after updating these structures. + +This pattern keeps up with the full AT Protocol firehose — thousands of events +per second — on a €5/month server. + +### Flush worker + +Runs every 5 seconds. Atomically swaps the in-memory buffer out, then executes +a single `INSERT ... ON CONFLICT DO UPDATE` multi-row upsert to Postgres — one +query per flush regardless of how many distinct names were seen. On error, the +buffer is restored so no events are silently dropped. + +### PDS resolver + +Runs every 2 seconds in a separate interval. Drains up to 100 DIDs from the +queue and resolves them in parallel batches of 10 with a 50ms gap between +batches (politeness to plc.directory). + +- `did:web:*` — host inferred directly from the DID string, no HTTP needed +- `did:plc:*` — fetches `https://plc.directory/{did}` and parses the W3C DID + document (`service` array, `#atproto_pds` entry, `serviceEndpoint` field) + +**Throughput:** ~50 DIDs/second → fills the active-user cache within a few hours +of a fresh deploy. + +Resolved mappings persist in `did_pds_cache` (Postgres) and are held in-memory +for O(1) lookup. The cache loads from Postgres on startup (last 7 days) and is +pruned monthly. + +--- + +## Web frontend + +React Router v7 in full SSR mode. All UI state is URL-driven — no client-side +state for filters, sort, pagination, or view mode. Every page state is shareable, +bookmarkable, and crawlable. + +**Domain grouping** happens in SQL: + +```sql +split_part(name, '.', 1) || '.' || split_part(name, '.', 2) +``` + +e.g. `social.attic.post` → prefix `social.attic` → URL `https://attic.social` + +**Main query** uses a CTE with window functions to avoid separate count queries: +- `COUNT(*) OVER ()` for total domain count +- `MAX(total_count) OVER ()` for the global max used to calibrate bar widths +- A second parallel query fetches all collections for visible cards via + `= ANY($domains_array)` — one round-trip for the full page + +**URL parameter defaults** follow a clean-URL convention: the most common state +(grid view, sort by first seen, descending, hide bsky) produces the shortest URL +(`/`). Non-default states emit explicit params (`view=list`, `sort=count`, etc.). + +--- + +## Database schema (key tables) + +| Table | Purpose | +|---|---| +| `collection_stats` | `name`, `count`, `first_seen`, `last_seen`, `last_at_uri` | +| `collection_pds` | `collection`, `pds_host`, `count` — per-collection PDS attribution | +| `did_pds_cache` | `did`, `pds_host`, `updated_at` — DID resolution cache | + +--- + +## Infrastructure + +| Layer | Choice | Cost | +|---|---|---| +| Server | Hetzner CX22 — 2 vCPU / 4 GB RAM / 40 GB SSD | ~€4.35/mo | +| IP | Static IPv4 | ~€0.50/mo | +| Provisioning | Terraform + cloud-init | — | +| Runtime | Docker Compose — `app`, `postgres`, `caddy` | — | +| TLS | Caddy — automatic Let's Encrypt | — | +| CI/CD | GitHub Actions → Docker Hub on push to `main` | free | +| **Total** | | **~€4.85/mo** | + +Deploy is a single script (`deploy.sh`) that syncs config files and restarts +the app container. Postgres and Caddy are never restarted during a normal deploy +— no downtime, no cert re-issue. + +--- + +## What makes it technically interesting + +**Non-blocking firehose processing.** The WebSocket message handler does zero I/O. +All accumulation is in memory; all persistence is deferred to a background worker. +This pattern can keep up with the full AT Protocol firehose on a €5/month server. + +**Bottom-up discovery.** Most AT Protocol tooling starts from known apps or known +DIDs. This tool inverts that — it watches what records are actually being written +and surfaces namespaces from the data. A brand-new app shows up the moment its +first user creates a record, with no announcement required. + +**DID resolution at scale.** Every AT Protocol user has a DID but the network +doesn't broadcast which PDS they use. Resolving DIDs in bulk without blocking the +event loop — batched parallel fetches, politeness limits, a persistent cache, +warm startup from the database — is a non-trivial systems problem at even modest +scale. + +**AT Protocol's open-world assumption.** Unlike Web2 platforms, AT Protocol has no +central app registry. The NSID namespace system (reverse-domain, developer-owned) +means the full ecosystem is only visible by watching the firehose. This tracker +gives a ground-truth view of what is actually being built and used across the +network. + +**Single-binary simplicity.** The relay and web app run in the same Docker image. +The relay starts as a background process alongside the Node.js web server — one +container to pull, one to restart, one set of logs to watch. -- knotmirror 0.0.1