CodeBattle transforms competitive programming from a solitary grind into a live, high-stakes esports experience. Think online chess platforms like Chess.com, but for competitive codingโdesigned for real-time 1v1 duels, college fests, hackathons, and coding tournaments.
Instead of asynchronous problem-solving, CodeBattle enables synchronous competitive duels where speed, accuracy, and strategy determine the winner in real time. Perfect for both online competitions and offline college coding events.
Most coding platforms (LeetCode, HackerRank) are built for learning, not competing:
- Static, asynchronous problem-solving
- No real-time competition pressure
- Lack of spectator engagement
- Not designed for organized events or tournaments
We're bringing the adrenaline of esports to competitive programming:
โ
Live 1v1 Battles โ Real-time synchronized duels with server-authoritative timing
โ
Offline Event Ready โ Ideal for college fests, hackathons, and coding competitions
โ
Flexible Time Control โ Users select match duration (perfect for event planning)
โ
Multi-Language Support โ Code in Python, JavaScript, C++, Java, Go, Rust, and more
โ
Live Spectator Mode โ Audiences watch real-time gameplay
โ
AI-Powered Post-Match Analysis โ Get instant feedback on your code logic and optimizations
โ
Easy Room Sharing โ Create a room, share the code, challenge a friend or stranger
Challenge friends or strangers to real-time coding battles. Set your own time limit and compete live.
Run live coding tournaments at your college events. Stream matches on a projector, engage the audience, crown a championโall on one platform.
Coming soon: Round-robin tournament brackets for larger competitive events. Automatically match players and track rankings.
Host a physical coding event while using CodeBattle's online platform to broadcast and manage competitions in real time.
| Feature | Details |
|---|---|
| Room-Based Matches | One player creates a room, shares the code, opponent joinsโinstant 1v1 |
| Custom Time Control | Set match duration to fit your event (5 min, 15 min, 30 min, custom) |
| Multi-Language Arena | Support for Python, JavaScript, C++, Java, Go, Rust, and more |
| Live Code Execution | Secure, sandboxed execution via Piston (Docker-based) |
| Real-Time Verdicts | Instant feedback on code submissions (Accepted/Rejected/TLE) |
| Feature | Details |
|---|---|
| Live Spectator Mode | Watch 1v1 matches in real-time via WebSocket streams |
| Synchronized Viewing | All spectators see the exact same stateโperfect for projector displays |
| Match History | Browse past duels and learn from top players |
| Feature | Details |
|---|---|
| Post-Match Analysis | AI coach (Gemini 2.5) reviews your solution |
| Logic Breakdown | Understand why your solution works (or doesn't) |
| Optimization Tips | Time complexity analysis (O(N) vs O(Nยฒ)), edge cases, improvements |
| Learning Mode | Not just a verdictโa coaching experience |
CodeBattle uses Motia Steps to orchestrate APIs, background jobs, AI agents, and real-time streamsโall within a single unified runtime.
graph TD
%% Nodes
User([Client / Frontend])
subgraph "Motia Unified Runtime"
direction TB
API[MatchAPI Step]
Engine{GameEngine Step}
Runner[CodeRunner Step]
Referee[AiReferee Step]
Stream[MatchStream]
end
subgraph "External Services"
Piston[Piston Engine]
AI[Gemini 2.5]
end
%% Main Input Flow
User ==>|HTTP POST| API
API -->|Event: player.joined| Engine
%% Worker Flows
Engine -->|Event: run.code| Runner
Runner <-->|Docker Exec| Piston
Runner -->|Event: code.processed| Engine
%% AI Logic
Engine -->|Event: analyze.code| Referee
Referee -->|API Call| AI
%% Output Stream
Engine -->|State Update| Stream
Stream -.->|Real-time WebSocket| User
-
Create a Room
Player A initiates a match, sets time limit โ MatchAPI persists state โ waits for opponent -
Share & Join
Player A shares room code โ Player B joins โ MongoDB atomic update ensures exactly 2 players โplayer.joinedevent fires -
Match Starts
GameEngine validates both players ready โ synchronized timer starts โ problem loaded โmatch.startedevent -
Live Coding
Both players write code in their language of choice โ real-time sync to spectators โ verdicts returned instantly -
Submission & Verdict
Code received โ CodeRunner executes in sandbox โ test cases validated โ instant feedback -
AI Analysis
Post-match, AiReferee (Gemini 2.5) analyzes code asynchronously and streams coaching feedback
- Node.js 18+
- MongoDB (Local or Atlas)
- Motia CLI
git clone https://github.com/sambhandavale/code-battle.git
# Backend
cd battle-engine
npm install
# Frontend
cd ../battle-frontier
npm installCreate a .env file in both directories.
MONGO_URI=mongodb://localhost:27017/codebattle
GEMINI_API_KEY=your_gemini_key_hereENV=dev
NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:2000
NEXT_PUBLIC_WS_GATEWAY_URL=ws://localhost:2000cd battle-engine
npm run dev
# Motia Dashboard: http://localhost:3000cd battle-frontier
npm run dev
# App: http://localhost:3000 (or configured port)| Layer | Technology |
|---|---|
| Orchestration | Motia (unified runtime) |
| Backend Runtime | Node.js 18+ (TypeScript) |
| Database | MongoDB |
| Code Execution | Piston (Docker-based, sandboxed) |
| AI Coaching | Google Gemini 2.5 Flash |
| Frontend | Next.js, Tailwind CSS, Monaco Editor |
| Real-Time | WebSocket streams via Motia |
- Live 1v1 real-time matches
- Multi-language code execution
- Custom time control
- Live spectator mode
- AI post-match analysis
- Tournament Mode โ Round-robin bracket system for organized events
- Leaderboards โ Global and event-specific rankings
- Problem Sets โ Curated difficulty tiers
- Team Battles โ 2v2 or team-based competitions
- Event Management Dashboard โ Tools for organizing college fests and hackathons
We built CodeBattle to showcase what Motia can do. This project demonstrates how a unified backend runtime collapses infrastructure complexity.
Express (API) + Redis (Pub/Sub) + Celery (Workers) + Socket.io (WebSockets)
= 4 separate systems to manage
Motia Steps: API โ GameEngine โ CodeRunner โ Stream
= 1 system, built-in event routing, automatic glue code
- Zero-config event bus โ Steps communicate via simple
emit()calls - Visual debugging โ Built-in dashboard shows match flow in real-time
- Reduced complexity โ 3ร less boilerplate, 2ร faster development
- Single deployment โ All components in one runtime
Learn more: Motia GitHub Repository
We welcome contributions! Whether you're fixing bugs, adding languages, or improving the AI coaching, PRs are always appreciated.
- Fork the repo
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add feature') - Push and open a PR
Have ideas for CodeBattle? Found a bug? Want to use it for your college event?
- Open an issue on GitHub
- Reach out with feedbackโwe'd love to hear how you use CodeBattle!
Massive shout-out to the Motia team. This project would have required 3ร the code and 2ร the infrastructure complexity without their unified runtime.
Motia made it possible to build APIs, background workers, real-time streams, and AI agents using a single architectural primitive โ Steps.
One runtime. One primitive. Infinite possibilities.
Built for competitive coding. Designed for esports. Ready for your event. ๐