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
- Model (Backend): Handles the core logic and data state.
- State:
GameAnalysisobjects hold moves, evaluation scores, and metadata. - Computation: The
Analyzerclass manages the heavy lifting of communicating with Stockfish.
- State:
- 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),MoveList.
- 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").
Key Components
Backend (src/backend/)
| Component | Responsibility |
|---|---|
analyzer.py | The Brain. Manages the analysis queue, calculates Win Probability Loss (WPL), determines move classifications (Brilliant, Blunder, etc.), and updates the game state. |
engine.py | Stockfish Bridge. Wraps the Stockfish process using python-chess. Handles UCI protocol commands (position, go, stop) and parses engine output. |
models.py | Data Types. functions as the single source of truth for data structures like GameAnalysis, MoveAnalysis, and FenData. |
pgn_parser.py | Data Ingestion. robust parsing of .pgn files to extract moves, headers, and comments into a usable format. |
GUI (src/gui/)
| Component | Responsibility |
|---|---|
main_window.py | Root Container. Initializes the application window, sidebar, and main layout. Routes global events. |
analysis_view.py | Dashboard. The central hub displaying the board, stats, graphs, and move list side-by-side. |
board_widget.py | Visuals. Renders the chess board, pieces, arrows (for best moves), and highlights (last move, check). |
graph_widget.py | Visualization. Uses matplotlib to draw the evaluation curve, allowing users to visualize the momentum of the game. |
Data Flow Example: Analysis Loop
- User Action: User clicks "Analyze Game".
- Controller:
MainWindowemits a signal to theAnalyzerworker thread. - Backend Processing:
Analyzeriterates through every move in theGameAnalysisobject.- For each position, it sends the FEN to
engine.py. engine.pyqueries Stockfish and returns the evaluation (Centipawns/Mate).Analyzercalculates win probability and classifies the move (e.g., "Best Move").
- UI Update:
Analyzeremits aprogress_updatesignal.AnalysisPanelcatches this signal and updates the progress bar and current stats in real-time.
