Skip to content

Latest commit

ย 

History

History
820 lines (655 loc) ยท 23.3 KB

File metadata and controls

820 lines (655 loc) ยท 23.3 KB

๐ŸŽฎ QPlay-Core: Quantum Physics Learning Game

A modern, interactive quantum physics education platform built with React, TypeScript, and Netlify Functions


๐Ÿ“‹ Table of Contents

  1. Project Overview
  2. Architecture
  3. Quick Start
  4. Project Structure
  5. Authentication Setup
  6. Development Workflow
  7. Technical Details
  8. Troubleshooting
  9. Deployment

๐ŸŽฏ Project Overview

What is QPlay-Core?

An immersive quantum physics learning game that makes complex quantum mechanics concepts accessible through interactive 3D visualizations, gamified challenges, and real-time simulations.

Key Features

  • ๐ŸŽฎ Interactive Quantum Rooms: Superposition Tower, Entanglement Bridge, Tunneling Vault
  • ๐Ÿ”ฌ Real Physics Simulations: Accurate quantum mechanics calculations
  • ๐Ÿ† Gamification: Achievements, leaderboards, progress tracking
  • ๐Ÿ” Modern Authentication: Supabase + Google OAuth integration
  • ๐Ÿ“ฑ Responsive Design: Works on desktop, tablet, and mobile
  • ๐Ÿš€ Serverless Backend: Netlify Functions for scalability

Technology Stack

  • Frontend: React 18.3.1, TypeScript, Three.js, Vite
  • Backend: Netlify Functions (serverless)
  • Database: Supabase (PostgreSQL)
  • Authentication: Supabase Auth + Google OAuth
  • Deployment: Netlify Edge Functions
  • Styling: Tailwind CSS

๐Ÿ—๏ธ Architecture

Monorepo Structure

QPlay-Core/
โ”œโ”€โ”€ ๐ŸŽจ apps/web/              # Frontend React Application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/       # React UI components
โ”‚   โ”‚   โ”œโ”€โ”€ contexts/         # React Context providers
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/           # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ services/        # API communication
โ”‚   โ”‚   โ”œโ”€โ”€ types/           # TypeScript definitions
โ”‚   โ”‚   โ””โ”€โ”€ utils/           # Helper functions
โ”‚   โ”œโ”€โ”€ public/              # Static assets
โ”‚   โ”œโ”€โ”€ dist/                # Build output (gitignored)
โ”‚   โ””โ”€โ”€ package.json         # Frontend dependencies (300MB+ node_modules)
โ”‚
โ”œโ”€โ”€ โšก netlify/functions/     # Serverless Backend
โ”‚   โ”œโ”€โ”€ auth-google.js       # Google OAuth handler
โ”‚   โ”œโ”€โ”€ auth-login.js        # User authentication
โ”‚   โ”œโ”€โ”€ auth-signup.js       # User registration
โ”‚   โ”œโ”€โ”€ achievements.js      # Achievement system
โ”‚   โ”œโ”€โ”€ game-session.js      # Game state management
โ”‚   โ”œโ”€โ”€ leaderboard.js       # Score tracking
โ”‚   โ”œโ”€โ”€ quantum-measurements.js # Physics calculations
โ”‚   โ””โ”€โ”€ package.json         # Backend dependencies (10MB node_modules)
โ”‚
โ”œโ”€โ”€ ๐Ÿ”ง Configuration Files
โ”‚   โ”œโ”€โ”€ .env                 # Environment variables
โ”‚   โ”œโ”€โ”€ netlify.toml         # Netlify deployment config
โ”‚   โ”œโ”€โ”€ package.json         # Root project scripts
โ”‚   โ”œโ”€โ”€ vite.config.ts       # Vite build configuration
โ”‚   โ””โ”€โ”€ tailwind.config.js   # Styling configuration

Data Flow Architecture

