# kanavgoyal898/arx architecture

> Architecture diagram of the GitHub repository kanavgoyal898/arx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kanavgoyal898/arx
- Repository: https://github.com/kanavgoyal898/arx

## Overview

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`](https://github.com/kanavgoyal898/arx/blob/main/schema.sql) (SQLite schema), [`app/page.tsx`](https://github.com/kanavgoyal898/arx/blob/main/app/page.tsx) (Route pages), [`lib/judge.ts`](https://github.com/kanavgoyal898/arx/blob/main/lib/judge.ts) (Judge core), [`app/api/auth/login/route.ts`](https://github.com/kanavgoyal898/arx/blob/main/app/api/auth/login/route.ts) (Auth API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web App"]
  node_app_shell["App shell<br/>Next.js app<br/>[layout.tsx]"]
  node_route_pages["Route pages<br/>App Router pages<br/>[page.tsx]"]
  node_shared_components["Shared UI<br/>UI components<br/>[NavigationBar.tsx]"]
end

subgraph group_api["HTTP API"]
  node_auth_api["Auth API<br/>auth routes<br/>[route.ts]"]
  node_problem_api["Problem API<br/>problem routes<br/>[route.ts]"]
  node_submission_api["Submission API<br/>submission routes<br/>[route.ts]"]
  node_profile_activity_api["Profile & activity API<br/>user workflow routes<br/>[route.ts]"]
  node_admin_api["Admin API<br/>admin routes<br/>[route.ts]"]
end

subgraph group_core["Core Logic"]
  node_auth_lib["Auth core<br/>session and hashing<br/>[auth.ts]"]
  node_middleware["Access control<br/>route guard<br/>[middleware.ts]"]
  node_judge_core["Judge core<br/>execution pipeline<br/>[judge.ts]"]
  node_language_consts["Language config<br/>judge constants<br/>[languages.ts]"]
  node_roles_consts["Role model<br/>access constants<br/>[roles.ts]"]
  node_problem_consts["Problem model<br/>domain constants<br/>[problem.ts]"]
end

subgraph group_data["Data & Fixtures"]
  node_schema[("SQLite schema<br/>database schema<br/>[schema.sql]")]
  node_seed["Seed data<br/>bootstrap data<br/>[seed.ts]"]
  node_fixtures["Testcases<br/>local fixtures<br/>[three-sum.cpp]"]
end

subgraph group_sandbox["Execution Sandbox"]
  node_docker_runtime["Docker runner<br/>sandbox runner<br/>[docker.ts]"]
  node_docker_images["Docker images<br/>language sandboxes"]
end

node_app_shell -->|"renders"| node_shared_components
node_route_pages -->|"uses"| node_shared_components
node_route_pages -->|"calls"| node_auth_api
node_route_pages -->|"calls"| node_problem_api
node_route_pages -->|"calls"| node_submission_api
node_route_pages -->|"calls"| node_profile_activity_api
node_route_pages -->|"calls"| node_admin_api
node_middleware -->|"verifies"| node_auth_lib
node_auth_api -->|"uses"| node_auth_lib
node_auth_api -->|"reads/writes"| node_schema
node_problem_api -->|"reads/writes"| node_schema
node_submission_api -->|"reads/writes"| node_schema
node_profile_activity_api -->|"reads/writes"| node_schema
node_admin_api -->|"updates"| node_schema
node_submission_api -->|"dispatches"| node_judge_core
node_judge_core -->|"runs in"| node_docker_runtime
node_docker_runtime -->|"selects"| node_docker_images
node_judge_core -->|"configures"| node_language_consts
node_problem_api -->|"validates"| node_problem_consts
node_middleware -->|"enforces"| node_roles_consts
node_judge_core -->|"persists"| node_schema
node_profile_activity_api -->|"aggregates"| node_schema
node_seed -.->|"initializes"| node_schema
node_fixtures -.->|"supports"| node_judge_core

click node_app_shell "https://github.com/kanavgoyal898/arx/blob/main/app/layout.tsx"
click node_route_pages "https://github.com/kanavgoyal898/arx/blob/main/app/page.tsx"
click node_shared_components "https://github.com/kanavgoyal898/arx/blob/main/app/components/NavigationBar.tsx"
click node_auth_api "https://github.com/kanavgoyal898/arx/blob/main/app/api/auth/login/route.ts"
click node_problem_api "https://github.com/kanavgoyal898/arx/blob/main/app/api/problems/route.ts"
click node_submission_api "https://github.com/kanavgoyal898/arx/blob/main/app/api/submissions/route.ts"
click node_profile_activity_api "https://github.com/kanavgoyal898/arx/blob/main/app/api/activity/route.ts"
click node_admin_api "https://github.com/kanavgoyal898/arx/blob/main/app/api/admin/setters/route.ts"
click node_auth_lib "https://github.com/kanavgoyal898/arx/blob/main/lib/auth.ts"
click node_middleware "https://github.com/kanavgoyal898/arx/blob/main/middleware.ts"
click node_judge_core "https://github.com/kanavgoyal898/arx/blob/main/lib/judge.ts"
click node_language_consts "https://github.com/kanavgoyal898/arx/blob/main/lib/constants/languages.ts"
click node_roles_consts "https://github.com/kanavgoyal898/arx/blob/main/lib/constants/roles.ts"
click node_problem_consts "https://github.com/kanavgoyal898/arx/blob/main/lib/constants/problem.ts"
click node_docker_runtime "https://github.com/kanavgoyal898/arx/blob/main/lib/docker.ts"
click node_docker_images "https://github.com/kanavgoyal898/arx/tree/main/docker/c/Dockerfile"
click node_schema "https://github.com/kanavgoyal898/arx/blob/main/schema.sql"
click node_seed "https://github.com/kanavgoyal898/arx/blob/main/seed.ts"
click node_fixtures "https://github.com/kanavgoyal898/arx/blob/main/testcases/three-sum.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_shell,node_route_pages,node_shared_components toneBlue
class node_auth_api,node_problem_api,node_submission_api,node_profile_activity_api,node_admin_api toneAmber
class node_auth_lib,node_middleware,node_judge_core,node_language_consts,node_roles_consts,node_problem_consts toneMint
class node_schema,node_seed,node_fixtures toneRose
class node_docker_runtime,node_docker_images toneIndigo
```

## Components

### Web App

Next.js routes, pages, and shared UI

- [App shell](https://github.com/kanavgoyal898/arx/blob/main/app/layout.tsx): Next.js app · Root layout, global styles, and home page composition · `app/layout.tsx`
- [Route pages](https://github.com/kanavgoyal898/arx/blob/main/app/page.tsx): App Router pages · Login, signup, problems, submissions, profile, activity, admin, and set pages · `app/page.tsx`
- [Shared UI](https://github.com/kanavgoyal898/arx/blob/main/app/components/NavigationBar.tsx): UI components · Navigation, sidebar, tables, editor, and local component primitives · `app/components/NavigationBar.tsx`

### HTTP API

Route handlers that expose the backend

- [Auth API](https://github.com/kanavgoyal898/arx/blob/main/app/api/auth/login/route.ts): auth routes · Login, logout, signup, and current-user session endpoints · `app/api/auth/login/route.ts`
- [Problem API](https://github.com/kanavgoyal898/arx/blob/main/app/api/problems/route.ts): problem routes · Problem listing and per-problem read/update endpoints · `app/api/problems/route.ts`
- [Submission API](https://github.com/kanavgoyal898/arx/blob/main/app/api/submissions/route.ts): submission routes · Submission listing, detail, and solve submission entrypoint · `app/api/submissions/route.ts`
- [Profile & activity API](https://github.com/kanavgoyal898/arx/blob/main/app/api/activity/route.ts): user workflow routes · Profile pages, activity dashboard, setter actions, and upload handling · `app/api/activity/route.ts`
- [Admin API](https://github.com/kanavgoyal898/arx/blob/main/app/api/admin/setters/route.ts): admin routes · Setter management endpoints for administrators · `app/api/admin/setters/route.ts`

### Core Logic

Auth, authorization, judging, and shared constants

- [Auth core](https://github.com/kanavgoyal898/arx/blob/main/lib/auth.ts): session and hashing · Password hashing, token creation/verification, and edge auth checks · `lib/auth.ts`
- [Access control](https://github.com/kanavgoyal898/arx/blob/main/middleware.ts): route guard · Pre-request auth and role enforcement for protected pages and APIs · `middleware.ts`
- [Judge core](https://github.com/kanavgoyal898/arx/blob/main/lib/judge.ts): execution pipeline · Queueing, compilation, execution, and verdict orchestration · `lib/judge.ts`
- [Language config](https://github.com/kanavgoyal898/arx/blob/main/lib/constants/languages.ts): judge constants · Supported languages and judge/runtime settings · `lib/constants/languages.ts`
- [Role model](https://github.com/kanavgoyal898/arx/blob/main/lib/constants/roles.ts): access constants · Solver, setter, and admin permissions · `lib/constants/roles.ts`
- [Problem model](https://github.com/kanavgoyal898/arx/blob/main/lib/constants/problem.ts): domain constants · Problem visibility, limits, and validation rules · `lib/constants/problem.ts`

### Data & Fixtures

Database schema and local support files

- [SQLite schema](https://github.com/kanavgoyal898/arx/blob/main/schema.sql): database schema · System-of-record tables for users, problems, submissions, and sessions · `schema.sql`
- [Seed data](https://github.com/kanavgoyal898/arx/blob/main/seed.ts): bootstrap data · Initial data population for local setup · `seed.ts`
- [Testcases](https://github.com/kanavgoyal898/arx/blob/main/testcases/three-sum.cpp): local fixtures · Sample inputs and reference problem material · `testcases/three-sum.cpp`

### Execution Sandbox

Language containers used to run user code

- [Docker runner](https://github.com/kanavgoyal898/arx/blob/main/lib/docker.ts): sandbox runner · Container execution and language-specific runtime wiring · `lib/docker.ts`
- [Docker images](https://github.com/kanavgoyal898/arx/tree/main/docker/c/Dockerfile): language sandboxes · C, C++, and Python execution images · `docker/c/Dockerfile`

## Connections

- 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
