The Ultimate Gamified Codeforces Companion
Collaborate. Compete. Conquer.
Transform your competitive programming journey with real-time battles, deep analytics, AI-powered hints, and a gamified ecosystem β all in one platform.
- About the Project
- Key Features
- Screenshots
- System Architecture
- Tech Stack
- Project Structure
- Getting Started
- Environment Variables
- API Reference
- Maintainers
CanonForces is a full-stack multiplayer competitive programming platform built on top of the Codeforces ecosystem. It bridges the gap between isolated practice and community engagement by combining a powerful in-browser IDE, real-time PvP battles, AI-assisted learning, and deep cross-platform analytics.
Why CanonForces?
- Your Codeforces submissions and rating history sync automatically
- Challenge friends or random opponents to real-time 1v1 coding duels
- Compare your Codeforces and LeetCode stats side-by-side with visual charts
- Stay consistent with daily POTD challenges, streaks, and leaderboards
- Track upcoming contests across Codeforces, LeetCode, CodeChef, AtCoder, and HackerEarth in one feed
| Feature | Description |
|---|---|
| 1v1 Real-time Battles | Challenge friends or get matched instantly via Redis-backed queues. Both players solve the same problem β fastest correct solution wins coins. |
| Battle Royale Lobbies | 20β30 player "King of the Hill" quiz sessions powered by Gemini-generated questions. |
| Coin & Streak System | Earn coins for every problem solved, POTD completed, daily streak maintained, or past contest solution uploaded. |
| Global Leaderboard | Multi-tiered: "Top Earners" (coins) and "Top Solvers" (problems). Includes a weekly POTD-specific board and a sticky "My Rank" footer for users outside the top 50. |
| Feature | Description |
|---|---|
| Full CP IDE | Monaco Editor + Judge0 API. Multi-language support: C++, Python, Java, JavaScript, TypeScript, C#. Real stdin/stdout, test case runner. |
| AI Hint System | Gemini-powered progressive hints inside the IDE. Hints reveal incrementally and reduce the coin reward β encouraging you to try first. |
| Rating-wise Problem Explorer | Browse Codeforces problems filtered by difficulty band (800β1600+). Track per-rating and overall solve progress. |
| Practice Mode | Progress bars, solved-problem tracking saved to Firestore, and a UI optimized for deep-focus sessions. |
| Feature | Description |
|---|---|
| Performance Dashboard | Aggregates rating, rank, max rating, problems solved, and submissions from both Codeforces and LeetCode. |
| Head-to-Head Comparison | Enter any Codeforces handle to see a rating progression chart capped to your own contest count. |
| PDF Export | Download a full personal analytics report as a PDF. |
| Problem-of-the-Day (POTD) | Auto-rotates daily based on a reference date. Admins can override. Solving POTD increments your streak and awards coins. |
| Feature | Description |
|---|---|
| Cross-Platform Contest Feed | Unified upcoming contest calendar for Codeforces, LeetCode, CodeChef, AtCoder, and HackerEarth. |
| Contest Archive & Solution Upload | Submit your code to past contest problems. A correct submission triggers the coin reward system. |
| Follow / Following | Discover and follow other competitive programmers. See suggestions in the sidebar. |
| User Profiles | Profile photos (Cloudinary), handle linkage, activity, rank, and an expandable stats card. |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client (Browser) β
β Next.js 14 Β· Tailwind CSS Β· ShadCN UI Β· Framer Motion β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β HTTP / WebSocket
ββββββββββββββββββββΌβββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ
β Next.js API β β Socket.IO β β Firebase Auth β
β Routes β β Server β β (Google/Email)β
βββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββββ¬ββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ
β Firestore DB β β Redis β β Cloudinary β
β (Users, β β (Matchmak- β β (Profile β
β Problems, β β ing queues,β β Photos) β
β POTD, Coins)β β Leaderbd.) β ββββββββββββββββββ
βββββββββββββββββ ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β External APIs β
β Codeforces API Β· LeetCode API β
β Judge0 (Code Execution) β
β Gemini AI (Hints & Quiz Generation) β
β Contest APIs (CF, LC, CC, AC, HE) β
ββββββββββββββββββββββββββββββββββββββββββββ
| Layer | Technology | Purpose |
|---|---|---|
| Framework | Next.js 14 (App Router) | SSR, routing, API routes |
| Language | TypeScript (76.6%) | Type safety across the codebase |
| Styling | Tailwind CSS + ShadCN UI | Utility-first design system |
| Auth | Firebase Authentication | Google OAuth + Email/Password |
| Database | Firestore (Firebase) | Users, problems, POTD, coins, sessions |
| Real-time | Socket.IO | Live 1v1 battle state synchronization |
| Queue / Cache | Redis | Matchmaking queues, leaderboard sorting |
| Code Execution | Judge0 API (via RapidAPI) | Multi-language sandbox execution |
| Code Editor | Monaco Editor | VS Code-grade in-browser editor |
| AI | Gemini AI (Google) | Progressive hints + quiz generation |
| File Storage | Cloudinary | Profile photo upload and delivery |
| Containerization | Docker | Consistent local and production environments |
| Testing | Jest | Unit and integration tests |
| External APIs | Codeforces API, LeetCode API, Contest APIs | Stats sync, problem data, contest calendar |
canonforces/
βββ .github/ # GitHub Actions workflows, issue templates
βββ public/ # Static assets (icons, images, fonts)
βββ src/
β βββ app/ # Next.js App Router
β β βββ (auth)/ # Auth pages: login, signup
β β βββ (dashboard)/ # Protected dashboard layout
β β β βββ home/ # Home feed, follow suggestions
β β β βββ stats/ # Analytics dashboard (CF + LC)
β β β βββ practise/ # Practice arena, rating-wise explorer
β β β βββ potd/ # Problem of the Day
β β β βββ contests/ # Cross-platform contest calendar
β β β βββ leaderboard/ # Global & POTD leaderboards
β β β βββ quiz/ # Battle Royale lobby + 1v1 duels
β β β βββ profile/ # User profile, edit, photo upload
β β βββ api/ # Next.js API routes
β β βββ auth/ # Auth helpers (CF handle linking)
β β βββ battle/ # Battle session management
β β βββ hints/ # Gemini hint generation endpoint
β β βββ judge/ # Judge0 proxy (code execution)
β β βββ leaderboard/ # Coin/solver ranking endpoints
β β βββ potd/ # Daily problem assignment
β β βββ stats/ # CF/LC stats aggregation
β βββ components/ # Reusable UI components
β β βββ ui/ # ShadCN base components
β β βββ ide/ # Monaco Editor wrapper, test runner
β β βββ charts/ # Recharts rating line charts, bar charts
β β βββ leaderboard/ # Leaderboard table, rank badge
β β βββ problem/ # Problem card, difficulty tag
β β βββ layout/ # Sidebar, navbar, footer
β βββ lib/ # Core utilities and service wrappers
β β βββ firebase/ # Firestore helpers, auth config
β β βββ redis/ # Redis client, queue helpers
β β βββ codeforces/ # CF API client (rating, problems, submissions)
β β βββ leetcode/ # LC API client (stats, problems)
β β βββ gemini/ # Gemini AI client (hints, quiz gen)
β β βββ judge0/ # Judge0 submission + polling
β β βββ cloudinary/ # Upload helpers
β βββ hooks/ # Custom React hooks
β β βββ useAuth.ts # Firebase auth state
β β βββ useBattle.ts # Socket.IO battle state
β β βββ useLeaderboard.ts # Real-time leaderboard polling
β βββ types/ # TypeScript type definitions
β βββ constants/ # App-wide constants (difficulty bands, etc.)
βββ tests/ # Jest test suites
βββ .env.example # Environment variable template
βββ Dockerfile # Docker configuration
βββ next.config.js
βββ tailwind.config.js
βββ tsconfig.json
βββ package.json
- Node.js v18+
- npm v9+
- Firebase project (free Spark plan works)
- Redis β optional for local dev, required for 1v1 matchmaking
- Judge0 API key via RapidAPI
- Gemini API key from Google AI Studio
1. Clone the repository
git clone https://github.com/OpenLake/canonforces.git
cd canonforces2. Install dependencies
npm install3. Configure environment variables
cp .env.example .env.localFill in your keys β see Environment Variables below.
4. Start the development server
npm run devOpen http://localhost:3000.
docker build -t canonforces .
docker run -p 3000:3000 --env-file .env.local canonforcesnpm test # run all tests
npm test -- --watch # watch mode
npm test -- --coverageCreate a .env.local file in the root directory. All variables prefixed with NEXT_PUBLIC_ are exposed to the browser.
# βββ Firebase ββββββββββββββββββββββββββββββββββββββββββββββ
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
# βββ Code Execution (Judge0 via RapidAPI) ββββββββββββββββββ
NEXT_PUBLIC_JUDGE0_API_KEY=your_rapidapi_key
# βββ Real-time & Queues ββββββββββββββββββββββββββββββββββββ
REDIS_URL=redis://localhost:6379 # or your Redis Cloud URL
# βββ AI (Google Gemini) ββββββββββββββββββββββββββββββββββββ
GEMINI_API_KEY=your_gemini_api_key
# βββ File Storage (Cloudinary) βββββββββββββββββββββββββββββ
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_secretTip: For local development without Redis, 1v1 matchmaking and real-time leaderboard updates will be unavailable. All other features work without it.
All API routes live under /src/app/api/. Key endpoints:
| Method | Route | Description |
|---|---|---|
GET |
/api/stats/codeforces?handle= |
Fetch rating, rank, and submission history for a CF handle |
GET |
/api/stats/leetcode?handle= |
Fetch LeetCode stats for a given username |
GET |
/api/potd |
Get today's Problem of the Day |
POST |
/api/potd/solve |
Mark POTD as solved, award coins and increment streak |
POST |
/api/judge/submit |
Proxy a code submission to Judge0 and return the verdict |
POST |
/api/hints |
Request a progressive AI hint for a given problem |
GET |
/api/leaderboard |
Get top earners and top solvers lists |
GET |
/api/contests |
Fetch upcoming contests across all platforms |
POST |
/api/battle/create |
Create a new 1v1 battle session |
POST |
/api/battle/join |
Join an existing battle via invite code |
Click to expand Feature Deep Dives
The IDE integrates a Gemini-powered hint engine designed to teach rather than reveal. Hints are tiered:
- Hint 1 β Topic: Names the algorithmic category (e.g., "Binary Search on Answer")
- Hint 2 β Approach: Describes the high-level strategy without implementation detail
- Hint 3 β Algorithm: Outlines the algorithm step-by-step, but leaves the code to you
Each revealed hint reduces the coin reward for that problem. This creates a deliberate trade-off between getting unstuck and maximising your score.
Built on Redis queues + Socket.IO:
- User joins the matchmaking queue (
LPUSHto Redis) - Server polls the queue; when 2 players are available, it pops them and creates a battle session
- Both clients receive a
match-foundevent and are directed to the same battle room - Problem is fetched from the Codeforces API and rendered in the split-pane IDE
- Submissions are evaluated by Judge0; the first accepted solution ends the match
- Coins are atomically credited to the winner via a Firestore transaction
The analytics page aggregates data from two sources:
- Codeforces API β rating history, max rating, rank, contest count, submission count, problem tags
- LeetCode API (unofficial) β solved count by difficulty, submission calendar
All data is displayed with Recharts visualizations: rating line charts, bar charts by problem tag, donut charts for difficulty breakdown. Users can also compare head-to-head with any other Codeforces handle, with the x-axis capped to the logged-in user's contest count for a fair comparison.
POTD uses a deterministic daily rotation based on a reference date, so no cron jobs or admin action is required. Admins can override the daily problem via a protected UI. Solving POTD within the day:
- Increments your daily streak
- Awards coins (scaled by difficulty rating)
- Appears on the weekly POTD leaderboard
|
Aviral Saxena @aviralsaxena16 |
Kamireddi Jaswanth Kumar @Jaswanth-Kumar-2007 |
Distributed under the MIT License. See LICENSE for details.
β Star this repo if CanonForces has helped your CP journey!
Built with β€οΈ by Aviral Saxena @ Openlake



