Logo
Chess Analyzer Pro
ReleasesDocsBlogDownload

Documentation

Getting StartedUsage GuideConfigurationArchitectureFiles & DataHow We Calculate AnalysisChangelogFor DevelopersTroubleshootingAPI ReferenceUI Components

Chess Analyzer Pro

Professional local-first chess analysis.

Project

  • GitHub Repository
  • Download
  • Documentation
  • Report Feedback/Bug

Resources

  • Stockfish Engine
  • Beekeeper Studio
  • My Lichess Profile
  • My Chess.com Profile

Developer

  • Portfolio
  • GitHub Profile
  • LinkedIn
  • Contact Me
© 2026 Utkarsh Tiwari. Open Source.

Architecture & Data Flow

Chess Analyzer Pro follows a Model-View-Controller (MVC) oriented architecture to ensure separation of concerns between the chess logic, the user interface, and the data management.

High-Level Pattern

  1. Model (Backend): Handles the core logic and data state.
    • State: GameAnalysis objects hold moves, evaluation scores, and metadata.
    • Computation: The Analyzer class manages the heavy lifting of communicating with Stockfish.
  2. View (GUI): Displays the data to the user.
    • PyQt6: The entire UI is built using the Qt framework.
    • Components: BoardWidget (Visual Board), AnalysisPanel (Stats/Graphs), MoveListPanel, MetricsWidget (Dashboard).
  3. Controller (Logic): Orchestrates the application.
    • Signals & Slots: The robust event system in Qt connects UI actions (like clicking "Next Move") to backend functions (like "Load Board State").

Directory Structure

Chess_analyzer/
├── main.py                 # Application entry point
├── config.json             # User configuration (saved settings)
├── analysis_cache.db       # SQLite database for game history & cache
├── requirements.txt        # Python dependencies
├── build.spec              # PyInstaller configuration
│
├── assets/                 # Static resources
│   ├── icons/              # SVG/PNG icons for classifications
│   ├── images/             # Logo, backgrounds
│   ├── pieces/             # Piece theme directories (cburnett, merida, etc.)
│   └── sounds/             # Audio files for moves, captures, etc.
│
├── src/                    # Source code
│   ├── backend/            # Core logic, analysis, and data handling
│   │   ├── analyzer.py     # Main analysis engine & move classification
│   │   ├── base_api.py     # Shared API utilities
│   │   ├── book.py         # Opening book lookups
│   │   ├── cache.py        # Position analysis caching
│   │   ├── chess_com_api.py # Chess.com API integration
│   │   ├── engine.py       # Stockfish UCI wrapper
│   │   ├── game_history.py # SQLite game persistence
│   │   ├── gemini_service.py # Google Gemini AI integration
│   │   ├── lichess_api.py  # Lichess API integration
│   │   ├── models.py       # Data structures (GameAnalysis, MoveAnalysis)
│   │   └── pgn_parser.py   # PGN file parsing
│   │
│   ├── gui/                # User Interface components (PyQt6)
│   │   ├── main_window.py  # Root application window
│   │   ├── analysis_view.py # Analysis dashboard layout
│   │   ├── analysis_worker.py # Background analysis thread
│   │   ├── graph_widget.py # Evaluation curve visualization
│   │   ├── game_list.py    # Game selection dialogs
│   │   ├── sidebar.py      # Navigation sidebar
│   │   ├── styles.py       # QSS theming & color constants
│   │   ├── gui_utils.py    # Shared UI helper functions
│   │   ├── live_analysis.py # Real-time position analysis
│   │   ├── loading_widget.py # Loading overlay animations
│   │   ├── metrics_widget.py # Stats dashboard with charts
│   │   │
│   │   ├── analysis/       # Analysis-specific widgets
│   │   │   ├── captured.py # Captured pieces display
│   │   │   └── controls.py # Game navigation buttons
│   │   │
│   │   ├── board/          # Chessboard components
│   │   │   ├── board_widget.py # Main board renderer
│   │   │   ├── eval_bar.py # Evaluation bar widget
│   │   │   └── piece_themes.py # Piece set management
│   │   │
│   │   ├── components/     # Reusable UI components
│   │   │   └── stat_card.py # Stat display card widget
│   │   │
│   │   ├── dialogs/        # Modal dialogs
│   │   │   ├── game_selection_dialog.py # Game picker dialog
│   │   │   └── splash_screen.py # Startup splash screen
│   │   │
│   │   ├── metrics/        # Dashboard charts & workers
│   │   │   ├── charts.py   # Chart generation (donut, line)
│   │   │   └── workers.py  # Background stat calculation
│   │   │
│   │   └── views/          # Main view pages
│   │       ├── history_view.py # Game history browser
│   │       └── settings_view.py # Settings panel
│   │
│   └── utils/              # Helper utilities
│       ├── config.py       # Configuration file management
│       ├── logger.py       # Logging setup
│       ├── path_utils.py   # Resource path resolution
│       └── resources.py    # Asset loading helpers
│
├── tests/                  # pytest suite

