A real-time football match streaming system with AI-powered chat using Kafka and Mistral AI.
Note: This demo link may expire. If it's not working, you can run the project locally following the setup instructions below.
Stream football matches in real-time and chat with an AI assistant that knows what's happening in the game. Ask questions like "What's the score?" or "Who scored?" and get instant, context-aware answers.
Match Data (JSON files)
โ
Kafka Producer (replay_streamer.py) - Streams match events
โ
Kafka Topics (comments, events, scores)
โ
Kafka Consumer (kafka_context_store.py) - Tracks last 30 events
โ
RAG Engine (rag_engine_simple.py) - Reads context + asks Mistral AI
โ
You get smart answers! ๐ค
- โก Real-time streaming - Watch matches unfold minute by minute
- ๐ค AI chatbot - Ask questions about the match in natural language
- ๐ฎ Multiple matches - Stream several games at once
- โฐ Start anywhere - Begin at any minute (e.g., 45'+2, 60')
- ๐ Smart context - AI knows the last 30 events (10 goals + 10 events + 10 comments)
macOS:
brew install kafka
brew services start kafkaLinux:
# Download and extract Kafka
wget https://downloads.apache.org/kafka/3.6.0/kafka_2.13-3.6.0.tgz
tar -xzf kafka_2.13-3.6.0.tgz
cd kafka_2.13-3.6.0
# Start Zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties &
# Start Kafka
bin/kafka-server-start.sh config/server.properties &Windows:
# Option 1: Use WSL2 (recommended)
# Install WSL2, then follow Linux instructions
# Option 2: Native Windows
# Download from https://kafka.apache.org/downloads
# Extract to C:\kafka
# Run from C:\kafka:
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
# In new terminal:
.\bin\windows\kafka-server-start.bat .\config\server.properties# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set Mistral API key (get yours at https://console.mistral.ai/)
export MISTRAL_API_KEY="your_key_here" # On Windows: set MISTRAL_API_KEY=your_key_here
# Start backend
uvicorn backend.app:app --reloadcd frontend
npm install
npm run devFrontend runs on http://localhost:3000
- Open http://localhost:3000
- Select a match from "Match history"
- Click "Stream selected games"
- Click the match in "Currently streaming"
- Ask questions in the chatbot!
- "What's the score?"
- "Who scored?"
- "Any yellow cards?"
- "What happened in the last 5 minutes?"
- "Tell me about the goals"
project/
โโโ backend/
โ โโโ app.py # FastAPI server
โ โโโ replay_streamer.py # Kafka producer (streams events)
โ โโโ kafka_context_store.py # Kafka consumer (tracks context)
โ โโโ rag_engine_simple.py # AI chatbot with Mistral
โ โโโ runtime/ # Generated context files
โ โโโ {game_id}/
โ โโโ rag_recap.txt # Last 30 events (used by AI)
โโโ data/
โ โโโ games/
โ โโโ {game_id}/
โ โโโ meta.json # Match info
โ โโโ events.json # Goals, cards, subs
โ โโโ comments.json # Commentary
โโโ frontend/
โ โโโ app/
โ โโโ page.tsx # React UI
โโโ requirements.txt
# Required
export MISTRAL_API_KEY="your_mistral_key"
# Optional (defaults shown)
export MISTRAL_MODEL="mistral-small-latest"
export KAFKA_BOOTSTRAP="localhost:9092"The AI sees the last 30 events:
- 10 goals with scorer info
- 10 events (cards, subs, VAR)
- 10 comments (commentary)
We use simple file-based RAG instead of vector databases because:
โ
Recent context is what matters - You care about the last 10 events, not searching through 500
โ
Simpler - No embeddings, no Qdrant, no complexity
โ
Faster - Direct file read (~1ms) vs vector search
โ
Cheaper - No embedding API calls
โ
Perfect for live matches - Chronological order, not semantic similarity
# Start at minute 45, extra time +2
{
"games": [{
"game_id": "chelsea_aston_villa_2025-12-27",
"startAtMinute": 45,
"startAtExtra": 2
}]
}# Stream 3 matches at once
{
"games": [
{"game_id": "match1", "startAtMinute": 0, "startAtExtra": 0},
{"game_id": "match2", "startAtMinute": 45, "startAtExtra": 0},
{"game_id": "match3", "startAtMinute": 60, "startAtExtra": 0}
]
}Check backend is running:
curl http://localhost:8000/api/games
# Should return JSON with game listCheck game data exists:
ls -la data/games/
# Should show game folders with meta.json, events.json, comments.jsonWait for streaming to start - Context builds as events stream
Check Kafka is running:
# Should show active brokers
kafka-broker-api-versions.sh --bootstrap-server localhost:9092Check API key is set:
echo $MISTRAL_API_KEY # Should show your keyVerify key is valid at https://console.mistral.ai/
List available matches
Start streaming match(es)
{
"games": [
{
"game_id": "match_id",
"startAtMinute": 0,
"startAtExtra": 0
}
]
}Get current match status
Ask AI about match
{
"game_id": "match_id",
"message": "What's the score?"
}Stop all streams
- Create new Railway project
- Connect your GitHub repo
- Set environment variables:
MISTRAL_API_KEY= your_keyKAFKA_BOOTSTRAP= (Railway provides this)
- Deploy!
- Create new Railway project
- Connect your GitHub repo
- Set environment variable:
- Deploy!
Important: Railway provides managed Kafka - you don't need to run it separately!
Create a folder in data/games/ with these files:
meta.json:
{
"game_id": "team1_team2_2026-01-01",
"team_home": "Team 1",
"team_away": "Team 2",
"competition": "League Name",
"date": "2026-01-01"
}events.json:
{
"response": [
{
"time": { "elapsed": 23, "extra": null },
"team": { "name": "Team 1" },
"player": { "name": "John Doe" },
"type": "Goal",
"detail": "Normal Goal"
}
]
}comments.json:
[
{
"minute": 1,
"extra": 0,
"type": "Commentary",
"text": "Match kicks off!"
}
]- Backend: FastAPI, Kafka, Mistral AI
- Frontend: Next.js, React, TypeScript
- Streaming: Apache Kafka
- AI: Mistral (mistral-small-latest)
Contributions welcome! Ideas:
- Add player statistics
- Support more data sources
- Add match highlights
- Multi-language support
- Voice input/output
- Live score notifications
Built with:
- Apache Kafka - Event streaming
- Mistral AI - Language model
- FastAPI - Backend framework
- Next.js - Frontend framework
Made for football fans
Questions? Open an issue on GitHub!