Skip to content

massab344/Online-Coding-Judge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OOP Online Judge

A web-based competitive programming platform built entirely in C++ (backend) with a custom HTML/CSS/JS frontend. No external frameworks or libraries used on the server side — everything from HTTP parsing to JSON building to the Virtual File System is hand-written.

Course: Object Oriented Programming (Spring 2026)
University: FAST-NUCES


Features

Core Functionality

  • User Registration & Login — with email verification (simulated), session management via cookies
  • 50 Practice Problems — across 5 difficulty levels (Easy → Hard), each with multiple test cases
  • Timed Contests — Easy (3 problems/60min), Medium (4/90min), Hard (5/120min)
  • Code Evaluation Engine — compiles and runs user C++ code against test cases
  • 5 Verdicts — AC (Accepted), WA (Wrong Answer), CE (Compile Error), RE (Runtime Error), TLE (Time Limit Exceeded)
  • Solution Persistence — all code saved to Virtual File System
  • Contest History & Scoring — time-based scoring with wrong attempt penalties

Technical Highlights

  • Custom HTTP Server — single-threaded server (Winsock2 on Windows, POSIX sockets on Linux/macOS) with full request/response parsing
  • Virtual File System (VFS) — hierarchical file system with volumes, partitions, directories, files, permissions, and users
  • Process Isolation — compiles and runs user code in a child process with I/O redirection and 5-second timeout (TLE detection). Uses CreateProcess on Windows, fork()/exec() on Linux/macOS
  • No STL Containers — custom implementations: MyString, StringMap (hash map), IntArray, BoolArray, StringPtrArray, ProblemPtrArray, UserMap
  • JSON Parser & Builder — hand-written JSON parsing (HttpRequest) and serialization (JsonBuilder)
  • Session-based Auth — random token generation, cookie-based sessions stored in VFS

OOP Concepts Demonstrated

  • InheritanceISerializable interface, FileSystemEntityFile/Directory, StorageMedium hierarchy
  • Polymorphism — virtual functions in VFS entities, serializable interface
  • Encapsulation — private members with public getters/setters throughout
  • CompositionVolume contains StorageMedium contains Partition contains Directory/File
  • Operator OverloadingMyString assignment operator, copy constructors
  • Abstract ClassesISerializable with pure virtual serialize()/deserialize()

Architecture

├── main.cpp                 # Entry point, wires everything together
├── CMakeLists.txt           # Build configuration
├── vfs/                     # Virtual File System (core OOP showcase)
│   ├── Volume.h/cpp         # Top-level container
│   ├── StorageMedium.h/cpp  # Disk abstraction
│   ├── Partition.h/cpp      # Partition with filesystem type
│   ├── Directory.h/cpp      # Directory node
│   ├── File.h/cpp           # File node with content
│   ├── Permission.h/cpp     # rwx permission model
│   └── User.h/cpp           # VFS user (not app user)
├── domain/                  # Data models
│   ├── Problem.h/cpp        # Problem with test cases
│   ├── TestCase.h/cpp       # Input/expected output pair
│   └── Submission.h/cpp     # Code + verdict + details
├── logic/                   # Business logic
│   ├── EvaluationEngine.h/cpp  # Compile + run + judge
│   ├── UserManager.h/cpp       # Registration, login, sessions
│   ├── ProblemBank.h/cpp       # 50 seeded problems
│   ├── ContestManager.h/cpp    # Contest lifecycle + scoring
│   └── PersistenceManager.h/cpp # VFS read/write helper
├── server/                  # HTTP layer
│   ├── HttpServer.h/cpp     # Winsock2 accept loop
│   ├── HttpRequest.h/cpp    # Parse method/path/headers/body/JSON
│   ├── HttpResponse.h/cpp   # Status codes, headers, file serving
│   ├── Router.h/cpp         # URL routing + static files
│   ├── ApiHandlers.h/cpp    # All REST endpoints
│   └── JsonBuilder.h/cpp    # JSON response construction
├── ds/                      # Custom data structures
│   ├── MyString.h           # Dynamic string (no std::string)
│   ├── StringMap.h          # Hash map (string → string*)
│   ├── IntArray.h           # Dynamic int array
│   ├── BoolArray.h          # Dynamic bool array
│   ├── StringPtrArray.h     # Dynamic MyString* array
│   └── ProblemPtrArray.h    # Dynamic Problem* array
├── interfaces/
│   └── ISerializable.h      # Pure virtual serialize/deserialize
└── frontend/                # Web UI
    ├── index.html           # Redirects to login
    ├── login.html           # Dual-panel sliding auth
    ├── verify.html          # Email verification
    ├── dashboard.html       # Contest start + history
    ├── problems.html        # Problem browser with filters
    ├── editor.html          # Code editor + submission
    ├── post-contest.html    # Contest results
    ├── solutions.html       # Saved solutions viewer
    ├── style.css            # Global theme (dark hacker terminal)
    ├── app.js               # Shared utilities (fetch, auth, toast)
    ├── editor.js            # Code editor with syntax highlighting
    └── timer.js             # Contest countdown timer

