# rachitnaruzu/codearena architecture

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

- Interactive diagram: https://gitdiagram.com/rachitnaruzu/codearena
- Repository: https://github.com/rachitnaruzu/codearena

## Overview

##### Project Type & Purpose
- Full‐stack Django web application for assessing student coding skills by scraping multiple coding platforms, ranking users, managing problem sets, and optionally providing Discourse SSO integration.

##### Main Components
a. Client (Browser)
– Static assets (HTML/CSS/JS) from codearena/static and templates/
b. Reverse Proxy
– Nginx (codearena_nginx.conf + uwsgi_params)
c. Application Server
– uWSGI (codearena_uwsgi.ini + codearena_uwsgi.conf)
d. Web Application
– Django project “codearena” (settings.py, urls.py, views.py)
– “codelabs” app (models, views, forms, admin, tasks.py, webscrape.py, pydiscourse for Discourse SSO)
e. Task Queue
– RabbitMQ broker (BROKER_URL in settings.py)
– Celery workers (configured in codearena/celery.py, tasks in codelabs/tasks.py)
f. Scheduler
– Cron job (codearena_webscrape script invoked daily via /etc/cron.daily)
g. Data Store
– PostgreSQL database (django.db.backends.postgresql_psycopg2)
h. External Systems
– Coding platforms (CodeChef, Hackerrank, TopCoder, InterviewBit, GeeksforGeeks)
– Optional Discourse forum (via pydiscourse SSO client)
i. Initialization Scripts
– seed.py (initial admin user), update.py

##### Component Relationships & Data Flows
- Browser →(HTTPS)→ Nginx → uWSGI → Django
- Django ←→ PostgreSQL (SQL queries)
- Django → RabbitMQ (AMQP enqueue) → Celery Workers → Django (DB updates, email tasks)
- Cron → codearena_webscrape → enqueues scraping tasks into RabbitMQ
- Celery Workers → External Coding Platforms (HTTP scraping) → Update DB → Trigger points allotment
- Django Web UI → Discourse SSO endpoint → Discourse API (OAuth‐like handshake)

##### Architectural Patterns & Principles
- MVC (Models → Views → Templates) in Django
- Layered architecture:
– Presentation (templates + static files)
– Application / Business logic (Django, codelabs)
– Data access (ORM → PostgreSQL)
– Background processing (Celery + RabbitMQ)
- Asynchronous processing for scraping & email sending
- Cron‐driven scheduling for periodic data refresh
- External integrations abstracted via service adapters (codelabs/pydiscourse, webscrape.py)

##### Technologies & Frameworks
- Python 3, Django
- Celery, RabbitMQ
- PostgreSQL
- Nginx, uWSGI
- Cron
- jQuery, particle.js, custom JS in codearena/static/js
- pydiscourse (Discourse SSO client)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Web Tier"
        Browser["Browser\n(codearena/static/, templates/)"] 
        Nginx["Nginx\n(codearena_nginx.conf,\nuwsgi_params)"] 
        uWSGI["uWSGI\n(codearena_uwsgi.ini,\ncodearena_uwsgi.conf)"] 
        Django["Django WebApp\n(settings.py,\nurls.py, views.py,\nwsgi.py, manage.py)"] 
    end

    subgraph "Business Layer"
        Codelabs["codelabs App\n(models.py, views.py,\nforms.py, admin.py,\ntasks.py, webscrape.py,\nconfig.py, context_processor.py,\ntests.py)"]
    end

    subgraph "Task Processing"
        Cron["Cron Scheduler\n(codearena_webscrape)"] 
        Rabbit["RabbitMQ"] 
        Celery["Celery Workers\n(tasks.py)"] 
    end

    subgraph "Data Layer"
        Postgres["PostgreSQL"] 
    end

    subgraph "External Services"
        Platforms["Coding Platforms\n(CodeChef, Hackerrank,\nTopCoder, InterviewBit,\nGeeksforGeeks)"] 
        Discourse["Discourse SSO\n(pydiscourse)"] 
        Init["Initialization Scripts\n(seed.py, update.py)"] 
    end

    Browser -->|"HTTPS"| Nginx
    Nginx -->|"uWSGI Protocol"| uWSGI
    uWSGI -->|"WSGI"| Django
    Django -->|"Uses"| Codelabs
    Django -->|"SQL"| Postgres
    Django -->|"AMQP"| Rabbit
    Django -->|"HTTP SSO"| Discourse
    Cron -->|"Cron→Task"| Rabbit
    Rabbit -->|"AMQP"| Celery
    Celery -->|"Executes"| Codelabs
    Celery -->|"SQL Update"| Postgres
    Celery -->|"HTTP Scrape"| Platforms
    Celery -->|"Email Tasks"| Django

    click Browser "https://github.com/rachitnaruzu/codearena/tree/master/codearena/static/"
    click Nginx "https://github.com/rachitnaruzu/codearena/blob/master/codearena_nginx.conf"
    click uWSGI "https://github.com/rachitnaruzu/codearena/blob/master/codearena_uwsgi.ini"
    click Django "https://github.com/rachitnaruzu/codearena/blob/master/codearena/settings.py"
    click Codelabs "https://github.com/rachitnaruzu/codearena/blob/master/codelabs/models.py"
    click Celery "https://github.com/rachitnaruzu/codearena/blob/master/codearena/celery.py"
    click Cron "https://github.com/rachitnaruzu/codearena/tree/master/codearena_webscrape"
    click Discourse "https://github.com/rachitnaruzu/codearena/blob/master/codelabs/pydiscourse/client.py"
    click Init "https://github.com/rachitnaruzu/codearena/blob/master/seed.py"

    classDef web fill:#cce5ff,stroke:#000
    classDef app fill:#ffe5cc,stroke:#000
    classDef task fill:#ffd699,stroke:#000
    classDef data fill:#d5f5e3,stroke:#000
    classDef ext fill:#e0e0e0,stroke:#000

    class Browser,Nginx,uWSGI,Django web
    class Codelabs app
    class Cron,Rabbit,Celery task
    class Postgres data
    class Platforms,Discourse,Init ext
```
