Skip to content

Masonleenf/LeageofRun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸƒ RunBattle

Social running competition app with real-time battles, leagues, and crew challenges

Flutter FastAPI Python PostgreSQL

πŸ“± Features

  • βœ… GPS Running Tracker - Track distance, pace, speed with Google Maps
  • βš”οΈ 1v1 Real-time Battles - Compete with runners of similar skill
  • πŸ† League System - Climb from Bronze to Diamond tier
  • πŸ‘₯ Crew System - Form teams and compete together
  • πŸ”— Strava Integration - Import your existing runs
  • 🎯 Virtual Marathons - User-hosted competitions
  • πŸ“Š Advanced Analytics - Detailed performance insights

🎯 Project Structure

LeageofRun/
β”œβ”€β”€ backend/          # Python FastAPI Backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ models/       # Database models
β”‚   β”‚   β”œβ”€β”€ schemas/      # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ api/          # API endpoints
β”‚   β”‚   β”œβ”€β”€ services/     # Business logic
β”‚   β”‚   └── utils/        # Utilities
β”‚   └── tests/            # Backend tests
β”‚
└── frontend/         # Flutter Mobile App
    β”œβ”€β”€ lib/
    β”‚   β”œβ”€β”€ core/         # Core utilities
    β”‚   β”œβ”€β”€ features/     # Feature modules
    β”‚   └── shared/       # Shared widgets
    └── test/             # Frontend tests

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Flutter 3.22+
  • PostgreSQL 15+
  • Redis 7+
  • Google Maps API Key

Backend Setup

# Navigate to backend directory
cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
cp .env.example .env
# Edit .env with your configuration

# Start the server
uvicorn app.main:app --reload

Server will be available at: http://localhost:8000

API Documentation: http://localhost:8000/docs

Frontend Setup

# Navigate to frontend directory
cd frontend

# Get dependencies
flutter pub get

# Configure Google Maps API
# Android: Edit android/app/src/main/AndroidManifest.xml
# iOS: Edit ios/Runner/AppDelegate.swift

# Run the app
flutter run

Docker Setup (Recommended)

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

πŸ”§ Configuration

Backend Environment Variables

Create backend/.env file:

DATABASE_URL=postgresql://runbattle:password@localhost:5432/runbattle
REDIS_URL=redis://localhost:6379/0
SECRET_KEY=your-secret-key-here
GOOGLE_MAPS_API_KEY=your-google-maps-api-key
STRAVA_CLIENT_ID=your-strava-client-id
STRAVA_CLIENT_SECRET=your-strava-client-secret

Frontend Configuration

Update frontend/lib/core/constants/api_constants.dart:

static const String baseUrl = 'http://your-backend-url:8000';

πŸ“š API Documentation

Authentication

# Register
POST /api/v1/auth/register
{
  "email": "[email protected]",
  "username": "runner123",
  "password": "securepassword"
}

# Login
POST /api/v1/auth/login
{
  "email": "[email protected]",
  "password": "securepassword"
}

# Get current user
GET /api/v1/auth/me
Headers: Authorization: Bearer <token>

Runs

# Create run
POST /api/v1/runs
{
  "distance_km": 5.2,
  "duration_seconds": 1800,
  "avg_pace": 5.77,
  "avg_speed": 10.4,
  "route": [
    {"lat": 37.7749, "lng": -122.4194},
    {"lat": 37.7750, "lng": -122.4195}
  ],
  "start_time": "2024-01-01T10:00:00Z",
  "end_time": "2024-01-01T10:30:00Z"
}

# Get user runs
GET /api/v1/runs?skip=0&limit=20
Headers: Authorization: Bearer <token>

For complete API documentation, visit: http://localhost:8000/docs

πŸ—οΈ Architecture

Backend Architecture

  • Framework: FastAPI (async Python web framework)
  • Database: PostgreSQL (relational data)
  • Cache: Redis (real-time battle data)
  • ORM: SQLAlchemy (database abstraction)
  • Auth: JWT tokens with bcrypt password hashing
  • Validation: Pydantic schemas

Frontend Architecture

  • Framework: Flutter (cross-platform mobile)
  • State Management: Provider
  • HTTP Client: Dio
  • Storage: flutter_secure_storage + shared_preferences
  • Maps: google_maps_flutter + geolocator
  • Charts: fl_chart

Database Schema

-- Users
users (id, email, username, password_hash, stats, rankings)

-- Runs
runs (id, user_id, distance, duration, pace, route, timestamps)

-- Battles
battles (id, user1_id, user2_id, winner_id, stats, status)

-- Crews
crews (id, name, captain_id, stats)
crew_memberships (id, crew_id, user_id, role)

πŸ§ͺ Testing

Backend Tests

cd backend
pytest tests/ -v
pytest tests/ --cov=app  # With coverage

Frontend Tests

cd frontend
flutter test
flutter test --coverage  # With coverage

πŸ” Security

  • βœ… JWT authentication with secure token storage
  • βœ… Password hashing with bcrypt
  • βœ… SQL injection prevention (SQLAlchemy ORM)
  • βœ… CORS protection
  • βœ… Rate limiting
  • βœ… Input validation (Pydantic schemas)
  • βœ… HTTPS only in production

🚒 Deployment

Backend Deployment

Option 1: Docker

docker build -t runbattle-backend ./backend
docker run -p 8000:8000 runbattle-backend

Option 2: Traditional

pip install gunicorn
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker

Frontend Deployment

Android:

flutter build apk --release
flutter build appbundle --release  # For Play Store

iOS:

flutter build ios --release

πŸ“Š Performance

  • API Response Time: < 100ms (average)
  • GPS Accuracy: Β±5-10 meters
  • Battery Usage: Optimized with distance filter
  • Database Queries: Indexed for fast lookups
  • Caching: Redis for real-time data (5min TTL)

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 (Python) and Dart style guide
  • Write tests for new features
  • Update documentation
  • Keep commits atomic and descriptive

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ—ΊοΈ Roadmap

Phase 1 (MVP) βœ…

  • Authentication system
  • GPS running tracker
  • Run history
  • Basic API structure

Phase 2 (Core Features) 🚧

  • Real-time battles
  • League system
  • Crew management
  • Strava integration

Phase 3 (Advanced) πŸ“‹

  • Virtual marathons
  • Premium subscription
  • Advanced analytics
  • Social features

πŸ“ˆ Stats

  • Backend: Python FastAPI
  • Frontend: Flutter (Dart)
  • Database Tables: 8 main tables
  • API Endpoints: 30+ endpoints (planned)
  • Test Coverage: Target 80%+

Made with ❀️ by the RunBattle Team

Run. Compete. Win. πŸƒβ€β™‚οΈπŸ†

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors