๐ Live App Deployment: https://code-clash-kohl.vercel.app
โก Backend API Server:https://codeclash-hmgz.onrender.com
CodeClash is a state-of-the-art, real-time competitive programming esports platform designed for high-speed duels on authentic Codeforces problems. Featuring Elo-rated matchmaking, 6-character private challenge rooms, Valorant-style match entrances, an embedded multi-language IDE with local execution, a smart non-destructive algorithm snippet vault, dynamic analytics radar charts, 3D holographic badges, zero-asset Web Audio synthesis, and an advanced client-side TeX math statement parser.
- Technical Stack
- System Design & Architecture Flowcharts
- Algorithmic & Mathematical Models
- Exhaustive Feature Directory
- Statement Slicer & TeX Math Cleaning Engine
- Performance Optimizations & Resilience
- Project Directory Structure
- Installation & Local Setup
- Environment Variables
- Core Framework: React 18, Vite 5, React Router v6
- Styling & Micro-Interactions: Tailwind CSS v4, Vanilla CSS Custom Variables, Framer Motion (3D spring physics, layout animations, cyber curtain route transitions with
AnimatePresence) - Design System & Theme: Cyber Slate Glassmorphism (
#111428) with wall-to-wall workstation setup wallpapers for Light Mode and dark Cyber aesthetics - Global Command Palette:
Ctrl + K/โKglassmorphic search overlay (CommandPalette.jsx) with 3D rotating SVG icons andscrollIntoViewviewport tracking - Code Studio IDE: Custom Monaco-inspired editor (
CyberMonacoEditor.jsx) supporting C++ 17 (g++), Python 3.10, Java 17, and JavaScript (Node 18) with auto-indentation and diff output comparison - Smart Snippet Vault: 1-click non-destructive algorithm snippet insertion (
CPSnippetVault.jsx) featuring Fast I/O, Modular Exponentiation, DSU, and Segment Trees - Dynamic Analytics: Recharts engine rendering live 6-axis Radar skill distribution charts and Win/Loss pie charts
- Audio Synthesizer: Custom Web Audio API synthesizer (
SoundContext.jsx) utilizing low-latency Web Audio API Oscillators, GainNodes, and Chrome async context resolution (Zero external MP3/WAV assets) - Toast Notifications: React Hot Toast
- API Framework: FastAPI (Python 3.10+) running on Uvicorn ASGI high-performance server
- Real-Time WebSockets: FastAPI WebSockets for live race events, opponent state broadcasting, and match countdown clocks
- Database Layer: PostgreSQL via
asyncpgwith connection pool recycling (max_inactive_connection_lifetime=180) for Neon serverless pool health - Security & Authentication: Flexible multi-identifier login (Email or Codeforces Handle) with JWT Tokens (
python-jose) + Password Hashing (passlibbcrypt) - Scraping Engine:
httpx+BeautifulSoup4+ Jina Reader Proxy (r.jina.ai) multi-selector parser for Codeforces statements
-
Code Execution API: Piston API (
https://emkc.org/api/v2/piston/execute) + Client-Side JS Sandbox -
Codeforces Verification Engine: Live Codeforces REST API polling (
user.status) with 60-second clock-drift grace window (after_timestamp - 60) to absorb server time offsets -
Codeforces Resilience Layer: Official REST API + Multi-Proxy Fallback Cluster (
r.jina.ai$\rightarrow$ api.allorigins.win$\rightarrow$ api.codetabs.com)
graph TD
Client["Client Frontend (React 18 + Vite + Tailwind)"]
subgraph FrontendSubsystems["Frontend Subsystems"]
Monaco["Monaco Code Studio IDE"]
Sound["WebAudio Synthesizer"]
CmdPal["Ctrl+K Command Palette"]
Parser["TeX Math & Statement Parser"]
Snippet["Smart Snippet Vault"]
end
Client --> Monaco
Client --> Sound
Client --> CmdPal
Client --> Parser
Client --> Snippet
subgraph BackendPlatform["Core Backend Platform (FastAPI + Uvicorn)"]
REST["REST API Server (Port 8000)"]
WS["WebSocket Connection Manager"]
JudgeEngine["Codeforces Verdict Engine"]
EloCalc["Elo Rating Calculator Engine"]
end
Client -- HTTP Requests --> REST
Client -- Full-Duplex WebSockets --> WS
subgraph DataStorageLayer["Data & Storage Layer"]
DB[("Neon PostgreSQL Database (asyncpg)")]
end
REST --> DB
WS --> DB
JudgeEngine --> REST
subgraph ExternalCompilers["External Systems & Compilers"]
CF_API["Codeforces Official REST API"]
Piston["Piston Compilation API"]
Jina_Proxy["Jina Reader & Proxy Cluster"]
end
JudgeEngine -- 60s Buffer Verdict Check --> CF_API
Monaco -- Code Execution --> Piston
Client -- Scraped Statement Proxy --> Jina_Proxy
Jina_Proxy --> CF_API
sequenceDiagram
autonumber
actor P1 as Player 1 (Creator/Queued)
actor P2 as Player 2 (Joiner/Queued)
participant Queue as Matchmaking / Challenge Engine
participant VS as Esports Entrance Screen
participant Arena as 1v1 Race Room
participant CF as Codeforces API
participant WS as WebSocket Server
alt Ranked Matchmaking Queue
P1->>Queue: Join Queue (Target ELO: 1400)
P2->>Queue: Join Queue (Target ELO: 1400)
Queue-->>Queue: Expanding Band Matchmaker (Purge >300s entries)
else Private Challenge Room
P1->>Queue: Create Room (Generates 6-Char Code "08B760")
P2->>Queue: Enter Code "08B760" to Join
end
Queue->>VS: Match Created Event
VS->>VS: Trigger 3.5s Valorant-Style Entrance + Sound Effect
VS->>Arena: Redirect Both Players to Race Room (/race/:id)
Arena->>WS: Connect WebSocket (/races/ws/:id)
WS-->>Arena: Broadcast Clocks, Opponent Status & Submission Events
Note over P1,P2: Match Starts (40 Minute Limit)
P1->>CF: Submit C++ Solution on Codeforces
P1->>Arena: Click 'โ Check Submission' (or Auto-Check every 10s)
Arena->>CF: Query user.status for P1 (after_timestamp - 60s)
CF-->>Arena: Verdict: OK (Accepted)
Arena->>WS: Broadcast Race Finished (Winner: P1)
WS-->>P1: Victory Screen & Elo Delta (+24)
WS-->>P2: Match Result Screen & Elo Delta (-24)
flowchart TD
A[User Code + Stdin + Expected Output] --> B{Select Language}
B -->|JavaScript| C[Client-Side JS Sandbox Engine]
B -->|C++ / Python / Java| D[Piston API Execution Endpoint]
C --> F[Capture Stdout & Stderr]
D --> F
F --> G{Check Exit Code & Stderr}
G -->|Error Code / Stderr| H[Status: COMPILE / RUNTIME ERROR]
G -->|Exit 0 & Clean Output| I{Expected Output Provided?}
I -->|Yes| J{Compare Trimmed Stdout vs Expected}
J -->|Matches| K[Status: PASSED - MATCHES EXPECTED]
J -->|Mismatch| L[Status: FAILED - OUTPUT MISMATCH]
I -->|No| M[Status: EXECUTED CLEANLY]
CodeClash enforces an idempotent Elo Rating Algorithm for all 1v1 ranked clashes:
Where
In the Analytics Engine, 6-axis skill proficiencies (Implementation, Math, Greedy, DP, Graphs, Strings) are dynamically calculated:
Where:
-
$\text{CF Solved}_T$ : Number of unique problems solved on Codeforces matching topic tag$T$ . -
$\text{Clash Wins}_T$ : Number of 1v1 match victories on problems containing topic tag$T$ .
- Multi-Language Support: C++ 17 (g++), Python 3.10, Java 17, JavaScript (Node.js 18).
- Smart Non-Destructive Snippet Insertion:
โก Fast I/O: Injectsios_base::sync_with_stdio(false); cin.tie(NULL);directly insidemain().๐ DSU,๐ข ModPow,๐ฒ SegTree: Injects helper structs and functions ABOVEint main()without overwriting solution code.
- Smart Auto-Indentation: Indents +4 spaces on opening blocks
{,:,(, auto-closes bracket pairs, and preserves leading indentation.
- Fast Guard Clause: Prevents double-parsing of generated HTML tags.
-
Title-to-Footer Slicing: Purges 100% of website navigation links (
Home,Top,Gym), language flags (๐ฌ๐ง,๐ท๐บ), contest sidebars, and copyright footers. -
TeX Symbol Cleaner:
- Converts
\ldots,\cdots,\dots$\rightarrow$ .... - Strips
\left.,\right.,โคft]bracket noise$\rightarrow$ [-4, 2, 3, -6]. - Formats exponents
10^{4},10^9$\rightarrow$ 10โด,10โน. - Formats subscript series
$a_1, a_2, \dots, a_n$ $\rightarrow$ aโ, aโ, ..., aโ. - Cleans inequalities
\leq/โคq$\rightarrow$ โค,\geq/โฅq$\rightarrow$ โฅ.
- Converts
-
Interactive 1-Click Copy Buttons: Every sample input/output testcase box is wrapped in high-contrast neon yellow header bars (
#ffe600) with working๐ COPYbuttons (data-copy-textevent delegation inmain.jsx).
- Live Submission Stream: 5s poll interval displaying recent submission verdicts for both players in real-time.
-
60s Clock-Drift Buffer:
effective_start = after_timestamp - 60to prevent server clock offsets from missing AC verdicts. -
Idempotent Forfeit & Victory SQL Transactions: Explicit PostgreSQL type-casting (
$2::integer,$3::integer) preventing transaction crashes. -
WebSocket Broadcasts: Instant
RACE_UPDATEandOPPONENT_CHECKINGnotifications.
- 6-Character Room Codes: Generates shareable codes (e.g.
08B760). - Creator vs Opponent Disambiguation: Waits for auth profile loading to ensure room creators always see creator lobby controls.
- Auto-Redirect: Polls room state and automatically launches the race room when the opponent accepts.
- Log in using EITHER Email address OR Codeforces Handle (case-insensitive & whitespace trimmed:
LOWER(TRIM(email)) = $1 OR LOWER(TRIM(cf_handle)) = $1). - Standardized HTTP 401 Unauthorized responses for invalid credentials.
- Recharts 6-axis Radar skill distribution chart and Win/Loss pie chart.
- Interactive 3D tilt physics holographic trophy cards with cursor-following metallic sheen reflections.
- Low-latency Web Audio API synthesizer utilizing sine, triangle, and sawtooth oscillators (
playCyberTap,playAction,playSadness,playVictory,playQueueFound).
- Neon DB Connection Recycling:
max_inactive_connection_lifetime=180inasyncpg.create_poolto recycle idle SSL sockets on Neon PostgreSQL serverless infrastructure. - Double-Parse Guard Clause: Eliminates DOM string corruption by bypassing parsed HTML strings.
- Storage Memory Lockup Prevention: Scraped statement strings are excluded from the timer loop to prevent local storage quota lockups.
- Global Event Delegation: Document-level click listener in
main.jsxcapturing copy button interactions across dynamically injected HTML elements.
CodeClash/
โโโ frontend/
โ โโโ src/
โ โ โโโ api/ # API client (auth, races, challenges, codeforces)
โ โ โโโ components/
โ โ โ โโโ common/ # CommandPalette, CPSnippetVault, AntigravityCyberBackground
โ โ โ โโโ editor/ # CyberMonacoEditor (Multi-lang IDE)
โ โ โ โโโ layout/ # Navbar, PageLayout, Footer
โ โ โโโ context/ # AuthContext, ThemeContext, SoundContext
โ โ โโโ pages/ # Landing, Practice, Race, FindRace, Challenge, JoinChallenge, Badges, Analytics, Settings, LinkCF, Docs
โ โ โโโ utils/ # markdownParser.js (Central statement slicer & TeX math cleaner)
โ โ โโโ App.jsx # Router configuration & AnimatePresence Page Transitions
โ โ โโโ index.css # Design tokens, cyber slate theme, math rendering rules
โ โ โโโ main.jsx # React entry point & global copy event delegation
โ โโโ package.json
โ
โโโ backend/
โ โโโ app/
โ โ โโโ middleware/ # Rate limiting & CORS middleware
โ โ โโโ routers/ # auth, users, codeforces, races, challenges, leaderboard, health
โ โ โโโ services/ # CF API client, match engine, race service, elo service, websocket manager
โ โ โโโ database.py # PostgreSQL asyncpg connection pool & schema initialization
โ โ โโโ dependencies.py # Database pool & JWT auth dependencies
โ โ โโโ main.py # FastAPI entry point, dual router registration & CORS configuration
โ โ โโโ models.py # Pydantic data schemas
โ โโโ requirements.txt
โ
โโโ README.md
- Node.js: v18.0.0 or higher
- Python: v3.10.0 or higher
cd frontend
npm install
npm run devThe frontend application will start at http://localhost:5173.
cd backend
python -m venv venv
# On Windows:
venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000The backend API server will start at http://localhost:8000.
# Local REST API Endpoint
VITE_API_URL=http://localhost:8000
# Local WebSocket Server Endpoint
VITE_WS_URL=ws://localhost:8000VITE_API_URL=https://codeclash-hmgz.onrender.com
VITE_WS_URL=wss://codeclash-hmgz.onrender.com# JWT Signing Key
JWT_SECRET=your_super_secret_jwt_key
# Neon PostgreSQL Database URI
DATABASE_URL=postgresql://user:password@ep-restless-mouse.aws.neon.tech/neondb?sslmode=requireMIT License. Built for competitive programmers who'd rather battle in 1v1 duels than grind alone.