Skip to content

setif-developers-group/rubik_cube_leaderboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Rubik's Cube Competition System - Complete Documentation

๐ŸŽฏ Overview

This project is a complete Rubik's Cube competition system with the following features:

โœ… Main Features

  • Secure QR code generation for administrators
  • Automatic time validation via QR code
  • Real-time leaderboard with positions
  • Admin session management with automatic expiration
  • Admin authentication system by email
  • Modern user interface with React and Tailwind CSS

๐Ÿ›ก๏ธ Security

  • Strict admin email validation (whitelist)
  • QR codes with expiration (24h)
  • Traceable sessions with unique IDs
  • CORS protection configured
  • Secure environment variables

๐Ÿ—๏ธ Architecture

Frontend (React + Vite)

  • Modern and responsive user interface
  • Integrated QR code scanner
  • Precise timer management
  • Real-time leaderboard
  • Automatic proxy to backend

Backend (Node.js + Express)

  • Complete REST API
  • PostgreSQL database
  • Automatic email sending
  • QR code generation
  • Secure validation

๐Ÿ”ฅ Detailed Features

๐Ÿ‘‘ Admin System

  • Unique QR code generation per email
  • Automatic email sending with attachment
  • Active session management
  • Competition data cleanup
  • Authorized email whitelist

โฑ๏ธ Timing System

  • Precise timers for different cube categories
  • Automatic participant ID generation
  • Admin QR code validation
  • Automatic time saving

๐Ÿ† Leaderboard

  • Times sorted in ascending order
  • Automatic positions
  • Filtering by session or admin
  • Complete performance history

๐Ÿ“ง Email System

  • Gmail configuration with App Passwords
  • Automatic QR code sending
  • Custom HTML templates
  • Complete error handling

๐Ÿš€ Installation

Prerequisites

  • Node.js (v16+ recommended)
  • PostgreSQL (v13+ recommended)
  • Gmail account for sending emails

Backend

cd backend
npm install

Frontend

cd frontend
npm install

๐ŸŽฎ Usage

Starting the Servers

Terminal 1 - Backend:

cd backend
npm start

โœ… Backend running on http://localhost:5000

Terminal 2 - Frontend:

cd frontend
npm run dev

โœ… Frontend running on http://localhost:5173

Competition Workflow

For Administrators:

  1. Access the admin panel via the "ADMIN PANEL" button
  2. Enter your authorized email
  3. Receive the QR code by email automatically
  4. Scan the QR code when validating times

For Participants:

  1. Select the cube type
  2. Generate a participant ID
  3. Complete the solve with the timer
  4. Wait for admin validation via QR code

๐Ÿ” Security

Admin Authentication

  • Email whitelist in ADMIN_EMAILS
  • Automatic validation before QR code generation
  • Protection against unauthorized access

QR Code Security

  • Automatic expiration after 24 hours
  • Unique session IDs for traceability
  • Encrypted data in the QR code

Best Practices

  • Environment variables for passwords
  • CORS configured to prevent attacks
  • Server-side data validation

๐ŸŒ API Endpoints

๐Ÿ“Š Admin Endpoints

Method Endpoint Description
POST /api/admin/generate-qr Generate and send a QR code
POST /api/admin/validate-qr Validate a time with QR code
GET /api/admin/leaderboard Retrieve the leaderboard
POST /api/admin/clear-records Clear the data
GET /api/admin/sessions/:adminEmail Active sessions of an admin
GET /api/admin/admin-emails List of authorized admin emails

๐Ÿ” Auth Endpoints

Method Endpoint Description
POST /api/auth/register User registration
POST /api/auth/login User login

๐Ÿ“ File Structure

rubiks-cube-competition/
โ”œโ”€โ”€ ๐Ÿ“ backend/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ .env                    # Environment variables
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ .gitignore             # Files to ignore
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ server.js              # Main server
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ controllers/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ adminController.js    # Admin logic
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ authController.js     # Authentication
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ models/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ QRSession.js         # QR session model
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Leaderboard.js       # Leaderboard model
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ User.js              # User model
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ routes/
โ”‚   โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ admin.js             # Admin routes
โ”‚   โ”‚       โ””โ”€โ”€ ๐Ÿ“„ auth.js              # Auth routes
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ package.json
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ frontend/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ index.html
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ package.json
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ vite.config.js         # Configuration with proxy
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ QRScanner.jsx         # QR scanner
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Timer.jsx             # Timer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Leaderboard.jsx       # Leaderboard
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ Admin.jsx             # Admin panel
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ config/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ api.js                # API configuration
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ pages/
โ”‚   โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ Index.jsx             # Main page
โ”‚   โ”‚       โ””โ”€โ”€ ๐Ÿ“„ Admin.jsx             # Admin page
โ”‚   โ””โ”€โ”€ ๐Ÿ“ public/
โ”‚
โ””โ”€โ”€ ๐Ÿ“„ README.md                  # This documentation

2. QR scanner not working

  • Allow camera access in the browser
  • Use HTTPS in production
  • Check lighting for scanning

3. API connection error

# Check if backend is running
curl http://localhost:5000/api/test

# Check proxy configuration
cat frontend/vite.config.js

4. Database

# Check PostgreSQL connection
cd backend && node -e "console.log('DB test')"

๐Ÿ” Useful Logs

# Backend logs
cd backend && npm start

# With more details
DEBUG=* npm start

๐Ÿ’ป Development

Available Scripts

Backend:

npm start      # Start the server
npm run dev    # Development with nodemon
npm test       # Tests

Frontend:

npm run dev    # Start development
npm run build  # Build production
npm run preview # Preview production

๐ŸŽ‰OverAll

This system provides a complete and secure solution for organizing Rubik's Cube competitions with:

โœ… Automatic QR code generation โœ… Secure time validation โœ… Real-time leaderboard โœ… Modern user interface โœ… Enhanced security โœ… Simple configuration

The system is production-ready and can be deployed immediately! ๐Ÿš€

About

rubik cube leaderboard for open day event

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors