- TypeScript 77%
- Svelte 10%
- JavaScript 10%
- Lua 2%
- CSS 1%
- 2 more languages <1%
atmo.sh #
SSH public keys, in the Atmosphere. atmo.sh displays the
sh.tangled.publicKey records any
account publishes, and lets signed-in users manage their own.
- Look up anyone at
/<handle>(e.g./bnb.im) or/<did>(e.g./did:plc:uashgn65n5z7aqwk5cbuba5c). Reads come from the HappyView AppView. - Manage SSH public keys from the dashboard. Authenticated with OAuth from any PDS.
- Share anywhere: profile pages carry
at-tags linking the page back
to the Atmosphere, and OpenGraph/Twitter metadata whose image is a
per-profile card rendered on demand at
/<identifier>/opengraph.
Architecture #
| Concern | How |
|---|---|
| Public key pages | GET {HAPPYVIEW_URL}/xrpc/sh.atmo.listPublicKeys?did=… (paginated, X-Client-Key header); when the index has nothing for the DID (or is down), the app reads the repo's PDS directly and, on confirmed drift, asks the instance to backfill the repo |
| Home feed | Same endpoint without the did filter — the endpoint's Lua handler orders by each record's createdAt (not index order, which backfill re-runs rewrite), the app re-sorts by parsed instant; owner handles resolved best-effort within a time budget |
| Share metadata | Profile pages emit at-tags (at:author for the account, one at:alternate per rendered record) plus OpenGraph/Twitter tags whose image is /<identifier>/opengraph: a 1200×630 PNG card (handle, key count, algorithm chips, avatar) built as SVG and rasterized with @resvg/resvg-js using bundled Inter TTFs, so it renders identically in fontless containers; the card degrades line-by-line when the index, profile record, or avatar blob can't be fetched |
| Identity | @atproto/identity: DNS/well-known handle resolution + PLC directory, verified both ways |
| Auth | @happyview/oauth-client-node: atproto OAuth against the user's PDS with HappyView-provisioned DPoP keys; minimal scope atproto repo:sh.tangled.publicKey?action=create&action=delete |
| Dashboard reads | Same HappyView list endpoint as the public pages — write-through keeps it read-your-writes |
| Writes | HappyView write-through procedures sh.atmo.addPublicKey / sh.atmo.deletePublicKey (Lua): proxied to the user's PDS and indexed in the same request, then confirmed by polling the list endpoint before the UI reports success |
| Network events | record.{create,update,delete}:sh.tangled.publicKey Lua record scripts index Jetstream events from outside the app (e.g. tangled): lexicon-invalid records are skipped, updates replace the indexed copy, deletes drop it at once |
| Session | HMAC-signed DID cookie; HappyView OAuth storage in Postgres (DATABASE_URL, jsonb kv table), JSON file store under DATA_DIR in loopback dev/e2e only |
Setup #
npm install
cp .env.example .env # fill in HAPPYVIEW_URL etc.
npm run dev
Browse via http://127.0.0.1:5173 (not localhost, since the atproto loopback
OAuth client requires 127.0.0.1 redirect URIs).
HappyView (one-time) #
Your HappyView instance needs the lexicons in lexicons/: the
sh.tangled.publicKey record lexicon (with backfill, so it indexes the
network's existing keys), the sh.atmo.listPublicKeys query lexicon with its
Lua handler serving the list endpoint newest-createdAt-first, the
sh.atmo.addPublicKey / sh.atmo.deletePublicKey write-through procedures
with their Lua handlers, and the
record.{create,update,delete}:sh.tangled.publicKey record scripts that keep
the index in lockstep with Jetstream events. Register everything with
your instance's admin API key:
HAPPYVIEW_URL=https://your-happyview.up.railway.app HAPPYVIEW_ADMIN_KEY=hv_... npm run happyview:setup
Then create a confidential API client in the HappyView dashboard (server-side
type — public clients are origin-validated and reject requests from a server,
failing sign-in for every account with "Origin header required") and set its
hvc_ key in HAPPYVIEW_CLIENT_KEY and hvs_ secret in
HAPPYVIEW_CLIENT_SECRET. All three HappyView variables are required for
sign-in — the OAuth flow runs through the instance.
Index freshness: writes made through atmo.sh can't drift — the procedures
update the index in the same request as the PDS write. Records created,
updated, or deleted outside the app (e.g. via tangled) arrive over the
firehose and are handled by the record scripts as each event lands:
lexicon-invalid records are kept out of the index, updates replace the indexed
copy (dropping it entirely if the new version is invalid — never serving
stale key material), and deletes remove the row immediately. Backfill order
never leaks into the UI: the list endpoint's Lua handler orders by each
record's createdAt, so canceling and restarting a backfill (which rewrites
index times) cannot resurface old keys at the top of the homepage feed. To
redeploy just the Lua scripts without re-registering lexicons (which would
kick off another backfill), run the setup with -- --scripts-only.
The uploaded copy of the record lexicon deliberately relaxes createdAt to
optional: records written by early tangled (pre-March-2025) carry a legacy
created field instead, and hundreds of real keys on the network would
otherwise be invisible. The record scripts normalize created into
createdAt at index time so every consumer sorts on one field, and the app
maps the legacy field too for records read straight off a PDS.
When the index misses a repo entirely — the backfill hasn't reached it
yet (or was canceled partway), or every one of its events landed while the
instance was down — profile pages, keyfiles, and the dashboard do not report
"no keys". The app falls back to reading the repo's PDS directly
(keys.ts), and if HAPPYVIEW_ADMIN_KEY is set it
also fires a DID-scoped backfill (deduplicated, fire-and-forget) so the index
heals itself for the next viewer. The fallback triggers only when the index
returns zero records for the DID, so indexed repos stay a single AppView
query; the same fallback answers when the AppView is down entirely, so a
HappyView outage degrades to slower pages instead of 502s.
Index drift has two directions, each with a reconcile script. Repos the
index missed entirely (the fallback's case, at network scale — compares the
relay's listReposByCollection against the index and requests DID-scoped
backfills):
HAPPYVIEW_ADMIN_KEY=hv_... npm run happyview:reconcile # dry-run report
HAPPYVIEW_ADMIN_KEY=hv_... npm run happyview:reconcile -- --apply
And index entries whose records were deleted upstream while the instance wasn't listening (checks every indexed repo against its PDS, the source of truth):
HAPPYVIEW_ADMIN_KEY=hv_... npm run happyview:prune # dry-run report
HAPPYVIEW_ADMIN_KEY=hv_... npm run happyview:prune -- --apply
Production #
Set the environment variables from .env.example:
APP_URL=https://atmo.sh(the public origin),COOKIE_SECRET(min 16 chars; required for any non-loopbackAPP_URL, including plain-http origins behind a TLS-terminating proxy — the app refuses to start without it),HAPPYVIEW_URL,HAPPYVIEW_CLIENT_KEYandHAPPYVIEW_CLIENT_SECRET(confidential API client),HAPPYVIEW_ADMIN_KEY(optional but recommended: lets drifted repos self-heal the index on view; a key scoped tobackfill:createis enough),DATABASE_URLpointing at a Postgres database so OAuth sessions survive deploys (required for any non-loopbackAPP_URL— the app refuses to start without it). On Railway: Create → Database → Add PostgreSQL in the project, then on the app service add a variableDATABASE_URL=${{Postgres.DATABASE_URL}}— a reference variable that resolves to the private-network connection string. Thekv_storetable is created automatically on first use.
Leave ALLOW_PRIVATE_NETWORK_FETCH unset in production. PDS endpoints come from
DID documents, which anyone can publish, so outbound fetches to loopback and
private addresses are refused by default (safe-fetch.ts);
only the local dev and e2e setups opt in to reach their mock services.
Build with npm run build and start with npm start (adapter-node; honors
PORT, and set ORIGIN to the public origin — or just reuse APP_URL — so
form actions pass SvelteKit's origin check). OAuth client metadata is served
at /oauth/client-metadata.json automatically once APP_URL is https.
Testing #
npm run test:unit # Vitest: node unit tests + browser-mode component tests
npm run test:e2e # Playwright against the production build + mock HappyView/PLC
npm test # both
npm run test:coverage # V8 coverage (@vitest/coverage-v8) across both Vitest projects
The e2e suite spins up e2e/mock-services.js — a mock
HappyView AppView and PLC directory — so it runs offline and deterministic.
Coverage uses @vitest/coverage-v8 and writes text, HTML, and lcov reports to
coverage/, spanning the node unit tests and the browser-mode component
tests. Route modules are exercised by the Playwright e2e suite, which runs
outside Vitest and therefore doesn't contribute to the coverage report.
Other scripts #
npm run check # svelte-check
npm run lint # prettier + eslint
npm run format # prettier --write