How kanavgoyal898/arx works
1. Overall shape
arX is a monolithic Next.js App Router application that combines the web UI, HTTP API, auth, and judge orchestration in one codebase. The main external dependency boundaries are SQLite for persistence and Docker for safe code execution.
2. User-facing routes
The UI is split into route groups for the major workflows: browsing problems, solving and submitting, viewing submission history, creating problems, reviewing activity, and admin management. The top-level pages under app/ are thin route entry points that compose shared components from app/components/ and components/ui/.
3. API-first backend
Most business logic is exposed through route handlers in app/api/*. These cover auth, problems, profiles, submissions, solve/judge, activity, admin setter management, and upload. The frontend pages likely call these endpoints rather than talking directly to the database.
4. Authentication and session boundary
Authentication is custom, not outsourced to an identity provider. lib/auth.ts and lib/auth.edge.ts manage password hashing, token creation/verification, and edge-compatible auth checks. Sessions are stored in HTTP-only cookies, which are then read by route handlers and middleware.
5. Authorization and route protection
middleware.ts enforces access control before requests reach protected pages or APIs. The role model is central to the architecture: solver, setter, and admin determine whether a user can browse only, create problems, or manage system-wide settings.
6. Problem management subsystem
Problems are a first-class domain object exposed through /api/problems and rendered via /problems and /problems/[slug]. The model includes title, statement, time/memory limits, visibility, deadlines, sample vs hidden test cases, and per-test weights. Visibility is not just public/private in the abstract; private problems are tied to allowed user emails.
7. Submission and judging pipeline
User code enters through the solve/submission APIs, then flows into a judge pipeline coordinated by lib/judge.ts, lib/queue.ts, and lib/docker.ts. This is the core execution path: source code is received, queued or processed, compiled/run, and verdicts plus logs are persisted for later display in submission history and problem activity views.
8. Sandboxed execution boundary
Execution is isolated in Docker containers using language-specific images under docker/. The repo supports C, C++, and Python, with compile/run commands and image selection driven by lib/constants/languages.ts. This boundary is important: the app never executes user code directly in Node.js.
9. Activity and setter workflows
Setters and admins get a higher-level activity dashboard at /activity backed by /api/activity. This subsystem aggregates creator-centric problem stats, submission counts, per-user summaries, and actions like editing problem metadata, clearing submissions, deleting problems, and inspecting submitted source code.
10. Admin management subsystem
The admin panel at /admin/setters and /api/admin/setters manages the setter allowlist. This is a lightweight governance layer: admins can promote or revoke setter access, and the effect is applied to registered users immediately or to future signups.
11. Persistence model
The repo uses SQLite as the system of record, initialized from schema.sql and optionally populated with seed.ts. That database likely stores users, roles, sessions, problems, test cases, submissions, allowed emails, and activity-related aggregates or references.
12. Shared application infrastructure
Cross-cutting helpers live in lib/ and hooks/. The shared UI layer is built from local shadcn-style components in components/ui/, while higher-level tables, editors, and navigation live in app/components/. useCurrentUser suggests the frontend reads session state from the auth APIs to personalize navigation and page access.
13. Static assets and local fixtures
testcases/ contains sample solution/problem inputs for supported languages, which likely serve as local fixtures or bootstrap material rather than runtime data. setup.sh and the Dockerfiles indicate this is designed to be self-hosted and brought up with a reproducible local bootstrap path.
14. Key end-to-end flow
A typical request path is: browser hits a protected route, middleware checks auth/role, the page calls an API route, the API reads/writes SQLite, and for submissions it hands execution to the judge layer, which runs code inside Docker and returns verdicts and logs back to the database for the UI to render.
Main entry points: schema.sql SQLite schema · page.tsx Route pages · judge.ts Judge core · route.ts Auth API
Components 19
Web App
Next.js routes, pages, and shared UI
- App shell · Root layout, global styles, and home page composition
app/layout.tsx - Route pages · Login, signup, problems, submissions, profile, activity, admin, and set pages
app/page.tsx - Shared UI · Navigation, sidebar, tables, editor, and local component primitives
app/components/NavigationBar.tsx
HTTP API
Route handlers that expose the backend
- Auth API · Login, logout, signup, and current-user session endpoints
app/api/auth/login/route.ts - Problem API · Problem listing and per-problem read/update endpoints
app/api/problems/route.ts - Submission API · Submission listing, detail, and solve submission entrypoint
app/api/submissions/route.ts - Profile & activity API · Profile pages, activity dashboard, setter actions, and upload handling
app/api/activity/route.ts - Admin API · Setter management endpoints for administrators
app/api/admin/setters/route.ts
Core Logic
Auth, authorization, judging, and shared constants
- Auth core · Password hashing, token creation/verification, and edge auth checks
lib/auth.ts - Access control · Pre-request auth and role enforcement for protected pages and APIs
middleware.ts - Judge core · Queueing, compilation, execution, and verdict orchestration
lib/judge.ts - Language config · Supported languages and judge/runtime settings
lib/constants/languages.ts - Role model · Solver, setter, and admin permissions
lib/constants/roles.ts - Problem model · Problem visibility, limits, and validation rules
lib/constants/problem.ts
Data & Fixtures
Database schema and local support files
- SQLite schema · System-of-record tables for users, problems, submissions, and sessions
schema.sql - Seed data · Initial data population for local setup
seed.ts - Testcases · Sample inputs and reference problem material
testcases/three-sum.cpp
Execution Sandbox
Language containers used to run user code
- Docker runner · Container execution and language-specific runtime wiring
lib/docker.ts - Docker images · C, C++, and Python execution images
docker/c/Dockerfile
Connections 24
- App shell → Shared UI: renders · Root layout composes shared navigation and UI chrome
- Route pages → Shared UI: uses · Pages assemble reusable tables, editors, and nav elements
- Route pages → Auth API: calls · Login and signup flows consume auth endpoints
- Route pages → Problem API: calls · Problem listing and detail pages load problem data
- Route pages → Submission API: calls · Submission history and solve pages read/write submissions
- Route pages → Profile & activity API: calls · Profile, activity, and setter workflows use these endpoints
- Route pages → Admin API: calls · Admin settings page uses setter management endpoints
- Access control → Auth core: verifies · Middleware checks session state and user identity
- Auth API → Auth core: uses · Auth handlers create, verify, and clear sessions
- Auth API → SQLite schema: reads/writes · Users and sessions are stored in SQLite
- Problem API → SQLite schema: reads/writes · Problem metadata and visibility rules persist in SQLite
- Submission API → SQLite schema: reads/writes · Submissions and verdicts are persisted for history views
- Profile & activity API → SQLite schema: reads/writes · Activity and profile views aggregate database records
- Admin API → SQLite schema: updates · Setter allowlist and role changes are stored in SQLite
- Submission API → Judge core: dispatches · New solves enter the judge pipeline
- Judge core → Docker runner: runs in · Judge delegates compilation and execution to containers
- Docker runner → Docker images: selects · Language-specific Dockerfiles define execution environments
- Judge core → Language config: configures · Supported languages and commands drive compilation/run steps
- Problem API → Problem model: validates · Problem limits, visibility, and submission rules are enforced
- Access control → Role model: enforces · Role gates distinguish solver, setter, and admin access
- Judge core → SQLite schema: persists · Verdicts, logs, and judge outcomes are stored for later display
- Profile & activity API → SQLite schema: aggregates · Activity dashboard summarizes user, problem, and submission data
- Seed data → SQLite schema: initializes · Seed script can populate the database on setup
- Testcases → Judge core: supports · Local testcase files help exercise the judge pipeline