User Browser (localhost:8888)
         โ†•๏ธ
    React Frontend
         โ†•๏ธ
   Netlify Functions (serverless)
         โ†•๏ธ
    Supabase Database
         โ†•๏ธ
    Google OAuth API

Why Monorepo + Two node_modules?

This is modern best practice for full-stack applications:

  1. Frontend (apps/web/node_modules/) - 300MB+

    • React ecosystem, Three.js, TypeScript, Vite
    • Rich UI libraries and development tools
    • Complete build system dependencies
  2. Backend (netlify/functions/node_modules/) - 10MB

    • Minimal serverless runtime dependencies
    • Only Google OAuth library needed
    • Optimized for cold starts

Benefits:

  • โœ… Performance: Faster cold starts for serverless functions
  • โœ… Maintainability: Clear separation of concerns
  • โœ… Scalability: Independent deployment and scaling
  • โœ… Development: Isolated dependency management

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Git

Installation & Setup

# Clone the repository
git clone https://github.com/Project-Qplay/QPlay-Core.git
cd QPlay-Core

# Install all dependencies
npm run install:all

# Start development server
npm run dev

Access Your Application

Open your browser and navigate to: http://localhost:8888

Available Scripts

{
  "dev": "netlify dev",                    # Start development server
  "preview": "cd apps/web && npm run preview",  # Preview production build
  "install:all": "cd apps/web && npm install && cd ../../netlify/functions && npm install"
}

๐Ÿ“ Detailed Project Structure

Frontend Components (apps/web/src/components/)

components/
โ”œโ”€โ”€ 3d/                      # Three.js 3D components
โ”‚   โ”œโ”€โ”€ CatModel.tsx         # Schrรถdinger's cat visualization
โ”‚   โ”œโ”€โ”€ LoadingScreen.tsx    # 3D loading animations
โ”‚   โ”œโ”€โ”€ QuantumScene.tsx     # Main 3D quantum world
โ”‚   โ”œโ”€โ”€ QuantumTerminalLoader.tsx
โ”‚   โ””โ”€โ”€ Spaceship.tsx        # 3D spaceship model
โ”‚
โ”œโ”€โ”€ rooms/                   # Quantum physics rooms
โ”‚   โ”œโ”€โ”€ EntanglementBridge.tsx    # Quantum entanglement concepts
โ”‚   โ”œโ”€โ”€ ProbabilityBay.tsx        # Probability distributions
โ”‚   โ”œโ”€โ”€ QuantumArchive.tsx        # Historical quantum experiments
โ”‚   โ”œโ”€โ”€ StateChamber.tsx          # Quantum state manipulation
โ”‚   โ”œโ”€โ”€ SuperpositionTower.tsx    # Superposition principles
โ”‚   โ””โ”€โ”€ TunnelingVault.tsx        # Quantum tunneling effects
โ”‚
โ”œโ”€โ”€ auth/                    # Authentication components
โ”‚   โ””โ”€โ”€ AuthModal.tsx        # Login/signup modal
โ”‚
โ”œโ”€โ”€ achievements/            # Gamification
โ”‚   โ””โ”€โ”€ Achievements.tsx     # Achievement system UI
โ”‚
โ”œโ”€โ”€ ui/                      # Reusable UI components
โ”‚   โ”œโ”€โ”€ Button.tsx           # Custom button component
โ”‚   โ”œโ”€โ”€ PortalTransition.tsx # Portal animation effects
โ”‚   โ””โ”€โ”€ ThemeProvider.tsx    # Theme management
โ”‚
โ””โ”€โ”€ Core Components
    โ”œโ”€โ”€ GameController.tsx   # Main game logic controller
    โ”œโ”€โ”€ MainMenu.tsx         # Main navigation menu
    โ”œโ”€โ”€ QuantumGuide.tsx     # Interactive tutorials
    โ”œโ”€โ”€ Settings.tsx         # Application settings
    โ””โ”€โ”€ Leaderboard.tsx      # Score display

