README.md

CorkboardSvelteKit — Chicago Action Corkboard (SvelteKit port) #

A SvelteKit port of CorkboardFrontend (the React SPA) — the same cork bulletin-board calendar of community.lexicon.calendar.event records — plus AT Protocol sign-in so the account owner can create and delete posts (event records, and reposts) straight from the board.

It renders events published by a preconfigured account (default corkboard.at) as a week calendar, and follows the account's pointer records (at.corkboard.alpha.repost, town.laugh.user.listitem) to events on other accounts. All reads still happen from the browser over public XRPC — no backend involved.

The header is a two-row sticky toolbar that a centre pull tab can hide to reclaim the screen space:

  • Row 1 — the account being read, with its avatar (tap it to switch board: a typeahead, the independent typeahead.waow.tech atproto actor search called straight from the browser, CORS-enabled, that routes to another account's corkboard via its #/p/<handle>), and on the right a menu (sign in/out, Create Event, My board, Contact, About).
  • Row 2 — the date navigation (week shifters / Today), and on the right the funnel filter button that opens the filter/view drawer.

The centre pull tab controls pinning: pinned (the default), the toolbar is sticky and stays put while you scroll; unpinned, it scrolls away with the board and comes back at the very top. The tab itself stays pinned (fixed) in both cases, but is hidden while the unpinned toolbar is fully on screen — there's nothing to pull then. Scrolling never changes that toggle. Both the board switcher and the menu's sign-in field use the same typeahead (src/lib/components/HandleTypeahead.svelte).

What SvelteKit adds is a thin server layer for OAuth + writes:

  • /oauth/login?handle=… → starts an AT Protocol OAuth sign-in (302 to the account's PDS authorization server)
  • /oauth/callback → exchanges the code, stores the session, sets the did cookie
  • /oauth/logout (POST) → revokes the session, clears the cookie
  • /oauth/client-metadata.json → the OAuth client metadata document (its URL is the client_id)
  • /oauth/jwks.json → the public JWKS for the confidential client
  • /api/session → the signed-in DID for the client UI
  • /api/events/create (multipart POST) → create an event record in the signed-in user's repo (see below)
  • /api/events/delete (POST { uri }) → delete a record, guarded server-side (see below)

Sign in, creating & deleting #

Sign-in/out lives in the header menu (the funnel filter button is filters/view only): Sign in expands in place to a handle field (with the same typeahead suggestions as the board switcher); once signed in the menu shows the account and Sign out. Editing and deleting work while you're signed in as the account whose repo you're viewing:

  • own event records (community.lexicon.calendar.event) — the event modal shows Edit event and Delete event (two-step confirm)
  • own reposts (at.corkboard.alpha.repost) — the modal for a reposted event shows Remove repost

Both go through POST /api/events/delete, which only acts when the session's DID matches the record's repo, the collection is in the allowlist above, and the at-uri parses — so a signed-in viewer can never delete records that aren't their own. Laugh-list items are favorites managed from the admin app, so they aren't deletable here.

When you're signed in and viewing someone else's board, the event modal also offers ↻ Repost: a small form with optional extra tags that writes an at.corkboard.alpha.repost (a strong ref to the event, plus the tags) into your repo via POST /api/reposts/create. The tags are merged into the event's tags when your board resolves the repost, so you can file another account's event under your own themes; re-submitting the form retags the existing repost rather than duplicating it.

The Create Event item in the header menu opens a modal:

  • signed in — a field-by-field submission form (ported from CorkboardCalAdmin's CreateEventView): name/description, America/Chicago wall-clock start/end, mode/status, an address, source links, and an optional flyer image. The server (POST /api/events/create) interprets the times, measures + WebP-converts the flyer (when smaller), uploads it as a PDS blob (media: role "flyer"), validates the record with @atproto/lex-document against the bundled lexicon JSONs, and writes it to the signed-in user's repo.
  • signed out — the modal explains how to submit events to the community calendars instead (The Jungle submit form, and the Chicago Activism Hub's new-post page), since that's how events normally reach the board.

Edit event opens the same form prefilled from the stored record (times converted back into America/Chicago wall clock) and saves via POST /api/events/update — a putRecord with the same repo/collection guards as delete (and a swapRecord check against concurrent edits). Only the fields the form owns are replaced; the rest of the record (createdWith, origin, facets, non-address locations, and the existing flyer unless it's replaced or removed) is preserved, and source links keep their stored names for URLs that survive the edit.

Scopes requested:

atproto repo:community.lexicon.calendar.event repo:at.corkboard.alpha.repost blob:image/webp blob:image/png blob:image/jpeg

Both collection scopes omit action (create/update/delete): the board creates events, creates and retags reposts, and deletes its own events and reposts. After a scope change you must sign out and re-authorize — existing tokens don't gain scopes retroactively.

The OAuth machinery (src/lib/server/auth/*) is a direct port of CorkboardCalAdmin's: loopback client in dev, confidential private_key_jwt client when PUBLIC_URL + PRIVATE_KEY are set. Sessions live in memory (dev) or SQLite (SESSION_DB_PATH, Node ≥ 23.4).

Running #

Requires Node 20+ (tested on 24).

npm install
npm run dev     # dev server on http://127.0.0.1:5173

The dev server binds to a loopback literal (see vite.config.ts) because that's where the OAuth flow redirects — open http://127.0.0.1:5173, not localhost. (RFC 8252 forbids localhost as a loopback redirect host; the app redirects to the IP literal it's bound to.) If 5173 is taken, set PORT (the OAuth redirect URIs follow it).

Prefer the IPv6 loopback? Bind to ::1 and open the [::1] URL:

DEV_HOST=::1 npm run dev   # → http://[::1]:5173

Both loopback literals (127.0.0.1 and [::1]) are registered in the dev OAuth client, and the login route picks whichever matches the request — so the two commands above each round-trip end-to-end. localhost itself won't work as a redirect target even when it resolves to ::1; use the literal form instead.

Production #

The app builds with @sveltejs/adapter-node (npm run build → build/), so the OAuth endpoints run behind the same Node server. Configure:

Env var Purpose
PUBLIC_URL Public base URL (e.g. https://chicago.corkboard.at) — required with PRIVATE_KEY
PRIVATE_KEY ES256 PKCS#8 PEM (BEGIN PRIVATE KEY) used to sign OAuth assertions. openssl ecparam -genkey emits SEC1 (BEGIN EC PRIVATE KEY), which JoseKey.fromPKCS8 rejects — convert with openssl pkcs8 -topk8 -nocrypt
SESSION_DB_PATH Persistent OAuth sessions via node:sqlite (Node ≥ 23.4); without it sessions live on globalThis
PUBLIC_ACCOUNT Default account whose repo the calendar reads (default corkboard.at)
PUBLIC_PDS_URL Bootstrap PDS for resolution (default https://bsky.social)
PUBLIC_MAX_RECORDS Safety cap when paging listRecords (default 2000)
TOKEN_* Build-time design-token overrides, e.g. TOKEN_HIGHLIGHT=#e11d48 (see below)

adapter-node assumes https origins (set PROTOCOL_HEADER / HOST_HEADER, e.g. x-forwarded-proto/x-forwarded-host, if you proxy plain http). Run npm run dev for local http testing — SvelteKit's CSRF form check is disabled (svelte.config.js) because the SameSite=Lax session cookie is the real cross-site defense; the create route adds its own explicit same-origin check instead.

PUBLIC_URL also fixes the OAuth redirect: the confidential client registers exactly ${PUBLIC_URL}/oauth/callback, and the login/callback routes use that — never the request Host, which behind a reverse proxy is the internal host. Point PUBLIC_URL at the browser-facing HTTPS origin.

Note: SvelteKit ignores dot-directories, so the confidential client's jwks_uri is ${PUBLIC_URL}/oauth/jwks.json rather than /.well-known/jwks.json — any HTTPS URL is a valid jwks_uri.

Deployment (Nix flake) #

flake.nix (package + app + NixOS module) packages the adapter-node server, modelled on CorkboardAdminSveltekit's flake:

git add flake.nix flake.lock nix package.json package-lock.json …   # flakes see git-tracked files only
nix build          # → result/bin/corkboard
nix run            # start it on http://127.0.0.1:3000

Run the wrapper with the runtime env (see the Production table above):

HOST=127.0.0.1 PORT=3000 PUBLIC_URL=https://… PRIVATE_KEY=… SESSION_DB_PATH=… result/bin/corkboard

Packaging notes specific to this app:

  • adapter-node keeps dependencies external, so the package ships a pruned node_modules beside build/ (the Next app's standalone output carried its own).
  • autoPatchelf corrupts sharp's prebuilt @img/* binaries (it rewrites their $ORIGIN RPATH with Nix store paths, producing a broken DT_INIT/init_array that SIGSEGVs on load), so nix/package.nix sets dontAutoPatchelf = true and the bin/corkboard wrapper puts stdenv.cc.cc.lib (libstdc++/libgcc_s) on LD_LIBRARY_PATH; the .node keeps its own $ORIGIN RPATH that finds the bundled libvips.
  • BODY_SIZE_LIMIT must be raised — adapter-node's 512K default rejects the Create Event flyer upload; the NixOS module sets 8M.
  • Build-time TOKEN_* overrides (see the Production table) are exposed as tokens on the package:
    (inputs.corkboard.packages.${pkgs.system}.default.override {
      tokens = { highlight = "#e11d48"; pin-top = "#ff6b5e"; };
    })
    
    Keys are CSS custom-property names; foo-bar becomes TOKEN_FOO_BAR.
  • npm run build is svelte-kit sync && vite build, so a clean checkout (no .svelte-kit/) builds without the missing-base-config warning.
  • Flake sources are git trees — nothing builds until committed.

NixOS module #

nixosModules.default runs the board as a hardened systemd service (services.corkboard, DynamicUser, StateDirectory = "corkboard"):

{
  inputs.corkboard.url = "git+https://…/CorkboardSvelteKit";

  services.corkboard = {
    enable = true;
    package = inputs.corkboard.packages.${pkgs.system}.default;
    origin = "https://chicago.corkboard.at";          # adapter-node ORIGIN (should equal PUBLIC_URL)
    account = "corkboard.at";                          # PUBLIC_ACCOUNT (optional)
    environmentFile = "/run/secrets/corkboard.env";    # PUBLIC_URL, PRIVATE_KEY
  };

  # terminate TLS in front of it (OAuth requires HTTPS)
  services.caddy.virtualHosts."chicago.corkboard.at".extraConfig = ''
    reverse_proxy 127.0.0.1:3000
  '';
}

The module sets HOST/PORT/NODE_ENV/BODY_SIZE_LIMIT (plus ORIGIN, SESSION_DB_PATH, and PUBLIC_ACCOUNT/PUBLIC_PDS_URL/ PUBLIC_MAX_RECORDS when configured). Set PUBLIC_URL + PRIVATE_KEY in the environment file to enable sign-in; without them the board is read-only.

URLs #

Hash-based routing, identical to the React app (any #/p/<account> route names the account to read; PUBLIC_ACCOUNT is only the default):

  • #/p/<handle-or-did> — that account's calendar (this week)
  • #/p/<handle-or-did>/w|s/<YYYY-MM-DD> — week / sparse view window
  • #/p/<handle-or-did>/e/<rkey> — a specific event's detail modal
  • ?tag=…&source=… — active filters, shareable and reload-safe

One grammar parses and builds the hashes (src/lib/router.ts, ported unchanged).

Shared code #

The read-path library (atproto, events, format, resolve, reposts, laughlists, cork) lives in the published @corkboard/commons package (a git dependency) and is imported as @corkboard/commons/*; the Create-Event flyer helper re-exports @corkboard/commons/rss/flyer. This app keeps src/lib/config.ts, src/lib/router.ts, the server auth/event code, and the components. Under Nix the package is a flake input resolved by a Vite alias.

Layout #

src/
  app.html / app.css        # shell + global CSS (Tailwind v4 + the style files)
  config.ts                 # PUBLIC_* runtime configuration + the SOURCES / tag catalogs
  content/about.md          # About modal prose (imported ?raw, rendered with marked)
  content/contact.md        # Contact modal prose (feedback@corkboard.at)
  fonts/                    # self-hosted Alegreya / Alegreya Sans / Bricolage Grotesque
  styles/
    tokens.css              # design tokens (:root CSS custom properties)
    cork.css / paper.css / pin.css / md.css   # component-layer classes
  lib/
    atproto.ts events.ts reposts.ts laughlists.ts resolve.ts format.ts cork.ts
    router.ts               # ported unchanged from CorkboardFrontend
    content.ts              # about.md / contact.md → HTML
    avatar.ts               # the loaded account's avatar (app.bsky.actor.profile blob)
    tags.ts                 # the tag-color catalog (rule → background)
    neighborhood-tags.ts    # the Chicago neighborhood tags the admin writes
    test-setup.ts           # vitest jsdom shims ($env/dynamic/public, Blob.text)
    test-fixtures/event.ics # .ics prefill fixture
    components/             # .svelte ports of the React components
      CreateEventModal.svelte   # signed-in: event form; signed-out: submission links
    server/auth/            # OAuth client, stores, session helpers (server-only)
    server/lexicons/        # bundled community.lexicon.{calendar,location} JSONs
    server/events/          # create: validate (lex-document), flyer prep, record build
  routes/
    +layout.ts/.svelte      # client-rendered shell (ssr = false) + cork board
    +page.svelte            # the calendar app (port of App.tsx) + the two-row header
    oauth/…                 # login / callback / logout / client-metadata / jwks
    api/session/            # GET signed-in DID
    api/events/create/      # POST multipart: create an event in the signed-in repo
    api/events/update/      # POST multipart: edit one of the signed-in account's events
    api/events/delete/      # POST delete own record
    api/reposts/create/     # POST: repost an event (+ optional tags) into your repo
flake.nix / flake.lock      # Nix flake: package + app + NixOS module
vitest.config.ts            # test runner (sveltekit plugin + .env.test)
nix/                        # package.nix (buildNpmPackage) / module.nix (systemd)
static/                     # favicons + site.webmanifest (served at /)

The port keeps the React app's look: same design tokens and component-layer classes in src/styles/, same self-hosted fonts, same procedural cork texture (src/lib/cork.ts seeds a fresh pattern per visit from +layout.svelte). Tailwind v4 is wired through @tailwindcss/vite; build-time TOKEN_* overrides work as before (vite.config.ts).

A card's pushpin color — and the source classification behind it — comes from SOURCES (src/lib/config.ts): a catalog of community calendars (id / label / hosts / color) built on @corkboard/commons/sources' DEFAULT_SOURCES, matched against each record's createdWith/uris hosts. Add a calendar or recolor one there. The card applies the color as an inline --pin-source and styles/pin.css derives the pin's shades and ring; a source with no color keeps the default red pin.

Hashtag pills are colored the same way, from TAG_RULES / DEFAULT_TAG_COLOR (src/lib/config.ts) via the catalog in src/lib/tags.ts: rules match tags by name or predicate, first match wins, and everything else gets the default. Out of the box the default is #ffedab and the Chicago neighborhood tags (lib/neighborhood-tags.ts, the admin's #LoganSquare-style facets) are #b2f1c2.

Scripts #

npm run dev      # dev server on http://127.0.0.1:5173 (loopback OAuth)
npm run build    # production build (adapter-node → build/)
npm run preview  # preview the production build
npm run check    # svelte-kit sync + svelte-check (typecheck)
npm test         # unit + component tests (no network)
npm run test:integration  # live-PDS create tests (see Testing)

Testing #

npm test runs Vitest and never touches the network:

  • Unit — the tag-color catalog (lib/tags.test.ts), the hash grammar (lib/router.test.ts), and chicagoTime (lib/server/events/time.test.ts, including both America/Chicago DST transitions).
  • Components (lib/components/modals.test.ts, jsdom) — dispatch real bubbling keyboard events through the modals: typing a space or Enter into the Create Event / Repost forms must not dismiss the sheet, inner links and buttons must keep their keyboard activation, and Escape/backdrop must close. A Create Event form with unsaved details must instead ask before discarding (backdrop, ✕, or Escape), while an empty form closes straight away. The .ics import is exercised too, with lib/test-fixtures/event.ics.

Tests compile .svelte files and resolve $lib/$env through the same SvelteKit Vite plugin as the app, so the component behaviour matches a browser. lib/test-setup.ts supplies the two jsdom shims this needs (the client $env/dynamic/public module and Blob.text()).

Live-PDS integration tests #

src/lib/server/events/createEvent.integration.test.ts writes real records to an ephemeral test account and deletes them afterwards: multipart form → record, DST-aware RFC3339 times, lex-document validation, flyer WebP upload (media: role "flyer"), read-back, and non-image rejection.

cp .env.test.example .env.test   # fill in the ephemeral account (gitignored)
npm run test:integration

npm test skips this suite (it requires TEST_INTEGRATION=1, which the integration script sets) so normal runs stay hermetic.

Notes #

  • The page is client-rendered (ssr = false) — reads happen in the browser against the PDS, exactly like the original SPA. Only the /oauth/* and /api/* routes execute server-side.
  • Creating an event writes to the signed-in user's repo (e.g. corkboard.at); the board refreshes when the create succeeds. The create flow validates with lex-document but skips the admin's panproto double-check — CorkboardCalAdmin remains the full-validation path.
  • Reposts (/api/reposts/create) are written straight through the atproto agent — deliberately not via @corkboard/commons/lexicons/records, whose validator pulls in @panproto/core. Keeps the board's footprint lean (and the Nix build working).
  • marked renders about.md and contact.md at runtime (the React app compiled it at build with a Vite plugin); the prose is small and repo-owned. Both open in the shared ContentModal sheet.
  • Event descriptions: atmo.rsvp publishes markdown, so those render as prose (marked, then an allowlist sanitizer — descriptions are untrusted records); every other source is plain text with bare URLs auto-linked (src/lib/description.ts).
  • A reposted event offers a View @source's board button that switches to the account that published it (the event's own repo).
  • The event modal's View on button opens the event on the ATProto calendar app it came from (createdWith, via the source classification) and defaults to atmo.rsvp; its dropdown offers the others (smokesignal.events, oso.social, blacksky.community) plus PDSls (the raw record, keyed by its at-uri). Links use the author's handle, or its DID until the handle resolves (src/lib/platforms.ts, src/lib/authority.ts).
  • iCalendar: the event modal offers Add to calendar (.ics) — the record serialized by @corkboard/commons/ics — and the Create Event modal can Import from .ics, prefilling name, description, times (converted to America/Chicago wall clock), location, and links from a downloaded file.
  • Switching board / tag / source with fewer than 20 events opens the sparse view; when nothing is on today or later, the sparse window falls back to the most recent event days.
  • The data layer (atproto, events, resolve, …) lives in @corkboard/commons; what this app still ports from CorkboardFrontend/ is the look (styles/, fonts/, the hash router) — keep those in sync when they change.
  • Compare with CorkboardCalAdmin/ for the OAuth pattern's origin.