How mevikrampawar/chesser works
Purpose and Runtime
Chesser is a browser-only chess opening trainer. A React/TypeScript SPA lets users play a position, identifies the opening with a locally executed WebLLM model, retrieves aggregate continuation statistics from Lichess, and optionally persists favorites in Firebase. The application starts at src/main.tsx, renders the root coordinator in src/App.tsx, and is built/served through Vite (vite.config.ts).
Application Composition
src/App.tsx is the primary composition boundary: it connects game state, model readiness, opening analysis, authentication, and the display panels. The interactive workflow is represented by focused UI components:
• Board input: src/components/ChessBoard.tsx
• Position/move context: src/components/MoveHistory.tsx
• Analysis presentation: src/components/OpeningPanel.tsx, src/components/StatsBar.tsx, src/components/TopMoves.tsx
• Account-specific saved records: src/components/SavedOpenings.tsx
• AI initialization state: src/components/SetupScreen.tsx
Chess Game State
src/hooks/useChessGame.ts owns chess gameplay state and move progression, backed by chess-specific dependencies described in package.json. It is the source of the move sequence/position passed downstream for analysis and displayed by ChessBoard and MoveHistory. This isolates rules-valid move handling from presentation and from remote/AI enrichment.
Opening Analysis Pipeline
src/hooks/useOpeningStats.ts coordinates analysis triggered by game changes. Its service boundary is src/services/opening.ts, which merges two independent results:
• Local opening recognition/coaching through src/services/llm.ts
• Lichess opening-explorer statistics and popular continuations through src/services/lichess.ts
The resulting typed opening data is consumed by the analysis UI rather than allowing components to call external sources directly. Shared domain contracts reside in src/types/index.ts.
In-Browser AI Boundary
src/hooks/useLLM.ts manages WebLLM engine/model lifecycle, including load progress and availability for the setup screen. src/services/llm.ts encapsulates inference against Phi-3.5 Mini via WebGPU; prompt construction is separated in src/utils/prompts.ts. Model execution and caching remain client-side, so no application backend is required for identification or coaching. Browsers without practical WebGPU support are a material runtime constraint.
External Data and Persistence
Lichess is an unauthenticated external data boundary accessed through src/services/lichess.ts; requests use the current game state to obtain community game statistics. Firebase configuration and Auth initialization are centralized in src/services/firebase.ts. src/hooks/useAuth.ts exposes Google sign-in state to the app, while src/services/firestore.ts performs cloud save/read operations for user-owned opening records surfaced in SavedOpenings.tsx.
Deployment and Offline Behavior
The client is hosted by Firebase Hosting (firebase.json). Firebase environment values are supplied through .env based on .env.example. public/sw.js provides service-worker support, complementing browser caching of the AI model for repeat/offline use. The deployed system therefore depends on Firebase for identity/storage and Lichess for live statistics, while core chess interaction and LLM inference execute locally.
Main entry points: App.tsx App coordinator · llm.ts Local Phi-3.5 inference · useChessGame.ts Chess game state · useOpeningStats.ts Opening stats coordinator
Components 22
Browser SPA
React application running entirely in the browser.
- Vite build/serve
vite.config.ts - Application entry
src/main.tsx - App coordinator · Connects game, analysis, model, auth, and panels.
src/App.tsx - Chess game state · Owns legal moves, position, and progression.
src/hooks/useChessGame.ts - Chess board
src/components/ChessBoard.tsx - Move history
src/components/MoveHistory.tsx - Opening analysis panels · OpeningPanel, StatsBar, and TopMoves present results.
src/components/OpeningPanel.tsx - Saved openings
src/components/SavedOpenings.tsx - AI setup screen
src/components/SetupScreen.tsx - Service worker · Supports repeat and offline browser use.
public/sw.js
Analysis pipeline
Local AI and Lichess enrichment behind typed services.
- Opening stats coordinator · Triggers enrichment when the game changes.
src/hooks/useOpeningStats.ts - Opening merger · Combines local recognition with Lichess statistics.
src/services/opening.ts - LLM lifecycle · Manages WebLLM readiness and load progress.
src/hooks/useLLM.ts - Local Phi-3.5 inference · Runs recognition and coaching client-side.
src/services/llm.ts - Prompt builder
src/utils/prompts.ts - Opening contracts
src/types/index.ts
Firebase services
Optional identity, persistence, and hosting.
- Authentication state · Exposes Google sign-in state.
src/hooks/useAuth.ts - Firebase initialization
src/services/firebase.ts - Saved opening records · Reads and saves user-owned opening records.
src/services/firestore.ts - Firebase Hosting
firebase.json
External runtime
Browser capabilities and third-party data source.
- Lichess explorer
src/services/lichess.ts - WebGPU browser runtime · Required for practical local model execution.
Connections 24
- Vite build/serve → Application entry: builds and serves
- Application entry → App coordinator: renders
- App coordinator → Chess game state: uses
- Chess game state → Chess board: position and moves
- Chess game state → Move history: move sequence
- App coordinator → Opening stats coordinator: requests analysis
- Chess game state → Opening stats coordinator: position changes
- Opening stats coordinator → Opening merger: coordinates
- Opening merger → Local Phi-3.5 inference: local recognition
- Opening merger → Lichess explorer: community statistics
- Opening stats coordinator → Opening analysis panels: typed results
- Opening contracts → Opening merger: domain types
- LLM lifecycle → Local Phi-3.5 inference: engine lifecycle
- App coordinator → LLM lifecycle: model readiness
- LLM lifecycle → AI setup screen: load state
- Local Phi-3.5 inference → Prompt builder: builds prompts
- Local Phi-3.5 inference → WebGPU browser runtime: executes on
- App coordinator → Authentication state: sign-in state
- Authentication state → Firebase initialization: initializes Auth
- Saved openings → Saved opening records: save and read
- Saved opening records → Firebase initialization: uses Firebase
- App coordinator → Saved openings: renders
- Firebase Hosting → Application entry: hosts SPA
- Service worker → Local Phi-3.5 inference: supports cached reuse