How recepsalih03/game-center works
Project type and purpose
• This is a full-stack, real-time, multiplayer gaming platform built as a modular monorepo (Lerna + NPM workspaces).
• Purpose: allow users to authenticate, join or create lobbies, play a synchronized Tombala game in real time, and receive notifications.
File structure
• Top-level “packages/” contains three key sub-packages:
• client (React/TS UI)
• server (Node/Express/TS REST + WebSocket backend)
• config (shared configuration, e.g. user lists)
• There’s also a “game-tombala” package holding core game logic used by the server.
• Client folder: public assets, React components, pages, contexts (Auth, Socket, Theme), hooks, services (API & socket wrappers).
• Server folder: Express app entrypoint, REST routes (auth, games, lobbies, public/protected), game-handlers for game logic, in-memory store, middleware (auth, error handler, logger), utils (JWT, hashing).
Inspect README for architecture insights
• JWT-based authentication, Socket.IO for real-time lobby & game sync.
• Modular game architecture: game-tombala plug-in.
• Two development servers (client:3000, server:4000) with proxying for CORS.
Main components and interactions
a. Components
• Frontend (React SPA)
– UI Layers: Pages, Components, Context Providers (AuthContext, SocketContext, ThemeContext)
– Services: Axios HTTP client, Socket.IO client
• Backend (Express API + WebSocket)
– HTTP REST endpoints: /auth, /games, /lobbies (public/protected)
– WebSocket channels (namespaces or events) for lobbies & game events
– Game Logic Engine (game-tombala handler)
– In-Memory Store for lobbies, active games, user sessions
– Middleware: JWT auth, logging, error handling
• Shared Config (users, settings)
• External concerns
– JWT issuer/validator (jsonwebtoken)
– Browser (sound & toast notifications via react-toastify)
– Developer machines running npm run dev
b. Relationships & data flow
1. User opens browser → React client served from dev server or build.
2. Client → HTTP POST /auth/login → Server (JWT issued).
3. Client stores JWT and attaches it to subsequent HTTP headers or Socket.IO handshake.
4. Client fetches game and lobby lists via REST.
5. Client connects to Socket.IO channel, authenticates via JWT on connect.
6. Real-time lobby events (join/leave/invite/start game) flow bi-directionally over WebSocket.
8. On game end, server broadcasts result; clients display GameOverDialog.
c. Architectural patterns & principles
• Monorepo modularization (shared config, game logic plug-in)
• Separation of concerns (UI vs API vs real-time engine)
• Context-driven state management in React
• Middleware pipeline for authentication, logging, error handling
• Single in-memory store (no external DB; extendable to Redis or SQL)
• Event-driven design via Socket.IO
d. Key technologies to call out
• React 18 + TypeScript + MUI v5 + React Router v6
• Axios + React-Toastify + Socket.IO client
• Node.js + Express.js + TypeScript + Socket.IO server
• jsonwebtoken for JWT, bcrypt or custom hash util
• Lerna + NPM workspaces for monorepo management