Context Providers (apps/web/src/contexts/)

contexts/
โ”œโ”€โ”€ AuthContext.tsx          # User authentication state
โ”œโ”€โ”€ GameContext.tsx          # Game state management
โ”œโ”€โ”€ LoadingContext.tsx       # Loading state management
โ””โ”€โ”€ SettingsContext.tsx      # User preferences

Backend Functions (netlify/functions/)

functions/
โ”œโ”€โ”€ auth-google.js           # Google OAuth flow handler
โ”œโ”€โ”€ auth-login.js            # User login validation
โ”œโ”€โ”€ auth-signup.js           # User registration processing
โ”œโ”€โ”€ achievements.js          # Achievement CRUD operations
โ”œโ”€โ”€ game-session.js          # Game state persistence
โ”œโ”€โ”€ leaderboard.js           # Score tracking and rankings
โ””โ”€โ”€ quantum-measurements.js  # Physics calculations and simulations

๐Ÿ” Authentication Setup

Environment Variables (.env)

# Supabase Configuration
SUPABASE_URL=https://ylahofxrvdhqkjmsolin.supabase.co
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_KEY=your_supabase_service_key

# Google OAuth Configuration  
GOOGLE_CLIENT_ID=your_google_client_id

# Vite Frontend Variables
VITE_SUPABASE_URL=https://ylahofxrvdhqkjmsolin.supabase.co
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
VITE_GOOGLE_CLIENT_ID=your_google_client_id

# Node Configuration
NODE_VERSION=18

Google Cloud Console Setup

  1. Go to Google Cloud Console
  2. Navigate to APIs & Credentials โ†’ OAuth 2.0 Client IDs
  3. Edit your OAuth client and add:

Authorized JavaScript Origins:

http://localhost:8888
https://your-production-domain.netlify.app

Authorized Redirect URIs:

http://localhost:8888/auth/callback
http://localhost:8888/auth/google/callback
https://your-production-domain.netlify.app/auth/callback

Supabase Dashboard Setup

  1. Go to Supabase Dashboard
  2. Navigate to Authentication โ†’ URL Configuration
  3. Configure:

Site URL: http://localhost:8888 (development) / https://your-domain.netlify.app (production)

Redirect URLs: http://localhost:8888/** (development) / https://your-domain.netlify.app/** (production)


๐Ÿ’ป Development Workflow

Starting Development

# Navigate to project root
Set-Location "c:\Users\Naren\Downloads\Q-RESEARCH\QPlay-Core"

# Start development server
npm run dev

What happens:

  1. Environment Loading: All .env variables injected
  2. Static Server: Frontend served from apps/web/dist on port 3999
  3. Main Server: Netlify dev server on port 8888
  4. Functions Loading: All 7 serverless functions become available
  5. Hot Reload: Changes automatically trigger rebuilds

Development Server Output

โ—ˆ Netlify Dev โ—ˆ
โ—ˆ Injected .env file env var: SUPABASE_URL
โ—ˆ Injected .env file env var: GOOGLE_CLIENT_ID
โ—ˆ Running static server from "apps/web/dist"
โ—ˆ Static server listening to 3999

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   โ—ˆ Server now ready on http://localhost:8888   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ—ˆ Loaded function auth-google
โ—ˆ Loaded function auth-login
โ—ˆ Loaded function achievements
โ—ˆ Loaded function game-session
โ—ˆ Loaded function leaderboard
โ—ˆ Loaded function quantum-measurements

Port Architecture

  • Port 8888: Main development server (your access point)
  • Port 3999: Internal static file server (background)

Making Changes

  • Frontend changes: Edit files in apps/web/src/ โ†’ Hot reload automatically
  • Backend changes: Edit files in netlify/functions/ โ†’ Restart npm run dev
  • Environment changes: Update .env โ†’ Restart npm run dev

๐Ÿ”ง Technical Details

