A comprehensive sports betting application built with Django REST Framework and React.
- JWT-based authentication
- User registration
- User login
- Email verification
- Password reset functionality
- View current balance
- Add balance functionality
- Home page with available bets
- Create new bets
- Place bets on available events
- View user's active bets
- Bet results processing (When the status of the match is changed to finished)
- Winnings calculation
- Persistent bet selections with auto-validation on page refresh
- Browse leagues
- View league details
- View upcoming and past matches
- Match status tracking
- Responsive design using Tailwind CSS
- Toast notifications for user feedback
- Dynamic forms with validation
- Error handling
- Card-based match display
- Python 3.12+
- Node.js 18+
- NPM 9+
-
Clone the repository
git clone https://github.com/yourusername/bettting-site.git cd bettting-site -
Set up environment variables
cd server cp .env.example .env # Update SECRET_KEY -
Set up Python virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install dependencies and set up database
cd server pip install -r requirements.txt python manage.py migrate python manage.py add_initial_data # Optional python manage.py runserver
-
Add a new league through Django admin panel
# First, create a superuser if you haven't already python manage.py createsuperuser # Access Django admin at http://localhost:8000/admin/ # Navigate to Sports > Leagues > Add League -
Configure league data source
- Set league name and associate with a sport
- Set data source to "flashscore"
- Add source URL from Flashscore (e.g., "https://www.flashscore.com/football/england/premier-league/fixtures/")
- Mark as active and save
-
Import matches using management command
# Import matches for all active leagues python manage.py import_matches # Import matches for a specific league (replace LEAGUE_ID with actual ID) python manage.py import_matches --league_id=LEAGUE_ID # Run import asynchronously using Celery (requires Celery setup) python manage.py import_matches --async # Run import odds python manage.py import_upcoming_odds -
Schedule regular updates (optional)
- Set up a cron job or use Celery beat to run import_matches periodically
- Configure Celery for asynchronous processing in production
The bet settlement logic is modular and extensible. Each sport can have its own settlement strategy, making it easy to implement sport-specific rules for evaluating bets.
-
Settlement Base Class:
All settlement strategies inherit from the abstractSettlementclass, which defines the interface for settling a bet. -
Settlement Factory:
TheSettlementFactoryselects the appropriate settlement strategy based on the sport type (e.g., "football").
Example:settler = SettlementFactory.create_settlement(match.league.sport.name)
-
Sport-specific Settlement:
Each sport has its own class, e.g.FootballSettlement, implementing the logic for settling bets for that sport. -
Integration with Bet Model:
TheBetmodel calls the correct settlement logic via itssettle_bet()method:def settle_bet(self) -> None: if not self.is_settled: from sports.services.settlement import SettlementFactory settler = SettlementFactory.create_settlement(self.match.league.sport.name) if settler: settler.settle_bet(self) self.bet_slip.settle_slip()
-
Extending for New Sports:
To add a new sport, create a new settlement class (e.g.BasketballSettlement) and update the factory method.
- For football, the
FootballSettlementclass determines the result based on match scores and bet type. - The system can be easily extended for other sports by adding new settlement classes.
- Redis (as a broker for Celery)
- Install Redis (macOS)
brew install redis
brew services start redis- Install Redis (Linux)
sudo apt install redis-server
sudo systemctl start redis- Check if Redis is running
redis-cli ping
# Should return: PONG- Running Celery
In one terminal, start the worker:
celery -A server worker -l infoIn another terminal, start the beat scheduler:
celery -A server beat -l info- Automatic Task Schedule
- Import matches: daily at midnight (00:00)
- Import odds: every 1 hour (you can change this in
server/server/celery.py)
The configuration is in server/server/celery.py:
app.conf.beat_schedule = {
'import-matches-daily': {
'task': 'sports.tasks.import_all_league_matches',
'schedule': crontab(hour=0, minute=0),
'kwargs': {'scheduled': True},
},
'import-upcoming-matches-odds': {
'task': 'sports.tasks.import_upcoming_matches_odds',
'schedule': timedelta(hours=1),
},
}- Manual Import
You can also run the import manually using a management command or from the Django shell.
Note:
Celery worker and beat must be running for automatic import to work!
-
Install dependencies and start development server
cd client npm install npm run dev -
Access the application at http://localhost:5173
- Swagger UI: http://localhost:8000/swagger/
- ReDoc: http://localhost:8000/redoc/
server/- Django Backendaccounts/- User management and authorizationsports/- Sports betting management
client/- React Frontendsrc/components/- React componentsatoms/- Basic UI componentsmolecules/- Composite componentsorganisms/- Complex components combining moleculesui/- Reusable UI components (shadcn/ui)
src/pages/- Application pagessrc/services/- API integrationsrc/context/- React contexts for state managementsrc/hooks/- Custom React hooks
- Django
- Django REST Framework
- Simple JWT
- drf-yasg (Swagger/OpenAPI)
- React
- React Router
- Axios
- Tailwind CSS
- shadcn/ui
- React Hook Form
- Radix UI primitives



