A scalable, microservices-based backend platform for sports betting analytics and odds management, built with modern Python technologies and containerized deployment.
- Overview
- Architecture
- Technologies
- Features
- Project Structure
- Getting Started
- API Endpoints
- Development
NeuralBets Backend is a production-ready microservices architecture designed to handle sports betting data, odds aggregation, and user management. The system integrates with external sports betting APIs to fetch real-time odds, stores and processes betting data, and provides RESTful APIs for frontend consumption.
- Microservices Architecture: Modular design with independent, scalable services
- Containerized Deployment: Docker and Docker Compose for easy deployment and scaling
- Data Modeling: Type-safe schemas with validation and transformation utilities
- Repository Pattern: Clean separation of data access logic
- Production-Ready: Gunicorn WSGI server, health checks, error handling
The backend follows a microservices architecture with the following services:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NeuralBets Backend β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β User Service β β Bet Service β β Auth Service β β
β β (Port 8081)β β (Port 8082) β β (Port TBD) β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ β
β β β β β
β ββββββββββββββββββββΌβββββββββββββββββββ β
β β β
β βββββββββΌβββββββββ β
β β Shared Utils β β
β β (Constants, β β
β β Validators) β β
β βββββββββ¬βββββββββ β
β β β
β ββββββββββββββββββββΌβββββββββββββββββββ β
β β β β β
β ββββββββΌβββββββ βββββββββΌβββββββ βββββββββΌβββββββ β
β β MongoDB β β External API β β Docker β β
β β Database β β Integration β β Containers β β
β βββββββββββββββ βββββββββββββββββ ββββββββββββββββ β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- User Service: User management and authentication
- Bet Service: Odds aggregation, betting data management, external API integration
- Auth Service: Authentication and authorization (planned)
- Account Service: User account management (planned)
- Wallet Service: Transaction and balance management (planned)
- Prediction Service: ML-based predictions (planned)
- Python 3.11 - Modern Python with latest features
- Flask 3.0.3 - Lightweight web framework for REST APIs
- Gunicorn 22.0.0 - Production WSGI HTTP Server
- MongoDB - NoSQL database for flexible data storage
- PyMongo - MongoDB driver for Python
- Docker - Containerization for consistent deployments
- Docker Compose - Multi-container orchestration
- Python-dotenv - Environment variable management
- Microservices - Service-oriented architecture
- Repository Pattern - Data access abstraction
- Schema/Model Pattern - Type-safe data structures
- Blueprint Pattern - Modular route organization
- The Odds API - Real-time sports betting odds aggregation
- β Real-time odds fetching from multiple bookmakers
- β Sports data aggregation and caching
- β Event data management
- β Data transformation and normalization
- β Schema-based validation
- β MongoDB persistence with optimized queries
- β Health check endpoints
- β Dual Storage Strategy: Full and simplified data formats
- β Type-Safe Schemas: Dataclass-based models with validation
- β Automatic Transformation: API data β Simplified format
- β JSON Serialization: Handles ObjectId, datetime, nested structures
- β Data Validation: Pre-storage validation for data integrity
- β Hot-reload support for development
- β Comprehensive error handling
- β Logging and debugging utilities
- β Environment-based configuration
- β Shared utilities package for code reuse
NeuralBets-backend/
βββ bet-service/ # Betting odds and data service
β βββ routes/ # API route definitions
β β βββ api_routes.py
β βββ schemas.py # Data models and transformations
β βββ respository.py # Data access layer
β βββ external_api_client.py # External API integration
β βββ config.py # Service configuration
β βββ app.py # Flask application entry point
β βββ Dockerfile # Service containerization
β βββ requirements.txt # Python dependencies
β
βββ user-service/ # User management service
β βββ routes/
β βββ app.py
β βββ Dockerfile
β βββ requirements.txt
β
βββ shared_utils/ # Shared code package
β βββ constants.py # Shared constants and validators
β βββ setup.py # Package configuration
β
βββ docker-compose.yml # Multi-service orchestration
βββ .env # Environment variables (not in repo)
βββ README.md # This file
- Docker and Docker Compose installed
- Python 3.11+ (for local development)
- MongoDB instance (or use Docker)
- API key for The Odds API
-
Clone the repository
git clone <repository-url> cd NeuralBets-backend
-
Set up environment variables
cp .env.example .env # Edit .env and add your API keys -
Build and start services
docker compose up --build
-
Verify services are running
# Check service health curl http://localhost:8081/health # User Service curl http://localhost:8082/health # Bet Service
For local development without Docker:
# Install shared utilities
cd shared_utils
pip install -e .
# Install service dependencies
cd ../bet-service
pip install -r requirements.txt
# Run service
python app.py| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Service health check |
/health |
GET | Health status |
/bets/status |
GET | API status |
/bets/getdefaultodds |
GET | Get cached/default odds |
/bets/getodds |
GET | Get odds for specific sport |
/bets/getevents |
GET | Get events for sport |
/bets/getdefaultevents |
GET | Get default events |
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Service health check |
/health |
GET | Health status |
/users/status |
GET | API status |
- Schemas (
schemas.py): Define data structures, transformations, and validation - Repository (
respository.py): Handle all database operations - Routes (
routes/api_routes.py): Thin HTTP layer, delegates to repository - External Client (
external_api_client.py): Third-party API integration
- Create service directory with
app.py,Dockerfile,requirements.txt - Add service to
docker-compose.yml - Use shared utilities from
shared_utils/package - Follow existing patterns for consistency
- β Use schemas for all data structures
- β Validate data before storage
- β Transform data on storage (not retrieval)
- β Handle errors gracefully
- β Use type hints where possible
- β Document functions and classes
Services are configured via environment variables:
ODDS_API_KEY: API key for The Odds APIMONGODB_URI: MongoDB connection stringFLASK_ENV: Environment (development/production