This document explains how Checkora integrates its Django backend with a high-performance C++ chess engine. It focuses on actual implementation — how commands flow, how communication works, and how AI decisions are computed.
Checkora uses a hybrid architecture:
- Django (Python) → Handles API, game state, and frontend communication
- C++ Engine → Handles computation (move generation, validation, AI)
The two systems communicate using a subprocess-based model.
- User performs an action on the frontend
- Django receives and processes the request
- Django sends a command to the C++ engine
- C++ engine processes the request
- Result is returned to Django
- Django sends response back to frontend
Django communicates with the C++ engine using Python’s subprocess module.
proc = subprocess.Popen(
self._build_engine_command(engine_path),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
stdout, _ = proc.communicate(input=command, timeout=5)
return stdout.strip()- Django runs the C++ engine as a separate process
- Commands are sent via stdin
- Output is received via stdout
👉 This forms a text-based communication protocol
Purpose: Get valid moves for a selected piece
Input:
MOVES <board> <castling_rights> <turn> <row> <col>
Output:
MOVES r c is_capture is_promotion ...
Used in: game/engine.py → _get_engine_moves()
Purpose: Calculate best move using AI
Input:
BESTMOVE <board> <castling_rights> <turn> <depth>
Output:
BESTMOVE <from_row> <from_col> <to_row> <to_col>
Used in: get_ai_move()
Purpose: Check game state
Output:
STATUS checkmate | stalemate | check | ok
Purpose: Handle pawn promotion
C++ engine works as a command processor:
- Reads input using
cin - Identifies command
- Executes logic
- Returns result using
cout
👉 This follows a command dispatcher pattern
- Explores possible moves
- Evaluates game states
- Selects best move
- Skips unnecessary branches
- Improves performance
depth = self._get_ai_search_depth()- User makes a move
- Django processes request
- Command is generated
- C++ engine is invoked
- Engine computes result
- Output returned
- Django parses result
- Frontend updates UI
Checkora combines:
- Python → control and flexibility
- C++ → speed and performance
- Communication → lightweight protocol
This results in a fast and scalable system.