The shared engine for co-op browser games built with Crystal and Amber V2. A game brings its rules, maps, art and sound; the kit brings everything else a phone game in a browser needs.
- Invite from inside the game. One Invite panel with a four-letter room code, the share sheet (or Copy link), and a QR code of the join link drawn on the phone for whoever stands beside the player.
- Saves on the player's own device. IndexedDB on each phone, party copies passed between phones, and save files to keep or move. A save is overwritten only by a later copy of itself; when a joining phone holds a newer copy or a branch, the host is asked "Play from theirs?", and the copy not played stays as an other-branch entry to open or export. The relay holds nothing between sessions.
- One input layer. Keyboard, touch, the on-screen thumb stick, gamepad and tilt all feed the actions a game declares once in Crystal.
- Shared movement and physics. Tile movement, route finding, a camera and 2D bodies in Crystal, compiled to WebAssembly by crystal-alpha, so every phone runs the same rules.
- An Amber V2 relay. Rooms, seats, host handoff, direct links with TURN fallback, a TLS 1.3 listener and per-network limits.
- A performance budget checked in CI. Frame time, input response, memory, first load and resume, measured on a reference phone profile on every change.
Play the sample game on your own computer. You need an Apple silicon Mac with Homebrew; the first block installs the pinned toolchain in the order the kit's CI uses (the locked Homebrew dependencies from their locked bottles, then crystal-alpha and minecart from their taps at the locked commits, then the WebAssembly toolchain and Chrome for Testing), and checks it.
Warning
install_homebrew_dependencies.rb replaces any other installed version of llvm@21, lld@21, zstd, xz, lz4 or pkgconf with the locked one (brew uninstall --ignore-dependencies --force, then the locked bottle). Formulas on your Mac that depend on them then run against the locked versions, so check before you run it on a Mac you rely on.
git clone https://github.com/amberframework/amber_game_kit.git
cd amber_game_kit
export HOMEBREW_NO_AUTO_UPDATE=1
read_lock() { /usr/bin/ruby -rjson -e 'puts JSON.parse(File.read("toolchain.lock.json")).dig(*ARGV)' "$@"; }
pin_tap() { brew tap "$1" && git -C "$(brew --repo "$1")" fetch --quiet origin "$2" && git -C "$(brew --repo "$1")" checkout --quiet --detach "$2"; }
/usr/bin/ruby tooling/install_homebrew_dependencies.rb
pin_tap crimson-knight/agent-crystal "$(read_lock crystal_alpha tap_commit)"
pin_tap amberframework/amber_cli "$(read_lock minecart tap_commit)"
brew install "$(read_lock crystal_alpha formula)" "$(read_lock minecart formula)"
/usr/bin/ruby tooling/fetch_wasm_toolchain.rb --chrome
/usr/bin/ruby tooling/verify_toolchain.rb --game-root sample_gameThen build the sample game and start its relay:
cd sample_game
minecart install --frozen
/usr/bin/ruby ../tooling/build_wasm.rb --game-root .
/usr/bin/ruby ../tooling/build_web.rb --game-root .
cd relay
minecart install --frozen
mkdir -p bin
crystal-alpha build src/relay.cr -o bin/relay
./bin/relayOpen http://127.0.0.1:4232/sample_game/, press Invite, and open the join link in a second browser window. Walk with the arrow keys, flip the lamp with Space, and watch both windows.
Tip
Play it the way CI does: from sample_game/, /usr/bin/ruby ../tooling/playtest.rb --game-root . --minutes 3 --runner local --serve, then /usr/bin/ruby ../tooling/budget_check.rb build/playtest/<run>.json prints each measure against its budget.
The relay's limits live in the game_limits: section of relay/config/environments/<env>.yml, and AMBER_GAME_LIMITS_<FIELD> overrides any one of them. The defaults and what each one does are in game_limits.cr. The ones an operator changes most often:
| Key | Default | What it sets |
|---|---|---|
max_active_games |
60 | games with a phone or TV connected; one more gets full |
max_players_per_room |
4 | phones one room seats |
room_grace_period_minutes |
15 | how long an empty room stays in memory before the host phone has to reopen it |
host_handoff_grace_seconds |
8 | how long the host role waits for a host whose socket dropped while another phone is seated (0 hands it over at once) |
reopen_token_lifetime_hours |
12 | how long a host's reopen token stays good |
seat_token_lifetime_hours |
168 | how long a seat token stays good; pages keep a seat until the expiry its token carries |
One $4 DigitalOcean droplet (1 vCPU, 512 MiB) runs the sample game's relay over WebSockets on TLS 1.3. We tested it for 10 minutes at each player count, with every message going through the relay (no direct links). The pass rule: p99 delivery at or under 50 ms, and no message lost.
| Players | Rooms of 4 | |
|---|---|---|
| Held on every droplet we measured (6 of 6) | 200 | 50 |
| Median droplet | 300 | 75 |
| Best droplet (a quiet host) | 600 | 150 |
What sets the limit is the latency tail, not the CPU. At 600 players the relay used about a third of its vCPU. Two things push the p99 past 50 ms:
- the garbage collector's pauses, about one a second, averaging 19 to 28 ms;
- busy neighbors on the droplet's host.
Memory stays far from the limit: about 170 KiB per player. Each player sends about 3.8 KB a second through the relay and receives about 12.8 KB, so the droplet's 0.5 TB monthly transfer covers about 10,900 player-hours of relay-fed play. Players on direct links cost the relay less.
The default max_active_games of 60 (240 players) sits between the guaranteed and the median figure. Raise it only on a bigger droplet, or after measuring yours with tooling/relay_load.
Method, raw data and every table: amberframework/amber, benchmarks/digitalocean/round28/AC5/RESULTS.md.
Making your own game? Read Your first co-op browser game.
flowchart LR
subgraph Phone["Each phone (browser)"]
Page["page modules<br/>web/kit/*.js"] -->|actions| Rules["rules in WebAssembly<br/>Crystal, wasm32"]
Rules -->|world| Page
Page --> Saves[("device saves<br/>IndexedDB")]
end
Page <-->|"WebSocket: snapshots, actions, invites"| Relay["relay<br/>Amber V2"]
Page <-.->|"direct link (WebRTC)"| Other["other phones"]
Relay <--> Other
classDef kit fill:#2B3245,stroke:#DAB56E,color:#ECE7DD
classDef store fill:#3F7A5F,stroke:#DAB56E,color:#ECE7DD
class Page,Rules,Relay,Other kit
class Saves store
The host phone runs the rules; guests send their actions and draw the host's snapshots. A TV can watch a room without a seat (watch) and draws the same snapshots. The relay seats phones in rooms and passes messages; it keeps no saves.
amber_game_kit/
shard.yml package manifest
toolchain.lock.json every tool pinned by version and sha256
src/amber_game_kit.cr rules side (bridge, saves, input, movement, physics); never requires Amber
src/amber_game_kit/relay relay base for a game's Amber V2 relay
web/kit/ page modules: rules loader, input, invite, device saves, copy exchange, relay link,
direct links, snapshot pacer, position hub, probe
tooling/ Ruby tools: wasm build, Chrome harness, playtest, soak, budget check, deploy
spec/ tooling/spec/ web/spec/
sample_game/ a one-room co-op game CI builds, plays and holds to the budget
docs/guide.md your first co-op browser game
A game keeps its own rules, maps, art, sound, relay messages and settings (web/game_config.js, config/performance_budget.json, config/tooling.json, config/deploy.json), and runs the kit's tools from lib/amber_game_kit/tooling/.
Every build, playtest, soak and CI job first runs tooling/verify_toolchain.rb, which stops on any mismatch with toolchain.lock.json.
| Tool | Pin | Checked by |
|---|---|---|
| crystal-alpha | 1.22.3-incremental-9 from crimson-knight/agent-crystal at e8907f0 |
bottle sha256, tap commit, --version |
| minecart (shards-alpha) | 2025.11.25.10 (revision 6) from amberframework/amber_cli at 049471b |
bottle sha256, tap commit, --version |
| WASI SDK | 33.0+m, macOS arm64 | tarball sha256 |
| wasm32 libraries | crystal-1.22.3-incremental-9 | tarball sha256 |
| binaryen (wasm-opt) | 126 | tarball sha256 and --version |
| Chrome for Testing | 158.0.8127.88 | zip sha256 |
| Homebrew dependencies | llvm@21 21.1.8_1, lld@21 21.1.8_1, zstd 1.6.0, xz 5.8.5, lz4 1.11.1, pkgconf 3.0.11 | bottle sha256, keg version, poured from a bottle |
| Linux relay sysroot | Alpine 3.22 musl-dev, gc-dev, gc-static, gcc .apk files, linked with ld.lld from lld@21 |
.apk sha256, sysroot tree sha256, linker --version |
| Ruby | macOS /usr/bin/ruby 2.6.10 |
version line |
| Amber V2 | c49aa654 |
the relay's shard.lock |
tooling/fetch_wasm_toolchain.rb downloads the WASI SDK, the wasm32 libraries, binaryen and (with --chrome) Chrome for Testing into ~/.amber_game_kit/toolchain/ and checks each sha256. The WebAssembly toolchain is published for Apple silicon Macs; tooling/build_linux_relay.rb cross-builds the relay for a Linux server. Only that build and deploy.rb need lld@21 and the Linux sysroot: they run verify_toolchain.rb --linux-relay, and a wasm-only build checks everything else.
The playtest, soak and page specs start that Chrome through tooling/chrome_pipe.rb, always with --use-mock-keychain --password-store=basic, so it runs the same on a CI runner whose user has no login session as on your own Mac. AMBER_GAME_KIT_CHROME_FLAGS adds Chrome switches (space-separated) after the kit's own.
| Measure | Kit budget | Sample game budget | Sample game measured |
|---|---|---|---|
| Frame work, p95 / p99 | 16.7 ms / 33.4 ms | same | 0.1 ms / 0.6 ms |
| Dropped frames (reference runner) | 2% | same | 0.063% |
| Input to visible response, p95, each action kind | 100 ms, 30 samples or more | same | 15.8 to 21.5 ms, 165 to 248 samples |
| WebAssembly memory, peak | 64 MiB | 32 MiB | 12.6 MiB, flat for 60 minutes |
| First load | 4 MiB | 2 MiB | 1.44 MiB |
| Resume after a reload or a dropped link | 3 s | same | 1.09 s |
Measured by tooling/playtest.rb in a 3-minute play on the reference phone profile (390 x 844 CSS px, device scale 3, touch, CPU throttled 4x, Fast 4G) on the reference runner, plus the tap soak in CI: 61 rounds of 60 s of wall time each (play, then the move and tap checks), so the relay's hourly reopen token reissue fires inside it and CI checks that it did. A game may only lower a number in its config/performance_budget.json. On GitHub-hosted runners tooling/budgets/hosted_runner.json sets the input-response ceiling to 189.6 ms (calibrated from 10 hosted runs) and skips dropped frames; the strict numbers hold on the reference runner.
sample_game/ is one room, a lamp switch and a walker per phone, laid out exactly like a real game that uses the kit: Crystal rules in src/, the page in web/, an Amber V2 relay in relay/, playtest steps and a soak bot in tooling/. CI builds it, plays it for 3 minutes, checks the budget and runs a 61-minute tap soak on every push.
| Host phone | Guest phone | Invite panel |
|---|---|---|
![]() |
![]() |
![]() |
Captured in headless Chrome at the reference phone size (390 x 844 CSS px, scale 3) by docs/assets/source/capture_readme_screenshots.rb on m4-mini-02.
Note
Teams who want stricter gates can add the premium layer: reference-runner budgets, multi-phone co-op soaks, the relay load test, nightly trends, per-chip relay builds and blue/green deploys. Ask at agentc.consulting.
See CONTRIBUTING.md. Report a vulnerability privately as described in SECURITY.md.
MIT. See LICENSE.
Built by AgentC Consulting for the Amber framework.