Build & Run

Prerequisites

  • Any OS: Windows 10/11, Linux (Ubuntu/Fedora/Arch/etc.), or macOS
  • C++17 compiler: g++ (6.3+) or clang++ — must be on system PATH (g++ --version should work in terminal)
  • CMake (3.15+) — only needed for the CMake build path

Build (Option A: Makefile)

Windows (MinGW):

mingw32-make

Linux / macOS:

make

Produces judge.exe (Windows) or judge (Linux/macOS) in project root.

Build (Option B: CMake)

Windows (MinGW):

mkdir build && cd build
cmake .. -G "MinGW Makefiles"
cmake --build . --target judge

Linux / macOS:

mkdir -p build && cd build
cmake ..
cmake --build . --target judge

Produces the judge binary in build/.

Run

./judge        # Linux/macOS
./judge.exe    # Windows

Server starts on http://localhost:8080. Opens browser automatically.

First Run

  • VFS is created fresh with 50 seeded problems
  • Register an account, verify with displayed code, login
  • Start practicing or enter a contest

API Endpoints

Method Path Description
POST /api/auth/register Create account
POST /api/auth/verify Verify email token
POST /api/auth/login Login (sets cookie)
POST /api/auth/logout Logout
GET /api/user/profile Current user info
GET /api/problems List all problems
GET /api/problems/:id Problem details
POST /api/practice/submit Submit practice solution
POST /api/contest/start Start timed contest
GET /api/contest/status Active contest info
GET /api/contest/problems Contest problem set
POST /api/contest/submit Submit contest solution
POST /api/contest/save Save code draft
POST /api/contest/end End contest early
GET /api/contest/history Past contest results
GET /api/solutions User's saved solutions

Scoring System

  • Base score per problem: difficulty * 50
  • Time bonus: decreases as more time passes
  • Wrong attempt penalty: -10 per failed submission
  • Final score: sum of all problem scores in contest

Security Measures

  • Directory traversal prevention (.. in paths rejected)
  • No path reflection in error responses (XSS prevention)
  • Password stored as-is (educational project, not production)
  • Session tokens: 6-digit random
  • 5-second execution timeout prevents infinite loops
  • Process isolation: CREATE_NO_WINDOW on Windows, fork()/exec() on Linux/macOS

Known Limitations

  • Single-threaded server (one request at a time)
  • No HTTPS
  • No persistent sessions across server restarts (VFS saves but sessions are in-memory)

Troubleshooting

Problem Solution
g++ not found or compiler check fails at startup Ensure g++ or clang++ is on your system PATH. Run g++ --version in terminal to verify. On macOS, install Xcode Command Line Tools: xcode-select --install.
Port 8080 already in use / bind fails Another process is using port 8080. Close it or wait a moment after previous server shutdown. Windows: netstat -ano | findstr 8080. Linux/macOS: lsof -i :8080.
Browser doesn't open automatically Manually navigate to http://localhost:8080. Auto-open uses ShellExecuteA (Windows), xdg-open (Linux), or open (macOS).
Server exits immediately with no output Check that data/ directory is writable. Try running from the project root directory (where main.cpp lives).
Existing accounts don't work after rebuild Delete data/volume.vfs to reset — password hashing may have changed between builds.

About

A complete Online Judge built in C++ without any external libraries. Handles raw socket parsing, JSON building, and secure code execution from the ground up.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors