Skip to content

Repository files navigation

LogicBuild β€” Dockerized Code Judge

A full-stack competitive programming platform where users can solve problems, battle in real-time, and track their progress on a leaderboard. Supports 9 programming languages with isolated Docker/Kubernetes sandbox execution.


πŸ“‹ Table of Contents


✨ Features

  • 🧩 Problem Library β€” Browse, search, and filter by difficulty and tags
  • βš”οΈ Code Battles β€” Real-time 1v1 matchmaking by difficulty using Socket.io
  • πŸ† Leaderboard β€” ELO-based global ranking with dynamic points per problem
  • πŸ–₯️ Multi-language IDE β€” Monaco editor with 9 language support
  • 🐳 Sandboxed Execution β€” Code runs in isolated Docker containers (or K8s pods)
  • πŸ“Š Admin Panel β€” Create, edit, delete problems with tags, difficulty, and custom points
  • βœ… Solved Tracking β€” Problems marked as solved after a correct submission

πŸ› οΈ Tech Stack

Layer Technology
Frontend React 18, Vite, Monaco Editor, Socket.io Client
Backend API Node.js, Express, Socket.io
Queue/Worker BullMQ (Redis-backed job queue)
Database PostgreSQL 15
Cache / Pub-Sub Redis
Code Execution Docker-in-Docker (DinD) or Kubernetes pods
Auth JWT (jsonwebtoken + bcryptjs)
Deployment Docker Compose (dev) / Kubernetes (prod)

πŸ“ Project Structure

Execution Engine/
β”œβ”€β”€ src/                    # Backend source
β”‚   β”œβ”€β”€ index.js            # Express API + Socket.io server
β”‚   β”œβ”€β”€ queue.js            # BullMQ worker (code execution)
β”‚   β”œβ”€β”€ db.js               # PostgreSQL queries
β”‚   β”œβ”€β”€ executor.js         # Docker / K8s sandbox runner
β”‚   └── schema.sql          # Database schema
β”œβ”€β”€ frontend/               # React frontend (Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ pages/          # Route-level page components
β”‚   β”‚   β”œβ”€β”€ components/     # Shared components
β”‚   β”‚   β”œβ”€β”€ context/        # Auth & Socket contexts
β”‚   β”‚   └── index.css       # Global styles
β”‚   └── Dockerfile.frontend
β”œβ”€β”€ docker/                 # Language runner Docker images
β”‚   β”œβ”€β”€ python-runner/
β”‚   β”œβ”€β”€ cpp-runner/
β”‚   β”œβ”€β”€ java-runner/
β”‚   β”œβ”€β”€ kotlin-runner/
β”‚   β”œβ”€β”€ go-runner/
β”‚   β”œβ”€β”€ php-runner/
β”‚   β”œβ”€β”€ dart-runner/
β”‚   β”œβ”€β”€ c-runner/
β”‚   └── sql-runner/
β”œβ”€β”€ k8s/                    # Kubernetes manifests
β”‚   β”œβ”€β”€ namespaces.yaml
β”‚   β”œβ”€β”€ backend.yaml
β”‚   β”œβ”€β”€ frontend.yaml
β”‚   β”œβ”€β”€ postgres.yaml
β”‚   β”œβ”€β”€ redis.yaml
β”‚   └── rbac.yaml
β”œβ”€β”€ migrations/             # SQL migration files
β”œβ”€β”€ seed.js                 # Database seeder (sample problems + users)
β”œβ”€β”€ Dockerfile.backend
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ deploy-k8s.ps1          # K8s deploy script (PowerShell)
└── build_k8s_images.ps1    # Build K8s images script (PowerShell)

βœ… Prerequisites

For Kubernetes deployment: Enable Kubernetes in Docker Desktop Settings β†’ Kubernetes β†’ Enable Kubernetes


πŸš€ Quick Start (Docker Compose)

Step 1 β€” Clone the repository

git clone <your-repo-url>
cd "Execution Engine"

Step 2 β€” Create the .env file

cp .env .env.local   # or create manually (see Environment Variables section)

Step 3 β€” Build language runner images

These sandbox images must be built before starting the API:

docker compose build cpp-runner python-runner java-runner kotlin-runner go-runner php-runner dart-runner c-runner sql-runner

Step 4 β€” Start the full stack

docker compose up -d db redis api frontend

