Skip to content

ycheng4-design/RallyCoach

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RallyCoach — Your AI Badminton Coach, Powered by Gemini 3

What if every badminton player had a world-class coach watching their every move — reacting in under 500ms?

RallyCoach is a full-stack AI coaching platform that transforms how athletes train. By fusing real-time computer vision with Google Gemini 3's structured reasoning, RallyCoach delivers live commentary, transparent corrections, and personalized training plans — all from a webcam.

No hardware. No sensors. Just you, your racket, and an AI coach that explains its thinking.


Demo

Live Practice Coaching Video Analysis 3D Strategy Board
Real-time skeleton overlay with sub-500ms Gemini 3 Flash feedback Deep form analysis + 5-day training plans via Gemini 3 Pro Three.js court visualization with tactical recommendations

Why Gemini 3 Changes Everything

RallyCoach isn't a thin wrapper around an LLM. It's an end-to-end coaching system that exploits three Gemini 3 breakthroughs:

1. Thinking Tokens = Transparent Coaching

Gemini 3 doesn't just say "raise your elbow" — it reasons why. Each coaching cue arrives with a reason field exposing the model's internal logic:

{
  "cue": "Elbow higher on backswing",
  "commentary": "Your elbow is dropping to 128° — you're losing 30% of your smash power!",
  "reason": "elbow_angle=128° is below the 150° threshold for overhead shots, reducing kinetic chain efficiency",
  "focus_metric": "elbow_angle",
  "is_green": false,
  "latency_ms": 340
}

Players don't just get corrected — they understand biomechanics. That's coaching, not autocorrect.

2. Flash Speed = Real-Time Reaction

At sub-500ms latency, Gemini 3 Flash delivers coaching cues fast enough for active movement correction. We measure and display latency per-cue so users can see the AI responding in real time. This isn't post-hoc analysis — it's a coach watching you swing.

3. Structured Output + Extended Reasoning = Production-Grade AI

Gemini 3's ResponseSchema validation ensures every response is machine-parseable JSON — no regex gymnastics, no prompt-and-pray. Combined with configurable thinkingBudget, we control the reasoning depth per use case:

Use Case Model Thinking Budget Latency
Live coaching cues gemini-3-flash-preview 200 tokens <500ms
Deep video analysis gemini-3-pro-preview 1000 tokens 3-8s
Drill illustrations gemini-3-pro-image-preview 5-10s
Backend feedback gemini-3-flash-preview 200 tokens <500ms

Features at a Glance

Real-Time Practice Mode

  • Live webcam pose tracking via MediaPipe (33-point skeleton, entirely client-side)
  • Green/red skeleton overlay — instant visual feedback on form quality
  • Gemini 3 Flash micro-coaching every 1-2 seconds with commentary + reasoning
  • 5 biomechanical rules: elbow angle (overhead/drive), knee bend, stance width, body rotation
  • Drill-specific form checks (smash drill vs. net play vs. footwork)
  • Session recording to Supabase cloud for later review
  • AI Insights sidebar showing live commentary stream and latency metrics

Video Analytics

  • Upload any badminton video — no special camera required
  • Multi-frame pose extraction with aggregated metrics
  • Gemini 3 Pro deep analysis: top issues (severity-ranked), targeted drills with step-by-step instructions, 5-day personalized training plan
  • Auto skill-level detection (Beginner / Intermediate / Advanced)
  • Optional drill visualization generated by Gemini 3 Pro Image
  • Multi-player detection for doubles analysis

Strategy Board

  • Court homography mapping normalizes video coordinates to BWF court space
  • Shot classification: clear, drop, smash, drive, net, serve, lift
  • 2D/3D trajectory visualization with Three.js + React Three Fiber
  • Deterministic tactical recommendations with confidence scoring
  • Position heatmap analysis to identify opponent weak zones

