Add multiplayer to your browser game.

Copy the prompt into your coding agent to add shared rooms, matchmaking and live game updates. lobbyboi is an open-source TypeScript library for multiplayer games on Cloudflare Workers and Durable Objects.

Explore the games ↓

Open source · TypeScript · Runs on Cloudflare

Illustrated flow · not a live session

One prompt.
A whole new way
to play.

You bring the idea. Your agent writes the game logic. lobbyboi takes care of the rooms, the players and everything that keeps them connected.

New to this? You’ll need a coding agent and a Cloudflare account to put your game online. Start with the setup checklist below, then come back and copy the prompt.

A field guide for your agent
Your next prompt PLAIN TEXT

“Make it multiplayer.”

Copy this into your coding agent with your game project open.

Start with your game

A prototype, a weekend idea, that thing you just vibe coded. Open it in your coding agent.

Give your agent the prompt

It gets the docs, a working example and a checklist for wiring multiplayer into your project.

Bring a friend

Test locally, deploy to Cloudflare, then share a room code. Add bots while you wait for the crew.

Before you start: sign up for Cloudflare to host your game online, and open your game project in a coding agent. Testing only on your computer? You can do that before setting up hosting.

First time doing this?
Start here.

Choose how you’re building your game. We’ll show you the accounts, tools and next steps for that path.

You’re building in your browser. Start with your builder account and Cloudflare; you don’t need to install local tools just to edit your game there.

1. Open your game in your builder

Sign in to Lovable or your chosen builder and open your game project. You’ll paste the prompt below into its chat. Keep using the builder for your game’s screens and design.

2. Sign up for Cloudflare

You still need your own Cloudflare account. lobbyboi’s multiplayer server runs on Cloudflare Workers and Durable Objects. Your builder’s Publish button alone doesn’t set that server up.

Create your Cloudflare account ↗

3. Arrange the server setup

Ask your builder whether it can create and deploy a Cloudflare Worker with Durable Objects. If it can’t, use its code export or GitHub connection, then have a local coding agent set up the multiplayer backend. For this handoff, create a GitHub account if needed and follow Lovable’s GitHub sync guide.

Your game has two parts

The part players see can stay hosted by your builder. The multiplayer server lives on Cloudflare. Your agent needs to connect the two using the server’s web address, allow connections from your game’s address, and test player sessions. Cloudflare login and a server secret are part of that setup. Keep the secret on the server.

Paste this into your builder

This prompt asks it to check what it can actually deploy before starting. If a local setup is needed, switch to the Local development tab for Node.js, Git, pnpm and Wrangler instructions.

Once both parts are online, open the game in two separate browser sessions and check that both players can join the same room and play together. Publishing a screen is only part of the setup.

Connect my game to lobbyboi

0runtime dependencies
~6 KBclient, gzipped
36tests in the Workers runtime
1Durable Object per room

A lot happens
between players.

Give your agent a foundation for the rooms, connections and match flow around your game.

Lobbies and quick-match

Readable room codes, a public room list and one-click quick-match. It reserves a seat before sending you in, so stale listings never strand a player.

A real match lifecycle

Ready-up, host controls, kick, chat, countdown, results and back again. Changing the rules un-readies everyone, so nobody agrees to a game they didn’t see.

Reconnects that keep your seat

One socket per player, so refreshing just works. Dropped players keep their slot, the client backs off and retries, and the host role moves on if the host leaves.

One shared source of truth

A fixed-step server tick with sequenced, validated, rate-limited inputs. Every snapshot carries an ack so clients can predict and reconcile.

Send only what changed

Per-connection, per-entity, per-field diffs. A moving player costs {"x":412}, not the whole world. Keyframes and resync handle lost baselines.

Bots that play fair

Bots fill empty seats and give them up when humans arrive. Their inputs go through the same path as players’, so your rules apply to them for free.

A little less jitter.
A lot more play.

