Practice algorithms with a smooth submit-and-run flow for the excellent CSES problem set — with your own backend, live status updates, and a sandboxed judge.
- CSES has a fantastic set of problems, but no built-in “code here and run” experience.
- I wanted the smoothest practice loop: browse problems, code in my editor, click submit, watch live verdicts, and inspect results — all locally hosted.
- This repo is the backend + judge that powers that experience. The frontend lives separately:
- Frontend repo: https://github.com/iqbal-sk/Code-Frontrend
- FastAPI backend with clean REST APIs and JWT auth (login/register/me).
- Problem library sourced from CSES (title, description, constraints, images, sample tests).
- Hidden/public test cases imported via a scraper (requires your CSES PHPSESSID).
- Submissions in multiple languages (Python, C++, Java, JavaScript) with resource limits.
- Asynchronous judge worker, sandboxed execution, and SSE live status updates.
- MongoDB persistence and Redis queue/pubsub.
- Single-command Docker Compose to run everything reproducibly.
Platform(FastAPI):- Endpoints under
/api/v1/...for users, problems, test-cases, submissions. - Streams submission updates via Server-Sent Events:
/api/v1/submissions/{id}/events. - Uses MongoDB for storage, Redis for queueing and pubsub.
- Endpoints under
judge_service(Worker):- Listens to Redis queue, executes code in a sandbox, updates Mongo, and publishes status.
scraper(One-shot job):- Pulls problems from CSES and downloads testcases; stores large inputs/outputs as local files.
- Requires your CSES
PHPSESSIDcookie.
- FastAPI, Uvicorn, Pydantic (v2), ODMantic (Mongo), Motor, Redis (asyncio), SSE
- Python sandbox for running code; installs
g++,default-jdk,nodein the judge container - Docker Compose for orchestration
Prerequisites: Docker and Docker Compose.
- Clone and enter the repo
git clone https://github.com/iqbal-sk/CodeForge.git
cd CodeForge- Start core services (Mongo, Redis, API, Judge)
docker compose up -d --build mongo redis platform judge- Seed problems and testcases (scrape 5 problems)
You need your CSES PHPSESSID cookie value (sign in to https://cses.fi and copy PHPSESSID).
export CSES_SESSION_ID='paste_your_cookie_here'
docker compose run --rm scraper- Open the API
http://localhost:8000
- Run the frontend
Clone and run the UI from: https://github.com/iqbal-sk/Code-Frontrend
Configure its API base to http://localhost:8000 and use the normal flow:
- Register:
POST /api/v1/users/register - Login:
POST /api/v1/users/login→ get JWT - Browse Problems:
GET /api/v1/problems - Submit Code:
POST /api/v1/submission - Live Status: connect to
GET /api/v1/submissions/{id}/events(SSE)
- Container env is the source of truth when running with Docker Compose. The
.envfiles in the repo are intended for local (non-container) runs and are overridden by Compose. - By default, Mongo is exposed on host port
27017. If you prefer27018on your host, change the mapping indocker-compose.yml:
services:
mongo:
ports:
- "27018:27017" # host:container- The scraper writes large test files into a shared volume mounted at
/data/testcasesin Platform, Judge, and Scraper. This ensures file paths saved in Mongo are valid in all containers. - JWT secret defaults are for development only. The frontend must login against the currently running backend to get a valid token.
-
Auth
POST /api/v1/users/register— create accountPOST /api/v1/users/login— returns{ access_token, token_type }GET /api/v1/users/me— profile (requiresAuthorization: Bearer <token>)
-
Problems & Test Cases
GET /api/v1/problems— list/browseGET /api/v1/problems/{problemId}— detailsGET /api/v1/problems/{problemId}/test-cases— full set (hidden included with?includeHidden=true)GET /api/v1/problems/{problemId}/test-cases/public— only public
-
Submissions
POST /api/v1/submission— enqueue a submissionGET /api/v1/submissions/{submissionId}— submission detailsGET /api/v1/submissions/{submissionId}/events— live SSE updates (status/results)
- Prefer Docker Compose for consistency. It builds images that include all required toolchains for the judge.
- If you want to run without Docker, use the Python requirements in
Platform/requirements-dev.txt, start Mongo and Redis locally, and runuvicorn Platform.src.main:app. The judge can be started withPYTHONPATH=$(pwd) python judge_service/main.py.
- Scraper requires your personal CSES
PHPSESSID. Treat it like a secret; do not commit it. - Resource limits are strongest on Linux; on macOS some memory limits are relaxed.
- Only use the provided development JWT secret in local setups. Rotate/change for any shared or hosted environment.
- Containerized “execution service” isolation profiles.
- More languages and tooling cache for faster builds.
- Enhanced problem browsing (search, tags, difficulty).
- Submission history insights and editor integrations.
- CSES Problem Set — https://cses.fi
- FastAPI, Pydantic, Uvicorn, ODMantic, Redis
Frontend repo again for convenience: https://github.com/iqbal-sk/Code-Frontrend