# qingdaou/onlinejudge architecture

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

- Interactive diagram: https://gitdiagram.com/qingdaou/onlinejudge
- Repository: https://github.com/qingdaou/onlinejudge

## Overview

##### Main Components
- Backend/Django Application: Represented by the core Django project found in folders like “oj” (settings, urls, wsgi) and several Django apps such as “account”, “announcement”, “conf”, “contest”, “problem”, “submission”, “judge”, “options”, etc. Each of these modules represents distinct domains (e.g., user management, contest operations, problem management, judging processes).
- Database: Although it is not directly visible in the file tree, the presence of Django migrations in nearly every app implies that a relational database (such as PostgreSQL or MySQL) is used via Django’s ORM.
- Judger/JudgeServer Integration: The “judge” and “fps” folders indicate that there is a subsystem dedicated to the judging process which handles code dispatching, language support, and possibly sandboxing.
- Deployment Infrastructure: Files such as “Dockerfile”, the “deploy” directory (with Docker Compose files, Nginx configuration, etc.), and scripts like “init_db.sh” show that deployment is containerized and managed with Docker. There is also infrastructure for reverse proxying (Nginx) and process supervision (supervisord).

##### Relationships and Interactions
- The Frontend (a separate Vue project, as referenced in the README) communicates with the backend via REST APIs. These APIs are routed through Django’s URL configurations (varied in each app like “account/urls”, “contest/urls”, “problem/urls”, etc.).
- The backend handles business logic across several modules and interacts with a central database using ORM models defined in each Django app.
- When a user submits a solution, the backend triggers a chain of actions that employs the judging subsystem (modules under “judge” and “fps”) to compile, run, and test code. This might be executed as asynchronous tasks (e.g., via “tasks.py” in several apps and “utils/tasks.py”).
- Deployment scripts and configuration files in the “deploy” directory ensure that the whole system (backend, judge services, data storage, etc.) is containerized and properly orchestrated.

##### Architectural Patterns and Design Principles
- Modular and Microservice Approach: The project separates functionality into multiple Django apps (each with their own models, views, serializers, and URLs) and even separates components into different repositories (backend, frontend, judger, etc.) indicating a loosely coupled architecture.
- Separation of Concerns: Distinct modules handle authentication (“account”), contests (“contest”), problems (“problem”) and submissions (“submission”), while the judging and testing logic is isolated (in “judge”, “fps”, etc.).
- Containerized Deployment: The use of Docker and separate deployment directories implies that environment isolation and easy deployment are key engineering aspects.

- Key technologies or libraries (e.g., “Django REST Framework”, “Celery or similar for asynchronous tasks” if applicable, “Nginx”, “Docker”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        FE["Vue Frontend"]:::frontend
    end

    %% Backend Layer (Django Application)
    subgraph "Backend (Django)"
        BE["Backend/Django Application"]:::backend
        ACC["account\n(User & Session Management)"]:::backend
        ANN["announcement\n(System Announcements)"]:::backend
        CONF["conf\n(Configuration)"]:::backend
        CONTEST["contest\n(Contest Management)"]:::backend
        PROB["problem\n(Problem Management)"]:::backend
        SUB["submission\n(Submission Handling)"]:::backend
        JUDGE["judge\n(Judging Process)"]:::judging
        FPS["fps\n(Judging Auxiliary)"]:::judging
        OPTIONS["options\n(Miscellaneous Options)"]:::backend
        UTILS["utils\n(Common Utilities)"]:::backend
    end

    %% Database Component
    subgraph "Database"
        DB["Relational Database"]:::database
    end

    %% Deployment Infrastructure
    subgraph "Deployment Infrastructure"
        DOCKER["Docker Containerization"]:::deploy
        DEPLOY["Deployment Scripts & Configs"]:::deploy
    end

    %% Connections
    FE -->|"API_calls"| BE
    BE -->|"ORM_CRTD"| DB

    %% Internal Backend Component Relationships
    BE --> ACC
    BE --> ANN
    BE --> CONF
    BE --> CONTEST
    BE --> PROB
    BE --> SUB
    BE --> OPTIONS
    BE --> UTILS

    SUB -->|"submit_for_judging"| JUDGE
    JUDGE -->|"utilizes_aux"| FPS
    JUDGE -->|"returns_results"| SUB

    %% Deployment Flow
    BE -->|"deployed_in"| DOCKER
    DOCKER -->|"configured_by"| DEPLOY

    %% Styles
    classDef frontend fill:#ffadad,stroke:#d62728,stroke-width:2px;
    classDef backend fill:#cce5ff,stroke:#2e6da4,stroke-width:2px;
    classDef judging fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef database fill:#d4edda,stroke:#34a853,stroke-width:2px;
    classDef deploy fill:#fddde6,stroke:#c0392b,stroke-width:2px;

    %% Click Events
    click BE "https://github.com/qingdaou/onlinejudge/tree/master/oj/"
    click ACC "https://github.com/qingdaou/onlinejudge/tree/master/account/"
    click ANN "https://github.com/qingdaou/onlinejudge/tree/master/announcement/"
    click CONF "https://github.com/qingdaou/onlinejudge/tree/master/conf/"
    click CONTEST "https://github.com/qingdaou/onlinejudge/tree/master/contest/"
    click PROB "https://github.com/qingdaou/onlinejudge/tree/master/problem/"
    click SUB "https://github.com/qingdaou/onlinejudge/tree/master/submission/"
    click JUDGE "https://github.com/qingdaou/onlinejudge/tree/master/judge/"
    click FPS "https://github.com/qingdaou/onlinejudge/tree/master/fps/"
    click OPTIONS "https://github.com/qingdaou/onlinejudge/tree/master/options/"
    click UTILS "https://github.com/qingdaou/onlinejudge/tree/master/utils/"
    click DOCKER "https://github.com/qingdaou/onlinejudge/tree/master/Dockerfile"
    click DEPLOY "https://github.com/qingdaou/onlinejudge/tree/master/deploy/"
```
