╔══════════════════════════════════════════════════════════════════════╗
║ ║
║ ♟️ I8O8IChessOnline - Multiplayer Chess ♟️ ║
║ ║
║ Modern Professional RealTime Chess Platform With A PHP Frontend ║
║ Python (Flask + Socket.IO) Backend, And MySQL Database ║
║ ║
╚══════════════════════════════════════════════════════════════════════╝
I8O8IChessOnline Is A PurposeBuilt RealTime Multiplayer Chess Platform Intended For Local Development, Testing, And Small Scale Deployment. The Project Combines A Lightweight PHP Frontend For The User Interface With A Python Backend That Handles Matchmaking, GameState, And RealTime Synchronization Via Socket.IO.
This Repository Contains Both Frontend And Backend Code, Database Schema, And Utility Modules For EloRating And ChessLogic.
╔════════════════════════════════════════════════════════════╗
║ FEATURE HIGHLIGHTS ║
╠════════════════════════════════════════════════════════════╣
║ ⚡ RealTime Multiplayer With LowLatency Move Sync ║
║ 🎯 Matchmaking Queue And QuickMatch Support ║
║ ⏱️ Multiple TimeControls (Classical, Rapid, Blitz) ║
║ 📊 EloRating Calculation And RatingHistory Tracking ║
║ 💬 InGame Chat And Basic Achievement System ║
║ 🔍 LiveGameAnalysis Hooks For Engine Integrations ║
║ 🐛 Local Debug Endpoints For Inspecting GameState ║
╚════════════════════════════════════════════════════════════╝
- Frontend: PHP, HTML5, CSS3, Javascript, Chessboard.js, Chess.js, Socket.IO Client.
- Backend: Python, Flask, Flask-SocketIO, Eventlet (Optional), PyMySQL, Python-Chess.
- Database: MySQL (DbSchema Provided In Backend/DbSchema.sql).
- DevTools: XAMPP For Local Frontend Hosting, Virtualenv For Python Backend.
The Backend Maintains Two Primary Concerns:
- Persistent Storage For Users, Games, And Ratings (MySQL).
- InMemory Structures For ActiveGames, Timers, And Matchmaking Queues.
Socket.IO Is Used For RealTime Notifications. The Backend Emits MatchFound Events And GameUpdate Events. The Frontend Joins Rooms Using A JoinToken Provided By The Backend.
Follow These Steps For A Local Development Environment On Windows. Commands Are Shown For PowerShell Where Applicable.
- Windows With Administrative Privileges (For XAMPP).
- XAMPP Or Equivalent PHP Server (For Frontend).
- Python 3.8+ Installed And On PATH.
- MySQL Server Or XAMPP MySQL Enabled.
git clone https://github.com/YourUser/I8O8IChessOnline.git
cd ChessOnline- Create The Database And Import The Schema.
# From Project Root
mysql -u root -p < .\Backend\DbSchema.sql- Verify Tables Exist Using PhpMyAdmin Or Mysql Client.
- Create And Activate A Virtual Environment.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r .\Backend\Requirements.txt- Review And Update
Backend/Config.pyTo Match Your Environment.
- DatabaseHost
- DatabasePort
- DatabaseUser
- DatabasePassword
- DatabaseName
- SocketIoCorsOrigins
- FlaskHost
- FlaskPort
- Run The Backend Server.
# From Repository Root
python .\Backend\App.pyThe Backend By Default Binds To The Host And Port Defined In Backend/Config.py.
- Copy Or Symlink The
FrontendFolder Into Your Webserver DocumentRoot. For XAMPP Use The Following Path:
C:\xampp\htdocs\ChessOnline
-
Edit
Frontend/Config.phpAnd SetApiBaseUrlTo Your Backend Address (For Examplehttp://localhost:5000). -
Open The Frontend In A Browser, Example:
http://localhost/ChessOnline/Frontend/index.php
The Backend Exposes A RESTful API Under The /api Prefix. The Most Common Endpoints Are Documented Below Along With Example PowerShell Requests.
- Endpoint: POST /api/register
- Payload: { "UserName": "Alice", "Password": "S3cret" }
Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/register" -Body (@{UserName='Alice';Password='S3cret'} | ConvertTo-Json) -ContentType 'application/json'- Endpoint: POST /api/login
- Payload: { "UserName": "Alice", "Password": "S3cret" }
- Endpoint: POST /api/quickmatch
- Payload: { "UserId": 123, "GameType": "blitz" }
Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/quickmatch" -Body (@{UserId=123;GameType='blitz'} | ConvertTo-Json) -ContentType 'application/json'- Endpoint: POST /api/cancel-match
- Payload: { "UserId": 123 }
- Endpoint: GET /debug/inmemory/game/
- Note: Endpoint Is Intended For Localhost Debugging Only.
The Following JSON Schemas Use PascalCase Keys To Match The Project Naming Style.
{
"UserName": "Alice",
"Password": "S3cret"
}{
"Success": true,
"UserId": 42,
"Message": "UserRegistered"
}{
"UserId": 42,
"GameType": "Blitz",
"PreferredTimeControl": "3+0"
}{
"GameId": "game_abc123",
"JoinToken": "token_xyz",
"Fen": "startfen",
"WhiteUserId": 42,
"BlackUserId": 99
}{
"GameId": "game_abc123",
"UciMove": "e2e4",
"MoveSan": "e4",
"NewFen": "fen_after_move",
"MoverUserId": 42,
"MoveNumber": 1,
"RemainingTimeMs": 295000
}SocketIO Is Used For MatchNotifications And GameEvents. The Backend Emits Events And Accepts Client Connections That Join Game Rooms.
- connected — Emitted By The Server After A Successful Socket Connection.
- matchFound — Emitted When The Matchmaker Pairs Players. Payload Includes GameId, JoinToken, Fen, WhiteUserId, BlackUserId.
- gameUpdate — Emitted When A Move Is Made. Payload Includes UciMove, NewFen, MoveSan, MoveNumber, RemainingTime.
- playerDisconnected — Emitted When A Player Drops Out Of A Game.
The Following Examples Use PascalCase Keys For All Message Fields.
{
"Event": "MatchFound",
"Payload": {
"GameId": "game_abc123",
"JoinToken": "token_xyz",
"Fen": "startfen",
"WhiteUserId": 42,
"BlackUserId": 99
}
}{
"Event": "GameUpdate",
"Payload": {
"GameId": "game_abc123",
"UciMove": "e2e4",
"MoveSan": "e4",
"NewFen": "fen_after_move",
"MoverUserId": 42,
"MoveNumber": 1,
"RemainingTimeMs": 295000
}
}- Player Requests QuickMatch Via POST /api/quickmatch.
- Server Places Player In A Queue Indexed By GameType And Rating Bracket.
- Server Attempts To Pair Players Periodically.
- When A Pair Is Found, Server Creates An InMemory Game And Emits matchFound To Both Players.
- Players Use The JoinToken To Join The SocketIO Room And Begin The Game.
- Moves Are Exchanged Via Socket Events And Validated On The Server Using python-chess.
- GameResult Is Calculated And EloRating Is Updated Persistently.
The InMemory GameState Contains The Following Conceptual Fields:
- GameId
- WhiteUserId
- BlackUserId
- CurrentFen
- MoveHistory
- Clocks (WhiteRemainingMs, BlackRemainingMs)
- GameStateStatus (Waiting, Active, Finished)
- JoinTokens
Persistent Representation Is Stored In The Database Via Models.py When Games End.
Example Data Models Use PascalCase For Field Names.
- UserId
- UserName
- HashedPassword
- CreatedAt
- LastActiveAt
- EloClassical
- EloRapid
- EloBlitz
- GameId
- WhiteUserId
- BlackUserId
- StartFen
- EndFen
- Result
- Moves
- StartedAt
- EndedAt
- Backend Logs Are Appended To
Logs/Backend.logBy Default. - Use The Log File To Debug Matchmaking, Exception Traces, And Timer Behavior.
- Add Additional Monitoring Or Instrumentation As Needed (Prometheus, Sentry, Etc.).
A Minimal DockerCompose Example Is Included In docker-compose.yml. The Backend Also Includes A Dockerfile Under Backend/ To Build The Service.
# Register
Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/register" -Body (@{UserName='Alice';Password='S3cret'} | ConvertTo-Json) -ContentType 'application/json'
# Login
Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/login" -Body (@{UserName='Alice';Password='S3cret'} | ConvertTo-Json) -ContentType 'application/json'
# QuickMatch
Invoke-RestMethod -Method Post -Uri "http://localhost:5000/api/quickmatch" -Body (@{UserId=42;GameType='Blitz'} | ConvertTo-Json) -ContentType 'application/json'const socket = io(ApiBaseUrl, { transports: ['websocket'] });
socket.on('connect', () => {
console.log('Connected');
});
socket.on('matchFound', (data) => {
console.log('MatchFound', data);
});
socket.on('gameUpdate', (data) => {
console.log('GameUpdate', data);
});- Do Not Commit Production Credentials To Source Control.
- Use Environment Variables For Secrets In Deployment.
- Consider Using HTTPS/TLS For All Client–Server Communication In Production.
- Validate And Sanitize All Inputs From The Frontend, Including Chess Moves And Chat Messages.
- FrontendCannotConnect: Verify
Frontend/Config.phpApiBaseUrlMatches The Backend Address And That Socket Io Origins Are Allowed InBackend/Config.py. - MysqlConnectionError: Confirm Mysql Is Running And Credentials Are Correct. Test With The Mysql Client Or PhpMyAdmin.
- SocketIoVersionMismatch: Ensure The Client And Server Socket Io Versions Are Compatible; Check Browser Console For Errors.
- PortInUse: If Port 5000 Is In Use, Change
FlaskPortInBackend/Config.pyAnd Update FrontendApiBaseUrl.
- OpenAnIssue For Bugs Or FeatureRequests Before Starting Significant Work.
- Fork The Repository And Open A Pull Request Against
mainWhen Changes Are Ready. - Include Tests For New Or Changed Business Logic Where Practical.
- Maintain Clear And Focused Commits.
If You Would Like, A CONTRIBUTING.md File Is Provided In The Repository With Additional Guidance.
This Project Is Licensed Under The MIT License. See The LICENSE File For Full Text.
Open An Issue On GitHub For Support, Or Use The Repository's Issue Tracker To Report Bugs And Request Features




