Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Masters — README

Project overview

Chess Masters is a small multiplayer chess web app built with Express + EJS, real-time gameplay via Socket.IO, and persistent user accounts stored in MongoDB. The server validates moves using the chess.js library. Authentication uses JWT stored in an HTTP-only cookie.

Tech stack

Quick setup

  1. Install dependencies:
npm install
  1. Ensure MongoDB is running and accessible. Default URI is in the project's .env file:
  • MONGODB_URI (default: mongodb://localhost:27017/chess-app)
  • JWT_SECRET
  • PORT (optional)
  1. Start the server:
node app.js

Open http://localhost:3000 (or your configured PORT).

Note: package.json does not include a start script by default — start with node app.js or add a script.

Important files (overview & links)

Routes & API

Public (no auth):

Protected (requires JWT cookie, enforced by auth):

  • GET / — main game page (views/index.ejs)
  • GET /logout — clears cookie (note: route is GET /logout in server)

Client side code:

Auth flow (high level)

  1. Signup/login endpoints create or verify a user via User.
  2. On success the server signs a JWT with JWT_SECRET and sets it as an HTTP-only cookie named token.
  3. The auth middleware reads the cookie, verifies the JWT, loads the user from DB and attaches req.user for protected routes.
  4. Views use req.user (e.g., views/index.ejs shows user.username).

Real-time gameplay flow

  • On Socket.IO connection (app.js), the server assigns roles: white, black, or spectator.
  • The chess game state is managed server-side using chess.js (new Chess() in app.js).
  • Client emits "move" with coordinates (client: public/javascripts/chessgame.js). Server validates with chess.js, broadcasts "move" and "boardState" (FEN) to all clients.
  • Client listens for "boardState" and "move" to update the UI.

Client specifics

Known issues & TODOs

  • Logout mismatch: client logout in public/javascripts/auth.js posts to /api/logout (POST), but the server exposes GET /logout. Update either client or server for consistency.
  • No start script in package.json — add "start": "node app.js" if desired.
  • Consider rate limiting, stronger JWT secret management, HTTPS in production, and CSRF protections for added security.
  • The server currently assigns player roles purely by connection order and does not persist games or reconnect players to prior roles.

Security notes

  • JWT secret is stored in .env — do not commit secrets to git.
  • Cookies are HTTP-only; in production they are marked secure when NODE_ENV is production.
  • Passwords are hashed with bcrypt (see User).

Where to start exploring the code

About

This is the site link

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages