- TypeScript 96%
- HTML 4%
atplace #
An r/place clone on atproto, running on Cloudflare Workers.
Running locally #
You need Node 24+, pnpm, and an atproto account (e.g. Bluesky) with an app password.
-
Install dependencies:
pnpm install -
Create a canvas record in your repo:
ATP_IDENTIFIER=you.bsky.social ATP_APP_PASSWORD=xxxx-xxxx-xxxx-xxxx pnpm create-canvas --rkey testThe script logs in at your account's own PDS, found from your handle; set
ATP_SERVICEto override it. It prints the canvas's AT-URI. Optional flags:--name,--width,--height,--cooldown(seconds),--palette(comma-separated#rrggbb),--starts-atand--ends-at(ISO datetimes). The defaults are 1000×1000, the 2017 r/place palette and a 5-minute cooldown. -
Tell your local instance to serve that canvas:
echo 'CANVAS_ALLOWLIST=at://did:plc:.../dev.marantz.atplace.canvas/test' > .dev.vars -
Start the dev server:
pnpm dev -
Open http://127.0.0.1:5173. Use
127.0.0.1, notlocalhost, or OAuth sign-in will fail.
If you add more than one canvas, the URIs in CANVAS_ALLOWLIST are comma-separated. Pick one with ?canvas=<at-uri>.
Building a custom client #
Any atproto client can play. The page in src/web is just one implementation.
Placing a pixel takes two calls:
-
Create a
dev.marantz.atplace.pixelrecord in the player's own repo withcom.atproto.repo.createRecord, leaving the rkey unset so the PDS generates one:{ "canvas": "<canvas at-uri>", "x": 12, "y": 34, "color": 5, "createdAt": "<ISO datetime>" }coloris an index into the canvas palette. The schema is inlexicons/. -
POST the new record's URI to the instance:
POST /api/canvas/<canvas did>/<canvas rkey>/place {"uri": "at://<player did>/dev.marantz.atplace.pixel/<rkey>"}The response is
{"ok": true, "nextPlaceAt": <ms>}or{"ok": false, "error": "...", "nextPlaceAt"?: <ms>}. If a placement is rejected, delete the record so it doesn't linger in the player's repo.
The instance fetches the record from the player's PDS to verify it, so the POST needs no authentication. Each new pixel record must have a newer rkey than the player's last accepted one.
Watching a canvas: open a WebSocket to /api/canvas/<canvas did>/<canvas rkey>/ws.
GET /api/canvases lists the canvases an instance serves.
| Message | Format |
|---|---|
| Config | JSON text: {"type": "config", "config": {...}} |
| Snapshot | Binary: byte 1, then gzipped palette indices (1 byte per pixel, row-major) |
| Diff | Binary: byte 2, then repeated 5-byte entries (u16 x, u16 y, u8 color, big-endian) |
The server sends the config and then the snapshot when you connect, then diffs about
once a second. A config message can arrive again at any time if the canvas owner edits
it. Diffs can arrive before the snapshot, so buffer them until it does. src/shared/protocol.ts
has an encoder and decoder you can reuse.
Deploying your own instance #
Each instance runs on its operator's own Cloudflare account. It fits within the free plan.
-
Create a canvas record as in step 2 above. Choose its size carefully, because it can't change later.
-
Copy
deploy.env.exampletodeploy.envand fill it in. You needCANVAS_ALLOWLIST, and optionallyDEPLOY_DOMAIN, a custom domain on a zone in your Cloudflare account. Without a domain, the instance is served onworkers.dev. -
Log in and deploy:
pnpm exec wrangler login pnpm run deployUse
pnpm run deploy, notpnpm deploy, which is a pnpm built-in.
The deploy sets the allowlist on every run. Change deploy.env and redeploy, rather
than editing variables in the Cloudflare dashboard, which the next deploy overwrites.
See CONTRIBUTING.md for how it works.