For Developers
A technical guide for contributors to the Chess Analyzer Pro codebase.
Project Overview
Chess Analyzer Pro is a desktop application built with Python and PyQt6. It follows a modular architecture to separate the GUI from the heavy Stockfish analysis logic.
- Stack: Python 3.10+, PyQt6 (GUI), Stockfish (Engine), Google Gemini (AI).
- Repo:
imutkarsht/Chess_analyzer
Directory Structure
Chess_analyzer/
├── main.py # Entry point - initializes app and splash screen
├── config.json # User configuration (auto-generated)
├── analysis_cache.db # SQLite database (auto-generated)
├── requirements.txt # Python dependencies
├── build.spec # PyInstaller configuration
│
├── assets/ # Static resources
│ ├── icons/ # Classification icons (brilliant.svg, blunder.svg, etc.)
│ ├── images/ # Logo, backgrounds
│ ├── pieces/ # Piece themes (cburnett/, merida/, etc.)
│ └── sounds/ # Move sounds (move.mp3, capture.mp3, etc.)
│
├── src/
│ ├── backend/ # Core logic layer
│ │ ├── analyzer.py # Main analysis engine (~680 lines)
│ │ ├── models.py # Data structures
│ │ ├── engine.py # Stockfish wrapper
│ │ ├── pgn_parser.py # PGN parsing
│ │ ├── game_history.py # SQLite persistence
│ │ ├── cache.py # Position caching
│ │ ├── book.py # Opening book
│ │ ├── base_api.py # Shared API utilities
│ │ ├── chess_com_api.py # Chess.com API
│ │ ├── lichess_api.py # Lichess API
│ │ └── gemini_service.py # AI integration
│ │
│ ├── gui/ # UI layer (PyQt6)
│ │ ├── main_window.py # Application window (~720 lines)
│ │ ├── analysis_view.py # Analysis dashboard
│ │ ├── metrics_widget.py # Stats dashboard
│ │ ├── graph_widget.py # Evaluation chart
│ │ ├── styles.py # QSS styling
│ │ ├── gui_utils.py # UI helpers
│ │ ├── sidebar.py # Navigation
│ │ │
│ │ ├── board/ # Board components
│ │ ├── views/ # Main pages (history, settings)
│ │ ├── dialogs/ # Modal dialogs (splash, game picker)
│ │ ├── analysis/ # Analysis widgets (captured, controls)
│ │ ├── components/ # Reusable widgets (stat_card)
│ │ └── metrics/ # Dashboard helpers (charts, workers)
│ │
│ └── utils/ # Utilities
│ ├── config.py # Config file management
│ ├── logger.py # Logging setup
│ ├── path_utils.py # Resource paths
│ └── resources.py # Asset loading
│
├── tests/ # pytest suite
└── docs/ # Documentation
Setup for Development
Prerequisites
- Python 3.10 or higher
- Git
- Stockfish engine
Clone & Install
git clone https://github.com/imutkarsht/Chess_analyzer.git
cd Chess_analyzer
# Create virtual environment
python -m venv venv
# Activate (Windows)
.\venv\Scripts\activate
# Activate (macOS/Linux)
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
Alternative: Using uv (Faster)
pip install uv
uv venv .venv
.venv\Scripts\activate # Windows
uv pip install -r requirements.txt
Run Locally
python main.py
[!NOTE] On first run, go to Settings and configure your Stockfish engine path.
Development Guides
Scenario 1: Changing Move Classification Thresholds
To adjust how strict the move classification is:
- File:
src/backend/analyzer.py - Method:
_classify_move()(around line 568) - Action: Adjust the WPL (Win Probability Loss) thresholds:
# Current thresholds in _classify_move():
if wpl >= 0.20: # 20% → Blunder
elif wpl >= 0.09: # 9% → Mistake
elif wpl >= 0.04: # 4% → Inaccuracy
elif wpl >= 0.01: # 1% → Good
else: # <1% → Excellent
Scenario 2: Adding a New Column to Move List
- File:
src/gui/analysis_view.py - Class:
MoveListPanel - Steps:
- In
__init__, updateself.table.setColumnCount(3)to4. - Add a new header label to the headers list.
- In the
refresh()method, populate the new column data.
- In
Scenario 3: Adding a New Board Theme
- File:
src/gui/styles.py - Location:
BOARD_THEMESdictionary - Steps:
- Add a new entry with light and dark square colors:
BOARD_THEMES = { "default": {"light": "#EEEDD2", "dark": "#769656"}, "my_theme": {"light": "#F0F0F0", "dark": "#404040"}, # ... } - The theme will automatically appear in Settings.
- Add a new entry with light and dark square colors:
Scenario 4: Adding a New Piece Theme
- Directory:
assets/pieces/ - Steps:
- Create a new folder with your theme name (e.g.,
assets/pieces/mytheme/). - Add 12 SVG files named:
wK.svg,wQ.svg,wR.svg,wB.svg,wN.svg,wP.svg,bK.svg,bQ.svg,bR.svg,bB.svg,bN.svg,bP.svg. - Update
src/gui/board/piece_themes.pyto include your theme.
- Create a new folder with your theme name (e.g.,
Scenario 5: Adding a New API Integration
- Reference:
src/backend/lichess_api.py(orchess_com_api.py) - Steps:
- Create
src/backend/your_new_api.pyextendingBaseChessAPI. - Implement
get_user_games()andget_game_by_id()methods. - In
src/gui/main_window.py:- Import your new API class.
- Add a new button to the load menu.
- Connect the action to a handler method.
- Create
Scenario 6: Adding a Reusable UI Component
- Directory:
src/gui/components/ - Steps:
- Create your widget class (e.g.,
my_widget.py). - Export it in
src/gui/components/__init__.py. - Import and use in your views.
- Create your widget class (e.g.,
Key Files Reference
| File | Lines | Purpose |
|---|---|---|
analyzer.py | ~680 | Core analysis logic, accuracy calculation, move classification |
main_window.py | ~720 | Application orchestration, game loading, event handling |
analysis_view.py | ~630 | Analysis dashboard layout and move list |
metrics_widget.py | ~810 | Stats dashboard with charts and AI insights |
styles.py | ~350 | All QSS styles, color constants, theme definitions |
game_history.py | ~220 | SQLite persistence for analyzed games |
Testing
We use pytest for stability testing.
# Run all tests
pytest
# Run specific test file
pytest tests/test_game_load.py
# Run with verbose output
pytest -v
# Run with coverage
pytest --cov=src
[!IMPORTANT] Always run tests after adding a new feature.
Test Structure
tests/
├── test_game_load.py # Game loading and parsing tests
├── test_analysis.py # Analysis engine tests
├── test_api.py # API integration tests
└── conftest.py # Shared fixtures
Building for Distribution
To create the ChessAnalyzerPro.exe standalone executable:
# Install PyInstaller if needed
pip install pyinstaller
# Build using the spec file
pyinstaller build.spec
The output will be located in the dist/ directory.
Build Configuration
The build.spec file includes:
- All asset directories (icons, images, pieces, sounds)
- Hidden imports for
python-chessandPyQt6 - One-file mode with console disabled
- Custom icon from
assets/images/logo.ico
Code Style Guidelines
- Imports: Group by stdlib → third-party → local, separated by blank lines.
- Docstrings: Use triple-quoted docstrings for classes and public methods.
- Type Hints: Use type annotations for function parameters and returns.
- Signals: Define custom signals at class level with descriptive names.
- Logging: Use the
loggerfromsrc.utils.loggerfor all log output.
Useful Debug Commands
# In any file, add:
from src.utils.logger import logger
logger.debug("My debug message")
logger.info("Info message")
logger.error("Error message", exc_info=True)
# Check logs in: chess_analyzer.log