<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Udit Raj</title>
    <description>The latest articles on DEV Community by Udit Raj (@uditrajmr3).</description>
    <link>https://dev.to/uditrajmr3</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3979336%2F2ea5bb69-4c55-464d-b91d-257dd6dfd82b.png</url>
      <title>DEV Community: Udit Raj</title>
      <link>https://dev.to/uditrajmr3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/uditrajmr3"/>
    <language>en</language>
    <item>
      <title>ChessMaster: Building a Personal Chess Coach on Stockfish and Claude</title>
      <dc:creator>Udit Raj</dc:creator>
      <pubDate>Wed, 04 Nov 2026 09:01:57 +0000</pubDate>
      <link>https://dev.to/uditrajmr3/chessmaster-building-a-personal-chess-coach-on-stockfish-and-claude-3koj</link>
      <guid>https://dev.to/uditrajmr3/chessmaster-building-a-personal-chess-coach-on-stockfish-and-claude-3koj</guid>
      <description>&lt;p&gt;ChessMaster transforms raw game data into actionable coaching insights. Chess.com and Lichess show you blunders in individual games — ChessMaster detects the systemic patterns that keep repeating across your entire game history and generates a personalized training plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;Next.js 14 frontend communicates with a FastAPI (Python) backend over REST. The backend orchestrates multi-platform game sync, Stockfish engine analysis, cross-game pattern detection, and Claude-powered report generation.&lt;/p&gt;

&lt;p&gt;The service layer contains 15+ specialized services — sync, analysis, patterns, time management, tilt detection, rating prediction, endgame classification, opponent scouting, puzzle generation with spaced repetition — all composable through shared filtering patterns.&lt;/p&gt;

&lt;p&gt;SQLite with SQLAlchemy ORM handles storage. Smart indexing on &lt;code&gt;played_at&lt;/code&gt;, &lt;code&gt;opening_eco&lt;/code&gt;, and &lt;code&gt;time_class&lt;/code&gt; keeps aggregate queries fast across thousands of games and hundreds of thousands of move analyses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Platform Game Sync
&lt;/h2&gt;

&lt;p&gt;Games are fetched from Chess.com (monthly archive endpoints) and Lichess (NDJSON streaming) in parallel with independent error handling — one platform failing doesn't block the other.&lt;/p&gt;

&lt;p&gt;Deduplication uses &lt;code&gt;platform + platform_id&lt;/code&gt; as a unique constraint. Clock times are extracted from PGN &lt;code&gt;[%clk H:M:S.F]&lt;/code&gt; comments for time management analysis. Lichess NDJSON streaming handles large game counts without memory issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimized Stockfish Analysis Pipeline
&lt;/h2&gt;

&lt;p&gt;The key optimization: &lt;strong&gt;single-pass evaluation with carry-forward&lt;/strong&gt;. Instead of evaluating both the position before and after each move (2 evals per move), the engine evaluates each position once — the eval_after for move M becomes eval_before for move M+1. This cuts engine calls by 50%.&lt;/p&gt;

&lt;p&gt;At depth 20, analysis runs ~20 seconds per game. Moves are classified by centipawn loss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Great: CPL &amp;lt; 10 (best move found)&lt;/li&gt;
&lt;li&gt;Good: CPL 10-50&lt;/li&gt;
&lt;li&gt;Inaccuracy: CPL 50-150&lt;/li&gt;
&lt;li&gt;Mistake: CPL 150-300&lt;/li&gt;
&lt;li&gt;Blunder: CPL &amp;gt; 300&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A tactical motif detection algorithm uses ray-tracing to identify forks, pins, skewers, discovered attacks, and back-rank threats in blundered positions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross-Game Pattern Engine
&lt;/h2&gt;

