Skip to content

Play, bet, and spin - AI-assisted roulette in your browser.

License

Notifications You must be signed in to change notification settings

karved/Ai-Roulette

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฐ AI-Roulette

Play, bet, and spin - AI-assisted roulette in your browser.

A sophisticated, interactive multiplayer roulette game featuring AI assistance, voice commands, and real-time gameplay. This project demonstrates full-stack development skills, system architecture design, and creative UX implementation.

๐ŸŽฏ Project Overview

This take-home project showcases:

  • Full-Stack Architecture: React TypeScript frontend with FastAPI Python backend
  • Interactive Gameplay: Multi-input betting system (mouse, keyboard, voice)
  • AI Integration: Dual-layer AI system with OpenAI + backup parser
  • Real-Time Features: Live multiplayer lobbies and game state synchronization
  • Data Persistence: Comprehensive user/game data storage with Supabase
  • Modern UX: Optimistic UI updates with backend verification

โœจ Features

  • ๐ŸŽฎ Interactive Roulette Table: Click to place bets on numbers, colors, and groups
  • ๐ŸŽค Voice Betting: Use natural language commands like "bet 10 on red"
  • ๐Ÿค– AI Assistant: Get help with rules, strategies, and automated bet parsing
  • ๐Ÿ“Š Real-time Analytics: Hot/cold numbers, recent spins, and leaderboards (Future)
  • ๐Ÿ‘ฅ Multiplayer: Join lobbies with other players (Future)
  • ๐Ÿ’ฐ Balance Tracking: Start with $100, win or lose based on your bets
  • ๐Ÿ”„ Backup Systems: Fallback parsers ensure functionality without external APIs

๐Ÿ› ๏ธ Tech Stack

Frontend

  • React 18 with TypeScript
  • Vite for fast development
  • Tailwind CSS for styling
  • Zustand for state management
  • Supabase for authentication
  • Web Speech API for voice input

Backend

  • FastAPI with Python
  • Supabase (PostgreSQL + Auth)
  • WebSockets for real-time updates
  • OpenAI API (optional, with backup parser)
  • Pydantic for data validation

Deployment

  • Frontend: Firebase/Netlify/Vercel
  • Backend: Railway/Render
  • Database: Supabase

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • Python 3.8+
  • Supabase account (free tier works)

1. Clone and Setup

git clone https://github.com/yourusername/Ai-Roulette.git
cd Ai-Roulette

2. Database Setup (Supabase)

  1. Create a new Supabase project at supabase.com
  2. Go to SQL Editor and run the schema from docs/corrected-database-schema.sql
  3. Note your project URL and anon key from Settings > API

3. Backend Setup

cd backend
pip install -r requirements.txt

# Create environment file
echo "SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
OPENAI_API_KEY=your_openai_api_key" > .env

# Start the server
python main.py

4. Frontend Setup

cd frontend
npm install

# Create environment file
echo "VITE_SUPABASE_URL=your_supabase_project_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
VITE_API_URL=http://localhost:8000" > .env.local

# Start the development server
npm run dev

5. Access the Game

๐Ÿ”ง Configuration

Environment Variables

Backend (.env)

SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
OPENAI_API_KEY=your_openai_api_key  # Optional

Frontend (.env.local)

VITE_SUPABASE_URL=your_supabase_project_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
VITE_API_URL=http://localhost:8000

๐ŸŽฏ Game Rules

Betting Types & Payouts

  • Straight (Single Number): 35:1
  • Red/Black: 1:1
  • Even/Odd: 1:1
  • Low (1-18) / High (19-36): 1:1
  • Dozens/Columns: 2:1
  • Split (2 numbers): 17:1
  • Street (3 numbers): 11:1
  • Corner (4 numbers): 8:1
  • Line (6 numbers): 5:1

Voice Commands

  • "Bet 10 on red"
  • "Place 5 on black"
  • "Put 25 on number 7"
  • "Bet 15 on even"

AI Assistant

Ask about rules, strategies, or get help with betting. The AI can also parse natural language betting commands automatically.

๐Ÿ—๏ธ System Architecture

High-Level Design

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   React Client  โ”‚โ—„โ”€โ”€โ–บโ”‚  FastAPI Server โ”‚โ—„โ”€โ”€โ–บโ”‚   Supabase DB   โ”‚
โ”‚   (Frontend)    โ”‚    โ”‚   (Backend)     โ”‚    โ”‚   (PostgreSQL)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ–ผ                       โ–ผ                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Web Speech API โ”‚    โ”‚   OpenAI API    โ”‚    โ”‚   Auth Service  โ”‚
โ”‚ (Voice Commands)โ”‚    โ”‚ (AI Assistant)  โ”‚    โ”‚  (JWT Tokens)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Project Structure

Ai-Roulette/
โ”œโ”€โ”€ frontend/                 # React TypeScript app
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/       # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ contexts/         # React state management
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/           # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ assets/          # Static assets
โ”‚   โ”‚   โ””โ”€โ”€ App.tsx          # Main application
โ”‚   โ”œโ”€โ”€ package.json         # Dependencies & scripts
โ”‚   โ””โ”€โ”€ vite.config.ts       # Build configuration
โ”œโ”€โ”€ backend/                  # FastAPI Python server
โ”‚   โ”œโ”€โ”€ models/              # Pydantic data models
โ”‚   โ”‚   โ””โ”€โ”€ game.py          # Game state models
โ”‚   โ”œโ”€โ”€ services/            # Business logic layer
โ”‚   โ”‚   โ”œโ”€โ”€ ai_service.py    # AI integration
โ”‚   โ”‚   โ”œโ”€โ”€ auth_service.py  # Authentication
โ”‚   โ”‚   โ””โ”€โ”€ database.py      # Database operations
โ”‚   โ”œโ”€โ”€ utils/               # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ websocket_manager.py # Real-time updates
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application
โ”‚   โ””โ”€โ”€ requirements.txt     # Python dependencies
โ”œโ”€โ”€ docs/                    # Project documentation
โ”‚   โ”œโ”€โ”€ corrected-database-schema.sql # Database setup
โ”‚   โ”œโ”€โ”€ AI-INTEGRATION.md    # AI system documentation
โ”‚   โ””โ”€โ”€ SETUP.md            # Detailed setup guide
โ””โ”€โ”€ README.md               # This file

Key Design Decisions

Frontend Architecture:

  • Optimistic UI Updates: Immediate visual feedback with backend verification
  • Context-based State: React contexts for game state, auth, and player data
  • Component Composition: Modular, reusable components for maintainability
  • TypeScript: Full type safety across the application

Backend Architecture:

  • Service Layer Pattern: Separation of concerns with dedicated service classes
  • Dual AI System: Primary OpenAI integration with JavaScript/TypeScript backup parser
  • Database-First: Supabase as single source of truth for all game data
  • RESTful API: Clear endpoint structure with automatic OpenAPI documentation

๐Ÿ”’ Security Features

  • Row Level Security (RLS) in Supabase
  • JWT authentication
  • Input validation and sanitization
  • Rate limiting on API endpoints

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

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

About

Play, bet, and spin - AI-assisted roulette in your browser.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published