Snapshots arrive late, in bursts, or not at all. The left side draws each one as it lands. The right side runs the same packets through lobbyboi’s Interpolator. The dashed ring is where the server really is.

Latest snapshot
Interpolated, 100 ms behind
Snapshot rate

One object per room, asleep when idle

Every room code maps to one Durable Object, so all players share one process and one source of truth. Timers are alarms, so a lobby of idle players hibernates and costs nothing. The tick loop only runs during a match.

  1. LobbyReady-up, bots, settingsalarm · hibernates
  2. CountdownCancelled if someone joins or un-readiesalarm
  3. Playingstep() at tickHz, snapshots at snapshotHzfixed-step loop
  4. ResultsWhatever step() returnedalarm
WebSocket list · quick-match heartbeat Player Player Player Workerchecks the session GameRoomone per room code LobbyDirectory45 s leases

Small API.
Room for your ideas.

Your agent writes the game hooks and connects your UI. Peek at the shape of the code below, or explore the full README.

import { GameRoom, createLobby } from 'lobbyboi/server';

export class TagRoom extends GameRoom<State, Input> {
  static config = { maxPlayers: 8, tickHz: 30 };

  createGame(ctx) {
    return spawn(ctx.players); // bots included
  }
  step(state, ctx) {
    for (const [id, input] of ctx.inputs)
      move(state, id, input, ctx.dt);
    if (ctx.tick > 1800) return { winner: leader(state) };
  }
  view(state, playerId) {
    return { players: state.players };
  }
  botInput(state, botId) {
    return chaseNearest(state, botId);
  }
}

const lobby = createLobby({ rooms: 'ROOMS' });

1 Bind the objects

// wrangler.jsonc
"durable_objects": {
  "bindings": [
    { "name": "ROOMS", "class_name": "TagRoom" },
    { "name": "LOBBY", "class_name": "LobbyDirectory" }
  ]
},
"migrations": [{
  "tag": "v1",
  "new_sqlite_classes": ["TagRoom", "LobbyDirectory"]
}]

2 Write the room

export class TagRoom extends GameRoom<State, Input> {
  createGame(ctx) { /* initial state */ }
  step(state, ctx) { /* one tick */ }
  view(state, playerId) { /* what they see */ }
}
export { LobbyDirectory } from 'lobbyboi/server';

const lobby = createLobby({ rooms: 'ROOMS' });
export default {
  fetch: async (req, env) =>
    (await lobby(req, env)) ?? env.ASSETS.fetch(req),
};

3 Join from the browser

const lobby = new LobbyClient();
await lobby.login(name);

const room = lobby.join(await lobby.quickMatch());
room.on('room', renderLobby);
room.on('snapshot', render);
room.sendInput({ x: 1, y: 0 });
Sessions are signed, so set a secret once: npx wrangler secret put SESSION_SECRET

Browser multiplayer, explained.

How do I add multiplayer to my browser game?

Give your coding agent the lobbyboi integration prompt. It guides the agent through adding rooms, player connections and server-side game rules to your existing project. Use the setup guide for local tools or all-in-one builders.

Do I need a Cloudflare account?

Yes, to host your multiplayer server online. lobbyboi uses Cloudflare Workers and Durable Objects. You can test the example on your computer with Wrangler’s local runtime before deploying.

Can I use lobbyboi with Lovable?

Your frontend can stay in Lovable if it supports the integration. The multiplayer backend still needs to be deployed to Cloudflare. If your builder cannot deploy it, export or sync your code and have a local coding agent set up the backend. The builder setup guide explains the steps.

Is lobbyboi free?

The library is open source under the MIT license. Cloudflare hosting and your coding tool have their own usage limits and pricing.

Is there a working multiplayer example?

Play the Coin Rush example or read its source code. It demonstrates rooms, bots, player movement and reconnects.

Made for playing.
Better with friends.

A collection of multiplayer games I’ve made with Cloudflare. Pick one, send a friend the link, and jump in.

More of my work ↗