Services will start in order:

  • db β€” PostgreSQL on port 5433
  • redis β€” Redis on port 6379
  • api β€” Express API on port 3000
  • frontend β€” React app on port 5173

Step 5 β€” Seed the database

On first run, seed the database with sample problems and a test admin user:

node seed.js

Step 6 β€” Open the app

http://localhost:5173

Default seeded credentials:

Role Email Password
User test@example.com password123

πŸ”§ Environment Variables

The .env file in the project root is used for the backend API:

PORT=3000
DB_USER=postgres
DB_PASSWORD=engine_password
DB_HOST=localhost
DB_PORT=5433
DB_NAME=postgres
JWT_SECRET=your-secret-key-here
REDIS_HOST=localhost
REDIS_PORT=6379
EXECUTION_STRATEGY=docker      # 'docker' or 'k8s'
DOCKER_TEMP_VOLUME=execution_engine_temp

Note: When running via Docker Compose, DB_HOST must be db and REDIS_HOST must be redis (the Docker service names). The .env values with localhost are for running the API natively outside Docker.


🌱 Seeding the Database

node seed.js

This will:

  • Create all tables (if they don't exist) from src/schema.sql
  • Insert 10 sample problems (Easy / Medium / Hard)
  • Create a default test user

To reset and re-seed:

# Stop the DB container, remove its volume, then restart
docker compose down -v
docker compose up -d db
node seed.js

πŸ’» Running Locally (Development)

To develop without Docker (API and frontend only, DB + Redis still via Docker):

# Terminal 1 β€” Start DB & Redis only
docker compose up -d db redis

# Terminal 2 β€” Start the backend API
npm install
npm run dev

# Terminal 3 β€” Start the frontend
cd frontend
npm install
npm run dev

Frontend: http://localhost:5173
API: http://localhost:3000


☸️ Kubernetes Deployment

Requires Kubernetes enabled in Docker Desktop.

Step 1 β€” Build K8s images

.\build_k8s_images.ps1

Step 2 β€” Deploy to cluster

.\deploy-k8s.ps1

Or use the slash command from the IDE:

/deploy-k8s

Step 3 β€” Verify pods

kubectl get pods -n code-judge
kubectl get pods -n sandbox

K8s port mappings:

Service Port
API (LoadBalancer) localhost:3001
Frontend (LoadBalancer) localhost:80

πŸ“– API Reference

Auth

Method Endpoint Description
POST /register Register a new user
POST /login Login, returns JWT
GET /me Get current user (auth required)

Problems

Method Endpoint Description Query Params
GET /problems List problems (paginated) page, difficulty, tag, search
GET /problems/:id Get problem details + test cases β€”
POST /problems Create a problem β€”
PUT /problems/:id Update a problem β€”
DELETE /problems/:id Delete a problem β€”

Create/Update problem body:

{
  "title": "Sum of Two Numbers",
  "description_bn": "...",
  "input_format_bn": "...",
  "output_format_bn": "...",
  "sample_input": "1 2",
  "sample_output": "3",
  "difficulty": "Easy",
  "points": 5,
  "tags": ["Math", "Basic"],
  "test_cases": [
    { "input": "1 2", "expected_output": "3", "is_sample": true }
  ]
}

Submissions

Method Endpoint Description
POST /submit Submit code for a problem
GET /submissions List user's submissions
DELETE /submissions Clear submission history
GET /jobs/:id Poll job status (playground)

Leaderboard

Method Endpoint Description
GET /leaderboard Paginated leaderboard

🌐 Supported Languages

Language Runner Image
Python 3 python-runner
C++ 17 cpp-runner
Java 17 java-runner
Kotlin kotlin-runner
Go 1.21 go-runner
PHP 8.2 php-runner
Dart dart-runner
C c-runner
SQL sql-runner

πŸ”„ Updating the App

After making code changes:

# Rebuild and restart only API and frontend (preserves DB data)
docker compose up -d --build api frontend

To rebuild a specific language runner:

docker compose build python-runner

πŸ› Troubleshooting

Issue Fix
Cannot connect to Docker socket Make sure Docker Desktop is running
Port 5433 already in use Change DB_PORT in .env or stop the conflicting service
JWT_SECRET not set Set JWT_SECRET in .env
Submission stuck in Queued Check Redis is running: docker compose ps redis
No runner image found Build runner images: docker compose build python-runner

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages