# vinkentli/online-judge architecture

> Architecture diagram of the GitHub repository vinkentli/online-judge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vinkentli/online-judge
- Repository: https://github.com/vinkentli/online-judge

## Overview

##### Main Components
- Server Component:
- server.js – This is the main entry point for the Node.js server that initializes the service.
- judge.js – Likely responsible for handling the judging process (invoking isolate and comparing output against expected testcases).
- Problems Management:
- The “problems” directory contains several helper scripts (getProblems.js, getServer.js, submit.js) and individual directories for each problem.
- Inside each problem folder (e.g., “problems/test”), you have frontend files (index.html, script.js, style.css) which provide a user interface for each problem.
- Each problem folder has a “testcases” subdirectory containing input/output pairs formatted consistently.
- There is also a “submissions” folder within problems/test where user submissions are stored.
- External Dependencies:
- “isolate” tool – Mentioned in the README, used for sandboxed execution. This is a crucial external service that must be depicted in the architecture.

##### Relationships and Data Flow
- Client/Browser:
- Users access a problem’s frontend pages (HTML/CSS/JavaScript) which display problem statements.
- Node.js Server:
- The server (server.js) receives HTTP requests. It is responsible for routing these requests to various components such as problem retrieval and submission processing.
- The server utilizes getProblems.js to organize available problems and getServer.js to configure or determine which problem server is running.
- Judge Module:
- When a submission is made, the process (likely triggered through submit.js on the frontend and handled by the server) calls judge.js, which then uses the external “isolate” tool to run the submission safely.
- The results are compared against expected outputs found in the “testcases” subdirectories.
- Data Flow:

##### Architectural Patterns and Technologies
- Layered Architecture:
- The separation between frontend assets (HTML/CSS/JS in each problem directory) and backend logic (server.js, judge.js) should be clearly depicted.
- Component-based Separation:
- Isolate the “Problems Module” (all scripts within the “problems” folder) which encapsulates problem content, testcases, and submission processes.
- Integration with External Services:
- Dependency on the external “isolate” tool; highlight that it runs via a system service (isolate.service mentioned in the README) on Linux.
- Environment Constraints:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        CLIENT["Client/Browser"]:::frontend
        PUI["Problem UI (index.html, script.js, style.css)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        SERVER["Node.js Server (server.js)"]:::backend
        JUDGE["Judge Module (judge.js)"]:::backend
        subgraph "Problems Helpers"
            GP["getProblems.js"]:::backend
            GS["getServer.js"]:::backend
            SUBMIT["submit.js"]:::backend
        end
    end

    %% External Services
    subgraph "External Services"
        ISOLATE["External Isolate Service"]:::external
    end

    %% Data Flow Connections
    CLIENT -->|"request"| SERVER
    SERVER -->|"serves UI"| PUI
    PUI -->|"submit_solution"| SUBMIT
    SERVER -->|"invokes"| JUDGE
    SERVER -->|"uses"| GP
    SERVER -->|"uses"| GS
    JUDGE -->|"calls"| ISOLATE
    ISOLATE -->|"returns_result"| JUDGE
    JUDGE -->|"sends_result"| SERVER
    SERVER -->|"notifies"| CLIENT

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;

    %% Click Events
    click SERVER "https://github.com/vinkentli/online-judge/blob/main/server.js"
    click JUDGE "https://github.com/vinkentli/online-judge/blob/main/judge.js"
    click GP "https://github.com/vinkentli/online-judge/blob/main/problems/getProblems.js"
    click GS "https://github.com/vinkentli/online-judge/blob/main/problems/getServer.js"
    click SUBMIT "https://github.com/vinkentli/online-judge/blob/main/problems/submit.js"
    click PUI "https://github.com/vinkentli/online-judge/tree/main/problems/test"
```