Key Components

Backend (src/backend/)

ComponentResponsibility
analyzer.pyThe Brain. Manages the analysis queue, calculates Win Probability Loss (WPL), determines move classifications (Brilliant, Blunder, etc.), computes accuracy using Lichess-style algorithm, and updates the game state.
engine.pyStockfish Bridge. Wraps the Stockfish process using python-chess. Handles UCI protocol commands (position, go, stop) and parses engine output.
models.pyData Types. Single source of truth for data structures: GameAnalysis, MoveAnalysis, GameMetadata.
pgn_parser.pyData Ingestion. Robust parsing of .pgn files to extract moves, headers, and comments.
game_history.pyPersistence. SQLite database manager for saving/loading analyzed games with full metadata and move data.
cache.pyPerformance. Caches engine analysis results by FEN to avoid re-analyzing known positions.
book.pyOpening Detection. Interfaces with opening book to identify known opening positions.
chess_com_api.pyChess.com Integration. Fetches games from Chess.com usernames or game URLs.
lichess_api.pyLichess Integration. Fetches games from Lichess usernames or game URLs with token auth.
gemini_service.pyAI Summaries. Connects to Google's Gemini API to generate natural language game summaries and coaching insights.
base_api.pyAPI Utilities. Shared request handling, error logging, and JSON parsing for API classes.

GUI (src/gui/)

ComponentResponsibility
main_window.pyRoot Container. Initializes the application window, sidebar, page stack, and routes global events. Manages game loading and analysis orchestration.
analysis_view.pyDashboard. The central hub displaying the board, stats, graphs, and move list side-by-side. Contains AnalysisPanel and MoveListPanel.
board/board_widget.pyVisuals. Renders the chess board with customizable themes, pieces, arrows (for best moves), and highlights (last move, check).
board/eval_bar.pyEvaluation Bar. Vertical bar showing white/black advantage percentage.
board/piece_themes.pyPiece Sets. Manages loading and applying different piece styles (cburnett, merida, etc.).
graph_widget.pyVisualization. Uses matplotlib to draw the evaluation curve with hover tooltips and classification markers.
metrics_widget.pyStatistics Dashboard. Displays aggregate performance metrics, charts (donut, line), openings analysis, and AI coaching insights.
views/settings_view.pySettings Panel. UI for configuring engine path, API keys, themes, and usernames.
views/history_view.pyGame History. Browse, reload, and manage previously analyzed games.
dialogs/splash_screen.pyStartup Screen. Displays branded splash with progress during app initialization.
dialogs/game_selection_dialog.pyGame Picker. Modal dialog for selecting from multiple loaded games.
styles.pyTheming. Contains CSS-like stylesheets (QSS) for the application. Defines colors, fonts, and widget styles.
gui_utils.pyHelpers. Reusable utility functions for creating buttons, labels, and other common UI patterns.

Utils (src/utils/)

ComponentResponsibility
config.pyManages config.json for saving user settings (theme, engine path, API keys, board/piece themes, usernames).
logger.pySets up the application logging (writes to chess_analyzer.log).
path_utils.pyResolves resource paths correctly for both development and PyInstaller builds.
resources.pyHelper functions for loading images, icons, and sounds from the assets directory.

Data Flow Example: Analysis Loop

  1. User Action: User clicks "Analyze Game".
  2. Controller: MainWindow creates an AnalysisWorker thread and starts it.
  3. Backend Processing:
    • AnalysisWorker calls Analyzer.analyze_game() with the GameAnalysis object.
    • Analyzer iterates through every move in the game.
    • For each position, it checks cache.py for existing analysis.
    • If not cached, it sends the FEN to engine.py.
    • engine.py queries Stockfish and returns multi-PV analysis.
    • Analyzer calculates win probability, move accuracy, and classifies the move.
    • Results are cached for future use.
  4. UI Update:
    • AnalysisWorker emits progress_update signal with current/total move count.
    • MainWindow updates the progress display.
    • When complete, finished signal triggers UI refresh.
  5. Persistence:
    • GameHistoryManager.save_game() stores the analyzed game to SQLite.

Data Flow: Stats Dashboard

  1. User Action: User navigates to Stats page.
  2. Background Worker: StatsWorker runs in a separate thread to calculate aggregate statistics.
  3. Data Collection: Worker queries GameHistoryManager for all games matching configured usernames.
  4. Calculation: Aggregates win/loss/draw rates, accuracy trends, opening frequency, termination types, and color performance.
  5. UI Update: Worker emits signals with stats; MetricsWidget displays charts and metrics.
  6. AI Insights (optional): If Gemini API is configured, generates coaching insights from the stats.

Architecture Diagram