8000 GitHub - Dev-Leet/OJ Β· GitHub
[go: up one dir, main page]

Skip to content
Dev-LeetPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CodeForge Logo

Online Judge

A high-performance, modern, and intelligent algorithmic coding platform.

Vite Tailwind CSS Node.js MongoDB Redis Docker Gemini


πŸ“‘ Table of Contents


✨ Key Features

  • 🐳 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.

πŸ—οΈ System Architecture

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_process to 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
Loading

πŸ”„ Submission Data Flow

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
Loading

πŸš€ Getting Started

πŸ’» System Requirements

  • 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

1. Prerequisites

2. Environment Variables

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_key
Judge Engine /judge-engine/.env
MONGODB_URI=mongodb://localhost:27017/codeforge
REDIS_URL=redis://localhost:6379
MAX_CONCURRENT_JOBS=5

3. Installation & Setup

Install dependencies across all workspaces:

cd backend && npm install
cd ../judge-engine && npm install
cd ../frontend && npm install

Build 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.js

4. Running the Stack

Open 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0