A modern, full-stack online judge platform for competitive programming and coding practice
- Multi-language Support: C++, Java, and Python compilation and execution
- Real-time Code Editor: Monaco Editor with syntax highlighting and auto-completion
- Problem Management: Create, edit, and solve coding problems with custom test cases
- Automated Testing: Run code against sample and hidden test cases
- Submission Tracking: Complete history of user submissions with results
- AI Code Review: Get intelligent code analysis using Google Gemini AI
- Code Quality Assessment: Automated suggestions for improvements
- Best Practices Guidance: Learn better coding patterns and techniques
- Modern UI/UX: Beautiful dark/light mode interface with Tailwind CSS
- Responsive Design: Works seamlessly on desktop, tablet, and mobile
- Real-time Updates: Live compilation results and feedback
- Boilerplate Templates: Auto-generated starter code for each language
- JWT Authentication: Secure user sessions with HTTP-only cookies
- Protected Routes: Role-based access control
- Input Validation: Comprehensive validation for all user inputs
- CORS Configuration: Secure cross-origin resource sharing
Frontend/
├── src/
│ ├── components/ # React components
│ │ ├── Compiler.jsx # Code editor and execution
│ │ ├── Problem.jsx # Problem management
│ │ ├── Auth/ # Authentication components
│ │ └── ...
│ ├── context/ # React context providers
│ ├── api.js # API configuration
│ └── index.css # Tailwind CSS styles
├── public/ # Static assets
└── package.json
Backend/
├── Controller/ # Route controllers
├── models/ # MongoDB models
│ ├── User.js # User schema
│ ├── Problem.js # Problem schema
│ └── Submission.js # Submission schema
├── routes/ # API routes
├── Compiler/ # Code execution engines
│ ├── executeCpp.js # C++ compiler
│ ├── executeJava.js # Java compiler
│ └── executePython.js # Python interpreter
├── middleware/ # Custom middleware
├── database/ # Database configuration
└── index.js # Server entry point
Our Online Judge features a custom-designed compiler engine built entirely from the ground up, without relying on any external sandbox libraries or third-party compilation services.
- Native Implementation: Direct system calls to language compilers (g++, javac, python3)
- File-based Execution: Secure temporary file handling with UUID-based naming
- Process Management: Custom subprocess execution with timeout controls
- Memory Management: Automatic cleanup of temporary files and processes
- Error Handling: Comprehensive error capture and user-friendly messaging
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Code │────│ File Generator │────│ Temp Directory │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Compiler Engine │────│ Process Spawn │────│ Execution │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Output Cap. │────│ Error Handling │────│ Cleanup │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- No Sandbox Dependencies: Built without Docker sandboxes or external isolation tools
- Direct Compilation: Interfaces directly with system compilers
- Resource Control: Built-in timeout and memory management
- Multi-language Support: Unified interface for C++, Java, and Python
- Real-time Feedback: Immediate compilation and execution results
- Code Reception: User code received via API endpoint
- File Generation: Unique temporary file created with UUID naming
- Compilation: Direct system call to appropriate compiler
- Execution: Process spawning with input/output redirection
- Result Capture: Output collection and error handling
- Cleanup: Automatic removal of temporary files and processes
This custom approach provides maximum control, optimal performance, and simplified deployment without the overhead of complex sandboxing solutions.
- Node.js (≥16.0.0)
- MongoDB Atlas account
- Google Gemini API key
- Docker (optional)
- Clone the repository
git clone https://github.com/Guru2006ug/OJ-Project.git
cd Online-Judge- Set up environment variables
# Backend/.env
MONGODB_URL=your_mongodb_connection_string
SECRET_KEY=your_jwt_secret_key
GOOGLE_GEMINI_API_KEY=your_gemini_api_key
FRONTEND_URL=http://localhost:3000
PORT=5000# Frontend/frontend/.env
# For local development:
VITE_API_BASE_URL=http://localhost:5000
# For production:
# VITE_API_BASE_URL=https://backend.code-guru.online- Run with Docker
cd Backend
docker-compose up --build- Start Frontend
cd Frontend/frontend
npm install
npm run devcd Backend
npm install
npm run devcd Frontend/frontend
npm install
npm run dev| Variable | Description | Required |
|---|---|---|
MONGODB_URL |
MongoDB connection string | ✅ |
SECRET_KEY |
JWT signing secret | ✅ |
GOOGLE_GEMINI_API_KEY |
Google AI API key | ✅ |
FRONTEND_URL |
Frontend application URL | ✅ |
PORT |
Server port (default: 5000) | ❌ |
| Variable | Description | Required |
|---|---|---|
VITE_API_BASE_URL |
Backend API base URL | ✅ |
- Framework: React 18.2.0
- Build Tool: Vite
- Styling: Tailwind CSS
- Code Editor: Monaco Editor
- HTTP Client: Axios
- Routing: React Router DOM
- Markdown: React Markdown
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose
- Authentication: JWT + bcryptjs
- AI Integration: Google Generative AI
- File Handling: UUID for unique file names
- Containerization: Docker & Docker Compose
- Process Management: PM2 (production)
- Environment: Environment variables with dotenv
POST /api/auth/register # User registration
POST /api/auth/login # User login
GET /api/auth/me # Get current user
POST /api/auth/logout # User logoutGET /api/problems # Get all problems
GET /api/problems/:id # Get problem by ID
POST /api/problems # Create new problem (authenticated)
PUT /api/problems/:id # Update problem (authenticated)
DELETE /api/problems/:id # Delete problem (authenticated)POST /api/compiler # Compile and run codePOST /api/ai/ai-review # Get AI code review (authenticated)GET /api/submissions/:problemId # Get user submissions for a problem
POST /api/submissions # Submit solution- Sign Up: Create an account on the platform
- Browse Problems: Explore available coding challenges
- Solve Problems: Use the built-in code editor with boilerplate templates
- Test Solutions: Run code against sample and hidden test cases
- Get AI Review: Receive intelligent feedback on your code
- Track Progress: Monitor your submission history
- Create Problems: Add new coding challenges with test cases
- Set Difficulty: Categorize problems as easy, medium, or hard
- Define Test Cases: Create both visible sample and hidden test cases
- Monitor Submissions: Track student progress and submissions
| Language | File Extension | Compiler/Interpreter |
|---|---|---|
| C++ | .cpp |
g++ (GNU Compiler) |
| Java | .java |
javac + java |
| Python | .py |
python3 |
- C++: STL libraries, competitive programming headers
- Java: Scanner input handling, Main class structure
- Python: Common imports, proper main function structure
- Dark/Light Mode: Toggle between themes
- Responsive Layout: Mobile-first design approach
- Modern Aesthetics: Glassmorphism effects and smooth animations
- Intuitive Navigation: Clear user flow and navigation
- Code Syntax Highlighting: Monaco Editor with VS Code experience
- Keyboard Navigation: Full keyboard support
- Screen Reader Compatible: ARIA labels and semantic HTML
- High Contrast Support: Accessible color schemes
- Responsive Text: Scalable font sizes
- Build Frontend
cd Frontend/frontend
npm run build- Deploy Backend
cd Backend
docker build -t online-judge-backend .
docker run -p 5000:5000 online-judge-backend- Environment Configuration
- Set production environment variables
- Configure MongoDB Atlas for production
- Set up SSL certificates for HTTPS
- Configure reverse proxy (Nginx recommended)
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcrypt for password security
- CORS Configuration: Controlled cross-origin requests
- Input Sanitization: Prevention of code injection attacks
- Rate Limiting: Protection against abuse (recommended to add)
- Environment Variables: Sensitive data protection
Backend Connection Issues
- Verify MongoDB connection string
- Check if backend server is running on correct port
- Ensure environment variables are properly set
Frontend Build Issues
- Clear node_modules and reinstall dependencies
- Check Node.js version compatibility
- Verify environment variables format
Code Execution Issues
- Ensure Docker containers have necessary compilers installed
- Check file permissions in codes/ and outputs/ directories
- Verify language-specific syntax in boilerplate templates
- Code Splitting: Lazy loading for better performance
- API Caching: Optimized database queries
- File Cleanup: Automatic temporary file management
- Connection Pooling: MongoDB connection optimization
- Compression: Gzip compression for API responses
- Contest Mode: Time-based competitive programming contests
- Leaderboards: User ranking and achievement system
- Discussion Forums: Community interaction for each problem
- Video Tutorials: Integrated learning content
- Code Templates: More language support and templates
- Plagiarism Detection: Code similarity analysis
- Administrative Dashboard: Enhanced problem management
- API Rate Limiting: Enhanced security measures
This project is licensed under the ISC License - see the LICENSE file for details.
- Monaco Editor: Providing excellent code editing experience
- Google Gemini AI: Powering intelligent code reviews
- MongoDB Atlas: Reliable cloud database service
- Tailwind CSS: Beautiful and responsive UI components
- React Community: Extensive ecosystem and support
For support, please reach out through:
- Email: [email protected]
Made with ❤️ to all the learners