How lokesh-reddy18/chess-master works
Project Type & Purpose
• Chess Master is a full-stack web application for playing chess: local, global (real-time multiplayer), AI (Stockfish), and puzzles.
• It consists of a React/Vite/Tailwind frontend, a Node.js/Express backend, real-time via Socket.io, MongoDB Atlas storage, JWT auth, and the Stockfish engine.
Main Components
a. Frontend Client
• React app (Vite)
• UI Components (e.g., Game board, Navbar, Modals, Puzzles)
• State Management (Redux store via authSlice.js + store.js)
• SocketManager (real-time events)
• HTTP client for REST calls (auth-utils.js)
b. Backend Server
• Express.js HTTP API (userRoutes, profileRoutes)
• Socket.io server for real-time gameplay and matchmaking
• MVC layers:
• Controllers (UserController)
• Services (auth logic)
• Models (Mongoose userModel)
• Middlewares (JWT auth)
• Config & DB connection (connect.js, db.js)
c. Database
• MongoDB Atlas (users, profiles, game history)
d. External Services
• Stockfish chess engine (invoked for AI mode)
• Optionally, third-party hosting (Vercel/Render)
Component Interactions
• User opens React UI → makes HTTP requests to Express API for signup/login (JWT)
• On successful auth, client stores JWT and connects via Socket.io
• Socket.io channels handle:
• Global match queue (matchmaking)
• Real-time move events (broadcast between peers)
• Game over notifications
• For AI games, backend spawns Stockfish process or communicates via a Stockfish service
• Backend persists game results / profiles in MongoDB
Architectural Patterns & Design Principles
• Separation of concerns:
• Frontend vs Backend
• MVC pattern in backend
• Flux/Redux in frontend
• Layered architecture: API layer, business‐logic layer, data layer
• Event-driven design for real-time gameplay (Socket.io)
• Security: JWT authentication middleware
• Extensibility: services folder encapsulates auth, chess‐engine logic