Skip to content

Latest commit

Β 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CodeArena

A Real-Time 1v1 Competitive Programming Duel Platform where developers and competitive programmers compete head-to-head on official Codeforces problems with automated submission verification, live matchmaking, and global rankings.

πŸ”— Live Client: https://code-arena-ochre.vercel.app
πŸ“‘ Live Backend API: https://codearena-backend-z759.onrender.com


1. Project Overview & System Architecture

CodeArena transforms solitary algorithm practice into an interactive, high-stakes competitive duel. Players can create custom rooms and share a 6-character room code, configure problem rating difficulties, and race against the clock. The backend engine continuously polls the official Codeforces REST API to automatically detect accepted verdicts (OK) in real-time.

High-Level Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    React 18 Single Page App                 β”‚
β”‚            (Vite + Custom CSS Design System + Lucide Icons) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚ REST API / WebSockets       β”‚ JSON / Socket Events
                β–Ό                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Node.js & Express Server                  β”‚
β”‚    β”œβ”€β”€ JWT Authentication & bcrypt Password Hashing         β”‚
β”‚    β”œβ”€β”€ Socket.IO Auth Middleware (JWT Handshake)             β”‚
β”‚    β”œβ”€β”€ Real-Time Duel Engine & Room State Machine            β”‚
β”‚    β”œβ”€β”€ Background Codeforces API Poller (every 5s)          β”‚
β”‚    β”œβ”€β”€ Rate-Limited Auth Routes (express-rate-limit)         β”‚
β”‚    └── PostgreSQL Database Layer (Neon Serverless)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚ Polling                     β”‚ SQL Queries
                β–Ό                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Codeforces REST API       β”‚ β”‚    PostgreSQL (Neon)      β”‚
β”‚  (Submissions & Problemset)   β”‚ β”‚      (Users, Matches)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

2. Core Features & Duel Workflow

A. 1v1 Real-Time Duel Arena

  • Custom Duel Settings: Choose problem difficulty ratings (800–3500) and match durations (1–300 mins).
  • Synchronized Match Lifecycle:
    1. Lobby (WAITING): Host creates room and shares 6-character room code; opponent joins.
    2. Live Duel (ACTIVE): Codeforces problem unveiled with synchronized countdown timer.
    3. Automated Verification: The server polls Codeforces every 5 seconds for accepted submissions (verdict: OK).
    4. Resolution (FINISHED): Winner declared instantly upon solve; if timer expires without a solution, the match resolves as a Draw (winner is null).

B. Leaderboard & Stats Engine

  • Rankings Table: Global top 50 rankings featuring Rank, Player, Codeforces Handle, Wins, Losses, Draws, and Matches Played.
  • Profile Dashboard: Track your personal match history and competitive record.

C. Solo Practice Mode

  • Customizable timed solo practice sessions with automatic Codeforces submission verification.

D. Codeforces Handle Verification

  • Real-time handle verification via the Codeforces user.info API during registration and profile updates, with debounced inline feedback (rating, rank, and validity).

3. Database Schema & Data Models

CodeArena utilizes a relational PostgreSQL schema with atomic transactions for match resolution:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                             users                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ id                β”‚ UUID (PK, uuid_generate_v4) β”‚ PRIMARY KEY β”‚
β”‚ username          β”‚ VARCHAR(255)                β”‚ NOT NULL    β”‚
β”‚ email             β”‚ VARCHAR(255)                β”‚ UNIQUE      β”‚
β”‚ password_hash     β”‚ VARCHAR(255)                β”‚ NOT NULL    β”‚
β”‚ cf_handle         β”‚ VARCHAR(255)                β”‚ Codeforces  β”‚
β”‚ wins              β”‚ INT                         β”‚ DEFAULT 0   β”‚
β”‚ losses            β”‚ INT                         β”‚ DEFAULT 0   β”‚
β”‚ draws             β”‚ INT                         β”‚ DEFAULT 0   β”‚
β”‚ created_at        β”‚ TIMESTAMP                   β”‚ CURRENT_TIMEβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β–²
                                β”‚ 1:N (Player1, Player2, Winner)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            matches                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ id                β”‚ UUID (PK, uuid_generate_v4) β”‚ PRIMARY KEY β”‚
