A starter repository for building browser games on Crowded Kingdoms with the CrowdyJS SDK.
The SDK gives you the platform. This repo gives you the rest of a game: an engine-agnostic platform layer, two renderers driven by the same session, a server-authoritative world hub on ck-exec, an in-game Crowdy Studio IDE where players write and run their own mods, hosted sign-in (your players sign in on Crowded Kingdoms and come back holding a token for your game -- your page never sees a password), and a one-command Setup that creates your org and app on Crowded Kingdoms — no card, no operator, no infra.
Clone it, run it, then replace the demo scenes with your game.
| Area | What it is | Where |
|---|---|---|
| Holodeck | A three.js hub where players arrive, see each other, chat, and step on pads | src/scenes/holodeck-three/ |
| Paint | A pixi.js program: a shared canvas painted with persisted voxels | src/scenes/program-pixi/ |
| Platform layer | Hosted sign-in, app entry, presence, chunks, save state, chat, proximity webcam (B) and voice (V), the world hub connection, Studio — engine-agnostic | packages/construct/src/platform/ |
| Adapter boundary | The small GameScene contract both renderers implement |
packages/construct/src/engine/, docs/RENDERER-ADAPTER.md |
| Crowdy Studio | The in-game IDE: players claim a chunk and write Rust mods on ck-exec — a SERVER half, and a CLIENT half that runs in the browser of whoever stands on their grid and says yes — and use the Ask/Build/Play agent | packages/construct/src/platform/studio/, docs/MODDING.md |
| World hub | A ck-exec hub in Rust: a minute pulse while players are in, the program catalog, the claim registry, each player's progression | exec/, docs/ARCHITECTURE.md |
| Setup | org → free app → access tier → redirect URIs → world hub → Studio starter files, from a shell (npm run setup) |
packages/construct/src/platform/onboarding/, scripts/setup.mjs |
| Security headers | COOP/COEP/CSP that make CLIENT halves possible, plus the Permissions-Policy the camera needs, wired into Vite and documented per host | security-headers.mjs, docs/HOSTING.md |
Prerequisites: Node 20+ and a modern browser. Nothing else.
git clone https://github.com/CrowdedKingdoms/the-construct.git
cd the-construct
npm install-
Create your app from a shell. You need a Crowded Kingdoms account (sign up at studio.crowdedkingdoms.com if you do not have one), then:
CONSTRUCT_EMAIL=you@example.com CONSTRUCT_PASSWORD=... \ npm run setup -- --org "My studio" --app "The Construct"
Nine idempotent steps run: organization, free app on shared hosting, a Constructor access tier with the Crowdy Studio code keys and
use_studio_agent, the dev server registered as a redirect URI, an app token, the self-claim grid policy, the world hub (the Rust crates underexec/, built on the platform and deployed with ck-exec — no Rust toolchain needed), the Studio starter files, and the Studio Agent app policy. Setup never writes operator platform policy. If the platform catalog is unpublished the dock stays closed (an operator publishes it; a third-party clone cannot). It prints an app id; copy.env.exampleto.env.localand setVITE_APP_IDto it.The world hub runs on ck-exec, the platform's execution service; see ck-exec.
Why a shell and not the browser: creating an app needs your account's session, and a game on its own domain never holds one -- see step 2.
-
npm run dev, open http://localhost:5175, press Sign in with Crowded Kingdoms. You sign in (or create an account) on Crowded Kingdoms and come straight back holding a token confined to your app. Your page never sees a password: since ck-api v1.88.0 the direct sign-in calls are served only to Crowded Kingdoms' own pages, so this hosted flow is the only one a game on its own domain can use. -
Enter The Construct. You are in the holodeck.
WASDmoves, click the canvas or hold right-mouse to look, scroll to zoom,Tor Enter chats,Bcamera,Vvoice,Eon a pad,F1for the control list. Open a second browser (or a friend does) at the same URL — you see each other. -
Step on Load: Paint and press
E: the pixi.js program. Click to paint; scroll to zoom; middle-drag or Alt+click to pan. The cells replicate live and persist. -
Step on Claim & Studio and press
E: you claim the chunk you stand on and Crowdy Studio opens beside the game. The Ask/Build/Play agent lives in that dock (Constructor tier; model usage is metered to your player wallet by default, or the app's org wallet — no provider key in this game). Wallet in the HUD opens Studio for that wallet, which also pays for your mods. Follow docs/MODDING.md to deploy a SERVER mod everyone on your grid sees, and a CLIENT half that runs in the browser of every player who stands on your grid and says yes to it.
Everything but VITE_APP_ID is optional: the installed SDK build already knows
the API origin for its tier. When you deploy somewhere other than
http://localhost:5175, register that origin too -- npm run setup -- --origin https://play.example.com, or Studio > Apps > Settings > Sign-in & redirect
URIs. That list is both where sign-in may return your players and the API's
CORS allow-list for your app. If VITE_CROWDY_HTTP_URL is a same-origin proxy
or raw IP rather than a CK tier host, set VITE_AUTHORIZE_URL to Studio's
/authorize (the SDK cannot derive it).
A local ck-api or IDE-on-public-IP stack is opt-in. Default npm run dev
sends the same COOP/COEP as preview/production and does not proxy the API.
Put VITE_DEV_PROXY=1, VITE_DEV_ALLOWED_HOSTS=1, and/or
VITE_DEV_RELAX_ISOLATION=1 in gitignored .env.local only — see
.env.example. A normal clone talking to a CK tier leaves them unset.
| Command | Purpose |
|---|---|
npm run dev |
Vite dev server with the production security headers |
LIVE_DRAFT=1 npm run dev |
The same, with this checkout as Crowdy Studio's game-editor draft (below) |
npm run build / npm run preview |
Production bundle, and serve it locally with the same headers |
npm test |
Unit tests (vitest) + CSP builder tests (node --test) |
npm run test:e2e |
Playwright: boots cross-origin isolated and shows hosted sign-in; with CONSTRUCT_E2E=1 and credentials, completes Studio login / consent and opens Studio. Node token-seed is CONSTRUCT_E2E_SEED_TOKEN=1 + CROWDY_HTTP_URL only |
npm run lint / npm run typecheck / npm run format:check |
Quality gates CI runs |
npm run setup -- --org "…" --app "…" [--origin https://…] |
Setup: org, app, tier, redirect URIs, world hub, starter files; needs CONSTRUCT_EMAIL / CONSTRUCT_PASSWORD |
npm run deploy:exec [-- --restart] |
Build exec/ on the platform and deploy it to APP_ID; --restart moves the running world hub to the new version |
npm run seed |
Re-deploy the world hub + Studio starter files to APP_ID after editing exec/, model/ or mods/ |
npm run build:exec-sources |
Regenerate the hub's program catalog and the SERVER starter strings from model/catalog.mjs and exec/mods/ (the unit tests fail while they are stale) |
npm run smoke |
Verify an app has everything Setup should have produced, the world hub included |
npm run check:pin |
The CrowdyJS pin is exact and matches the branch tier |
flowchart LR
subgraph platform [src/platform — engine agnostic]
Net[NetworkManager]
Stores[WorldStores]
Session[GameSession]
Studio[StudioService]
Model[ModelService]
Onb[onboarding]
end
subgraph engine [src/engine]
Loop[GameLoop]
Router[SceneRouter]
Input[Input]
end
Holo[holodeck-three] --> Router
Paint[program-pixi] --> Router
Router --> Session
Loop --> Session
Session --> Stores --> Net
Studio --> Net
Model --> Net
Onb --> Net
Net -->|GraphQL + realtime| CK[Crowded Kingdoms]
Net -->|ck-exec connection| Hub[world hub, exec/]
- Two tokens, one endpoint: an identity session for account and admin work,
a short-lived app-scoped token per game for everything else.
NetworkManagerowns both. Scenes never see a token. - The loop reads the active scene's
localPose()every frame and hands it to the replication store, which sends at 5 Hz on change. Scenes render other players fromsession.players(). That is the whole adapter boundary. - The browser presents intent and renders results. Inventories, scores, grids, and who may run code are decided server-side by the world hub and the platform. See docs/ARCHITECTURE.md.
- The world hub (
exec/construct, a ck-exec hub in Rust) is the game's own server code.ModelServiceandGridServicecall it over one exec connection per page;npm run deploy:execships a change.
Bind the game's repository to a Crowdy Studio project and Studio edits the
game itself (its game editor), not mods: the Files pane shows the
repository, the agent works on it, the running world reloads what changed,
and Commit publishes the changes to GitHub as one commit with a message.
Nothing reaches GitHub before that. Studio's Live code link opens it, through a
sign-in if the player has none: main.ts keeps the link's project for the tab
(rememberRequestedProject) and the editor opens it once the player is in.
- The content layer is what reloads in place:
src/game/content.ts(contentApi: 1: the scenes, the home scene and spawn, the programs) and everything it imports.main.tsloads the game through it and nothing else, so adding a scene never editsmain.ts. Other files (main.ts,src/ui/, the world hub inexec/) still need a reload, a build or a deploy. - On a dev server, run
LIVE_DRAFT=1 npm run devin a clone of the bound repository: the checkout is the draft, Vite hot-reloads it, and after a commit the checkout moves to it (git reset --mixed, files untouched). The draft API answers this machine only;LIVE_DRAFT_REMOTE=1opens it to the network the dev server listens on, which hands that network your checkout. - On the hosted game, the draft lives in the owner's browser and a service worker previews it (docs/HOSTING.md).
- The agent's guide is STUDIO.md (a map of the content
layer), plus the skills of an optional Studio playbook
(
CONSTRUCT_PLAYBOOK_DIR, copied intopublic/playbook/).
Needs CrowdyJS 18.23 or later (the framework takes the game editor's types from it)
and @crowdedkingdoms/crowdy-dsh 0.5 or later; with an older crowdy-dsh the agent
says it cannot edit the game repository.
- docs/ARCHITECTURE.md — layers, authority, the boot sequence, what is generic and what is demo
- docs/RENDERER-ADAPTER.md — replacing a scene or the whole renderer
- docs/PLATFORM-MAP.md — game concept → platform surface, with links to the public docs
- docs/MODDING.md — Crowdy Studio: permissions, mods on ck-exec and their CLIENT halves, the browser sandbox, templates, visitors' consent, security posture
- docs/NEW-GAME-CHECKLIST.md — turning this into your game
- docs/HOSTING.md — static hosting with the headers CLIENT halves require
- docs/MANAGED-PLAYERS.md — signing in your own players (org-managed players) instead of hosted sign-in
- CHANGELOG.md
An organization's apps on shared hosting share one free monthly allowance (egress, ingress, compute hours, storage, and module writes), and making more apps does not add to it. Nothing here asks for a card. Sustained usage above the allowance bills the org wallet; a player's mods run on ck-exec and, on the dev preview, bill that player's own wallet after a monthly trial. Crowdy Agent tokens are platform-funded on Crowded Kingdoms (this game never asks for an OpenRouter key). The HUD Wallet link is for the player's wallet, not the agent. Current figures: Shared environment and Player billing.
Crowded Kingdoms does not host games. npm run build produces a static site you put
on any host that can set response headers. The host must send the cross-origin
isolation headers, or CLIENT halves will not run (the game says so on screen), and the
agent pane's files under /dsh/ need a policy of their own. Register the address with
npm run setup -- --origin https://your.host (it becomes the app's launch URL when the
app has none) so players can sign in there and Crowdy Studio's Live code opens it.
docs/HOSTING.md has the steps and recipes for common hosts.
dev, test and prod track the three Crowded Kingdoms tiers. Each pins the
exact CrowdyJS build published for its tier (X.Y.Z-dev.N, X.Y.Z-test.N,
X.Y.Z), because each build carries its tier's API origin. Clone prod
unless you are working with the platform team. npm run check:pin enforces it.
MIT — see LICENSE. The Crowded Kingdoms platform and the CrowdyJS SDK have their own terms.