- π³ Secure Docker Sandboxing: Executes untrusted C++, Java, Python, and JavaScript code in isolated, ephemeral containers with strict CPU and memory bounds.
- β‘ Asynchronous Execution Pipeline: Built on Redis and BullMQ to efficiently queue, distribute, and process high volumes of submissions.
- π€ AI-Powered Analysis: Integrated with Google Gemini 2.0 Flash to provide automated Time/Space complexity analysis and actionable optimization tips.
- π¨ Premium UI/UX: Dark-mode-first aesthetic with glassmorphism, sleek bento-grid dashboards, a GitHub-style heatmap, and Monaco Editor.
- π ACID Compliant DB Operations: Utilizes MongoDB Sessions & Transactions to guarantee atomic updates between submission verdicts and user statistics.
CodeForge is built on a modern, decoupled microservices architecture designed for scalability and fault tolerance:
- Frontend (Vite + React): A responsive Single Page Application (SPA) providing a seamless IDE-like experience using Monaco Editor.
- Backend API (Express.js): Serves RESTful endpoints, handles JWT authentication, and acts as the Producer, publishing code submissions to the Redis queue.
- Message Broker (Redis + BullMQ): Decouples the API from the heavy lifting of code execution, allowing the system to easily handle traffic spikes.
- Judge Engine (Node.js Worker): Consumes jobs from BullMQ. It uses
child_processto dynamically spin up language-specific Docker containers, executing user code securely. - Database (MongoDB): Stores user data, problem definitions, and submission metadata. The Judge Engine directly updates verdicts via ACID transactions.
- AI Integration (Gemini): Enhances the developer experience by generating real-time algorithmic complexity analysis and optimization hints.
graph TD
subgraph Frontend ["π₯οΈ Client Layer (Vite + React)"]
UI[User Interface]
Editor[Monaco Code Editor]
UI <--> Editor
end
subgraph Backend ["βοΈ API Layer (Express.js)"]
API[REST API]
Auth[JWT Auth]
API --- Auth
end
subgraph MessageBroker ["π΄ Message Broker"]
Redis[(Redis Queue)]
end
subgraph Execution ["π Judge Engine (Node.js)"]
Worker[BullMQ Worker]
Docker[π³ Docker Sandbox]
Worker -->|Spins up| Docker
Docker -->|Executes Code| Docker
Docker -->|Returns Output| Worker
end
subgraph Storage ["π Data Layer"]
MongoDB[(MongoDB)]
end
subgraph AI ["π€ External Services"]
Gemini[Google Gemini 2.0 Flash]
end
%% Core Flow Connections
UI -->|HTTP/REST| API
API -->|Read/Write Data| MongoDB
API -->|Enqueues Job| Redis
Redis -->|Consumes Job| Worker
Worker -->|ACID Updates Verdict| MongoDB
API -->|Code Context| Gemini
Gemini -->|Analysis & Hints| API
sequenceDiagram
autonumber
actor User
participant Frontend as React UI
participant API as Express API
participant DB as MongoDB
participant Redis as Redis Queue
participant Worker as Judge Engine
participant Docker as Docker Sandbox
participant AI as Gemini API
User->>Frontend: Writes code & clicks "Submit"
Frontend->>API: POST /api/submissions (Code, Lang, ProblemID)
API->>DB: Save "Pending" Submission
API->>Redis: Enqueue Job
API-->>Frontend: Return Submission ID
rect rgb(30, 41, 59)
Note right of Frontend: Client Short-Polling
Frontend->>API: GET /api/submissions/:id/status (Every 2s)
end
Redis-->>Worker: Dequeue Job
Worker->>Docker: Spawn Sandbox (Enforce memory/CPU limits)
Docker-->>Worker: Return stdout/stderr & metrics
Worker->>Worker: Resolve Verdict (e.g., Accepted, WA, TLE)
rect rgb(30, 41, 59)
Note right of Worker: ACID Transaction
Worker->>DB: Update Submission Status & Metrics
Worker->>DB: Update User Solved Stats
end
API-->>Frontend: Return Final Status
Frontend->>User: Display Result (Green/Red Badge)
User->>Frontend: Clicks "β¨ Ask AI for Optimization"
Frontend->>API: POST /api/ai/analyze-code
API->>AI: Request algorithmic analysis
AI-->>API: JSON Feedback (Time/Space Complexity)
API-->>Frontend: Send AI Analysis
Frontend->>User: Render glowing AI Feedback Panel
- OS: Windows 10/11, macOS, or Linux
- RAM: Minimum 8GB (16GB recommended for running Docker alongside the stack)
- Disk Space: At least 5GB free for Docker images and Node modules
- Network: Stable internet connection for Docker pulls and Gemini API access
- Node.js (v18+)
- Docker Desktop (Running locally)
- Redis (via Docker, WSL, or Memurai for native Windows)
- MongoDB (Local or Atlas URL)
- Google Gemini API Key
Create .env files in each service directory based on the templates below:
Backend /backend/.env
PORT=5000
MONGODB_URI=mongodb://localhost:27017/codeforge
JWT_SECRET=your_jwt_secret
REDIS_URL=redis://localhost:6379
GEMINI_API_KEY=your_gemini_keyJudge Engine /judge-engine/.env
MONGODB_URI=mongodb://localhost:27017/codeforge
REDIS_URL=redis://localhost:6379
MAX_CONCURRENT_JOBS=5Install dependencies across all workspaces:
cd backend && npm install
cd ../judge-engine && npm install
cd ../frontend && npm installBuild the Docker Sandbox Images for the Judge Engine:
cd judge-engine/containers
docker build -t codeforge-python -f Dockerfile.python .
docker build -t codeforge-cpp -f Dockerfile.cpp .
docker build -t codeforge-java -f Dockerfile.java .Seed the Database:
cd backend && node scripts/seedDatabase.jsOpen 3 terminal instances and run the following concurrently:
# Terminal 1: Backend
cd backend && npm run dev
# Terminal 2: Judge Engine Worker
cd judge-engine && npm start
# Terminal 3: Frontend
cd frontend && npm run dev
Built with β€οΈ for algorithmic mastery.