Racket Finder

  • AI-powered equipment matching based on skill level + specific weaknesses
  • 15+ racket catalog (Yonex, Li-Ning, Victor) with detailed specs
  • Match scoring (0-100) with reasoning for each recommendation
  • eBay purchase links for instant buying
  • Favorites system synced to user profile

Dashboard & History

  • Progress visualization with Recharts (session trends, improvement tracking)
  • Detailed session replay with skeleton overlay, metrics timeline, form scores
  • Aggregate statistics across all sessions

Architecture

┌─────────────────────────────────────────────────────┐
│                    Browser (Client)                  │
│  ┌──────────┐  ┌──────────┐  ┌───────────────────┐  │
│  │ MediaPipe│  │  Canvas   │  │   React Three     │  │
│  │ Pose     │→ │  Skeleton │  │   Fiber (3D)      │  │
│  │ (WASM)   │  │  Overlay  │  │   Court View      │  │
│  └──────────┘  └──────────┘  └───────────────────┘  │
│       ↓ pose metrics (33 landmarks per frame)        │
└──────────────────────┬──────────────────────────────┘
                       │ JSON (every 1-2s)
                       ▼
┌─────────────────────────────────────────────────────┐
│              Next.js 14 API Routes                   │
│  ┌────────────────┐  ┌────────────────────────────┐  │
│  │ Rules Engine   │  │ Gemini 3 Flash / Pro       │  │
│  │ (local eval)   │→ │ Structured JSON output     │  │
│  │ 5 form rules   │  │ + thinking tokens          │  │
│  └────────────────┘  └────────────────────────────┘  │
│       ↓ coaching cues + commentary + reasoning       │
└──────────────────────┬──────────────────────────────┘
                       │
                       ▼
┌─────────────────────────────────────────────────────┐
│                   Supabase                           │
│  ┌────────┐  ┌──────────┐  ┌───────────────────┐    │
│  │  Auth   │  │ Postgres │  │ Storage (videos)  │    │
│  │  (JWT)  │  │ sessions │  │ TUS resumable     │    │
│  │         │  │ analysis │  │ upload            │    │
│  └────────┘  └──────────┘  └───────────────────┘    │
└─────────────────────────────────────────────────────┘

Key design decisions:

  • Hybrid AI architecture: Local rules engine provides instant validation; Gemini 3 adds nuanced, contextual coaching
  • Client-side pose detection: Zero server load for video processing — MediaPipe WASM runs entirely in-browser
  • Rate-limited AI calls: 2-second minimum between Gemini requests to prevent token waste without sacrificing responsiveness
  • Graceful degradation: If Gemini API fails, cached responses keep the session running

Tech Stack

Layer Technology Why
Frontend Next.js 14, React 18, TypeScript App Router for streaming, server components
Styling Tailwind CSS + custom design tokens Dark/light theme system with premium UI
Pose Detection MediaPipe Tasks Vision (WASM) Client-side, zero-latency landmark extraction
3D Visualization Three.js + React Three Fiber Interactive court trajectories
Charts Recharts Progress tracking dashboards
AI Engine Google Gemini 3 (Flash + Pro + Pro Image) Structured reasoning with thinking tokens
Auth & DB Supabase (PostgreSQL + Auth + Storage) Full backend-as-a-service
Backend Python 3.11 + FastAPI Server-side video analysis pipeline
CV Pipeline MediaPipe + OpenCV Server-side pose extraction + video annotation

Project Structure

