A comprehensive web-based competitive programming platform for hosting local contests and managing programming problems. This system provides a complete online judge experience with user management, contest organization, problem submission, and real-time grading.
Important: This system executes user-submitted code directly on the server without sandboxing. Only use this on trusted networks with trusted participants. Do not expose this system to the public internet without proper security measures.
- Create and manage programming contests with start/end times
- Register participants for contests
- Real-time scoreboards with penalty calculations
- Support for both contest-specific and public problems
- Create and edit programming problems with rich text statements
- Upload test cases via files or direct text input
- Configure time and memory limits per problem
- Bulk import test cases from zip files
- Support for large input/output files
- Supported Languages: C++ (with g++ compiler)
- Real-time code compilation and execution
- Detailed test case results and scoring
- Submission history and status tracking
- Compile error reporting
- User registration and authentication
- Role-based access control (admin/user/banned)
- Secure password hashing with bcrypt
- Session management
- Complete problem and contest management
- User administration
- Test case management with file uploads
- Bulk operations for contest setup
- Backend: Node.js, Express.js
- Database: MySQL/MariaDB
- Template Engine: Nunjucks
- Frontend: Semantic UI, jQuery
- Authentication: bcrypt, express-session
- File Handling: multer for uploads
- Node.js (v14 or higher recommended)
- MySQL or MariaDB database server
- g++ compiler (for C++ code execution)
-
Clone the repository:
git clone https://github.com/CuteMurasame/local-online-judge.git cd local-online-judge -
Install dependencies:
npm install
-
Set up the database:
# Create database and user (adjust credentials as needed) mysql -u root -p < init_db.sql
-
Configure environment variables (optional):
export DB_HOST=127.0.0.1 export DB_USER=root export DB_PASSWORD=your_password export DB_NAME=cp_platform export SESSION_SECRET=your-secure-session-secret
-
Start the server:
ulimit -s unlimited && node server.js
-
Access the application: Open your browser and navigate to
http://localhost:3000
The application supports the following environment variables:
| Variable | Default | Description |
|---|---|---|
DB_HOST |
127.0.0.1 |
MySQL database host |
DB_USER |
root |
MySQL username |
DB_PASSWORD |
`` | MySQL password |
DB_NAME |
cp_platform |
MySQL database name |
SESSION_SECRET |
please-change-me |
Session encryption secret |
PORT |
3000 |
Server port |
-
Create an admin account:
- Register a regular user account
- Manually update the database to set role to 'admin'
UPDATE users SET role = 'admin' WHERE username = 'your_username';
-
Create problems:
- Navigate to Admin β Problems
- Click "Create New Problem"
- Set title, statement, time/memory limits, and scoring
- Add test cases by uploading files or entering text
-
Set up contests:
- Navigate to Admin β Contests
- Create a new contest with start/end times
- Add problems to the contest
- Participants can register once the contest is created
- Register an account on the platform
- Browse available contests on the home page
- Register for contests you want to participate in
- Submit solutions during the contest period
- View results and scoreboard in real-time
The system uses the following main tables:
users- User accounts and rolesproblems- Problem definitions and metadatatestcases- Test case files and datacontests- Contest information and timingcontest_problems- Problem-contest associationssubmissions- Code submissions and resultsattempts- Submission attempts for scoringregistrations- Contest participant registrations
GET /- Home page with contests and problemsGET /login- Login pagePOST /login- User authenticationGET /register- Registration page (if implemented)GET /logout- User logout
GET /contests/:id- Contest detailsPOST /contests/:id/register- Register for contestGET /contest/:cid/problem/:pid- Contest problem viewGET /contests/:id/scoreboard- Contest scoreboard
GET /admin/problems- Problem managementGET /admin/problems/create- Create new problemPOST /admin/problems/create- Save new problemGET /admin/problems/:id- Edit problemPOST /admin/problems/:id/edit- Update problemPOST /admin/problems/:id/add_test- Add test caseGET /admin/contests- Contest managementPOST /admin/contests/create- Create new contest
POST /submit- Submit solutionGET /submission/:id- View submission detailsGET /submissions- List user submissions
local-online-judge/
βββ server.js # Main application server
βββ package.json # Node.js dependencies
βββ init_db.sql # Database schema
βββ static/
β βββ style.css # Custom styles
βββ views/ # Nunjucks templates
β βββ layout.njk # Base template
β βββ index.njk # Home page
β βββ admin_*.njk # Admin interfaces
β βββ contest_*.njk # Contest pages
β βββ problem_*.njk # Problem pages
βββ data/
β βββ testcases/ # Test case files (created automatically)
βββ uploads/ # Temporary upload directory
To add support for additional programming languages:
- Modify the language detection logic in
server.js - Add compilation and execution commands for the new language
- Update the submission form to include the new language option
- Test thoroughly with sample submissions
Common extensions might include:
- Dockerized execution environment for better security
- Additional programming language support
- More sophisticated scoring algorithms
- Team-based contests
- Problem difficulty ratings
- Editorial and solution viewing
- Code Execution: User code runs directly on the server without sandboxing
- Network Security: Only deploy on trusted networks
- Input Validation: While basic validation exists, additional sanitization may be needed
- File System: Uploaded files are stored locally without advanced security measures
- Database: Use strong passwords and limit database access
- Implement Docker containers for code execution
- Add rate limiting for submissions
- Implement file type validation for uploads
- Add CSRF protection
- Use HTTPS in production
- Regular security audits
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Node.js best practices
- Test all new features thoroughly
- Update documentation for new features
- Ensure backward compatibility when possible
- Add proper error handling
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Express.js and Node.js
- Uses Semantic UI for styling
- Inspired by competitive programming platforms like Codeforces and AtCoder
For issues, questions, or contributions, please use the GitHub issue tracker or submit a pull request.
Note: This is a development/educational tool. For production competitive programming platforms, consider using established solutions with proper security measures and sandboxing.