A Next.js application that analyzes baseball swings using AI pose detection and provides personalized coaching feedback to improve your swing.
- AI Pose Detection: Client-side (TensorFlow.js) and server-side (MediaPipe) pose detection
- Storage: Local PC server storage
- Database: MongoDB Atlas
- AI Coaching: Get instant feedback from AI coaches on your swing mechanics
- Drill Recommendations: Receive personalized drill suggestions based on your analysis
- Photo & Video Support: Capture or upload photos/videos, extract best frame from videos
- Frontend: Next.js 14+, React, TypeScript, Tailwind CSS
- AI: TensorFlow.js, MoveNet (SinglePose Lightning)
- Database: MongoDB Atlas
- Storage: Local PC Server
- Auth: Auth0 Authentication
- Backend: Main Gateway (Node.js) + Flask Services (Python)
- Pose Detection Service (MediaPipe)
- Drill Recommender Service
- Blast Connector Service
- Node.js 18+ and npm
- Auth0 account (for authentication)
- MongoDB Atlas account (for database)
Quick Install (Recommended):
npm run install:allThis will install:
- Node.js dependencies
- Python dependencies for all Flask services (pose-detection-service, drill-recommender, blast-connector)
- AI models (~17MB)
Manual Install:
# Install Node.js dependencies
npm install
# Install Python dependencies for all services
npm run install:python
# Or install individually:
npm run install:python:pose # Pose Detection Service
npm run install:python:drills # Drill Recommender
npm run install:python:blast # Blast Connector
# Install AI models (optional - will download on first use)
npm run install:modelsNote: Make sure you have Python 3.8+ and pip installed. The install script will automatically detect your Python installation.
Create a .env.local file in the root directory:
# Auth0 Configuration
AUTH0_DOMAIN=your-app.auth0.com
AUTH0_CLIENT_ID=your_client_id
AUTH0_CLIENT_SECRET=your_client_secret
AUTH0_BASE_URL=http://localhost:3001
AUTH0_AUDIENCE=your_api_identifier
AUTH0_SCOPE=openid profile email
# MongoDB Atlas
MONGODB_URI="mongodb+srv://username:password@cluster.mongodb.net/database?retryWrites=true&w=majority"
# Or specify database separately:
MONGODB_DATABASE=baseball
# Storage & Database Toggles
STORAGE_TYPE=local
DATABASE_TYPE=mongodb
# Backend Gateway Configuration
GATEWAY_PORT=3001
GATEWAY_URL=http://localhost:3001
NEXT_PUBLIC_GATEWAY_URL=http://localhost:3001 # For frontend
# Flask Services Configuration
POSE_DETECTION_SERVICE_PORT=5000
POSE_DETECTION_SERVICE_URL=http://localhost:5000
DRILL_RECOMMENDER_PORT=5001
DRILL_RECOMMENDER_URL=http://localhost:5001
BLAST_CONNECTOR_PORT=5002
BLAST_CONNECTOR_URL=http://localhost:5002
# Demo Mode (for Flask services - allows independent testing with demo user)
DEMO_MODE=false
DEMO_USER_ID=demo_user
# Test Mode (for Flask services - bypasses authentication)
TEST_MODE=false
# Ngrok Configuration (optional - for remote backend and/or public frontend)
# Backend via ngrok (if backend is on different PC)
NEXT_PUBLIC_BACKEND_URL=https://baseball.ngrok.app
NGROK_URL=https://baseball.ngrok.app
# Frontend via ngrok (optional - for public access)
NEXT_PUBLIC_NGROK_FRONTEND_URL=https://baseball.ngrok.dev
NGROK_FRONTEND_URL=https://baseball.ngrok.dev
Quick Setup (5 minutes):
- Go to Auth0 Dashboard
- Create a new application (Regular Web Application)
- Configure callback URLs:
- Allowed Callback URLs:
http://localhost:3001/api/auth/callback - Allowed Logout URLs:
http://localhost:3000 - Allowed Web Origins:
http://localhost:3000
- Allowed Callback URLs:
- Get your Auth0 credentials:
- Domain: Found at the top of your Auth0 Dashboard
- Client ID: Found in your Application settings
- Client Secret: Click "Show" in Application settings
- Add config to
.env.local(see example above)
See docs/AUTH0_SETUP.md for detailed step-by-step instructions.
- Create a MongoDB Atlas account at MongoDB Atlas
- Create a new cluster
- Create a database user
- Whitelist your IP address (or use 0.0.0.0/0 for development)
- Get your connection string and add it to
.env.localasMONGODB_URI
# Start Next.js dev server
npm run dev
# (Optional) Start Express server for local storage
npm run dev:serverThe Next.js app will run on http://localhost:3000 The Express server will run on http://localhost:3001 (if started)
npm run build
npm startbaseballhackathon/
├── app/ # Next.js app directory
│ ├── api/ # API routes
│ ├── mission/ # Mission page
│ ├── leaderboard/ # Leaderboard page
│ └── login/ # Login page
├── components/ # React components
│ ├── Auth/ # Authentication components
│ ├── Mission/ # Mission flow components
│ └── Leaderboard/ # Leaderboard components
├── lib/ # Core libraries
│ ├── database/ # Database adapters (MongoDB)
│ ├── storage/ # Storage adapters (Local)
│ ├── pose/ # Pose detection (client/server)
│ ├── game/ # Game logic (physics, zones, labels)
│ ├── auth0/ # Auth0 configuration
│ └── mongodb/ # MongoDB configuration
├── pose-detection-service/ # Pose detection service (MediaPipe)
├── types/ # TypeScript type definitions
└── public/ # Static assets
- local: Uses local Python backend for file storage (default)
- mongodb: Uses MongoDB Atlas (default)
Set these in .env.local:
STORAGE_TYPE=local
DATABASE_TYPE=mongodb- Sign In: Use Google OAuth authentication via Auth0
- Upload Video: Upload a video of your swing from the Analyze or Blast Off page
- Get Analysis: AI will analyze your swing using pose detection and object tracking
- Review Metrics: See detailed metrics including bat speed, exit velocity, launch angle, and biomechanics
- Get Coaching: Receive AI-powered coaching feedback with specific recommendations
- View Drills: Get personalized drill recommendations to improve your swing
- Track Progress: View all your videos and analyses in your video library
- Pose Detection: MediaPipe-based pose detection with 33 body landmarks
- Object Detection: YOLOv8-based detection of person, bat, and ball
- Metrics Calculation: Bat speed, exit velocity, launch angle, and more
- Swing Phases: Automatic detection of load, stride, contact, and follow-through phases
- Biomechanics: Analysis of hip rotation, shoulder separation, weight transfer, and more
- Form Errors: Identification of common swing flaws with recommendations
- OpenRouter Integration: Get instant coaching feedback from Claude 3.5 Sonnet
- Gemini Integration: Receive personalized drill recommendations based on your analysis
- Voice Over: Listen to coaching feedback with ElevenLabs text-to-speech
POST /api/pose- Server-side pose detectionPOST /api/storage/upload- Upload file to local storageGET /api/storage/:path- Get file from local storagePOST /api/sessions- Create a sessionGET /api/sessions- Get user sessions
POST /api/pose/detect- Pose detection endpointPOST /api/storage/upload- File uploadGET /api/storage/:path- File servingDELETE /api/storage/:path- File deletion
- Ensure TensorFlow.js models are loaded (check browser console)
- Run
npm run install:modelsto pre-download and cache models - Verify image has clear pose visibility
- Try server-side detection if client-side fails
- Run
npm run install:modelsto install models manually - Check your internet connection (models download from Google CDN)
- Models are cached after first download (~17MB total)
- See
docs/MODEL_INSTALLATION.mdfor detailed instructions
- "Auth0 not configured":
- Check that
.env.localhas allAUTH0_*variables set - Make sure
AUTH0_DOMAIN,AUTH0_CLIENT_ID, andAUTH0_CLIENT_SECRETare set - Restart dev server after adding config
- Check that
- "Invalid token" errors:
- Check that callback URLs are configured in Auth0 Dashboard
- Ensure
AUTH0_BASE_URLmatches your backend gateway URL - Verify
AUTH0_DOMAIN,AUTH0_CLIENT_ID, andAUTH0_CLIENT_SECRETare set correctly - See
docs/AUTH0_SETUP.mdfor complete setup guide
- Google Sign-In not working:
- Make sure Google sign-in is enabled in Auth0 Dashboard
- Check that callback URLs are configured correctly
- Try clearing browser cache
- Verify connection string format
- Check IP whitelist in MongoDB Atlas
- Ensure database user has proper permissions
- Ensure Express server is running (
npm run dev:server) - Check
LOCAL_SERVER_URLin.env.local - Verify
server/uploads/directory exists and is writable
MIT
Contributions are welcome! Please open an issue or submit a pull request.