RallyCoach/
├── backend/                    # Python FastAPI server
│   ├── main.py                 # API endpoints
│   ├── analysis.py             # Video analysis pipeline
│   ├── pose_estimation.py      # Server-side MediaPipe
│   ├── gemini_client.py        # Gemini 3 Flash integration
│   ├── video_annotator.py      # Skeleton overlay rendering
│   └── requirements.txt
├── rallycoach/                 # Next.js 14 frontend
│   ├── src/
│   │   ├── app/
│   │   │   ├── page.tsx              # Landing page
│   │   │   ├── dashboard/            # Progress dashboard
│   │   │   ├── analytics/            # Video analysis
│   │   │   ├── practice/             # Real-time coaching
│   │   │   ├── strategy/             # Tactical analysis
│   │   │   ├── racket/               # Equipment finder
│   │   │   ├── history/              # Session history
│   │   │   └── api/                  # Route handlers
│   │   │       ├── practice/tick/    # Gemini 3 Flash live cues
│   │   │       ├── analysis/start/   # Gemini 3 Pro analysis
│   │   │       ├── strategy/         # Tactical engine
│   │   │       └── racket/           # AI recommendations
│   │   ├── components/               # React components
│   │   │   ├── PoseSandbox3D.tsx     # 3D skeleton viewer
│   │   │   ├── CourtTrajectory3D.tsx # 3D court visualization
│   │   │   └── DashboardNav.tsx      # Navigation
│   │   └── lib/
│   │       ├── gemini.ts             # Gemini 3 client
│   │       ├── rules-engine.ts       # Form evaluation (5 rules)
│   │       ├── pose-utils.ts         # Angle calculations
│   │       ├── scoring-rules.ts      # Banded scoring system
│   │       ├── strategy_engine/      # Rally analysis
│   │       └── courtSpec.ts          # BWF court specs
│   └── package.json
├── supabase-setup.sql                # Database schema
└── supabase-migration-v2.sql         # Extended schema

Quick Start

Prerequisites

1. Database Setup

# Create Supabase project, then run in SQL Editor:
# → supabase-setup.sql (base tables)
# → supabase-migration-v2.sql (extended schema)
# Create a Storage bucket named "videos"

2. Backend

cd backend
python -m venv venv && venv\Scripts\activate  # Windows
pip install -r requirements.txt
# Configure .env: GEMINI_API_KEY, SUPABASE_URL, SUPABASE_ANON_KEY, SUPABASE_SERVICE_KEY
python main.py  # → http://localhost:8000

3. Frontend

cd rallycoach
npm install
# Configure .env.local: NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY, GEMINI_API_KEY
npm run dev  # → http://localhost:3000

What Sets RallyCoach Apart

Traditional Coaching Apps RallyCoach
Pre-recorded video tutorials Live AI coach that reacts to YOUR form in real time
Generic tips Personalized cues based on your specific joint angles
Black-box corrections Transparent reasoning — see WHY each correction matters
Post-session summaries Sub-500ms feedback during active movement
Manual skill assessment Auto-detected skill level via Gemini 3 Pro
One-size-fits-all drills Targeted drill plans addressing YOUR top weaknesses

API Reference

Frontend Routes (Next.js)

Route Method Gemini Model Description
/api/practice/tick POST Flash Live coaching cue + commentary + reasoning
/api/analysis/start POST Pro Deep video analysis + training plan
/api/analysis/auto-level POST Pro Skill level auto-detection
/api/strategy/recommend POST Tactical recommendations
/api/racket/recommend POST Flash AI equipment matching

Backend Routes (FastAPI)

Route Method Description
/api/analyze POST Server-side video analysis pipeline
/api/sessions GET List user sessions
/api/sessions/{id} GET Session details with pose data
/api/practice POST Save practice session
/api/stats/dashboard GET Aggregate dashboard stats

The Biomechanics Engine

RallyCoach evaluates form against 5 research-backed biomechanical rules:

Rule Metric Ideal Range What It Catches
Overhead Elbow Elbow angle 150°-180° Dropped elbow on smash/clear = lost power
Drive Elbow Elbow angle 90°-120° Over-extension on drives = poor control
Knee Bend Knee angle 100°-160° Locked knees = slow footwork
Stance Width Shoulder ratio 0.8x-1.5x Narrow stance = instability
Body Rotation Hip-shoulder separation 10°-45° Flat body = no rotational power

Each frame is evaluated against active rules, producing a green/red classification displayed as the skeleton overlay color. The pass/fail ratio across a session becomes the player's form score.


Built With


License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors