Django REST API backend for Speed Champions, a karting race results tracking and analytics platform.
Frontend Repository: https://github.com/COU7INHO/speedway-stats
This backend provides a robust REST API for managing karting race data, including AI-powered OCR for automatic race result extraction from timing sheet images. Built with Django and PostgreSQL, it handles driver statistics, race results, circuit information, and performance analytics.
Automatically extract race results from timing sheet images using Mistral AI's vision model. Upload a photo and get structured race data instantly.
- Driver performance tracking and evolution
- Circuit-specific statistics
- Leaderboard rankings
- Lap time analysis
- Race history and comparisons
Session-based authentication with CSRF protection, designed to work seamlessly with modern frontend frameworks.
Configured for production deployment with proper CORS policies, security headers, and optimized for serving behind Cloudflare.
- Django 6.0 - Web framework
- Django REST Framework - API toolkit
- PostgreSQL - Database (production)
- Mistral AI - OCR vision model
- Gunicorn - WSGI server
- Docker - Containerization
- Nginx - Reverse proxy & static files
┌─────────────┐
│ Cloudflare │ HTTPS/SSL, CDN
└──────┬──────┘
│
┌──────▼──────┐
│ Nginx │ Reverse proxy, static files
└──────┬──────┘
│
┌──────▼──────┐
│ Django │ API logic, OCR processing
│ (Gunicorn) │
└──────┬──────┘
│
┌──────▼──────┐
│ PostgreSQL │ Race data storage
└─────────────┘
speed_champion/
├── speed_champion/
│ ├── settings/ # Environment-specific settings
│ │ ├── base.py # Common settings
│ │ ├── development.py # Local development
│ │ └── production.py # Production config
│ ├── api/
│ │ ├── drivers/ # Driver management
│ │ ├── circuits/ # Circuit management
│ │ └── races/ # Race results & OCR
│ └── urls.py
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── manage.py
POST /api/auth/login/- User loginPOST /api/auth/logout/- User logoutGET /api/auth/status/- Check authentication status
GET /api/drivers/- List all driversGET /api/drivers/{id}/- Driver details and statsGET /api/drivers/{id}/evolution/- Performance over timeGET /api/drivers/compare/- Compare multiple drivers
GET /api/circuits/- List all circuits
GET /api/races/- List races (filterable by circuit/driver)GET /api/races/{id}/- Race details with resultsPOST /api/races/upload-image/- OCR extraction from imagePOST /api/races/save-results/- Save race results
GET /api/leaderboard/- Current rankings
- Python 3.12+
- PostgreSQL (production) or SQLite (development)
- Docker & Docker Compose (recommended)
# Clone repository
git clone https://github.com/COU7INHO/karst-app-backend.git
cd karst-app-backend/speed_champion
# Install dependencies (using uv)
uv pip install -r requirements.txt
# Create .env file
cp .env.example .env
# Edit .env with your configuration
# Run migrations
python manage.py migrate
# Create superuser
python manage.py createsuperuser
# Run development server
python manage.py runserver# Build and start containers
docker compose up -d --build
# Collect static files
docker compose exec web python manage.py collectstatic --noinput
# Create superuser
docker compose exec web python manage.py createsuperuserRequired variables in .env:
# Environment
DJANGO_ENV=production
# Security
SECRET_KEY=your-secret-key-here
# Database (PostgreSQL)
DB_NAME=karts_db
DB_USER=karts_user
DB_PASSWORD=your-db-password
DB_HOST=db
DB_PORT=5432
# AI/OCR
MISTRAL_API_KEY=your-mistral-api-keyThe application is designed to run on a Raspberry Pi using:
- Docker Compose for container orchestration
- Nginx for serving static files and reverse proxy
- Cloudflare Tunnel for HTTPS and external access
See DEPLOY.md for detailed deployment instructions.
Settings are split by environment:
base.py- Common settings (installed apps, middleware, etc)development.py- Local dev (SQLite, debug mode, CORS allow all)production.py- Production (PostgreSQL, security headers, restricted CORS)
Switch environments via DJANGO_ENV environment variable.
Logs are configured to output to:
- Console - All environments
app_logs.log- Application logsdjango.log- Framework logs
Private project - All rights reserved
Live Application: karts.tiago-coutinho.com