Skip to content

itsmemidhuz123/mcubescomps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

583 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCUBES - Online Speedcubing Competition Platform

A complete full-stack platform for hosting official-style online speedcubing competitions with payment integration, WCA-style timer, and global leaderboards.

🚀 Features Completed

✅ Phase 1 & 2 & 3 - ALL DONE

Authentication System

  • Email/Password + Google OAuth via Firebase
  • Auto WCA-style ID generation (Format: 2026RAHK1)
  • Role-based access (Admin/User)
  • Admin email added

Admin Panel (/admin)

  • Create competitions with multiple events (17 WCA events)
  • FREE or PAID competition types
  • Flexible pricing models:
    • Flat price (entire competition)
    • Per event pricing
    • Base + extra per additional event
  • Currency support (INR/USD)
  • Enter 5 scrambles per event
  • Manage competitions (view/delete)

Competition System

  • Competition detail page with registration
  • Event selection (checkboxes)
  • FREE registration (one-click)
  • Razorpay payment integration
  • Payment verification (server-side)
  • Competition status (UPCOMING/LIVE/ENDED)
  • Registration tracking

WCA Timer (/compete/[competitionId]/[eventId])

  • 15-second inspection countdown
  • Audio beeps at 8s and 5s
  • Auto +2 penalty (15-17 seconds)
  • Auto DNF (>17 seconds)
  • Space bar controls
  • Scramble reveal (locked after reveal)
  • Refresh protection (warns before unload)
  • Auto-save solves to Firestore
  • Auto-move to next scramble
  • Attempt tracking (1/5, 2/5, etc.)

Leaderboard (/leaderboard/[competitionId])

  • Public access (no auth required)
  • Multi-event tabs
  • Ao5 calculation (drop best/worst)
  • DNF handling
  • Sort by average, then best single
  • Medal badges for top 3
  • Display: Rank, Username, WCA ID, Country, All 5 solves, Average, Best

Profile Page (/profile)

  • View and edit profile
  • Display: WCA ID, stats, best singles, best averages
  • Competition history
  • Payment history
  • Event-wise personal records

Competitions Listing (/competitions)

  • Browse all competitions
  • Search functionality
  • Filter by status (All/Live/Upcoming/Ended)
  • Competition stats display

API Routes (/api/...)

  • Payment creation (Razorpay)
  • Payment verification
  • Free registration
  • Submit solve
  • Calculate Ao5 results
  • Registration status

Security

  • Firestore security rules implemented
  • Server-side payment verification
  • Solve immutability
  • Registration permanence
  • Role-based access control

📁 Project Structure

/app/
├── app/
│   ├── admin/page.js                           # Admin Panel
│   ├── competition/[competitionId]/page.js     # Competition Detail + Payment
│   ├── compete/[competitionId]/[eventId]/page.js # Timer Component
│   ├── leaderboard/[competitionId]/page.js     # Leaderboard
│   ├── competitions/page.js                    # All Competitions Listing
│   ├── profile/page.js                         # User Profile
│   ├── auth/
│   │   ├── login/page.js                       # Login
│   │   └── register/page.js                    # Register
│   ├── page.js                                 # Homepage
│   ├── layout.js                               # Root Layout
│   └── api/[[...path]]/route.js                # API Routes
├── contexts/
│   └── AuthContext.js                          # Auth State Management
├── lib/
│   ├── firebase.js                             # Firebase Config
│   ├── wcaEvents.js                            # 17 WCA Events
│   └── wcaId.js                                # WCA ID Generator
├── components/ui/                              # shadcn Components
├── .env.local                                  # Environment Variables
├── firestore.rules                             # Firestore Security Rules
├── PENDING_FEATURES.md                         # Roadmap
└── package.json                                # Dependencies

🔧 Setup Instructions

1. Firebase Setup

Create Firebase Project:

  1. Go to https://console.firebase.google.com
  2. Create a new project
  3. Enable Authentication (Email/Password + Google)
  4. Create Firestore Database (Production mode)

Configure Firebase:

  • All config is already in /app/lib/firebase.js
  • Update .env.local if needed

Deploy Firestore Rules:

cd /app
firebase deploy --only firestore:rules

2. Razorpay Setup

Get API Keys:

  1. Go to https://dashboard.razorpay.com
  2. Navigate to Settings → API Keys
  3. Copy Key ID and Secret

Already Configured:

NEXT_PUBLIC_RAZORPAY_KEY_ID=rzp_live_kyn4dKuIvsesAX
RAZORPAY_KEY_SECRET=28uEFtbhWrRp7RhPiS2uyuvY

3. Admin Setup

First user to register with mail becomes admin automatically.


🎮 User Workflows

Admin Workflow

  1. Login as admin (midhun.speedcuber@gmail.com)
  2. Go to Admin Panel (shield icon in header)
  3. Create Competition:
    • Enter name, description, dates
    • Select FREE or PAID
    • Choose pricing model
    • Select events (e.g., 3x3, 2x2, Pyraminx)
    • Enter 5 scrambles for each event
    • Submit

User Workflow

  1. Register/Login
  2. Browse Competitions (Home or /competitions)
  3. View Competition Detail
  4. Select Events (checkboxes)
  5. Register:
    • FREE: Click "Register (Free)"
    • PAID: Click "Pay & Register" → Razorpay checkout → Complete payment
  6. Start Competition
  7. For each solve:
    • Click "Reveal Scramble"
    • Hold SPACE to start 15s inspection
    • Press SPACE to start solve
    • Press SPACE to stop timer
    • Auto-submits and moves to next
  8. After 5 solves: Auto-redirect to leaderboard

🔐 Security Features

