How ahmed5145/chessmate works
Purpose and Entry Points
ChessMate is a chess-coaching platform: users import Chess.com/Lichess games, spend credits to run Stockfish analysis, and receive personalized feedback. The backend is a Django application entered through chess_mate/manage.py, served via chess_mate/chess_mate/asgi.py or chess_mate/chess_mate/wsgi.py. The React client starts at chess_mate/frontend/src/index.js and composes the application in chess_mate/frontend/src/App.js.
Backend HTTP and Application Boundary
Django project routing is defined in chess_mate/chess_mate/urls.py; the core application exposes its API routes through chess_mate/core/urls.py and request handlers in chess_mate/core/views.py. This is the main trust boundary for JWT-authenticated user actions, game import/selection, analysis requests, account flows, and payments. Environment-specific deployment configuration is separated between chess_mate/chess_mate/settings.py and chess_mate/chess_mate/settings_prod.py.
Domain, Persistence, and Account State
chess_mate/core/models.py is the central persistent-domain layer, covering users’ platform state such as games, analyses, and credits. Django migrations live under chess_mate/core/migrations. Views and service layers should treat models as the durable source of truth, while transient analysis status/results can be cached. Administrative access is connected through chess_mate/core/admin.py.
Analysis Pipeline
The core business pipeline is split across chess_mate/core/chess_services.py, chess_mate/core/game_analyzer.py, and chess_mate/core/tasks.py. Requests initiate work; Celery tasks move expensive or long-running game analysis off the HTTP path. Analysis invokes the locally configured Stockfish engine, processes chess-game moves and positions, then persists or exposes results for later retrieval. Batch and single-game execution are represented in the frontend by chess_mate/frontend/src/components/BatchAnalysis.js and chess_mate/frontend/src/components/SingleGameAnalysis.js.
Feedback and External Chess Sources
chess_mate/core/ai_feedback.py produces personalized coaching output from analysis results, using an OpenAI API key configured via environment. Chess import and engine-facing orchestration belong to chess_mate/core/chess_services.py; external dependencies include Chess.com and Lichess APIs, Stockfish, and OpenAI. These integrations form failure-prone boundaries and should remain behind service/task interfaces rather than UI or model code.
Credits, Payments, and Async Infrastructure
Credit purchase and consumption are architecturally coupled to analysis authorization. Stripe payment integration is handled in chess_mate/core/payment.py, with frontend purchase/status screens in chess_mate/frontend/src/components/Credits.js and chess_mate/frontend/src/components/PaymentSuccess.js. Redis is required as the Celery broker/result or caching infrastructure; cache access is centralized in chess_mate/core/cache_manager.py. Rate limiting in chess_mate/core/rate_limiter.py protects externally costly endpoints.
Frontend Control Flow
The React SPA uses route composition in chess_mate/frontend/src/routes/AppRoutes.js, protected navigation in chess_mate/frontend/src/routes/ProtectedRoute.js, and shared authenticated-user state in chess_mate/frontend/src/contexts/UserContext.js. chess_mate/frontend/src/api.js is the client/server boundary for API calls and JWT handling. Primary user flows cover authentication, game fetching, analysis, feedback display, profiles, and payment completion through components under chess_mate/frontend/src/components.
Deployment and Operational Dependencies
The system requires Python/Django, Node/React, PostgreSQL or default SQLite, Redis, Celery workers, Stockfish, Stripe, OpenAI, email delivery, and external chess-platform APIs. AWS-related deployment/storage support is represented by chess_mate/chess_mate/aws.py and chess_mate/chess_mate/storage_backends.py. Database backup operations are isolated in chess_mate/scripts/backup_db.py.
Main entry points: views.py Core API · AppRoutes.js Client routes · game_analyzer.py Game analyzer · tasks.py Analysis tasks
Components 19
React client
- React entry
chess_mate/frontend/src/index.js - App shell
chess_mate/frontend/src/App.js - Client routes · Protected routes and authenticated navigation.
chess_mate/frontend/src/routes/AppRoutes.js - User state
chess_mate/frontend/src/contexts/UserContext.js - API client
chess_mate/frontend/src/api.js - Analysis UI
chess_mate/frontend/src/components/BatchAnalysis.js - Credits & payment UI
chess_mate/frontend/src/components/Credits.js
Django application
- Django entry · Served through ASGI or WSGI.
chess_mate/manage.py - Project routing
chess_mate/chess_mate/urls.py - Core API · Trust boundary for accounts, games, analysis, and payments.
chess_mate/core/views.py - Domain models · Durable games, analyses, users, and credits.
chess_mate/core/models.py - Rate limiter
chess_mate/core/rate_limiter.py - Payment service
chess_mate/core/payment.py
Analysis pipeline
- Chess service · Encapsulates chess-source imports and engine-facing work.
chess_mate/core/chess_services.py - Analysis tasks · Moves long-running analysis off the HTTP path.
chess_mate/core/tasks.py - Game analyzer
chess_mate/core/game_analyzer.py - Coaching feedback
chess_mate/core/ai_feedback.py
Infrastructure & integrations
- Redis
- External services · Chess.com, Lichess, Stockfish, OpenAI, and Stripe.
Connections 24
- React entry → App shell: mounts
- App shell → Client routes: composes
- Client routes → User state: uses auth state
- Client routes → Analysis UI: serves flows
- Client routes → Credits & payment UI: serves flows
- Analysis UI → API client: requests analysis
- Credits & payment UI → API client: purchases credits
- API client → Project routing: JWT API calls
- Django entry → Project routing: loads
- Project routing → Core API: dispatches
- Core API → Rate limiter: protects costly endpoints
- Core API → Domain models: reads and writes
- Core API → Chess service: imports games
- Core API → Analysis tasks: queues analysis
- Core API → Payment service: handles payments
- Analysis tasks → Redis: broker and results
- Analysis tasks → Game analyzer: executes
- Game analyzer → Domain models: persists results
- Game analyzer → Coaching feedback: supplies analysis
- Coaching feedback → Domain models: stores feedback
- Chess service → External services: imports games
- Game analyzer → External services: uses Stockfish
- Coaching feedback → External services: uses OpenAI
- Payment service → External services: uses Stripe