Skip to content

nivethadhanakoti/CodeSentinel

Repository files navigation

AlgoJudge

A minimalist, open-source coding judge with secure Docker sandboxing and instant AI code analysis using a local Ollama LLM (Phi-4-mini).

Features

  • Secure code execution in Docker containers (no network, memory/time limits)
  • Automatic code analysis and optimization feedback after every run
  • Streaming AI chat about your code
  • Multi-language: Python, C++, C, Java, JavaScript, Go
  • Modern React frontend with Monaco editor

Quick Start

1. Clone the repo

git clone <repo-url>
cd AlgoJudge

2. Install and start Ollama

# Install Ollama from https://ollama.ai
ollama serve &
ollama pull phi4-mini

3. Pull sandbox language images

docker pull python:3.11-slim
docker pull gcc:latest
docker pull node:latest
docker pull golang:latest
docker pull eclipse-temurin:latest

4. Setup environment

cp backend/.env.example backend/.env
# Edit backend/.env with your settings

5. Build and run

docker compose up --build

6. Access

Tech Stack

  • Frontend: Next.js, Tailwind CSS, Monaco Editor
  • Backend: FastAPI, SQLAlchemy, JWT Auth
  • AI: Ollama (local) with Phi-4-mini (3.8B) — no API keys needed
  • Sandbox: Docker (per-language containers, no network, memory/time limited)
  • Database: PostgreSQL

API Endpoints

Method Endpoint Description
POST /auth/register Register user
POST /auth/login Login, get JWT
POST /submit Run code, returns execution result immediately
GET /ai-result/{id} Poll for AI analysis result
POST /chat Streaming AI chat about your code
GET /dashboard List submissions
GET /healthz Health check

Security

  • All user code runs inside isolated Docker containers
  • No network access inside sandbox containers
  • Memory and time limits enforced
  • JWT authentication on all endpoints
  • Passwords bcrypt-hashed in PostgreSQL

Test Cases

Python — Hello World

print("Hello, AlgoJudge!")

Python — Sum of Two Numbers

a, b = map(int, input().split())
print(a + b)

Input: 3 5 → Expected: 8

Python — Fibonacci

n = int(input())
a, b = 0, 1
for _ in range(n):
    print(a, end=" ")
    a, b = b, a + b

Input: 7 → Expected: 0 1 1 2 3 5 8

Python — Two Sum (O(n²) — AI will suggest hashmap fix)

n = int(input())
nums = list(map(int, input().split()))
target = int(input())
for i in range(len(nums)):
    for j in range(i+1, len(nums)):
        if nums[i] + nums[j] == target:
            print(i, j)
            break

Input: 4\n2 7 11 15\n9 → Expected: 0 1

C++ — Sort Array

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &x : v) cin >> x;
    sort(v.begin(), v.end());
    for(auto x : v) cout << x << " ";
}

Input: 5\n3 1 4 1 5 → Expected: 1 1 3 4 5

Testing

# Backend
cd backend && pytest

# Frontend
cd frontend && npm test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages