Shackworks Net internals
shackworks-net is an Astro site on Cloudflare Workers with D1, R2 (for themes) and Clerk (for hub accounts). Its bindings are DB and THEMES. It uses no sessions and no KV.
- Net is never on an instance’s critical path. Instances sync about every 15 minutes with jitter, only when they have something to send. They back off and queue on
429ortry_later. - Accounts exist only to add and remove instances. You can sign up only from
/link/<request id>, and you can also sign in at/account. The public site has no Log in or Sign up link and no/sign-inor/sign-uproute, so never link to/accountfrom a public page. Keep Clerk’s hosted Account Portal unlinked. A daily job deletes accounts that have no instance and no link request after 24 hours. - Net stores no IP addresses, in tables, in
audit_logor in rate-limit keys. - Net holds summaries only, never QSOs.
The public pages are Home, Contests, Calendar (with calendar.ics), Themes and Leaderboard. They are prerendered or cached for 5 to 15 minutes. Dynamic routes set export const prerender = false. /admin is for reviewers only and returns 404 to everyone else.
The API lives under /api/v1: link, instance, telemetry, scores, submissions, library, templates, themes, events, health, account and admin.
Linking
Section titled “Linking”Linking is the OAuth 2.0 authorization code flow with PKCE, narrowed to registering a public key.
POST /api/v1/link/starttakes the instance’s Ed25519 public key, its name, its version, the exactredirect_uriand an S256code_challenge. It returns a request id that is valid for 15 minutes.- The browser opens
/link/<id>?state=…. The person signs in or signs up with Clerk (only here) and approves. Net issues a one-time code, valid for 2 minutes, and redirects to the registered URI. The page also shows the code so the person can paste it. POST /api/v1/link/tokentakes thecodeandcode_verifier, signed. Net creates the instance row at this point and returns theinstance_id.
There is no polling endpoint. Every failure that an instance can see is 400 {"error":"invalid_request"}. The logic lives in src/lib/link.ts, which is pure and tested.
Signed requests
Section titled “Signed requests”After linking, every request carries three headers: x-instance-id, x-timestamp (unix seconds, within five minutes of Net’s clock) and x-signature. The signature is an Ed25519 signature over this string:
METHOD \n path \n timestamp \n sha256(body) base64urlThe code is in src/lib/signing.ts and signed-route.ts. The private key never leaves the instance, which stores it in hub-key.json with mode 600. Removing an instance deletes everything Net holds for it, and removing the last instance deletes the account.
Sharing and library
Section titled “Sharing and library”The sharing scopes are system_info, incidents and scores, and all are off by default. server/lib/hub/payloads.ts is the only place that shapes outgoing data. A contest shares scores only when it has config.share_scores and the instance has the scores scope.
A submission starts as pending, then becomes listed, rejected or withdrawn. A linked instance must sign every library request. Listed versions are immutable. The sender chooses a credit byline, and a reviewer can edit it. Reviewers can mark a template as verified, and a resubmission clears that mark. Net checks theme packages in the reviewer’s browser to save Worker CPU. Administrator changes go through POST /api/v1/admin/manage (src/lib/manage.ts) and are audited.
Each instance has these limits: 60 list requests per hour, 40 downloads per hour and 200 per day, 20 submissions per day at up to 4 MB each, and 5 packages waiting for review. docs/hub-limits.md explains the free-plan arithmetic, and test/limits.test.ts simulates 300 instances over a 12-hour contest.
Conventions
Section titled “Conventions”- Handlers take a
Db, which is a slice of D1 defined insrc/lib/db.ts, so tests need no Cloudflare. Tests usenode:sqlite. - Tables are
STRICTand timestamps are UTC ISO strings. Apply migrations before you deploy the code that needs them withnpm run migrate:remote. Runnpm run typesafter you changewrangler.jsonc. - Every state change writes
audit_logwithout personal data. Rate-limit every unauthenticated endpoint withsrc/lib/ratelimit.ts. src/lib/brand.tsmust match the app’sshared/brand.ts.src/styles/foundation.cssis a copy, whichnpm run sync-designrefreshes.- Clerk forms use
routing="hash"and live on their own page. Do not set the globalPUBLIC_CLERK_SIGN_IN_URLorSIGN_UP_URL, which sent people to/accountbetween steps. - To run locally with real bindings, put the keys in
.dev.vars, which is never committed, then runnpm run build && npx wrangler dev.
Instance side
Section titled “Instance side”The instance code is in server/lib/hub/:
| File | Role |
|---|---|
client.ts |
Linking, signing, check-in and unlinking. |
keys.ts |
The instance’s key pair. |
state.ts |
hub.json. It is a file because the panel process writes it. |
sync.ts, outbox.ts |
Scheduled sync and the queue of items waiting for Net. |
share.ts, collect.ts |
The sharing scopes and the data they collect. |
cache.ts |
hub-cache.json. It caches templates and themes for 1 hour, the calendar for 30 minutes and review status for 10 minutes. |
library.ts |
The library client. |
Library fetches happen on demand, and the instance shows a stale copy if Net is down. server/hub-fake.ts stands in for Net in tests.