This project has been created as part of the 42 curriculum by vfrants, tkafanov.
Red Tetris is a full-stack, real-time multiplayer implementation of the classic Tetris game. It is built as a modern web application with a React Router client, an Express/Socket.IO API server, and a MySQL database. Players can register, log in, create or join games, and play simultaneously in the same room while the server enforces the game rules.
Main technologies:
- Client: React 19, React Router, TypeScript, Vite, Tailwind CSS, Redux Toolkit
- Server: Node.js, Express, Socket.IO, TypeScript
- Database: MySQL with SQL migration files and a simple migration runner
- Tooling & Quality: ESLint, Prettier, Vitest (client), Mocha + NYC (server), Sentry for monitoring
- Each game is hosted in a room with one or more players, all playing at the same time on their own board.
- The rules follow the classic falling-block Tetris: tetrominoes spawn at the top, you move and rotate them to complete horizontal lines, which are then cleared.
- The server runs the game engine and keeps the state authoritative for all players: piece generation, gravity, line clears, score, KO detection and the overall game status (waiting, running, finished).
- Multiple line clears at once not only increase your score but also send garbage lines to opponents, making their boards harder to manage.
- The engine supports several game modes with different board sizes and piece sets:
Classic– 10×20 board with the 7 classic tetrominoes.Narrow– 6×22 board, classic pieces but less horizontal space.Pentominoes– 12×22 board using five-cell pentomino pieces.Cyber– 8×18 board with custom “cyber” shapes.
- Node.js and pnpm installed (the repository is configured as a pnpm workspace)
- A running MySQL instance with access credentials
git clone <your-repo-url> red-tetris
cd red-tetrisThe root of the project contains an example environment file:
cp .env.example .envKey variables (see .env.example for full list):
DB_HOST,DB_USER,DB_PASSWORD,DB_NAME,DB_PORT– main MySQL databaseDB_PASSWORD_TEST,DB_NAME_TEST– test databaseCLIENT_URL,CLIENT_PORT– allowed frontend origins and client dev portSERVER_PORT– HTTP/Socket.IO server port (defaults to 3002)JWT_SECRET,JWT_EXPIRES_IN– JWT authentication settings
Make sure the configured MySQL user and databases exist (for example red_tetris and
red_tetris_test). The server will apply all SQL migrations from server/migrations on
startup.
At the repository root:
pnpm installThis installs dependencies for both client and server workspaces.
From the repository root:
pnpm run devThis starts, in parallel:
- The API + WebSocket server (Express + Socket.IO, default on port 3002)
- The React Router client dev server (default on port 3001)
You can then open the client in your browser, e.g.:
http://localhost:3001
The server also exposes:
GET /– simple welcome message ("Welcome to Red Tetris API")GET /health– health check including database statusGET /api-docs– Swagger UI with API documentation
To create a production build of both client and server:
pnpm run buildThis will produce:
- Client bundle under
client/build - Server JavaScript under
server/dist
To start both in a production-like mode:
pnpm run startRun linters and formatters across client and server:
pnpm run lint # fix
pnpm run lint:check # check only
pnpm run prettier
pnpm run prettier:checkRun all tests:
pnpm testRun coverage:
pnpm coverageYou can also run commands per workspace (from the repo root):
pnpm --filter=client test
pnpm --filter=server test- User authentication with JWT (register, login) and protected routes
- REST API for authentication and game management (create/join/list games)
- Real-time gameplay using Socket.IO between clients and server
- Game rooms managed by a
GameManagerkeeping track of active games - Tetris game engine on the server (piece generation, game loop, scoring rules)
- React Router front-end with routes for home, login, register, and game screen
- Global state management on the client using Redux Toolkit
- Error and performance monitoring on the client using Sentry (via @sentry/react and @sentry/vite-plugin)
- Automatic database migrations on server startup (MySQL + SQL files)
- Swagger-based API documentation available at
/api-docs - Test suites for both client and server, plus coverage reporting
- Start the application in development mode (
pnpm run dev). - Open the client URL in your browser.
- Register a new account and log in.
- Create a new game (or join an existing one) from the UI.
- Play Tetris in real time; the server manages game state, pieces, and scoring for each room while broadcasting updates via WebSockets.
Exact UI flows (available screens, buttons, etc.) are defined in the client under
client/app/routes and related components.
- Tetris Guidelines / Rules:
- React & React Router:
- Redux Toolkit:
- Socket.IO (real-time communication):
- Express (API server):
- MySQL:
- JSON Web Tokens (JWT):
- Sentry (error & performance monitoring):
- GitHub Copilot (GPT-5.1) was used to assist with:
- Drafting and structuring this README file.
- Suggesting small refactorings, tests, and utility code during development.
- Providing quick feedback and alternatives for TypeScript, React, Express, Socket.IO, and SQL patterns.
- Claude Opus 4.6 was also used by teammate
tkafanovfor higher-level design discussion, alternative implementation ideas, and additional wording suggestions. - All generated suggestions from both tools were reviewed, adapted, and validated by the authors (vfrants, tkafanov), who remain responsible for the design, logic, and final implementation of the project.