All projects

Escape Game

An escape room you book, pay for and then actually play in the browser — tasks, hints, QR codes and inventory, all in one Next.js + Payload CMS app.

Escape Game Hero

Who it is for

Teams of friends looking for a night out — and the operator who has to run the room without a developer on call.

My contribution

  • Game domain in Payload: 12 collections from games and tasks to teams, sessions and payments
  • Full-screen play UI — lobby, task flow, hints, results — with QR scanning
  • Reservations, payments, transactional email and scheduled clean-up jobs
  • AI editorial assistant and custom editor features carried over from my template
  • Unit and end-to-end tests with Vitest and Playwright

Collaboration

A two-person team where I wrote almost all of the code — from the booking calendar to the game engine.

The challenge

Selling a time slot is the easy part. Ztracený kód arény also had to run the game itself — tasks, hints, scanned props, a ticking clock — without a second system bolted on.

The solution

One Next.js + Payload CMS app. The game is modelled as content — rooms, tasks, hints, items, QR and access codes — so a new puzzle is an edit, not a deploy. A separate full-screen route group runs the play session: lobby, tasks, hints, results.

Results & impact

  • Marketing, booking, payment and the game itself run in a single application.

  • The operator adds rooms and rewrites puzzles in the CMS — no developer needed.

The game lives in the CMS

Tasks, hints and their time penalties are just a Payload collection. The solution field is locked to authenticated staff — players never get to read it.

collections/Game/Tasks.tsIllustrative example
// Illustrative — puzzles are content, so the operator edits them.
import type { CollectionConfig } from "payload";

export const Tasks: CollectionConfig = {
  slug: "tasks",
  admin: { useAsTitle: "title", group: "Game" },
  fields: [
    { name: "game", type: "relationship", relationTo: "games", required: true },
    { name: "title", type: "text", required: true, localized: true },
    { name: "prompt", type: "richText", localized: true },
    { name: "order", type: "number", required: true },
    {
      name: "solution",
      type: "text",
      required: true,
      // Never leaves the server — the client only ever sends guesses.
      access: { read: ({ req }) => Boolean(req.user) },
    },
    {
      name: "hints",
      type: "array",
      fields: [
        { name: "text", type: "textarea", localized: true },
        { name: "penaltySeconds", type: "number", defaultValue: 60 },
      ],
    },
  ],
};

Scan, guess, check — on the server

Physical props carry QR codes. The phone sends a guess, the server compares, logs the attempt and returns a boolean. That's all the client ever learns.

app/api/validate-code/route.tsIllustrative example
// Illustrative — checking a scanned code on the server.
export async function POST(req: Request) {
  const { sessionId, taskId, code } = schema.parse(await req.json());
  const payload = await getPayload({ config });

  const task = await payload.findByID({ collection: "tasks", id: taskId });
  const correct = normalise(code) === normalise(task.solution);

  await payload.create({
    collection: "task-attempts",
    data: { session: sessionId, task: taskId, correct },
  });

  return Response.json({ correct }); // the answer itself never ships
}

A session you can refresh

Someone always reloads the page mid-game. A discriminated union keeps the states honest, and the client store just mirrors what the server says.

components/Game/play/session.tsIllustrative example
// Illustrative — a session that survives a refresh.
type SessionState =
  | { status: "lobby"; teamId: string }
  | { status: "playing"; teamId: string; taskIndex: number; startedAt: string }
  | { status: "finished"; teamId: string; durationSeconds: number };

export const useGameSession = create<{ state: SessionState | null }>(() => ({
  state: null,
}));

// The server is the source of truth; the store is just a fast mirror of it.
export async function resume(sessionId: string) {
  const res = await fetch(`/api/game/session/${sessionId}`);
  useGameSession.setState({ state: await res.json() });
}

Key decisions

Puzzles are CMS content

Puzzles get reworded after every few runs. As collections, the operator retunes the room in the admin instead of waiting for a deploy.

Answers never reach the browser

Codes are validated server-side, so a curious team with DevTools open finds guesses, not solutions.

A separate full-screen shell for play

The marketing site wants SEO and scrolling; the game wants full screen and state. Different jobs, different layouts.

What I learned

Game state is merciless. A refresh mid-session has to land the team exactly where they were — treating the session as server state from day one saved a rewrite.