How dhakalnirajan/stockzero works
Main components
• Backend/Django Infrastructure:
• Core project configuration under the "stockzero" directory (settings, URLs, ASGI/WGSI).
• REST API components as part of the "webapp/chessgame" Django app (models, serializers, views) for game logging and communication.
• Frontend serving via the "webapp/frontend" app; includes HTML templates, static CSS/JS assets (chess_gui.js, styles.css).
• AI Engine Components:
• Chess engine modules in the "engine" directory (MCTS implementation, policy/value network in model.py, RL agent in rl_agent.py, and traditional engine).
• Inference layer in the "inference" directory which optimizes move generation using GPU and Redis caching.
• Training Infrastructure:
• Training scripts and utilities in the "training" directory for self-play, data handling, and neural network training.
• Django management command for training (located in "management/commands/train_model.py") to trigger model training.
• Model Management:
• Storage of versioned model weights within the "models" directory.
• Logging & Deployment:
• Logging directories ("logs") for both engine and webapp events.
• Supporting deployment scripts (manage.sh, setup_server.sh) and documentation files.
Relationships and interactions
• The Frontend (in "webapp/frontend") communicates with the Django backend API (in "webapp/chessgame") to facilitate real-time game play and log PGN game data.
• The Django backend interacts with the RL chess engine:
• It calls services in the "engine" to compute moves (via RL agent, MCTS, etc.) when a game is in session.
• When a move requires inference, the call goes to the "inference" module which uses Redis for caching and leverages GPU acceleration.
• The training module regularly updates model weights which are stored in the "models" directory. There is a feedback loop where post-training, the engine loads the new model for gameplay.
• External systems like PostgreSQL (for game logging) and Redis (for caching inference results) are critical external dependencies.
Key architectural patterns and design principles
• Layered Architecture: Clear separation between the presentation (frontend), application logic (Django REST API), business logic (engine & inference modules), training routines, and persistent storage.
• Modular design: Distinct modules for inference, training, and game execution allow independent scalability and maintenance.
• Separation of Concerns:
• UI rendering vs. API logic.
• Real-time game interaction vs. background training.
• Static asset management and backend processing are separated.
• Use of management commands and scripts facilitates clear CI/CD and deployment practices.
Relevant technologies, frameworks, and libraries
• Backend: Django (including Django REST Framework), Gunicorn (for production deployment), PostgreSQL, and Redis.
• AI/ML Components: TensorFlow/Keras for neural network implementations.
• Frontend: HTML/CSS/JavaScript.
• Auxiliary Tools: Scripts for management and deployment (Bash scripts like manage.sh, setup_server.sh), Docker or similar containerization (if applicable based on deployment docs).