How qingdaou/onlinejudge works
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”).