β”‚ room_code         β”‚ VARCHAR(6)                  β”‚ UNIQUE      β”‚
β”‚ player1           β”‚ UUID (FK -> users.id)       β”‚ NULLABLE    β”‚
β”‚ player2           β”‚ UUID (FK -> users.id)       β”‚ NULLABLE    β”‚
β”‚ problem_id        β”‚ VARCHAR(255)                β”‚ Problem Ref β”‚
β”‚ winner            β”‚ UUID (FK -> users.id)       β”‚ Winner User β”‚
β”‚ start_time        β”‚ TIMESTAMP                   β”‚ Start Date  β”‚
β”‚ end_time          β”‚ TIMESTAMP                   β”‚ End Date    β”‚
β”‚ status            β”‚ VARCHAR(50)                 β”‚ Duel Status β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

4. API Endpoints Specification

Authentication & Profiles

Method Endpoint Description Auth Required
POST /auth/register Register new user account No
POST /auth/login Authenticate user & return JWT No
GET /auth/me Get authenticated player stats Yes (JWT)
POST /auth/update-cf Link Codeforces handle to account Yes (JWT)

Duel Rooms & Matchmaking

Method Endpoint Description Auth Required
POST /create-room Create new duel room with custom rating/timer Yes (JWT)
POST /join-room Join an existing duel room via 6-character room code Yes (JWT)
GET /room/:id Get room configuration and participants by room code Yes (JWT)
GET /winner Get winner details for a room by room code No
GET /leaderboard Get global rankings (Wins, Losses, Draws) No
GET /problem Fetch random Codeforces problem by rating range No
GET /verify-cf Verify a Codeforces handle exists via CF API No

5. Real-Time Socket.IO Protocol

All Socket.IO connections are authenticated via JWT middleware β€” the client must provide a valid token in the handshake auth object.

Event Name Direction Payload / Description
join-room Client β†’ Server { roomId, userId } β€” Join duel room via room code
room-updated Server β†’ Room { room } β€” Notify room of updated state (player joined)
start-match Client β†’ Server { roomId } β€” Host triggers match start
start-match Server β†’ Room { room } β€” Synchronized match start with problem
problem-selected Server β†’ Room { contestId, index, name, rating } β€” Problem details
submission-found Server β†’ Room { player, cfHandle, problem } β€” Accepted submission detected
match-ended Server β†’ Room { roomId, winner, winnerId } β€” Match finished (win or draw)

6. Technology Stack

  • Frontend:
    • React 18 (Hooks, Functional Components)
    • Vite (Build & Development Server)
    • React Router v6 (Client-side routing)
    • Custom CSS Design System (1,500+ lines β€” dual-theme dark/light mode, design tokens, responsive)
    • Socket.IO Client (Authenticated WebSocket connection)
    • Lucide React (Icons)
  • Backend:
    • Node.js & Express.js (REST API & WebSocket gateway)
    • Socket.IO (JWT-authenticated connections, room isolation, broadcast channels, match timers)
    • PostgreSQL & pg (Relational persistence with transactions)
    • Neon Database (Serverless PostgreSQL with connection pooling)
    • bcryptjs & jsonwebtoken (Password hashing & stateless JWT authentication)
    • express-rate-limit (Rate limiting on authentication endpoints)
    • Codeforces REST API (Problem fetching, live submission verification, handle verification)

7. Getting Started & Local Development

Prerequisites

  • Node.js: v18+ or v20.20.2
  • PostgreSQL Database: Local PostgreSQL or a Neon Serverless PostgreSQL instance
  • Git

1. Environment Configuration

Backend (backend/.env):

PORT=3000
JWT_SECRET=your_jwt_secret_here
DATABASE_URL=postgresql://username:password@localhost:5432/database_name
CLIENT_URL=http://localhost:5173

Frontend (frontend/.env):

VITE_API_URL=http://localhost:3000

2. Database Initialization

Run the initialization script to create required tables, indexes, and extensions:

# Run schema initialization against your database (Neon or local PostgreSQL):
psql "$DATABASE_URL" -f init.sql

3. Installation & Running

Terminal 1 (Backend)

cd backend
npm install
npm run dev      # Starts server on http://localhost:3000

Terminal 2 (Frontend)

cd frontend
npm install
npm run dev      # Starts client on http://localhost:5173

8. License

Distributed under the MIT License. Designed and developed by Sasank Reddy.

About

Real-time 1v1 competitive programming duel platform on Codeforces problems with automated submission verification and live rankings.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages