# fossee/online_test architecture

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

- Interactive diagram: https://gitdiagram.com/fossee/online_test
- Repository: https://github.com/fossee/online_test

## Overview

##### Project type and purpose
- This is a full-stack, monolithic Django web application (“online_test”) that exposes both web pages (via Django templates and static assets) and a REST-style API, and supports interactive, language-agnostic programming quizzes.
- It features synchronous web interactions (course/quiz creation, browsing) and asynchronous code evaluation via Celery/Redis and an isolated code server.

##### Core components
a. Clients
- Web Browser (Teacher, Student, Admin)
- Optional: CLI or SDK consuming the REST API
b. Django Web Application
- online_test project (settings, URLs, WSGI entry point)
- Django apps (“yaksh” core, “api”, “grades”, “stats”, “upload”)
- Templates & static files (JavaScript, CSS, CodeMirror, TinyMCE)
c. Database
- Relational database (e.g., PostgreSQL/MySQL) storing users, courses, questions, submissions, grades
d. Message Broker / Cache
- Redis used as Celery broker and cache
e. Asynchronous Workers
- Celery worker processes (spawned via “celery -A online_test worker -B”)
- Periodic tasks (Beat scheduler) for regrading, notifications, email sending
f. Code Execution Service (“Code Server”)
- Containerized sandbox (Docker) or local unsafe server
- Exposes an API over HTTP or TCP for running user code in isolated environments
g. External services
- Email server (SMTP) for notifications, password resets
- Optional: Docker daemon for sandboxing

##### Interactions & data flow
1. User → Browser → HTTP request → Django Web App (Gunicorn/uWSGI)
– Authentication, page rendering (templates) or JSON API (api/serializers & views).
2. Quiz submission → Django view enqueues Celery task → message posted to Redis.
3. Celery worker subscribes to Redis → picks up evaluation task → requests code execution from Code Server → receives verdict → updates database.
4. Django Web App polls or listens (WebSockets or AJAX) to display results to user.
5. Periodic tasks (Beat) handle email reminders/regrading, using Redis scheduler → tasks.py/send_emails.py.
6. Admin interface uses built-in Django admin & custom admin apps (grades, stats).

##### Architectural patterns & design principles
- Modular monolith: independent Django apps (“yaksh” core, API, grading, stats, upload) arranged by feature.
- Asynchronous processing: Celery + Redis decouple user requests from compute-heavy evaluations.
- Microservice for sandboxing: Code Server isolated via Docker to securely execute untrusted code.
- Configuration & Deployment: Docker Compose orchestrates web, worker, Redis, code server; `.sampleenv`, `docker-compose.yml` for env vars & container setup.

##### Technologies & frameworks
- Backend: Python 3.6+, Django 3.0.3
- Asynchronous queue: Celery 4.4.2, Redis
- Containerization: Docker, Docker Compose
- Web assets: CodeMirror, TinyMCE, Bootstrap, jQuery
- Testing: pytest/unittest in `*-tests.py`, Django test runner
- Documentation: Sphinx (Yaksh docs), reStructuredText

