Code walkthrough — every file explained

Plain-language documentation for every file in this project. Each page covers one source file and explains the code line by line.

If you are reading this to prepare for an interview, read them in this order. The first four are where the interesting decisions live.

Read these first

#FileWhat it does
1domain/GameRoom.mdThe heart of the project. One lobby: players, movement, collisions, scoring, the leaderboard.
2domain/GameManager.mdHolds all the lobbies and decides which one you join.
3loop/GameLoop.mdThe heartbeat — wakes 20 times a second and drives every lobby.
4realtime/socketServer.mdTalks to browsers over WebSocket.

The rest of the server

FileWhat it does
domain/types.mdThe shapes of all the data. No logic, just definitions.
domain/rng.mdRepeatable random numbers, so tests can replay a board.
config/gameConfig.mdEvery tunable number in one place.
realtime/validation.mdChecks messages from browsers before trusting them.
realtime/rateLimiter.mdStops one player flooding the server.
persistence/GameRepository.mdThe saving contract, plus a fake for tests.
persistence/PrismaGameRepository.mdThe real PostgreSQL saving.
persistence/PersistenceSubscriber.mdListens for "game over" and queues a save.
persistence/WriteQueue.mdStops 100 saves at once from crushing the database.
http/app.mdThe plain web pages and JSON endpoints.
server.mdWires every piece together.
entrypoint.mdindex.ts — starts the process and picks a database.

Frontend, database and tests

FileWhat it does
frontend.mdpublic/index.html — the browser game.
database-schema.mdprisma/schema.prisma — the three tables.
tests/unit-tests.mdThe 53 tests that need no network or database.
tests/integration-tests.mdThe 17 tests over real WebSockets.
loadtest/stress.mdThe 2,000-player stress test.
loadtest/worker.mdThe fake players it drives.
loadtest/smoke.mdPlays one full game end to end.
project-setup.mdpackage.json, tsconfig.json, docker-compose.yml, .env.

How to read a page

Every page has the same four parts:

  1. In one sentence — what the file is for.
  2. Why this file exists — the decision behind it.
  3. The code, line by line — small blocks of code, each followed by an explanation of what every line does.
  4. If an interviewer asks — the short answer to say out loud.

The one-paragraph summary of the whole project

Players join a lobby and race to collect items. The server decides everything — the browser only says which direction a key is pressed. Twenty times a second the server moves everyone, checks who touched an item, awards points, and sends the new picture to every player in that lobby. Live state lives in memory because it changes too fast for a database; PostgreSQL is written once, when a game ends.

Built with LogoFlowershow