A comprehensive full-stack web application for analyzing historical New Zealand lottery data and generating intelligent predictions using statistical analysis, machine learning, and AI-powered predictions with multi-line coverage optimisation.
LottoLens employs a microservices architecture with five main components:
- Frontend: Vue.js 3 single-page application with TypeScript
- Backend: .NET 8 Web API with Entity Framework Core
- Predictor: Python FastAPI service with ML and GPT integration
- Database: PostgreSQL 15 with automated migrations
- Cache: Redis 7 for distributed caching and performance optimization
graph TB
subgraph "Frontend Layer"
VUE[Vue.js SPA]
end
subgraph "Backend Layer"
API[.NET 8 Web API]
STATS[Statistical Analysis Engine]
DB[(PostgreSQL Database)]
REDIS[(Redis Cache)]
end
subgraph "Prediction Layer"
GROQ[GroqCloud LLM]
FASTAPI[Python FastAPI Service]
ML[ML Models]
GPT[GPT Integration]
end
subgraph "Future Services"
AWS[AWS Bedrock LLM]
end
VUE --> API
API --> DB
API --> REDIS
API --> STATS
API --> GROQ
API --> FASTAPI
API -.-> AWS
FASTAPI --> ML
FASTAPI --> GPT
- Docker: Version 20.10 or higher
- Docker Compose: Version 2.0 or higher
- .NET SDK: Version 8.0 or higher
The backend API includes comprehensive Swagger/OpenAPI documentation for easy testing and exploration of all available endpoints.
- Docker Development: http://localhost:5000/swagger
- Root Redirect: In development, visiting the root URL (/) automatically redirects to Swagger
- Production: Swagger UI is disabled in production for security reasons
- Interactive Testing: Test all API endpoints directly from the browser (development only)
- Comprehensive Documentation: Detailed parameter descriptions and response examples
- Authentication Support: Test secured endpoints with JWT tokens
- Development Environment: Available only in development mode for security
For detailed API documentation, see docs/SWAGGER.md
The project includes LangSmith integration for comprehensive observability and tracing of AI-powered predictions.
- Automatic Tracing: All LLM calls are automatically logged with inputs, outputs, and metadata
- Performance Monitoring: Track response times, error rates, and token usage
- Debugging Tools: Visual inspection of prediction chains and reasoning steps
- Feedback Collection: Track prediction accuracy against actual lottery results
- Dataset Management: Store and evaluate test cases
- Get your LangSmith API key from smith.langchain.com
- Add to
.envfile:LANGCHAIN_TRACING_V2=true LANGCHAIN_API_KEY=your_langsmith_api_key LANGCHAIN_PROJECT=predict-lotto-nz
- Install dependencies:
pip install -r predictor/requirements.txt - View traces: https://smith.langchain.com
For detailed setup instructions, see:
-
Node.js: Version 18 or higher with npm
-
Python: Version 3.11 or higher with pip
-
PostgreSQL: Version 15 or higher (optional, can use Docker)
- OpenAI API Key: For GPT-powered predictions
- AWS Account: For AWS LLM service integration
-
Clone the repository
git clone <repository-url> cd predict-lotto-nz
-
Configure environment variables
cp .env.example .env
Edit the
.envfile with your configuration:# Database Configuration POSTGRES_PASSWORD=your_secure_password POSTGRES_DB=predict_lotto_nz POSTGRES_USER=postgres # Service Ports BACKEND_PORT=5000 FRONTEND_PORT=3001 PREDICTOR_PORT=8000 POSTGRES_PORT=5434 # Optional: AI Services OPENAI_API_KEY=your_openai_api_key AWS_REGION=us-west-2 AWS_ACCESS_KEY_ID=your_aws_access_key AWS_SECRET_ACCESS_KEY=your_aws_secret_key
-
Start all services
# Production mode docker-compose up -d # Or development mode with hot reload docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
-
Verify deployment
# Test Docker setup ./scripts/test-docker.ps1 -HealthCheck # Or manually check services docker-compose ps
-
Access the application
- Frontend: http://localhost:3001
- Backend API: http://localhost:5000
- API Documentation: http://localhost:5000/swagger
- Predictor Service: http://localhost:8000
- Predictor Docs: http://localhost:8000/docs
- Database: localhost:5434
-
Start PostgreSQL
docker-compose up -d postgres
-
Backend Setup
cd backend dotnet restore dotnet ef database update dotnet run -
Frontend Setup
cd frontend npm install npm run dev -
Predictor Service Setup
cd predictor pip install -r requirements.txt uvicorn main:app --reload --port 8000
| Variable | Required | Default | Description |
|---|---|---|---|
POSTGRES_PASSWORD |
β | - | PostgreSQL database password |
POSTGRES_DB |
β | predict_lotto_nz |
Database name |
POSTGRES_USER |
β | postgres |
Database username |
POSTGRES_PORT |
β | 5434 |
Database port |
| Variable | Required | Default | Description |
|---|---|---|---|
BACKEND_PORT |
β | 5000 |
Backend API port |
FRONTEND_PORT |
β | 3001 |
Frontend application port |
PREDICTOR_PORT |
β | 8000 |
Predictor service port |
| Variable | Required | Default | Description |
|---|---|---|---|
GROQCLOUD_API_KEY |
β | - | GroqCloud API key (primary LLM) |
GROQCLOUD_MODEL |
β | llama-3.3-70b-versatile |
GroqCloud model to use |
GROQCLOUD_BASE_URL |
β | https://api.groq.com/openai/v1 |
GroqCloud API base URL |
FASTAPI_BASE_URL |
β | http://predictor:8000 |
FastAPI predictor service URL |
OPENAI_API_KEY |
β | - | OpenAI API key for GPT predictions |
AWS_REGION |
β | ap-southeast-2 |
AWS region for LLM services |
AWS_ACCESS_KEY_ID |
β | - | AWS access key ID |
AWS_SECRET_ACCESS_KEY |
β | - | AWS secret access key |
| Variable | Required | Default | Description |
|---|---|---|---|
ASPNETCORE_ENVIRONMENT |
β | Development |
.NET environment |
VUE_APP_API_BASE_URL |
β | http://localhost:5000 |
Frontend API base URL |
LOG_LEVEL |
β | INFO |
Python service log level |
Important: Your Docker setup supports two modes:
- Production Mode (current): Code changes require rebuild
- Development Mode (recommended): Automatic hot-reload
π Complete Guide: See DEVELOPMENT_VS_PRODUCTION.md for detailed comparison
# Start with automatic hot-reload (recommended for development)
.\scripts\dev-start.ps1
# View logs
.\scripts\dev-logs.ps1
# Restart a service
.\scripts\dev-restart.ps1 backend-
Start development environment
# Start all services in development mode with hot-reload docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d # Or use the helper script (Windows) .\scripts\dev-start.ps1 # Or start individual services docker-compose up -d postgres # Database only
-
Edit code and see changes automatically
- Backend: Edit .cs files β Auto-recompiles via
dotnet watchin ~5-10 seconds - Frontend: Edit .vue/.ts files β Hot-reload in ~1-2 seconds
- Predictor: Edit .py files β Auto-restarts in ~2-3 seconds
- Backend: Edit .cs files β Auto-recompiles via
-
When to rebuild (only needed for dependency changes)
# After adding new packages .\scripts\dev-rebuild.ps1 backend # Added NuGet packages .\scripts\dev-rebuild.ps1 frontend # Added npm packages .\scripts\dev-rebuild.ps1 predictor # Added pip packages
-
Run services locally for development (alternative to Docker)
# Backend with hot reload cd backend dotnet watch run # Frontend with hot reload cd frontend npm run dev # Predictor with hot reload cd predictor uvicorn main:app --reload --port 8000
cd backend
dotnet test # Run all tests
dotnet test --filter "Category=Unit" # Unit tests only
dotnet test --filter "Category=PBT" # Property-based tests onlycd frontend
npm run test # Run tests in watch mode
npm run test:run # Run tests once
npm run test:coverage # Run with coverage reportcd predictor
python -m pytest # Run all tests
python -m pytest test_api.py # Specific test file
python -m pytest -v --tb=short # Verbose outputcd backend
dotnet ef migrations add <MigrationName> # Create migration
dotnet ef database update # Apply migrations
dotnet ef database drop # Drop database# Import sample lottery data
curl -X POST -F "file=@sample-data.csv" http://localhost:5000/api/lotto/uploadpredict-lotto-nz/
βββ backend/ # .NET Core Web API
β βββ Controllers/ # API controllers
β βββ Services/ # Business logic services
β βββ Models/ # Data models and DTOs
β βββ Data/ # Entity Framework context
β βββ Migrations/ # Database migrations
β βββ PredictLottoNZ.Tests/ # Unit and property-based tests
β βββ Dockerfile # Production container
β βββ Dockerfile.dev # Development container
β βββ Program.cs # Application entry point
βββ frontend/ # Vue.js application
β βββ src/
β β βββ components/ # Vue components
β β βββ views/ # Page components
β β βββ services/ # API services
β β βββ stores/ # Pinia state management
β β βββ assets/ # Static assets
β βββ Dockerfile # Production container
β βββ Dockerfile.dev # Development container
β βββ nginx.conf # Nginx configuration
β βββ package.json # Dependencies and scripts
βββ predictor/ # Python FastAPI service
β βββ main.py # FastAPI application
β βββ ml_predictor.py # ML prediction models
β βββ gpt_predictor.py # GPT integration
β βββ blended_predictor.py # Combined predictions
β βββ test_*.py # Test files
β βββ Dockerfile # Production container
β βββ Dockerfile.dev # Development container
β βββ requirements.txt # Python dependencies
βββ scripts/ # Deployment and utility scripts
β βββ init-db.sql # Database initialization
β βββ test-docker.ps1 # Docker testing script
β βββ test-docker.sh # Docker testing script (Linux)
βββ .kiro/specs/predict-lotto-nz/ # Feature specifications
β βββ requirements.md # System requirements
β βββ design.md # Technical design
β βββ tasks.md # Implementation tasks
βββ .env # Environment variables (create from .env.example)
βββ .env.example # Environment variables template
βββ docker-compose.yml # Production Docker services
βββ docker-compose.dev.yml # Development overrides
βββ Makefile # Build and deployment commands
βββ README.md # This documentation
Port: 5000 | Health Check: /api/health
Features:
- CSV file upload and parsing with duplicate detection
- Historical lottery data management (1500+ draws from 2008-present)
- Statistical analysis engine (number gaps, sum distributions, pair co-occurrence, draw patterns)
- Enhanced AI prediction with GroqCloud LLM using statistical context
- Multi-provider prediction chain with availability checks and circuit breakers
- Multi-line coverage optimisation with sum range validation
- Backtesting framework for strategy comparison (enhanced vs random)
- Ticket tracking with auto-verification against draw results
- Prediction accuracy scoring and history tracking
- RESTful API with Swagger documentation
- Entity Framework Core with PostgreSQL
- Redis distributed caching
- Comprehensive logging and error handling
Key Endpoints:
GET /api/predictions/generate?count=4- Generate AI predictionsGET /api/predictions/stored- Get stored predictionsGET /api/backtest/compare?drawCount=50&linesPerDraw=4- Compare strategiesGET /api/backtest/run?drawCount=50&enhanced=true- Run single strategy backtestPOST /api/ticket- Add a purchased ticket (auto-checks against draw)GET /api/ticket- List tracked tickets with resultsGET /api/ticket/summary- Performance summary (ROI, match distribution)POST /api/lotto/upload- Upload lottery CSV filesGET /api/lotto/latest- Get latest lottery drawGET /api/lotto/draws?page=1&pageSize=10- Paginated draw historyGET /api/health- Health check
Port: 3001 (dev) / 3000 (production) | Health Check: /health
Features:
- Modern Vue 3 with TypeScript and Composition API
- Prediction generation with statistical reasoning display
- Ticket tracker with number highlighting (matched/bonus/powerball)
- Backtest dashboard with strategy comparison visualisation
- File upload with real-time progress tracking
- Responsive design for desktop and mobile
- Toast notifications for user feedback
- Help guide with feature documentation
- State management with Pinia
- Component-based architecture
Key Pages:
PredictionsView- Generate and browse AI predictionsTicketsView- Track purchased tickets, view results with colour-coded matchesBacktestView- Run enhanced vs random strategy comparisonsDrawsView- Browse historical draw resultsLookupView- Number frequency lookupHelpView- Feature documentation and usage guide
Port: 8000 | Health Check: /health
Features:
- Machine learning prediction models using scikit-learn
- OpenAI GPT integration for AI-powered predictions
- Blended prediction algorithms combining ML and AI
- Automatic model training with historical data
- RESTful API with OpenAPI documentation
- Async request handling for performance
Key Endpoints:
POST /predict- Generate predictionsPOST /train- Train ML modelsGET /health- Health checkGET /docs- API documentation
Port: 5434 | Health Check: Built-in
Features:
- Stores historical lottery draws with full metadata
- Number combination management with timestamps
- Prediction tracking with source identification
- Data preservation for ML training
- Automated migrations and seeding
- Performance optimized with indexes
Port: 6379 | Health Check: PING command
Features:
- Distributed caching for improved performance
- Session storage and temporary data
- Frequency analysis result caching
- Prediction result caching
- Automatic cache invalidation
- Memory-efficient data structures
- Persistence with append-only file (AOF)
Once services are running, comprehensive API documentation is available:
-
Backend API: http://localhost:5000/swagger
- Swagger UI with interactive endpoint testing
- Complete request/response schemas
- Authentication and error handling examples
-
Predictor API: http://localhost:8000/docs
- FastAPI automatic documentation
- Request validation and examples
- Model schemas and response formats
# Upload lottery CSV file
POST /api/lotto/upload
Content-Type: multipart/form-data
Body: file (CSV file)
# Check if draw exists
GET /api/lotto/exists/{drawNumber}
Response: { "exists": boolean }
# Get latest draw
GET /api/lotto/latest
Response: LottoDrawDto# Upload number combinations
POST /api/combinations/upload
Content-Type: multipart/form-data
Body: file (CSV/TXT/PDF file)
# Get predictions
GET /api/combinations/predictions?count=5
Response: PredictionResult[]
# Generate predictions (Predictor service)
POST /predict
Content-Type: application/json
Body: { "weekly_numbers": [1, 2, 3, 4, 5, 6] }All services include comprehensive health checks:
| Service | Endpoint | Port | Status |
|---|---|---|---|
| Backend | /api/health |
5000 | Application health |
| Frontend | /health |
3001 | Nginx status |
| Predictor | /health |
8000 | Service health |
| Database | Built-in | 5434 | PostgreSQL ready |
| Redis | PING command |
6379 | Cache availability |
# Check all service health
./scripts/test-docker.ps1 -HealthCheck
# View service status
docker-compose ps
# View service logs
docker-compose logs [service-name]
# Monitor resource usage
docker stats# Production deployment
docker-compose up -d
# Development deployment with hot reload
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d-
Set up AWS credentials
export AWS_ACCESS_KEY_ID=your_access_key export AWS_SECRET_ACCESS_KEY=your_secret_key export AWS_REGION=us-west-2
-
Deploy using Docker Compose
# Update environment variables for cloud cp .env.example .env.production # Edit .env.production with cloud-specific values # Deploy docker-compose --env-file .env.production up -d
-
Configure Azure Container Instances
# Set Azure credentials az login # Create resource group az group create --name predict-lotto-rg --location eastus # Deploy container group az container create --resource-group predict-lotto-rg \ --file docker-compose.yml
- Change default passwords in production
- Use secrets management for API keys
- Enable HTTPS with SSL certificates
- Configure firewall rules for database access
- Use non-root users in containers
- Configure database connection pooling
- Set up Redis for caching (optional)
- Use CDN for static assets
- Configure load balancing for high availability
- Set up application logging
- Configure health check monitoring
- Use container orchestration (Kubernetes)
- Implement backup strategies
- System Status: See
SYSTEM_STATUS.mdfor current service status - Docker Build Issues: See
DOCKER_FIX_SUMMARY.mdfor recent fixes - Quick Fix Guide: See
DOCKER_QUICK_FIX.mdfor common solutions - Detailed Troubleshooting: See
docs/DOCKER_TROUBLESHOOTING.md
# Verify all services are healthy
.\scripts\verify-services.ps1
# Start database only (quick access)
.\scripts\start-db-only.ps1
# Rebuild predictor service
.\scripts\rebuild-predictor.ps1
# Full rebuild with cache clearing
.\scripts\docker-rebuild.ps1If the Docker build hangs on package downloads:
# Use the rebuild script (includes fixes)
.\scripts\docker-rebuild.ps1
# Or manually rebuild with no cache
docker-compose build --no-cache predictorSee DOCKER_FIX_SUMMARY.md for details on the recent pydantic version conflict fix.
# Check which ports are in use (Windows)
netstat -ano | Select-String ":3001"
netstat -ano | Select-String ":5000"
netstat -ano | Select-String ":8000"
netstat -ano | Select-String ":5434"# Check PostgreSQL container status
docker-compose ps postgres
# View PostgreSQL logs
docker-compose logs postgres
# Connect to database manually
docker-compose exec postgres psql -U postgres -d predict_lotto_nz
# Or use the quick script
.\scripts\start-db-only.ps1# Check service health
curl http://localhost:5000/api/health
curl http://localhost:8000/health
curl http://localhost:3001
# Or use the verification script
.\scripts\verify-services.ps1
# Restart specific service
docker-compose restart backend
docker-compose restart predictor
docker-compose restart frontend# Verify environment variables are loaded
docker-compose config
# Check specific service environment
docker-compose exec backend env | grep POSTGRES
docker-compose exec predictor env | grep OPENAI# All services
docker-compose logs -f
# Specific service
docker-compose logs -f backend
docker-compose logs -f predictor
docker-compose logs -f frontend
# Last 100 lines
docker-compose logs --tail=100 backend# List running containers
docker ps
# Inspect container
docker inspect predict-lotto-backend
# Execute commands in container
docker-compose exec backend bash
docker-compose exec predictor bash# Connect to database
docker-compose exec postgres psql -U postgres -d predict_lotto_nz
# Check database tables
\dt
# View recent lottery draws
SELECT * FROM "LottoDraws" ORDER BY "Date" DESC LIMIT 5;
# Check predictions
SELECT * FROM "Predictions" ORDER BY "CreatedAt" DESC LIMIT 10;# Stop services and remove volumes
docker-compose down -v
# Start fresh
docker-compose up -d postgres
# Apply migrations
docker-compose exec backend dotnet ef database update# Remove all containers and images
docker-compose down --rmi all
# Remove unused Docker resources
docker system prune -a
# Rebuild everything
docker-compose build --no-cache
docker-compose up -dcd backend
dotnet test # All tests
dotnet test --filter "Category=Unit" # Unit tests only
dotnet test --filter "Category=PBT" # Property-based tests
dotnet test --logger "console;verbosity=detailed" # Verbose outputcd frontend
npm run test # Interactive test runner
npm run test:run # Single test run
npm run test:coverage # With coverage reportcd predictor
python -m pytest # All tests
python -m pytest test_api.py # Specific file
python -m pytest -v --tb=short # Verbose with short traceback
python -m pytest --cov=. --cov-report=html # Coverage reportThe system includes comprehensive property-based tests that verify correctness properties:
- CSV Parsing: Validates data extraction and transformation
- Duplicate Detection: Ensures data integrity during imports
- Prediction Generation: Verifies prediction algorithms
- File Format Parsing: Tests multi-format file handling
- Database Operations: Validates data persistence
Traditional unit tests cover:
- Individual service methods
- Controller endpoints
- Component behavior
- Error handling scenarios
End-to-end tests verify:
- Complete user workflows
- Service communication
- Database transactions
- File upload processes
- Navigate to http://localhost:3001
- Click "Upload CSV File"
- Select a Powerball NZ CSV file
- Monitor upload progress
- View import results (records added/skipped)
- Upload historical lottery data (optional)
- Click "Generate Predictions"
- Select number of predictions (1-10)
- View predictions with sources:
- Frequency-based predictions
- ML model predictions
- GPT-powered predictions
curl -X POST \
-F "file=@powerball-data.csv" \
http://localhost:5000/api/lotto/uploadcurl -X GET \
"http://localhost:5000/api/combinations/predictions?count=5" \
-H "Accept: application/json"curl -X POST \
-H "Content-Type: application/json" \
-d '{"weekly_numbers": [5, 12, 18, 20, 33, 40]}' \
http://localhost:8000/predictWe welcome contributions! Please follow these guidelines:
-
Fork the repository
git clone https://github.com/your-username/predict-lotto-nz.git cd predict-lotto-nz -
Create a feature branch
git checkout -b feature/your-feature-name
-
Set up development environment
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
-
Make your changes
- Follow existing code style and patterns
- Add tests for new functionality
- Update documentation as needed
-
Run tests
# Backend tests cd backend && dotnet test # Frontend tests cd frontend && npm run test:run # Predictor tests cd predictor && python -m pytest
-
Submit a pull request
- Provide clear description of changes
- Reference any related issues
- Ensure all tests pass
- Follow Microsoft C# coding conventions
- Use async/await for I/O operations
- Implement proper error handling
- Add XML documentation for public APIs
- Use TypeScript for type safety
- Follow Vue 3 Composition API patterns
- Use Pinia for state management
- Implement proper component props validation
- Follow PEP 8 style guidelines
- Use type hints for function signatures
- Implement proper async patterns
- Add docstrings for all functions
- All new features must include tests
- Property-based tests for core algorithms
- Unit tests for individual components
- Integration tests for API endpoints
This project is licensed under the MIT License - see the LICENSE file for details.
- New Zealand Lotteries Commission for lottery data format specifications
- OpenAI for GPT API integration
- FastAPI and Vue.js communities for excellent frameworks
- Property-Based Testing community for correctness verification approaches
For support and questions:
- Check the documentation in this README
- Search existing issues on GitHub
- Create a new issue with detailed information:
- Environment details (OS, Docker version)
- Steps to reproduce the problem
- Expected vs actual behavior
- Relevant logs and error messages
- Statistical analysis engine (number gaps, sum distributions, pair co-occurrence)
- Enhanced GroqCloud LLM prediction with full statistical context
- Multi-line coverage optimisation with sum range validation (P10-P90)
- Backtesting framework with enhanced vs random strategy comparison
- Ticket tracking with auto-verification against draw results
- Provider availability checks (IsAvailableAsync) to prevent timeouts
- Frontend: Ticket Tracker page with colour-coded number matching
- Frontend: Backtest Dashboard with comparison table and distribution charts
- Frontend: Help Guide with feature documentation
- Fixed Docker hot-reload (WORKDIR alignment with volume mount)
- Added FASTAPI_BASE_URL to docker-compose for proper service discovery
- Initial release with full-stack architecture
- CSV file upload and parsing
- Frequency-based predictions
- ML and GPT integration via FastAPI
- Multi-provider prediction chain with circuit breakers
- Docker containerization with dev/production modes
- Comprehensive property-based testing suite
- Redis distributed caching
- Prediction accuracy tracking
- AWS Bedrock LLM integration (provider registered, not yet implemented)
- Ensemble scoring (generate many candidates, pick best statistically)
- Temperature/model tuning experiments
- Automated CSV import from Lottolyzer
- Mobile-responsive ticket entry
- Cloud deployment automation (AWS ECS)