##### Final checklist
- [ ] Annotations for tech stack (Django, Celery, Redis, Docker)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Web Browser\n(Teacher/Student/Admin)"]:::clients
        CLI["CLI/SDK"]:::clients
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        subgraph "Django Monolith" 
            direction TB
            Monolith["online_test Django App"]:::webapp
            subgraph "Project Config"
                manage["manage.py"]:::webapp
                settings["settings.py"]:::webapp
                testSettings["test_settings.py"]:::webapp
                urlsConf["urls.py"]:::webapp
                wsgi["wsgi.py"]:::webapp
                celeryConf["celery_settings.py"]:::webapp
            end
            subgraph "Apps"
                direction TB
                yakshApp["yaksh App"]:::webapp
                apiApp["api App"]:::webapp
                gradesApp["grades App"]:::webapp
                statsApp["stats App"]:::webapp
                uploadApp["upload App"]:::webapp
            end
            subgraph "Static & Templates"
                templates["Templates"]:::webapp
                staticFiles["Static Assets"]:::webapp
            end
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        db["Relational DB\n(PostgreSQL/MySQL)"]:::db
        redis["Redis\n(Broker & Cache)"]:::queue
        celeryWorkers["Celery Workers\n& Beat"]:::worker
        codeServer["Code Execution Service\n(Containerized)"]:::service
        smtp["SMTP Email Server"]:::external
        dockerDaemon["Docker Daemon"]:::external
    end

    %% Flow connections
    Browser -->|HTTP Requests| Monolith
    CLI -->|API Calls| Monolith
    Monolith -->|Reads/Writes| db
    Monolith -->|Cache/Broker| redis
    Monolith -->|Enqueue Task| celeryWorkers
    celeryWorkers -->|Dequeue Task| redis
    celeryWorkers -->|Executes Code| codeServer
    codeServer -->|Verdict| celeryWorkers
    celeryWorkers -->|Updates| db
    Monolith -->|Polls/AJAX| redis
    Monolith -->|Sends Email| smtp
    codeServer -->|Uses| dockerDaemon

    %% Click Events - Project Config
    click manage "https://github.com/fossee/online_test/blob/master/manage.py"
    click settings "https://github.com/fossee/online_test/blob/master/online_test/settings.py"
    click testSettings "https://github.com/fossee/online_test/blob/master/online_test/test_settings.py"
    click urlsConf "https://github.com/fossee/online_test/blob/master/online_test/urls.py"
    click wsgi "https://github.com/fossee/online_test/blob/master/online_test/wsgi.py"
    click celeryConf "https://github.com/fossee/online_test/blob/master/online_test/celery_settings.py"

    %% Click Events - yaksh App
    click yakshApp "https://github.com/fossee/online_test/tree/master/yaksh/"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/models.py"
    click yakshApp "https://github.com/fossee/online_test/tree/master/yaksh/migrations/"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/views.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/urls.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/urls_password_reset.py"
    click yakshApp "https://github.com/fossee/online_test/tree/master/yaksh/templates/"
    click yakshApp "https://github.com/fossee/online_test/tree/master/yaksh/static/"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/management/commands/create_moderator.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/tasks.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/send_emails.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/code_server.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/python_stdio_evaluator.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/cpp_code_evaluator.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/r_code_evaluator.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/scilab_code_evaluator.py"
    click yakshApp "https://github.com/fossee/online_test/tree/master/yaksh/middleware/"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/forms.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/file_utils.py"
    click yakshApp "https://github.com/fossee/online_test/blob/master/yaksh/storage_backends.py"

    %% Click Events - API App
    click apiApp "https://github.com/fossee/online_test/blob/master/api/apps.py"
    click apiApp "https://github.com/fossee/online_test/blob/master/api/serializers.py"
    click apiApp "https://github.com/fossee/online_test/blob/master/api/views.py"
    click apiApp "https://github.com/fossee/online_test/blob/master/api/urls.py"
    click apiApp "https://github.com/fossee/online_test/blob/master/api/tests.py"

    %% Click Events - Grades App
    click gradesApp "https://github.com/fossee/online_test/blob/master/grades/models.py"
    click gradesApp "https://github.com/fossee/online_test/tree/master/grades/migrations/"
    click gradesApp "https://github.com/fossee/online_test/blob/master/grades/views.py"
    click gradesApp "https://github.com/fossee/online_test/blob/master/grades/urls.py"
    click gradesApp "https://github.com/fossee/online_test/blob/master/grades/admin.py"
    click gradesApp "https://github.com/fossee/online_test/blob/master/grades/forms.py"
    click gradesApp "https://github.com/fossee/online_test/tree/master/grades/templates/"
    click gradesApp "https://github.com/fossee/online_test/blob/master/grades/tests.py"

    %% Click Events - Stats App
    click statsApp "https://github.com/fossee/online_test/blob/master/stats/models.py"
    click statsApp "https://github.com/fossee/online_test/tree/master/stats/migrations/"
    click statsApp "https://github.com/fossee/online_test/blob/master/stats/views.py"
    click statsApp "https://github.com/fossee/online_test/blob/master/stats/urls.py"
    click statsApp "https://github.com/fossee/online_test/blob/master/stats/admin.py"
    click statsApp "https://github.com/fossee/online_test/tree/master/stats/templates/"
    click statsApp "https://github.com/fossee/online_test/blob/master/stats/tests.py"
    click statsApp "https://github.com/fossee/online_test/blob/master/stats/test_models.py"

    %% Click Events - Upload App
    click uploadApp "https://github.com/fossee/online_test/blob/master/upload/models.py"
    click uploadApp "https://github.com/fossee/online_test/blob/master/upload/views.py"
    click uploadApp "https://github.com/fossee/online_test/blob/master/upload/urls.py"
    click uploadApp "https://github.com/fossee/online_test/blob/master/upload/utils.py"

    %% Click Events - Docker & Deployment
    click codeServer "https://github.com/fossee/online_test/tree/master/docker/Dockerfile_codeserver"
    click codeServer "https://github.com/fossee/online_test/blob/master/docker/Files/Start-codeserver.sh"
    click celeryWorkers "https://github.com/fossee/online_test/blob/master/docker/docker-compose.yml"
    click dockerDaemon "https://github.com/fossee/online_test/tree/master/docker/Dockerfile_django"
    click dockerDaemon "https://github.com/fossee/online_test/blob/master/docker/Files/000-default.conf"
    click dockerDaemon "https://github.com/fossee/online_test/blob/master/docker/docker-compose.yml"
    click dockerDaemon "https://github.com/fossee/online_test/blob/master/.sampleenv"

    %% Static Editors
    click staticFiles "https://github.com/fossee/online_test/tree/master/yaksh/static/yaksh/js/codemirror/"
    click staticFiles "https://github.com/fossee/online_test/tree/master/yaksh/static/yaksh/js/tinymce/"
    click staticFiles "https://github.com/fossee/online_test/tree/master/yaksh/static/yaksh/css/"
    click staticFiles "https://github.com/fossee/online_test/tree/master/yaksh/static/yaksh/js/"

    %% Testing & Docs
    click Monolith "https://github.com/fossee/online_test/tree/master/yaksh/live_server_tests/"
    click Monolith "https://github.com/fossee/online_test/tree/master/yaksh/evaluator_tests/"
    click Monolith "https://github.com/fossee/online_test/tree/master/yaksh/tests/"
    click apiApp "https://github.com/fossee/online_test/blob/master/api/tests.py"
    click Monolith "https://github.com/fossee/online_test/tree/master/yaksh/documentation/"
    click Monolith "https://github.com/fossee/online_test/blob/master/release_testing_guide.md"
    click Monolith "https://github.com/fossee/online_test/blob/master/requirements/requirements-*.txt"

    %% Styles
    classDef clients fill:#FFD580,stroke:#333,stroke-width:1px
    classDef webapp fill:#B3D9FF,stroke:#333,stroke-width:1px
    classDef db fill:#A3E4D7,stroke:#333,stroke-width:1px
    classDef queue fill:#F9E79F,stroke:#333,stroke-width:1px
    classDef worker fill:#F5B7B1,stroke:#333,stroke-width:1px
    classDef service fill:#D2B4DE,stroke:#333,stroke-width:1px
    classDef external fill:#D5DBDB,stroke:#333,stroke-width:1px
```
