CodeClash is a real-time 1v1 competitive coding platform where two players race to solve the same DSA problem within a shared countdown timer. Think LeetCode — but multiplayer, live, and competitive.
- 🔴 Live synchronization — both players see the same timer, ticking down in real time
- ⚡ Instant verdicts — code is evaluated against hidden test cases via a sandboxed execution engine
- 🏆 Ranked outcomes — the first correct submission wins; results and stats are persisted
| Feature | Description |
|---|---|
| 🔐 Google OAuth | One-click sign-in via Firebase Authentication |
| 🏠 Lobby System | Create or join a battle room with a unique room ID |
| 🧑💻 In-browser IDE | CodeMirror-powered editor with syntax highlighting |
| 🌐 Multi-language | Supports Python, JavaScript, Java, C++ |
| ⏱️ Synced Timer | Shared countdown timer synced in real time for both players |
| 🤖 Verdict Engine | Evaluates against hidden test cases via Judge0 API |
| 📊 Leaderboard | Global rankings persisted in MongoDB |
| 👤 Profile Page | Match history, win/loss record, and stats per player |
| 🛡️ Rate Limiting | Helmet + express-rate-limit for API security |
┌─────────────────────────────────────────────────────────┐
│ Frontend (React) │
│ Vite · React Router · Zustand · shadcn/ui │
└───────────────────┬─────────────────────────────────────┘
│
┌───────────┴───────────┐
│ │
▼ ▼
┌──────────────┐ ┌──────────────────────┐
│ Firebase │ │ Express REST API │
│ Realtime DB │ │ (Node.js + MongoDB) │
│ (live sync) │ │ (match history, │
│ Firebase │ │ leaderboard, │
│ Auth │ │ user profiles) │
└──────────────┘ └──────────┬───────────┘
│
┌────────▼────────┐
│ Judge0 API │
│ (sandboxed code │
│ execution) │
└─────────────────┘
Two separate real-time concerns, cleanly split:
- Firebase Realtime Database → live battle state (timer sync, submission events, opponent status)
- MongoDB via Express → persistent data (match results, leaderboard, user stats)
Frontend
- React 19 + Vite
- React Router v7
- Zustand — global state management
- TanStack Query — server state & caching
- CodeMirror 6 — in-browser code editor
- shadcn/ui + Tailwind CSS v4
- Firebase SDK — Auth + Realtime Database
Backend
- Node.js + Express.js
- MongoDB + Mongoose
- Firebase Admin SDK — JWT verification
- Helmet + express-rate-limit — security
Infrastructure
- Firebase Realtime Database — live sync
- Judge0 API — sandboxed code execution
- Vercel — frontend deployment
- Firebase Auth — Google OAuth
code-clash/
├── src/ # React frontend
│ ├── pages/
│ │ ├── Home.jsx # Landing + room creation
│ │ ├── Auth.jsx # Google OAuth login
│ │ ├── Lobby.jsx # Pre-battle waiting room
│ │ ├── Battle.jsx # Live coding arena
│ │ ├── Results.jsx # Post-match results
│ │ ├── LeaderBoard.jsx # Global rankings
│ │ └── Profile.jsx # User stats & history
│ ├── components/ # Shared UI components
│ ├── firebase/ # Firebase config & helpers
│ ├── store/ # Zustand global state
│ ├── api/ # Axios API client
│ └── hooks/ # Custom React hooks
│
└── server/ # Express backend
└── src/
├── routes/
│ ├── user.js # User upsert & profile
│ ├── matches.js # Match CRUD + verdict
│ ├── leaderboard.js # Rankings endpoint
│ └── determineWinner.js
├── models/
│ ├── User.js # Mongoose user schema
│ └── Match.js # Mongoose match schema
├── middleware/
│ └── error.middleware.js
└── config/
└── db.js # MongoDB connection
- Node.js 18+
- A Firebase project with Realtime Database + Auth enabled
- A Judge0 API key (via RapidAPI)
- MongoDB connection string (local or MongoDB Atlas)
git clone https://github.com/vedantdadhich21/code-clash.git
cd code-clashnpm installCreate a .env file in the root:
VITE_FIREBASE_API_KEY=your_key
VITE_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
VITE_FIREBASE_DATABASE_URL=https://your_project-default-rtdb.firebaseio.com
VITE_FIREBASE_PROJECT_ID=your_project_id
VITE_FIREBASE_APP_ID=your_app_id
VITE_JUDGE0_API_KEY=your_judge0_key
VITE_API_BASE_URL=http://localhost:3000cd server
npm installCreate a .env file inside server/:
PORT=3000
MONGO_URI=mongodb://localhost:27017/codeclash
CLIENT_URL=http://localhost:5173Place your Firebase service account key at server/serviceAccountKey.json.
# Terminal 1 — frontend
npm run dev
# Terminal 2 — backend
cd server && npm run dev1. Player A creates a room → unique roomId generated (nanoid)
2. Player B joins with the roomId
3. Both land in the Lobby → ready-up screen
4. Battle starts → shared timer begins via Firebase Realtime DB
5. Both players code in their in-browser IDE (CodeMirror)
6. On submit → code sent to Judge0 API → evaluated against hidden test cases
7. First correct submission wins → Firebase notifies both clients instantly
8. Results page → winner determined, match saved to MongoDB
9. Leaderboard updated
- All backend routes protected via Firebase ID token verification (JWT)
- API endpoints rate-limited (
20 req / 15 minon auth routes) - HTTP headers hardened with Helmet
- Request body size capped at
10kb - CORS restricted to whitelisted origins only
MIT © Vedant Dadhich
Built with ☕ and competitive frustration.