Build Configuration

Vite Config (vite.config.ts)

export default defineConfig({
  plugins: [react()],
  build: {
    outDir: 'dist',
    sourcemap: true,
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ['react', 'react-dom'],
          three: ['three', '@react-three/fiber']
        }
      }
    }
  },
  server: {
    port: 3000,
    host: true
  }
})

Netlify Config (netlify.toml)

[build]
  command = "cd apps/web && npm run build"
  functions = "netlify/functions"
  publish = "apps/web/dist"

[build.environment]
  NODE_VERSION = "18"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

TypeScript Configuration

  • Strict mode enabled: Maximum type safety
  • Path aliases: Clean import statements
  • Vite environment types: Full development environment support

Dependencies Overview

Frontend Key Dependencies:

{
  "@react-three/fiber": "^8.15.11",    // Three.js React integration
  "@supabase/supabase-js": "^2.38.5",  // Supabase client
  "react": "^18.3.1",                  // Core React
  "react-router-dom": "^6.20.1",       // Client-side routing
  "three": "^0.158.0",                 // 3D graphics library
  "tailwindcss": "^3.3.6"             // Utility-first CSS
}

Backend Key Dependencies:

{
  "google-auth-library": "^9.4.1"      // Google OAuth verification
}

๐Ÿ› Troubleshooting

Common Issues & Solutions

Server Won't Start

# Check if you're in the correct directory
Get-Location  # Should be: C:\Users\Naren\Downloads\Q-RESEARCH\QPlay-Core

# Navigate to correct directory
Set-Location "c:\Users\Naren\Downloads\Q-RESEARCH\QPlay-Core"

# Try starting again
npm run dev

Environment Variables Not Loading

  1. Verify .env file exists in project root
  2. Check variable names match exactly (case-sensitive)
  3. Restart development server after changes
  4. Ensure no quotes around values unless needed

Google Authentication Fails

  1. Verify localhost:8888 is added to Google Console
  2. Check GOOGLE_CLIENT_ID matches exactly
  3. Ensure Supabase configuration includes correct redirect URLs
  4. Clear browser cache and cookies

Functions Not Loading

# Reinstall function dependencies
cd netlify/functions
npm install
cd ../..
npm run dev

TypeScript Errors

# Check TypeScript configuration
cd apps/web
npx tsc --noEmit

# Fix import issues
# Update vite-env.d.ts if needed

Debug Commands

# Check package.json syntax
Get-Content package.json | ConvertFrom-Json

# Verify environment variables
Get-Content .env

# Check function dependencies
Get-Content netlify/functions/package.json | ConvertFrom-Json

# Test individual function
curl http://localhost:8888/.netlify/functions/auth-login

๐Ÿš€ Deployment

Netlify Production Deployment

Automatic Deployment (Recommended)

  1. Connect Repository: Link GitHub repo to Netlify
  2. Build Settings:
    • Build command: cd apps/web && npm run build
    • Publish directory: apps/web/dist
    • Functions directory: netlify/functions
  3. Environment Variables: Add all .env variables to Netlify dashboard
  4. Deploy: Automatic deployment on git push

Manual Deployment

# Install Netlify CLI globally
npm install -g netlify-cli

# Build for production
cd apps/web
npm run build
cd ..

# Deploy to Netlify
netlify deploy --prod --dir=apps/web/dist --functions=netlify/functions

Environment Configuration for Production

Update your production environment variables:

  • Site URL: Your production domain
  • Google OAuth: Add production redirect URIs
  • Supabase: Update allowed origins

Performance Optimizations

  • โœ… Code Splitting: Automatic with Vite
  • โœ… Asset Optimization: Images, CSS, JS minification
  • โœ… CDN: Netlify global CDN
  • โœ… Edge Functions: Low-latency serverless execution

๐Ÿ“Š Project Metrics

Codebase Stats

  • Frontend: ~50+ React components
  • Backend: 7 serverless functions
  • Dependencies: 300MB+ frontend, 10MB backend
  • Build Time: ~30-60 seconds
  • Bundle Size: ~2-3MB (optimized)

Performance Targets

  • First Load: < 3 seconds
  • Cold Start: < 500ms (functions)
  • Interactive: < 1 second
  • Lighthouse Score: 90+ (all metrics)

๐ŸŽฏ Next Steps & Roadmap

Immediate Development Priorities

  1. Complete Authentication Flow: Implement full user registration/login
  2. Game Logic: Build core quantum physics simulations
  3. 3D Interactions: Enhance Three.js quantum visualizations
  4. Achievement System: Complete gamification features
  5. Mobile Optimization: Responsive design improvements

Future Enhancements

  • Multiplayer Support: Real-time collaborative learning
  • Advanced Physics: More complex quantum simulations
  • AI Tutor: Intelligent learning assistance
  • Content Management: Admin panel for educators
  • Analytics: Learning progress tracking

๐Ÿ“š Additional Resources

Documentation

Quantum Physics Resources


๐Ÿ“ Contributing

Development Guidelines

  1. Code Style: Follow existing TypeScript/React patterns
  2. Testing: Add tests for new features
  3. Documentation: Update this README for significant changes
  4. Commits: Use conventional commit messages
  5. Pull Requests: Include detailed descriptions

Getting Help

  • Issues: GitHub Issues for bug reports
  • Discussions: GitHub Discussions for questions
  • Email: Contact the QPlay team

๐ŸŽ‰ Happy coding with quantum physics! ๐Ÿš€โš›๏ธ๐ŸŽฎ


Last updated: November 23, 2025 Version: 1.0.0 Maintained by: QPlay Team

Port Architecture

  • Port 8888: Main development server (your access point)
  • Port 3999: Internal static file server (background)

Making Changes

  • Frontend changes: Edit files in apps/web/src/ โ†’ Hot reload automatically
  • Backend changes: Edit files in netlify/functions/ โ†’ Restart npm run dev
  • Environment changes: Update .env โ†’ Restart npm run dev

๐Ÿ”ง Technical Details

Build Configuration

Vite Config (vite.config.ts)

export default defineConfig({
  plugins: [react()],
  build: {
    outDir: 'dist',
    sourcemap: true,
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ['react', 'react-dom'],
          three: ['three', '@react-three/fiber']
        }
      }
    }
  },
  server: {
    port: 3000,
    host: true
  }
})

Netlify Config (netlify.toml)

[build]
  command = "cd apps/web && npm run build"
  functions = "netlify/functions"
  publish = "apps/web/dist"

[build.environment]
  NODE_VERSION = "18"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

TypeScript Configuration

  • Strict mode enabled: Maximum type safety
  • Path aliases: Clean import statements
  • Vite environment types: Full development environment support

Dependencies Overview

Frontend Key Dependencies:

{
  "@react-three/fiber": "^8.15.11",    // Three.js React integration
  "@supabase/supabase-js": "^2.38.5",  // Supabase client
  "react": "^18.3.1",                  // Core React
  "react-router-dom": "^6.20.1",       // Client-side routing
  "three": "^0.158.0",                 // 3D graphics library
  "tailwindcss": "^3.3.6"             // Utility-first CSS
}

Backend Key Dependencies:

{
  "google-auth-library": "^9.4.1"      // Google OAuth verification
}

๐Ÿ› Troubleshooting

Common Issues & Solutions

Server Won't Start

# Check if you're in the correct directory
Get-Location  # Should be: C:\Users\Naren\Downloads\Q-RESEARCH\QPlay-Core

# Navigate to correct directory
Set-Location "c:\Users\Naren\Downloads\Q-RESEARCH\QPlay-Core"

# Try starting again
npm run dev

Environment Variables Not Loading

  1. Verify .env file exists in project root
  2. Check variable names match exactly (case-sensitive)
  3. Restart development server after changes
  4. Ensure no quotes around values unless needed

Google Authentication Fails

  1. Verify localhost:8888 is added to Google Console
  2. Check GOOGLE_CLIENT_ID matches exactly
  3. Ensure Supabase configuration includes correct redirect URLs
  4. Clear browser cache and cookies

Functions Not Loading

# Reinstall function dependencies
cd netlify/functions
npm install
cd ../..
npm run dev

TypeScript Errors

# Check TypeScript configuration
cd apps/web
npx tsc --noEmit

# Fix import issues
# Update vite-env.d.ts if needed

Debug Commands

# Check package.json syntax
Get-Content package.json | ConvertFrom-Json

# Verify environment variables
Get-Content .env

# Check function dependencies
Get-Content netlify/functions/package.json | ConvertFrom-Json

# Test individual function
curl http://localhost:8888/.netlify/functions/auth-login

๐Ÿš€ Deployment

Netlify Production Deployment

Automatic Deployment (Recommended)

  1. Connect Repository: Link GitHub repo to Netlify
  2. Build Settings:
    • Build command: cd apps/web && npm run build
    • Publish directory: apps/web/dist
    • Functions directory: netlify/functions
  3. Environment Variables: Add all .env variables to Netlify dashboard
  4. Deploy: Automatic deployment on git push

Manual Deployment

# Install Netlify CLI globally
npm install -g netlify-cli

# Build for production
cd apps/web
npm run build
cd ..

# Deploy to Netlify
netlify deploy --prod --dir=apps/web/dist --functions=netlify/functions

Environment Configuration for Production

Update your production environment variables:

  • Site URL: Your production domain
  • Google OAuth: Add production redirect URIs
  • Supabase: Update allowed origins

Performance Optimizations

  • โœ… Code Splitting: Automatic with Vite
  • โœ… Asset Optimization: Images, CSS, JS minification
  • โœ… CDN: Netlify global CDN
  • โœ… Edge Functions: Low-latency serverless execution

๐Ÿ“Š Project Metrics

Codebase Stats

  • Frontend: ~50+ React components
  • Backend: 7 serverless functions
  • Dependencies: 300MB+ frontend, 10MB backend
  • Build Time: ~30-60 seconds
  • Bundle Size: ~2-3MB (optimized)

Performance Targets

  • First Load: < 3 seconds
  • Cold Start: < 500ms (functions)
  • Interactive: < 1 second
  • Lighthouse Score: 90+ (all metrics)

๐ŸŽฏ Next Steps & Roadmap

Immediate Development Priorities

  1. Complete Authentication Flow: Implement full user registration/login
  2. Game Logic: Build core quantum physics simulations
  3. 3D Interactions: Enhance Three.js quantum visualizations
  4. Achievement System: Complete gamification features
  5. Mobile Optimization: Responsive design improvements

Future Enhancements

  • Multiplayer Support: Real-time collaborative learning
  • Advanced Physics: More complex quantum simulations
  • AI Tutor: Intelligent learning assistance
  • Content Management: Admin panel for educators
  • Analytics: Learning progress tracking

๐Ÿ“š Additional Resources

Documentation

Quantum Physics Resources


๐Ÿ“ Contributing

Development Guidelines

  1. Code Style: Follow existing TypeScript/React patterns
  2. Testing: Add tests for new features
  3. Documentation: Update this README for significant changes
  4. Commits: Use conventional commit messages
  5. Pull Requests: Include detailed descriptions

Getting Help

  • Issues: GitHub Issues for bug reports
  • Discussions: GitHub Discussions for questions
  • Email: Contact the QPlay team

๐ŸŽ‰ Happy coding with quantum physics! ๐Ÿš€โš›๏ธ๐ŸŽฎ


Last updated: November 23, 2025 Version: 1.0.0 Maintained by: QPlay Team