~/vimal-jain
Real-Time MultiplayerNov 2026

Bended Queen — Multiplayer Card Game

Production-ready, server-authoritative multiplayer trick-taking card game for 3–13 players built with React 18, Node.js, Socket.IO, and Redis.

Problem Statement

Building a real-time multiplayer card game that scales dynamically from 3 to 13 players requires strict server-authoritative game state, resilient WebSocket reconnection handling, and deterministic deck/rule validation so clients cannot spoof cards or stall lobbies when connections drop.

System Architecture & Data Flow

The project is architected as a decoupled monorepo with an event-driven React 18 frontend (hearts-game/) and a Node.js + Express + Socket.IO authoritative backend (hearts-game-server/).

React 18 Client (Vite / React Router / Unified GameContext)
  │  ├── High-Frequency Memoized UI: Card, PlayerHand, ScoreBoard
  │  └── SocketService (Event-driven client + session persistence)
  │
  ▼ (Bidirectional WebSockets via Socket.IO)
Node.js + Express Authoritative Server (ESM)
  ├── Room & Matchmaking Handlers (Quick Match / Direct Room IDs)
  ├── Authoritative Game Engine
  │     ├── Dynamic 3–13 Player Dealing & Discarded-Card Tracking
  │     ├── Strict Rule Validator (Follow-suit, Turn Order, Possession)
  │     ├── Scoring Engine (Hearts, Queen of Spades, -5 Zero-Trick Bonus)
  │     └── Resiliency: 2-Min Reconnect Window & Bot Auto-Play Timeouts
  │
  ▼ (State Persistence Layer)
Redis Store (ioredis) ──▶ Automatic Zero-Config In-Memory Fallback

Core Features & Capabilities

•Dynamic 3–13 Player Scaling: Automatically adapts deck dealing and tracks discarded cards across any party size from 3 to 13 players.
•Quick Matchmaking & Private Lobbies: Supports random room matchmaking as well as direct Room ID invite codes.
•Multi-Round Lifecycle: Configurable round limits (3, 5, 7, 10 rounds) with intermediate round standings (RoundEndModal) and final winner podium (GameOverModal).
•Server-Authoritative Validation: Enforces follow-suit rules, turn order, card possession, and room boundaries strictly on the backend.
•Resilient Reconnection & Bot Fallback: Includes a 2-minute reconnect window with automatic session rejoin, plus bot auto-play when a player's turn times out.
•Performance Optimization: React memoization applied to high-frequency rendering components (Card, PlayerHand, ScoreBoard).

Technical Challenges & Engineering Solutions

•Zero-Config State Persistence: Integrated ioredis for multi-instance Redis room state, paired with an automatic in-memory fallback so the server boots and runs cleanly in local or single-node environments without external Redis dependencies.
•Disconnection & Turn-Stall Prevention: Handled mid-round network drops using session persistence tokens and a 2-minute grace window, automatically triggering server-side bot moves on turn expiration to keep matches moving smoothly.
•Production Hardening & Automated Testing: Built a native Node.js test suite (node --test) covering deck generation, scoring edge cases, trick rules, and room lifecycle, alongside a /health endpoint and graceful shutdown handlers.

Impact & Verification Status

•Automated test suite covering deck, scoring, rule validation, and game lifecycle.
•Verified across 3–13 player configurations with automated bot timeout recovery.

Stack

React 18Node.jsExpress.jsSocket.IORedisioredisViteReact RouterWebSocketsNode Test Runner