A machine learning-powered system to predict La Liga football match outcomes with real-time injury data integration.
- Match Predictions: Real-time predictions for upcoming La Liga matches using ML models
- Injury Integration: Real-time player injury data enrichment
- Historical Analysis: Team statistics and performance trends
- Key Player Impact: Identifies key players and their performance metrics
- Interactive Dashboard: React-based UI for exploring predictions and standings
- REST API: FastAPI backend for seamless data access
Backend:
- Python 3.x with FastAPI
- SQLAlchemy ORM for database operations
- PostgreSQL for data persistence
- Scikit-learn for ML model training
Frontend:
- React with Vite bundler
- Tailwind CSS for styling
- Axios for API communication
- Python 3.8+
- Node.js 16+
- PostgreSQL 12+
- Git
git clone https://github.com/niraj4rl/Laliga_gin.git
cd Laliga_ginpython -m venv .venv
# On Windows
.venv\Scripts\activate
# On Linux/Mac
source .venv/bin/activatecd backend
pip install -r requirements.txt
cd ..# Copy the example file
cp backend/.env.example backend/.env
# Edit .env and add your API keys
# Required:
# - FOOTBALL_API_KEY: Get from https://www.football-data.org/
# Optional:
# - RAPIDAPI_KEY: For enhanced injury data from RapidAPI
# - APIFOOTBALL_API_KEY: Alternative data provider
# Database:
# - DATABASE_URL: PostgreSQL connection string# Create database
createdb laliga_analytics
# Run migrations
cd backend
python -c "from database.db import Base, engine; Base.metadata.create_all(bind=engine)"
# Seed initial data (optional)
python database/seed.py
cd ..cd frontend
npm install
cd ..# Start both backend and frontend
python run.pyThe application will be available at:
- Frontend:
http://localhost:8002 - Backend API:
http://localhost:8001
GET /predict/upcoming- Get upcoming match predictionsGET /predict/upcoming?include_injuries=true- Include injury dataGET /predict/upcoming?include_injuries=false- Fast predictions without injury data
include_injuries(boolean): Include player injury data (default: true)- Response time varies: ~30s with injuries, ~5s without
βββ backend/
β βββ api/
β β βββ main.py # FastAPI endpoints
β βββ database/
β β βββ db.py # SQLAlchemy models & connection
β β βββ schema.sql # Database schema
β β βββ seed.py # Initial data setup
β β βββ download_real_data.py
β βββ ml/
β β βββ feature_engineering.py
β β βββ train_model.py
β βββ services/
β β βββ data_service.py
β βββ .env.example # Environment variables template
β βββ .env # Local secrets (gitignored)
β βββ requirements.txt
βββ frontend/
β βββ src/
β β βββ components/
β β βββ pages/
β β βββ services/
β β βββ App.js
β β βββ index.css
β βββ package.json
β βββ vite.config.js
βββ data/
β βββ features.csv
β βββ laliga_matches.csv
βββ models/
β βββ model_meta.json
βββ run.py # Main entry point
βββ README.md
- Never commit
.envfile - It's gitignored for security - Use
.env.exampleas reference for required variables - Rotate API keys if accidentally exposed
- All secrets are loaded from environment variables, not hardcoded
# Database (Required)
DATABASE_URL=postgresql://username:password@localhost:5432/laliga_analytics
# API Keys
FOOTBALL_API_KEY=your_key_here # Required - https://www.football-data.org/
RAPIDAPI_KEY= # Optional - for injury data
APIFOOTBALL_API_KEY= # Optional - alternative provider
# Features
ENABLE_INJURY_LOOKUP=1 # 1 to enable, 0 to disable
UPCOMING_MATCH_LIMIT=5 # Number of upcoming matches to fetch# PowerShell (Windows)
Get-NetTCPConnection -LocalPort 8001,8002 -State Listen | Stop-Process -Force
# Bash (Linux/Mac)
lsof -ti:8001,8002 | xargs kill -9This project is ready to deploy with:
- Backend on Render
- Frontend on Vercel
- Go to Render and create a Web Service from this GitHub repo.
- Render will detect
render.yamlautomatically. - Set required environment variables in Render:
DATABASE_URLFOOTBALL_API_KEY
- Optional variables:
RAPIDAPI_KEYAPIFOOTBALL_API_KEYENABLE_INJURY_LOOKUP(1or0)UPCOMING_MATCH_LIMIT
- Deploy and copy your backend URL (example:
https://laliga-api.onrender.com).
- Import the same repo in Vercel.
- Vercel will use
vercel.jsonfrom project root. - Add env var in Vercel project settings:
VITE_API_BASE_URL=https://<your-render-backend-url>
- Deploy.
After frontend is deployed, add this variable in Render backend:
FRONTEND_URL=https://<your-vercel-domain>
Then redeploy backend once so CORS allows your live frontend domain.
- Training Data: Historical La Liga match data (2017-present)
- Features: Team form, head-to-head records, player injuries, home/away advantage
- Model: Ensemble learning approach (Random Forest + Gradient Boosting)
- Accuracy: ~68% on test set
# Find and stop process using port 8001 or 8002
netstat -ano | findstr :8001 # Windows
lsof -i :8001 # Linux/Mac- Ensure PostgreSQL is running
- Verify DATABASE_URL is correct in
.env - Check database name matches:
laliga_analytics
- Verify FOOTBALL_API_KEY is valid at https://www.football-data.org/
- Injury data fails gracefully if RAPIDAPI_KEY is missing
- Use
include_injuries=falsefor faster responses if API limits hit
- Create a feature branch:
git checkout -b feature/YourFeature - Commit changes:
git commit -m 'Add YourFeature' - Push to branch:
git push origin feature/YourFeature - Open a Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
Author: Niraj
GitHub: @niraj4rl
Email: pashte.niraj2005@gmail.com
Last Updated: March 26, 2026
Repository: github.com/niraj4rl/Laliga_gin