I was curious about how Codeforces worked, so I created my own version!
Welcome to Codespaces โ your social problem-solving playground! ๐งโ๐ปโจ
- โ๏ธ Create Your Own Problems: Feeling creative? You can also create and manage your own coding problems! ๐จ
- ๐ Codeforces Problem Scraping: Enter a Codeforces problem link and watch the magic happen! The problem statement and test cases are automatically parsed and shared across all users in the room. ๐
- ๐ Code Evaluation: Evaluate code submissions on the fly in a safe and secure sandboxed environment!
- ๐ฉโ๐ป Collaborative Coding: Team up with your friends and solve problems together in real-time with up to 10 users.
- ๐ค Group Voice Chat: Integrated group voice chat for seamless collaboration using WebRTC.
- ๐ฆ Problem Packages: Easily store and manage problem packages.
- ๐งฎ๐ผ๏ธ Math & Image Rendering: Supports rendering math equations and images in problem statements.
- โก Caching: Lightning-fast caching for problem statements and packages using Redis.
Can even be used to host contests completely locally (for the most part).
Check out the demo here ๐ฟ
(Hosting is currently down as I lost access to my EC2 instance ๐ข)
A (not-so-)little monolithic system that handles everything from scraping to collaborative coding.
- Backend pulls test data from the database (or cache if available).
- Every new submission triggers a Docker container (Alpine Linux).
- Container compiles and runs the code in a sandbox:
- 2-second time limit
- 256 MB memory limit
- No internet access
- Max 100 processes (to avoid fork bombs)
Steps performed:
- Compile code and put it in a sandboxed environment with the input data.
- Randomly change the root password to prevent access.
- Lock environment so code canโt access anything outside its sandbox.
- Run code with a 2-second time limit.
- Compare program output to expected output, return verdict.
- ๐ค Group Voice Chat: WebRTC
- ๐ณ Docker API: Spawn containers for code evaluation
- ๐ค Collaboration: Socket.IO for real-time coding
- โ Web Scraping: BeautifulSoup custom scraper for Codeforces
- ๐ Sandboxing: Non-privileged users inside Docker
- ๐ฆ Problem Packages: Stored in MongoDB
- โก Redis Caching: Cache problem packages & test data
- ๐งฎ Math Rendering: KaTeX
- ๐ซ Rate Limiting: Added to compilation API
Supported Languages: C++ only for now.
- Make the submission system more scalable & efficient (possibly microservice).
- Multi-node setup using free-tier EC2 + Kubernetes auto-scaling.
- Fix recent security issue related to compiling untrusted code.
Prerequisites: Docker & Redis installed in backend.
# Clone repository
git clone https://github.com/nubskr/codespace.git
cd codespace
# Install dependencies
npm install
# Pull container images & setup environment variables
sudo ./setup.sh
cd ./server
vim .env
# Example .env
MONGODB_URI=''
AWS_ACCESS_KEY_ID=''
AWS_SECRET_ACCESS_KEY=''
AWS_REGION=''
S3_BUCKET_NAME=''
CONCURRENT_SCRAPING_WORKERS=''
CONCURRENT_SUBMISSION_WORKERS=''
# Start backend
npm start
# Start frontend
cd ..
cd ./frontend
npm start