Firestore Rules (/app/firestore.rules):

  • ✅ Only admin can create/edit/delete competitions
  • ✅ Users can only write their own solves
  • ✅ Solve records are immutable
  • ✅ Registration records are permanent
  • ✅ Payment records are read-only (except server)
  • ✅ Leaderboard is publicly readable

API Security:

  • Server-side payment verification (SHA256 HMAC)
  • User ID validation on all operations
  • Competition status checks
  • Registration duplicate prevention

🚀 Deployment

Deploy to Vercel

  1. Push to GitHub:
git init
git add .
git commit -m \"MCUBES Platform Complete\"
git branch -M main
git remote add origin YOUR_REPO_URL
git push -u origin main
  1. Import to Vercel:
  1. Add Environment Variables:
NEXT_PUBLIC_FIREBASE_API_KEY=...
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=...
NEXT_PUBLIC_FIREBASE_PROJECT_ID=...
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=...
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=...
NEXT_PUBLIC_FIREBASE_APP_ID=...
NEXT_PUBLIC_ADMIN_EMAIL=midhun.speedcuber@gmail.com
NEXT_PUBLIC_RAZORPAY_KEY_ID=rzp_live_kyn4dKuIvsesAX
RAZORPAY_KEY_SECRET=28uEFtbhWrRp7RhPiS2uyuvY
  1. Deploy

  2. Deploy Firestore Rules:

firebase deploy --only firestore:rules

📊 Database Collections

Firestore Structure:

users/
  - id, email, role, wcaStyleId, displayName, country, photoURL, createdAt

competitions/
  - id, name, description, startDate, endDate, type, pricingModel
  - flatPrice, basePrice, extraPrice, currency, solveLimit, events
  - scrambles (object: { eventId: [scr1, scr2, scr3, scr4, scr5] })

registrations/
  - id: {userId}_{competitionId}
  - userId, competitionId, events, paymentId, status, registeredAt

solves/
  - id, userId, competitionId, eventId, attemptNumber
  - time, penalty, timestamp

results/
  - id: {userId}_{competitionId}_{eventId}
  - userId, competitionId, eventId, times, average, bestSingle

payments/
  - id, userId, competitionId, paymentId, orderId
  - amount, currency, status, createdAt

🧪 Testing Checklist

Authentication:

  • Register with email/password
  • Login with email/password
  • Login with Google
  • WCA ID generated correctly
  • Admin role assigned to midhun.speedcuber@gmail.com

Admin:

  • Create FREE competition
  • Create PAID competition (flat pricing)
  • Create PAID competition (per event)
  • Create PAID competition (base + extra)
  • Enter scrambles for multiple events
  • View competitions list
  • Delete competition

User Registration:

  • Register for FREE competition
  • Select multiple events
  • Complete Razorpay payment (test mode)
  • Verify registration status

Competition Flow:

  • Start competition
  • Reveal scramble
  • 15-second inspection works
  • Beeps at 8s and 5s
  • +2 penalty applied correctly
  • DNF applied correctly
  • Timer stops correctly
  • Solve auto-submits
  • Moves to next scramble
  • Complete 5 solves

Leaderboard:

  • View leaderboard without login
  • Results sorted correctly
  • Ao5 calculated correctly
  • DNF handled correctly
  • Medal badges show for top 3
  • Switch between events

Profile:

  • View profile stats
  • Edit display name
  • Edit country
  • View competition history
  • View payment history
  • View best singles
  • View best averages

Competitions Listing:

  • View all competitions
  • Filter by status (Live/Upcoming/Ended)
  • Search competitions
  • Click to view detail

📝 API Endpoints

Authentication

  • Firebase Auth handles login/signup

Competitions

  • GET /competitions (via Firestore)
  • POST /api/competitions (admin only)

Registration & Payment

  • POST /api/payment/create-order - Create Razorpay order
  • POST /api/payment/verify - Verify payment signature
  • POST /api/competition/register - Free registration
  • GET /api/competition/registration-status?userId&competitionId

Solving

  • POST /api/competition/submit-solve - Submit solve time
  • POST /api/competition/calculate-results - Calculate Ao5

🎯 All 17 WCA Events Supported

  • 3x3x3 Cube
  • 2x2x2 Cube
  • 4x4x4 Cube
  • 5x5x5 Cube
  • 6x6x6 Cube
  • 7x7x7 Cube
  • 3x3x3 Blindfolded
  • 3x3x3 Fewest Moves
  • 3x3x3 One-Handed
  • Clock
  • Megaminx
  • Pyraminx
  • Skewb
  • Square-1
  • 4x4x4 Blindfolded
  • 5x5x5 Blindfolded
  • 3x3x3 Multi-Blind

🐛 Troubleshooting

Payment Not Working:

  • Check Razorpay keys in .env.local
  • Test with Razorpay test mode first
  • Check browser console for errors

Timer Issues:

  • Ensure audio context is initialized (user interaction required)
  • Check space bar event listeners
  • Verify Firestore connection

Firebase Errors:

  • Verify Firestore rules are deployed
  • Check Firebase console for quota limits
  • Ensure authentication is enabled

📈 Performance

Optimizations:

  • Firestore indexes for fast queries
  • Client-side caching
  • Lazy loading of components
  • Optimized images

🔮 Future Enhancements

  • Email verification
  • Forgot password flow
  • Export leaderboard to CSV
  • Mobile app
  • Real-time leaderboard updates
  • Push notifications
  • Multi-language support
  • Practice mode

📧 Support

For issues:

  1. Check Firestore rules are deployed
  2. Verify environment variables
  3. Check browser console
  4. Review Firebase console

📄 License

MIT License


Built with: Next.js 14, Firebase, Razorpay, Tailwind CSS, shadcn/ui

Platform is 100% COMPLETE and PRODUCTION READY! 🎉

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages