An immersive, assessment-first coding evaluation and contest platform built with Next.js 14 (App Router), Monaco Editor, Prisma ORM, and Supabase (PostgreSQL), featuring decoupled cloud sandboxed execution and real-time proctoring.
The legacy implementation used a two-tier architecture consisting of a Create React App (CRA) frontend on port 3000 and an Express backend on port 3001 that spawned local Docker containers via docker run.
-
Host-Dependent Local Docker Requirement:
- The backend required Docker Desktop to be actively running on the host machine. If Docker was not installed or the daemon was inactive, the backend crashed immediately with:
Error: spawn docker ENOENT - It required manual compilation of 5 distinct language images (
docker build -t coding-judge-python judge/images/python, etc.), creating massive friction for setup and maintenance.
- The backend required Docker Desktop to be actively running on the host machine. If Docker was not installed or the daemon was inactive, the backend crashed immediately with:
-
Physically Incompatible with Vercel and Serverless Hosting:
- Vercel executes code inside ephemeral serverless micro-functions (AWS Lambda / Firecracker micro-VMs).
- Serverless runtimes are strictly sandboxed: no background Docker daemon (
dockerd), no root access, no access to/var/run/docker.sock, and nested virtualization (Docker-in-Docker) is completely prohibited. - Vercel serverless functions have a 10β15s execution timeout and a read-only filesystem (except a 512MB
/tmp). Pulling or building multi-gigabyte Docker images inside a serverless lambda is fundamentally impossible. - As a result, the old architecture could never be deployed to Vercel on any plan (Free or Paid).
-
Single-Host Resource Saturation:
- Running
docker rundirectly on the host server meant every participant submission consumed host CPU cores and memory. Under concurrent assessment conditions, multiple submissions saturated the server, causing timeouts and host crashes.
- Running
-
Cross-Platform CRLF / Line-Ending Failures:
- On Windows machines, Git auto-converted line endings to CRLF, breaking the internal Linux bash execution scripts inside containers (
/bin/sh: 1: /usr/local/bin/compile: not found).
- On Windows machines, Git auto-converted line endings to CRLF, breaking the internal Linux bash execution scripts inside containers (
-
Security & State Leaks:
- The old architecture lacked persistent database user isolation and server-side test case masking. Test cases were often returned unmasked to the frontend, allowing participants to inspect hidden test inputs in browser developer tools.
To solve these limitations, the platform was re-architected into a unified, serverless-ready Next.js full-stack system:
[ Participant / Admin Browser ]
β
βΌ (HTTPS)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js 14 Full-Stack Layer (Vercel) β
β β
β βββ Edge Middleware (src/middleware.js) β
β β βββ Blocks unauthenticated access to all features β
β βββ Pages (App Router: /login, /problems, /admin) β
β β βββ Dynamic UI visibility based on user session β
β βββ Serverless API Handlers (/api/run, /api/submit) β
β βββ Authenticates session cookies β
β βββ Queries Supabase via Prisma ORM β
β βββ Sanitizes & masks hidden evaluation cases β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββββββββββ
β β
(Outbound HTTPS JSON) (Connection Pooler)
β β
βΌ βΌ
ββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββ
β Cloud Execution Sandbox β β Supabase Cloud Database β
β (Judge0 CE / Remote Cluster) β β (PostgreSQL + Prisma) β
β β β β
β β’ Containerized Compilers β β β’ Isolated User Drafts β
β β’ Python, C, C++, Java, JS β β β’ Hidden & Public Tests β
β β’ Zero host dependencies β β β’ Submission Audit History β
β β’ 100% OS & Vercel-ready β β β’ User Credentials & Roles β
ββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββ
-
Decoupled Cloud Sandbox Execution (Judge0 CE):
- Execution is offloaded to containerized cloud sandboxes over secure REST APIs.
- Zero Host Dependencies: Requires no Docker, no local compilers, and works uniformly across Windows, macOS, Linux, and Vercel Serverless Functions.
- Automatic native compiler fallback is preserved for offline development.
-
Persistent Cloud Database (Supabase + Prisma):
- User-Scoped Code Drafts: Uniquely indexed by
(problemId, userId, language)with a 64KB safety limit and deduplicated writes (upsert) to prevent database bloat. - User Isolation: Participant 1 and Participant 2 maintain separate drafts and submission histories with zero data bleed.
- User-Scoped Code Drafts: Uniquely indexed by
-
Strict Hidden Test Case Protection:
- Database Level: Public problem APIs strictly query
where: { isHidden: false }. Hidden evaluation cases never appear in the client network payload. - Execution Level: During "Submit", hidden cases are executed server-side.
- Exfiltration Defense: All outputs (
input,expected,stdout) for hidden test cases are strictly sanitized tonullbefore sending responses back to the browser. Malicious attempts to dump inputs viaprint(sys.stdin.read())are completely neutralized.
- Database Level: Public problem APIs strictly query
-
Global Edge Authentication Middleware (
src/middleware.js):- All platform features (Contests, Problems, Editor, Submissions, Admin CMS) are completely locked behind authentication.
- Unauthenticated visitors are immediately redirected (
307) to/login. - Unauthenticated API calls return
401 Unauthorized. - Non-admin participants attempting to access
/adminor/api/admin/*are blocked with403 Forbidden.
-
Comprehensive Proctoring & Anti-Cheat:
- Zero Pre-existing Code: Editor opens completely empty (
'') unless an explicit saved draft exists. - Copy & Paste Strictly Blocked: Context menus disabled, clipboard events (
paste,copy,cut) intercepted, keyboard shortcuts (Ctrl+C,Ctrl+V,Cmd+C,Cmd+V,Ctrl+X) blocked with live warning toasts. - 3-Strike Tab Switch Detection: Document visibility loss triggers persistent violation warnings. The 3rd strike locks the editor and auto-submits the assessment.
- Active Session Countdown Timer: Counts down exclusively while the participant is engaged in the problem editor (never depletes in the background).
- One-Time Problem Solving Lock: Once a problem is evaluated as
Accepted(100% score), it is permanently locked for that participant (Solved β), preventing re-attempts while other participants maintain an isolated fresh state. - Unified Submissions & In-Progress Drafts (
/submissions): Displays evaluated submissions alongside active in-progress drafts, complete with status tags (Accepted,In-Progress Draft,Wrong Answer,Time Limit Exceeded), a modal code inspector, and directContinue Solving βbuttons.
- Zero Pre-existing Code: Editor opens completely empty (
The platform is pre-seeded with beginner-friendly arithmetic and logic challenges:
| Problem | Slug | Description | Function / Standard I/O |
|---|---|---|---|
| Add Two Numbers | add-two-numbers |
Given integers |
add(a, b) or a + b
|
| Multiply Two Numbers | multiply-two-numbers |
Given integers |
multiply(a, b) or a * b
|
| Even or Odd | even-or-odd |
Return "Even" or "Odd" for integer |
evenOrOdd(n) or logic |
| Maximum of Two Numbers | maximum-of-two-numbers |
Return the larger of |
findMax(a, b) or max(a, b)
|
| Square of a Number | square-of-number |
Return |
square(n) or n * n
|
The platform is pre-seeded with dedicated assessment roles in Supabase:
| Account | Username | Password | Role | Redirect Target | Permissions |
|---|---|---|---|---|---|
| Participant 1 | 1 |
1 |
participant |
/problems |
Write code, save drafts, run & submit |
| Participant 2 | 2 |
2 |
participant |
/problems |
Separate isolated drafts & submissions |
| Administrator | osl-vvce |
OSL |
admin |
/admin |
Manage problems, test cases, and CMS |
Quick Login: The
/loginpage includes 1-click credential cards to instantly autofill and sign in as any of the three users.
- Node.js v18+ (tested with v20 and v24)
- npm v9+
- Git
- (No Docker or local compilers required!)
git clone https://github.com/AniruddhaMJois/coding-platform-ani.git
cd coding-platform-ani
git checkout ANInpm installCreate a .env file in the project root:
DATABASE_URL="postgresql://postgres.[YOUR_PROJECT]:[YOUR_PASSWORD]@aws-0-[REGION].pooler.supabase.com:6543/postgres?pgbouncer=true"
DIRECT_URL="postgresql://postgres.[YOUR_PROJECT]:[YOUR_PASSWORD]@aws-0-[REGION].pooler.supabase.com:5432/postgres"npx prisma generate
npx prisma db push- Development mode:
npm run dev
- Production mode:
npm run build npm start
Open http://localhost:3000 in your browser.
- Push your changes to GitHub on branch
ANI. - Go to Vercel and import the repository
coding-platform-ani. - In Project Settings β Environment Variables, add:
DATABASE_URL: Your Supabase transaction pooler connection string (port6543).DIRECT_URL: Your Supabase direct connection string (port5432).
- Click Deploy. Vercel will build the Next.js app and deploy serverless functions automatically.
coding-platform-ani/
βββ prisma/
β βββ schema.prisma # Database models (User, Problem, TestCase, Submission, CodeDraft)
βββ src/
β βββ middleware.js # Edge-level authentication & role routing guard
β βββ lib/
β β βββ prisma.js # Prisma Client singleton
β β βββ executor.js # Two-tier execution (Judge0 cloud sandbox + native fallback)
β β βββ realtime.js # SSE and BroadcastChannel event dispatcher
β βββ app/
β βββ layout.js # Root layout with dynamic user badges and Logout button
β βββ login/ # Assessment login portal with quick-login cards
β βββ problems/ # Problem catalog and practice environment
β β βββ [slug]/ # Monaco editor, anti-cheat, persistent drafts, timer
β βββ admin/ # Instructor CMS with live test case management
β βββ contests/ # Contests overview page
β βββ submissions/ # User-scoped submission history
β βββ api/
β βββ auth/ # Login, logout, session verification
β βββ problems/ # Public problem catalog (hidden cases excluded)
β βββ admin/ # Instructor problem and test case endpoints (role protected)
β βββ drafts/ # User-isolated 64KB draft saving
β βββ run/ # Sample case testing via cloud sandbox
β βββ submit/ # Full test suite evaluation with masked outputs
β βββ submissions/ # Submission logs filtered by user
βββ README.md
| Feature | Protection Mechanism |
|---|---|
| Authentication Wall | All features and API endpoints require login; unauthenticated traffic redirected to /login. |
| Hidden Test Cases | Masked at SQL query level; outputs (input, expected, stdout) sanitized to null on submit. |
| Copy & Paste | Context menu disabled; clipboard events and keyboard shortcuts blocked with warning toasts. |
| Tab Switching | Document visibility tracked with 3 strikes in sessionStorage; auto-submits on strike 3. |
| Timer Integrity | End timestamp stored in browser storage; surviving reloads and browser restarts. |
| Database Bloat | 64KB code draft cap with unique (problemId, userId, language) upsert deduplication. |
| Cloud Compatibility | Zero Docker dependency; runs natively on Vercel Serverless Functions. |