Provides server-authoritative multiplayer game architecture using Bun and Elysia: fixed-timestep tick loop, WebSocket delta broadcasts, Redis fan-out, and session-based auth. Use for real-time game servers with match rooms and state synchronization.
Ships in game-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The boilerplate targets elysia 1.4.32. Use the elysiajs skill if it is installed, otherwise https://elysiajs.com, and check which Elysia major the project runs: the Elysia 2 beta rewrites the WebSocket API, so the .ws() code here does not carry over unchanged.
betterauth-integration for the Better Auth instance, roles and trusted originsredis-game-patterns for presence keys and per-action rate limitsmove north), never the result (I am at 100, 200). The server validates the action against its own state, applies it, and tells clients what happened.dt, so the same inputs give the same result.GameLoop. Rooms share nothing, and one room runs on one server instance. This holds for session games, where a match has a fixed, small player count. It stops holding when one space must carry more players or entities than one process can tick in its budget; see "When one space outgrows a process".Origin plus the session cookie. Native clients (game-godot, game-unity) send no Origin and are checked by a bearer session.templates/message-types.ts. Every message is a member of a discriminated union on type. Client messages are one TypeBox schema, clientMessage; ClientMessage is derived from it with Static, and server.ts validates with it, so malformed messages are rejected before your code sees them and the type cannot drift from the check.createGameServer(auth, trustedOrigins), passing the Better Auth instance and the game client origins. Put the same origins in Better Auth's trustedOrigins option.authorizeUpgrade, called from .derive() on its own Elysia instance, so it does not run on the mounted auth routes. The route never upgrades on a failure. A direct auth.api call skips Better Auth's own origin checks, which is why the server checks Origin itself.
Origin header (a browser): the origin must be in trustedOrigins, else 403. The session comes from the cookie or a bearer token, as getSession reads it. No session is 401.Origin header (a native client): the request must carry Authorization: Bearer <token>, and the session must come from that token alone, else 403. A cookie on such a request does not count. RFC 6455 says only browser clients must send Origin (section 4.1), and that the check is not meant to keep non-browsers out (section 10.2).Origin the client sets proves nothing, because only a browser guarantees it. An untrusted Origin is 403 even with a valid token.Authorization header only, never from the query string: a URL ends up in access logs and proxies.bearer() plugin on the Better Auth instance (betterauth-integration). The token is a session credential: a native client keeps it in the OS secure store (Keychain, Android Keystore), never in a URL, a log line or a crash report..derive(), not in store. store is one object shared by every request.RoomManager.tickRoom and processAction. The pattern for one action:const result = validateAction(room.gameState, queued.playerId, queued.action);
if (!result.valid) {
this.sendToPlayer(room.id, queued.playerId, {
type: 'action_result',
action: queued.action.type,
success: false,
data: { reason: result.reason },
});
return;
}
applyAction(room.gameState, queued.playerId, queued.action);
Send the reason with a rejection; the client needs it to show the player why.
GameLoop adds real elapsed time to an accumulator and runs as many fixed dt steps as fit. The leftover stays for the next pass.
setSpeed() scales elapsed time, for fast-forward or slow motion. dt stays fixed.state_update. Removed keys arrive as null. Diffing against the previous tick is safe because WebSocket runs on TCP and delivers every message in order; over an unreliable transport, encode against the client's acknowledged snapshot instead (game-state-sync, step 3). Send the full state again when a client reconnects (room_joined carries it).processAction stops that room's loop, is logged, and closes that room. Other rooms keep running.A room lives in one instance's memory. Route every player of a room to the instance that holds it: return that instance's address when the room is created, or route on the room id at the load balancer.
Create one ioredis client when the server starts (new Redis(redisUrl), with a redis:// URL) and pass it to createFanOut and to the redis-game-patterns helpers. Use boilerplate/fan-out.ts only for messages that cross instances: a direct message to a player connected elsewhere, a server-wide announcement, or closing a banned player's sockets on every instance (a ban revokes sessions, but an open socket stays open until the server closes it). Implement LocalDelivery with a map from player id to socket that open fills and close clears.
Redis Pub/Sub delivers at most once. A message published while an instance is down or reconnecting is lost. Send match results, rewards and purchases through a queue (bullmq-game-queues), not through fan-out.
One room on one instance fits matches. A persistent world with crowds needs more.
bullmq-game-queues), never from inside a tick. CCP reports that after it moved some services to separate character nodes, up to 80% of the calls that had gone to the busiest system node went elsewhere. That figure is EVE's, not a target.GameLoop.setSpeed() does this: fewer fixed steps run per second, and dt stays fixed. Every time-based rule (cooldowns, regeneration, movement) must then read game time, not wall-clock time. Decide which timers must stay on real time. CCP exempts reinforcement timers from dilation, because players could otherwise move when they expire. The other option is to shed load: refuse joins to the busy zone, send low-priority updates less often (game-state-sync, step 8). CCP's pages do not say whether EVE dilates per node or for the whole cluster, so decide the scope for your game.redis-game-patterns). Redis persistence can lose data on a crash: an RDB snapshot setup can lose the latest minutes, and the AOF default (fsync every second) can lose about one second. Redis's own advice is RDB plus AOF for safety comparable to PostgreSQL. Treat anything you cannot afford to lose as not Redis-only.postgres-game-schema, which has the tables and the guarded-spend query).players rows with SELECT ... FOR UPDATE, ordered by id. Locking the player rows covers rows the trade inserts, such as merged stacks, which an inventory lock cannot. Then change inventory and currencies. Two opposite trades then take their locks in the same order and cannot wait on each other. If Postgres still aborts the transaction with SQLSTATE 40P01 (deadlock_detected), retry the whole transaction a small, bounded number of times. The Postgres docs give the two rules (acquire locks in a consistent order; retry transactions that abort for a deadlock). Applying them to a trade through the players rows is this skill's rule. It holds only if every other path that writes either player's inventory or currencies takes the same players locks first, in id order. A single guarded statement on one row, such as spendCurrency, is the one exception.The client sends ping; the server answers pong with its time. On each ping, refresh the player's presence key with a TTL of a few heartbeat intervals (redis-game-patterns, presence pattern). A missing key means offline, so a crashed client needs no cleanup message. When the socket closes, close removes the player from every room that socket is in. After a reconnect the new socket replaces the old one in the room, so the old socket's late close leaves the player in place (the room compares socket ids).
dt in game formulas. Game logic must see the fixed step, not wall-clock time.closing: stop the loop, persist, notify, then delete.Origin header to prove the client is your game. Anyone can set it. Origin only protects browsers from hostile pages; a native client is checked by its bearer session.Origin through on a cookie or on no credential. Without a bearer session it is 403./ws?token=...). It leaks into logs; the server ignores it.kick fan-out message.boilerplate/server.ts: copy when wiring the server. It mounts the Better Auth handler, runs authorizeUpgrade (Origin plus session, or bearer without Origin) in .derive() on the upgrade, and routes WebSocket messages to the room manager.boilerplate/room-manager.ts: copy when adding rooms. Read when plugging in game logic: tickRoom and processAction are the hooks.boilerplate/game-loop.ts: copy when a room needs its tick loop; it needs no changes.boilerplate/fan-out.ts: copy when you run more than one server instance.templates/message-types.ts: copy when defining the client-server protocol; extend the unions with your game's messages.references/architecture.md: read when you need the connection flow or room lifecycle as a diagram.references/sources.md: read when you need the page behind a rule here.game-state-sync for the client side: prediction, reconciliation, interpolationbullmq-game-queues for heavy or must-not-lose work off the tick looppostgres-game-schema for player profiles, inventory and match historymatchmaking-system for filling roomsboilerplate/fan-out.ts (opens in a new tab)boilerplate/game-loop.ts (opens in a new tab)boilerplate/room-manager.ts (opens in a new tab)boilerplate/server.ts (opens in a new tab)references/architecture.md (opens in a new tab)references/sources.md (opens in a new tab)templates/message-types.ts (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
game-server, multiplayer, real-time, websocket, server-authoritative
/game-dev:game-backend-architecturefrom game-dev
npx claudepluginhub fcsouza/agent-skills --plugin game-dev39 skills in this plugin
/betterauth-integrationCovers the game-specific layer of Better Auth: player, moderator and admin roles, session checks on game routes and WebSocket handshakes, and keeping the auth session apart from the game session. Use when a game needs player login, moderator or admin powers, or authenticated real-time connections, and the project uses Better Auth./bullmq-game-queuesBackground job design for game backends on BullMQ and Redis: one queue per game domain, idempotent reward fulfilment, and cron schedulers for daily rewards and season ends. Use when a game needs matchmaking requests, reward grants, match results, notifications or analytics processed off the request path, or recurring and timed jobs such as daily login rewards, leaderboard snapshots and season rollovers./character-design-narrativeCovers designing game characters: NPCs, companions, antagonists, player avatars, character bibles and branching dialogue. Use when a game needs a new character written, an NPC feels flat or interchangeable, or dialogue needs a branching format with conditions and effects./ci-cd-gameGitHub Actions pipeline rules for a Bun game backend on Neon and Fly.io: migrations before deploy, one Neon database branch per pull request, a smoke test after deploy, and a pinned Bun version. Use when a game project needs CI, a deploy workflow, preview databases for pull requests, or a safe order for schema migrations and server deploys./elevenlabs-sound-musicCovers generating game audio with ElevenLabs (voice lines, sound effects, music) and Google Lyria 2 (instrumental music clips), and playing it in the browser through an audio state machine with crossfades, per-layer volume and an unlock on the first user input. Use when a game needs sound effects, NPC voice lines or a soundtrack, when music must follow game state (menu, exploration, combat, boss) without hard cuts, when audio stays silent on a phone until the player taps, or when choosing between ElevenLabs and Lyria for music./game-anti-cheatCovers how a developer defends their own online game against cheating: server-side input validation, withholding hidden state, lag-compensation limits, dupe-proof transfers, detection from server data and reports, and enforcement with delayed bans, appeals and refunds to victims. Use when a multiplayer game has speed hacks, wallhacks, aimbots, bots, item or currency dupes, real-money trading, boosting or win trading, or when planning how to detect and ban cheaters.Other plugins' skills for the same job