&lt;p&gt;The pattern engine aggregates 12+ metrics across all analyzed games to surface systemic weaknesses rather than one-off errors:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Opening performance&lt;/strong&gt; — win/loss/draw rate per ECO code with average CPL&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Worst openings&lt;/strong&gt; — minimum 3 games, sorted by win rate&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Phase accuracy&lt;/strong&gt; — separate CPL for opening, middlegame, and endgame (using material-based phase detection, not move count)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Phase blunder rate&lt;/strong&gt; — percentage of blunders per game phase&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Missed tactical motifs&lt;/strong&gt; — forks, pins, skewers, discovered attacks, back-rank threats&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time trouble correlation&lt;/strong&gt; — blunder rate in normal time vs. under 60 seconds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Color performance&lt;/strong&gt; — white vs. black win rates and accuracy&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Endgame conversion&lt;/strong&gt; — percentage of won positions (eval &amp;gt;= 200cp) actually converted to wins&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blunder distribution&lt;/strong&gt; — by move bucket (1-10, 11-20, 21-30, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monthly trends&lt;/strong&gt; — CPL improvement or degradation over time&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streak analysis&lt;/strong&gt; — win/loss streaks and tilt patterns&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example positions&lt;/strong&gt; — 10 worst blunders with FEN, CPL, and tactical classification&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The same &lt;code&gt;PatternEngine&lt;/code&gt; class handles filtering by platform and time class — composable filters reduce code duplication across 8+ analysis modes.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI Coaching Report
&lt;/h2&gt;

&lt;p&gt;Claude Sonnet generates personalized coaching reports from the pattern data, structured into 5 sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Player profile summary&lt;/li&gt;
&lt;li&gt;Top 3-5 systemic weaknesses with actual FEN positions from the player's games&lt;/li&gt;
&lt;li&gt;Opening repertoire advice based on win rates and CPL&lt;/li&gt;
&lt;li&gt;Strengths to build on&lt;/li&gt;
&lt;li&gt;30-day training plan with specific exercises&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The prompt includes the player's top 15 openings, missed tactical motifs, phase accuracy, time trouble stats, color performance, endgame conversion rates, and actual blunder positions — so advice is specific ("practice forks in K+P endgames when the opponent king is on the rim") rather than generic ("practice tactics").&lt;/p&gt;

&lt;h2&gt;
  
  
  Time Management Analytics
&lt;/h2&gt;

&lt;p&gt;Time spent per move is calculated from consecutive clock readings. The system detects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overthinking&lt;/strong&gt;: opening moves with &amp;lt;10 CPL loss but &amp;gt;15 seconds spent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Underthinking blunders&lt;/strong&gt;: moves with &amp;gt;100 CPL loss but &amp;lt;5 seconds spent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time zone analysis&lt;/strong&gt;: critical (0-30s), low (30-60s), normal (60-180s), comfortable (180+s)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time vs. accuracy curves&lt;/strong&gt;: correlation between time spent and centipawn loss per move bucket&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tilt Detector
&lt;/h2&gt;

&lt;p&gt;Session-based analysis (games within 4 hours grouped as one session):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Win/loss/draw streak tracking with averages&lt;/li&gt;
&lt;li&gt;Blunder rate increase after 3+ consecutive losses&lt;/li&gt;
&lt;li&gt;Rating drop detection (sessions with &amp;gt;50-point drops)&lt;/li&gt;
&lt;li&gt;Auto-generated recommendations ("stop playing after a 3-loss streak")&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rating Predictor
&lt;/h2&gt;

&lt;p&gt;Linear regression on rating vs. days played:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Points-per-month projection&lt;/li&gt;
&lt;li&gt;Milestone estimates (when you'll hit 1000, 1200, 1500, etc.)&lt;/li&gt;
&lt;li&gt;Momentum comparison: last 30 games vs. prior 30 games&lt;/li&gt;
&lt;li&gt;Monthly weakness trends (CPL by phase over time)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Puzzle Training (SM-2 Spaced Repetition)
&lt;/h2&gt;

&lt;p&gt;Every blunder and mistake automatically becomes a training puzzle. The SM-2 algorithm schedules reviews:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Due puzzles first (next_review &amp;lt;= now)&lt;/li&gt;
&lt;li&gt;Then never-attempted positions&lt;/li&gt;
&lt;li&gt;Then worst blunders (highest CPL)&lt;/li&gt;
&lt;li&gt;Ease factor adapts based on success rate: &lt;code&gt;max(1.3, ease_factor + (0.1 - (5 - rating) * 0.08))&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Filterable by game phase, tactical motif, platform, and time control&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Opponent Scouting
&lt;/h2&gt;

&lt;p&gt;Fetches the opponent's last 100 games, breaks down their opening repertoire by frequency, cross-references against the player's record in those specific openings, and generates preparation recommendations.&lt;/p&gt;

&lt;p&gt;15+ services, 17 API routers, 109 backend tests, 19 frontend tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned building it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Single-Pass Evaluation Halves Engine Costs — evaluating each position once and carrying forward the result (eval_after for move M = eval_before for move M+1) eliminates redundant Stockfish calls. When processing thousands of games, this 50% reduction is the difference between hours and minutes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Material-Based Phase Detection &amp;gt; Move Count — classifying game phase by remaining material (opening: fullmove &amp;lt;= 10 AND material &amp;gt;= 50pts; endgame: material &amp;lt;= 26 OR no queens AND material &amp;lt;= 30) handles Chess960, gambits, and unusual openings correctly. Move count fails for any non-standard game.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cross-Game Pattern Detection Is the Real Value — individual game analysis (blunder classification) is commodity. The insight that changes behavior comes from aggregating across hundreds of games: "you blunder 3x more in endgames than middlegames" or "your fork detection drops 40% when you're in time trouble."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Composable Filters Prevent Service Explosion — the same PatternEngine class handles filtering by platform, time class, and game phase. Without composable filters, each combination would need its own service — 8+ analysis modes would become 24+ services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SM-2 Spaced Repetition for Auto-Generated Puzzles — every blunder becomes a training puzzle with adaptive scheduling. The algorithm naturally surfaces the hardest problems more frequently while letting mastered positions fade, without manual curation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Structured LLM Prompts with Real Game Data — generic chess advice is useless. Including actual FEN positions, CPL values, and opponent names in the Claude prompt forces specific, actionable recommendations instead of "practice more tactics."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NDJSON Streaming for Large Datasets — Lichess's NDJSON streaming API handles 1000+ games without buffering the entire response in memory. For any API that returns large collections, streaming prevents memory pressure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tactical Motif Detection via Ray-Tracing — detecting forks, pins, skewers, and discovered attacks by tracing attack lines from piece positions is computationally elegant. No need for ML — pure algorithmic detection on the board state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Session-Based Tilt Detection — grouping games within 4-hour windows as sessions and tracking blunder rate increase after consecutive losses quantifies tilt. This turns a subjective feeling ("I'm playing badly") into actionable data ("your blunder rate increases 60% after 3 losses — stop playing").&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Platform-Agnostic Data Normalization — unifying Chess.com and Lichess into a common schema at the ingestion layer means every downstream service (analysis, patterns, reports) works identically regardless of source. Add a third platform and nothing downstream changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/uditrajmr3/chessmaster" rel="noopener noreferrer"&gt;https://github.com/uditrajmr3/chessmaster&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://uditraj.site/workshop/chessmaster/" rel="noopener noreferrer"&gt;uditraj.site&lt;/a&gt; — from the Workshop.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>ai</category>
      <category>webdev</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
