How zhblue/hustoj works
Main Components
a. Judge Engine Layer:
• The “trunk/core” directory shows C/C++ code for judging tasks. It includes “judged” (the central judging daemon), “judge_client” (the component that runs in the sandbox environment to compile and run user submissions), and the “sim” subdirectory (for similarity checking and possibly plagiarism detection).
b. Web Frontend Layer:
• The “trunk/web” directory is huge and contains PHP files, admin panels, various templates (syzoj, bs3, sweet, bshark, mdui, sidebar, etc.), and other assets. This is the web application that provides user interfaces for problem submission, contest management, discussion, and announcements.
c. Database Layer:
• Though not directly visible as a directory, installation scripts and documentation refer to MySQL/MariaDB and even SQLite3 support. The web code (in “db_info.inc.php”) clearly ties in with a backend database for storing problems, submissions, users, and contest data.
d. Container and Deployment Components:
• The “docker” and “kubernetes” directories contain Dockerfiles, entrypoint scripts, and YAML definitions. These components indicate that the system supports containerized deployment, allowing for scalable judge workers and web services.
e. Administration and Build/CI:
• The “.github”, “.gitlab-ci.yml” and various build scripts (like build.sh) imply that continuous integration and automated builds are in place. This ensures that components (especially the judge engine binaries) are compiled correctly across various platforms.
Relationships and Data Flow
• The Web Server (PHP application in trunk/web) interacts with the Database (MySQL/MariaDB) to retrieve/store contest, problem, user, and submission data.
• The Web Frontend submits judging jobs to the judge engine layer. This is typically achieved by enqueuing a submission request, which is then picked up by the “judged” daemon.
• The “judged” core process (written in C++) manages job distribution to one or more instances of “judge_client”, which likely run inside sandboxes (or even separate Docker containers) to compile and run submitted code.
• The “sim” directory holds the similarity or plagiarism detection components that may compare source codes after submissions and reports results back to the web interface.
• Deployment components (docker, kubernetes) serve to encapsulate these services into isolated containers that communicate over defined network ports and interfaces.
Architectural Patterns & Design Principles
• Modular separation: The system is clearly segregated into independent modules – a web frontend, a judging backend (with its own client–server architecture), and auxiliary modules (like similarity checking).
• Containerization: Use of Dockerfiles and Kubernetes YAML files indicates that independent services can be deployed as containers that communicate via APIs (or message queues), enhancing scalability and reliability.
• CI/CD Integration: Presence of GitHub workflows and GitLab pipelines suggests continuous integration practices, which helps in automated building, testing, and deployment.
Technologies, Frameworks, and Libraries
• Server-side: PHP (for front-end and admin modules) and underlying web servers such as Nginx (or Apache) as shown by configuration guidance.
• Judge engine: C/C++ code compiled for various architectures, with makefiles and platform-specific optimizations.
• Database: MySQL/MariaDB (with support hinted at for SQLite in certain modules).
• Containerization/orchestration: Docker and Kubernetes for containerized deployments.
• Frontend Libraries: Support for multiple templates/themes (syzoj, bs3, sweet, etc.) that rely on Bootstrap, ACE editor, KindEditor, and more.
• Additional utilities: Various open-source libraries like PHPMailer, codemirror, katex, and mdui are referenced via the README and file structure.