- Project Overview
- System Architecture
- Backend (Django) Components
- Frontend (React) Components
- Judge0 Integration
- Database Schema
- API Endpoints
- Authentication & Authorization
- Deployment Configuration
- Management Commands
- File Structure Analysis
- Development Workflow
CodeTutor is a comprehensive lab management platform designed for educational institutions to manage programming courses, exercises, and automated code evaluation. The system integrates with Judge0 for real-time code execution and provides a complete learning management solution.
- Multi-Role System: Students, Faculty, and Administrators
- Automated Code Evaluation: Integration with Judge0 for 40+ programming languages
- Exercise Management: Pre-quiz, coding problems, and viva assessments
- Real-time Monitoring: Live progress tracking and instant feedback
- Plagiarism Detection: Automated similarity checking for submissions
- Certificate Generation: PDF reports and certificates
- Video Tutorials: Interactive learning with embedded questions
- LDAP Integration: University authentication system
- Frontend: React 18.3.1, Material-UI, Chakra UI, Monaco Editor
- Backend: Django 5.0.6, Django REST Framework
- Database: PostgreSQL (Production), SQLite (Development)
- Code Execution: Judge0 v1.13.1
- Authentication: Django-auth-LDAP, JWT
- Containerization: Docker, Docker Compose
- Web Server: NGINX with SSL/TLS
- Code Quality: SonarQube
- File Processing: LaTeX to PDF conversion
Purpose: User management, authentication, and department organization
Models:
User
: Extended AbstractUser with faculty flag and department relationDepartment
: Organizational units
Key Features:
- LDAP integration for university authentication
- Automatic department synchronization
- Username case normalization
Files:
user/
├── models.py # User and Department models
├── views.py # Authentication endpoints
├── serializers.py # User data serialization
├── permissions.py # Custom permission classes
├── admin.py # Django admin configuration
└── management/
└── commands/
├── sync_users.py # LDAP user synchronization
├── check_plagiarism.py # Plagiarism detection
└── populate_department.py
Purpose: Core business logic, course management, and code evaluation
Models (25+ models including):
Course
: Course definitions and metadataExercise
: Lab exercises within coursesQuestionBank
: Programming problems with test casesTestCase
: Input/output test cases for problemsSubmission
: Student code submissions with resultsCourseOffered
: Course instances for specific batchesBatchStudents
: Student enrollment managementViva/PreQuizz
: Assessment componentsJudge0
: Programming language configurations
Key Features:
- Automated code evaluation with Judge0
- Test case management and execution
- Batch processing for multiple submissions
- Video tutorial with interactive questions
- Plagiarism detection workflow
- PDF report generation
Files:
api/
├── models.py # 25+ data models
├── views.py # 50+ API endpoints (1364 lines)
├── serializers.py # Data serialization/validation
├── utils.py # Helper functions for grading
├── admin.py # Django admin interfaces
├── urls.py # API routing configuration
└── management/
└── commands/ # 12 management commands
├── populate_judge0.py # Language setup
├── populate_course.py # Course data
├── populate_problem.py # Problem import
├── export_problems.py # Data export
└── add_dummy_data.py # Test data generation
Purpose: Faculty-specific functionality and course management
Development: SQLite (db.sqlite3
)
Production: PostgreSQL with Docker
# settings.py excerpt
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "db.sqlite3",
}
}
- Supports 40+ programming languages
- Configurable time/memory limits
- Batch submission processing
- Real-time execution status tracking
- Pre-Quiz: Multiple choice questions before lab
- Coding Problems: Programming challenges with test cases
- Viva: Post-lab assessment questions
# Authentication backends
AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
]
frontend/src/
├── index.js # App entry point with routing
├── pages/ # Main application pages
├── components/ # Reusable UI components
├── context/ # Global state management
└── assets/ # Static resources
- University LDAP authentication
- JWT token management
- Role-based routing
- Student enrolled courses
- Course metadata display
- Navigation to exercises
- Exercise listing for courses
- Progress tracking
- Assessment type indicators
- Monaco code editor integration
- Multi-language support
- Real-time code execution
- Test case visualization
- Submission history
- File upload for code submission
- Batch management
- Student enrollment
- Excel file processing for bulk operations
- Problem statement rendering
- Test case display
- Coding environment integration
- Grade visualization
- Progress reports
- Certificate generation
- Navigation bar
- User authentication status
- Role-based menu options
- Quiz question rendering
- Multiple choice interface
- Timer functionality
- Answer validation
- Progress tracking
- Post-lab assessment
- Question randomization
- Keyboard/context menu restrictions
- Auto-submission
- Video playback
- Interactive questions
- Progress tracking
- Batch creation interface
- Student management
- Excel import functionality
// Global state contexts
- CoursesContext.js # Course selection state
- BatchesContext.js # Batch management
- ExercisesContext.js # Exercise data
- QuestionContext.js # Question navigation
- Material-UI: Primary component library
- Chakra UI: Alternative components
- Monaco Editor: Code editing interface
- React Router: Navigation management
- Port: 2358
- Languages: Standard programming languages
- Configuration: Basic limits and settings
- Port: 2359 (if configured)
- Languages: Extended language support
- Features: Additional tools and compilers
# Resource Limits
CPU_TIME_LIMIT=5 # Seconds
MEMORY_LIMIT=128000 # KB
WALL_TIME_LIMIT=10 # Seconds
MAX_PROCESSES_AND_OR_THREADS=60
# Database Configuration
POSTGRES_HOST=db
POSTGRES_USER=judge0
POSTGRES_PASSWORD=8PqhgXSyjcUAWrhs64ehKkRRbuUweAsC
# Redis Configuration
REDIS_HOST=redis
REDIS_PASSWORD=PsBxZ5sL3JgVw66RGR9fbgsCkya3urhL
- C/C++: Multiple GCC versions
- Python: 2.7.17, 3.8.1
- Java: OpenJDK 13.0.1
- JavaScript: Node.js 12.14.0
- And 35+ more languages
services:
server: # Judge0 API server
workers: # Background job processors
db: # PostgreSQL database
redis: # Cache and queue management
User (AbstractUser extension)
├── id, username, email, is_faculty
├── dept → Department
└── Related: BatchStudents, Submissions
Department
├── id, name
└── Related: Users, CourseOffered
Course
├── id, name, course_id, description, sem_available
└── Related: Exercises, QuestionBank, CourseOffered
Exercise
├── id, exercise_name, order
├── course → Course
└── Related: QuestionBank, Viva, PreQuizz
CourseOffered
├── id, batch, semester, year, is_active
├── course → Course
├── faculty → User
├── offered_department → Department
└── Related: BatchStudents, Submissions
QuestionBank
├── id, title, question, difficulty
├── language → Judge0
├── course → Course
├── exercise → Exercise
└── Related: TestCase, Submissions
TestCase
├── id, input, expected_output, hidden
├── question → QuestionBank
└── Related: TestCasesSolved
Submission
├── id, code, mark, is_accepted, created_at
├── user → User
├── problem → QuestionBank
├── batch → CourseOffered
└── result → ManyToMany(TestCasesSolved)
Judge0
├── id, language, lang_id, date_time
└── Related: QuestionBank
Submission
: (user, problem, batch)VivaAnswered
: (user, exercise, viva)ExerciseMarks
: (batch, student, exercise)
TestCasesSolved.judge0result
: Stores Judge0 execution resultsRunTestCasesSolved.judge0result
: For code runs (non-submissions)
Record.record
: Student submission recordingsBasic_Tutorial.video
: Tutorial videos
POST /user/login/ # LDAP authentication
POST /user/refresh/ # JWT token refresh
GET /user/profile/ # User profile data
GET /api/courses/ # Student enrolled courses
GET /api/exercise/{batch_id}/ # Exercises for batch
GET /api/exercises-questions/{batch_id}/ # Questions for batch exercises
GET /api/excersise_data/{exercise_id}/ # Exercise details
GET /api/question/{question_id}/ # Problem details
POST /api/code-submission/{question_id}/ # Submit code
POST /api/file-submission/{question_id}/ # Submit file
POST /api/code-run/{question_id}/ # Run code (test)
POST /api/file-run/{question_id}/ # Run file (test)
GET /api/viva/{exercise_id}/ # Viva questions
POST /api/viva/{exercise_id}/ # Submit viva answers
GET /api/tutorial/{pk}/ # Video tutorial
GET /api/basic-tutorials/ # Tutorial list
POST /api/record/{question_id}/ # Save recording
POST /api/process_tex/ # LaTeX to PDF conversion
GET /faculty/batches/ # Faculty batches
POST /faculty/create-batch/ # Create new batch
GET /faculty/students/{batch_id}/ # Batch students
POST /faculty/add-students/ # Add students to batch
GET /faculty/marks/{batch_id}/ # Student marks
# settings.py
AUTH_LDAP_SERVER_URI = "ldap://your-ldap-server.com"
AUTH_LDAP_BIND_DN = "CN=bind-user,CN=users,DC=domain,DC=com"
AUTH_LDAP_USER_SEARCH = LDAPSearch(
"CN=users,DC=domain,DC=com",
ldap.SCOPE_SUBTREE,
"(sAMAccountName=%(user)s)"
)
# Custom permissions
IsFaculty # Faculty-only access
IsAuthenticated # Logged-in users only
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
'ROTATE_REFRESH_TOKENS': True,
}
FROM node:21.7.1-bullseye
WORKDIR /app/frontend/
COPY package*.json /app/frontend/
RUN npm install -f
COPY . /app/frontend
CMD ["npm","start"]
FROM python:3.10
WORKDIR /app/backend
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
server {
listen 443 ssl;
server_name Codetutor.karunya.edu;
ssl_certificate /etc/pki/nginx/karunya.edu.crt;
ssl_certificate_key /etc/pki/nginx/karunya.edu.key;
location / {
proxy_pass http://0.0.0.0:8086;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
- Location:
/backend/certificates/
- Files:
karunya.edu.crt
,karunya.edu.key
- Frontend:
.env
files for API endpoints - Backend:
.env
files for database and LDAP settings
Purpose: Initialize Judge0 language configurations
Usage: python manage.py populate_judge0
Function: Creates Judge0 model entries for 40+ programming languages
Purpose: Create course entries
Usage: python manage.py populate_course
Purpose: Create exercise data
Usage: python manage.py populate_exercise
Purpose: Import problems from JSON files
Usage: python manage.py populate_problem
Purpose: Create test user accounts
Usage: python manage.py populate_users
Purpose: Synchronize users from LDAP via CSV
Usage: python manage.py sync_users users.csv
Features:
- LDAP user lookup
- Automatic batch assignment
- Department synchronization
Purpose: Create department structures
Usage: python manage.py populate_department
Purpose: Create viva questions
Usage: python manage.py populate_viva
Purpose: Create pre-quiz questions
Usage: python manage.py populate_prequizz
Purpose: Export problem data to JSON
Usage: python manage.py export_problems
Purpose: Generate test data for development
Usage: python manage.py add_dummy_data
Purpose: Extract and analyze code submissions for plagiarism
Usage: python manage.py check_plagiarism
Features:
- Code extraction by language
- Temporary file organization
- Similarity analysis preparation
Lab-Tutor/
├── README.md # Project documentation
├── data.json # LaTeX configuration
├── package.json # Node.js metadata
├── .gitignore # Git exclusions
├── backend/ # Django application
├── frontend/ # React application
├── judge0-v1.13.1/ # Standard Judge0
├── judge0-v1.13.1-extra/ # Extended Judge0
├── Doc/ # Documentation
└── snipert/ # Utility scripts
backend/
├── manage.py # Django management script
├── requirements.txt # Python dependencies (40 packages)
├── db.sqlite3 # Development database
├── Dockerfile # Container configuration
├── karunya_logo.png # University branding
├── sample.tex # LaTeX template
├── department.txt # Department data
├── backend/ # Django project settings
│ ├── settings.py # Configuration (255 lines)
│ ├── urls.py # URL routing
│ ├── wsgi.py # WSGI application
│ └── asgi.py # ASGI application
├── api/ # Core API application
│ ├── models.py # Data models (454 lines)
│ ├── views.py # API endpoints (1364 lines)
│ ├── serializers.py # Data serialization
│ ├── utils.py # Helper functions
│ ├── admin.py # Admin interface
│ ├── urls.py # API routing
│ └── management/commands/ # 12 management commands
├── user/ # User management
│ ├── models.py # User and Department models
│ ├── views.py # Authentication views
│ ├── permissions.py # Custom permissions
│ └── management/commands/ # User utilities
├── faculty/ # Faculty-specific features
├── certificates/ # SSL certificates
├── data/ # Problem and exercise data
│ ├── problems_export.json # Problem definitions (669 lines)
│ ├── excersise/ # Exercise data files
│ └── problems/ # Problem collections
├── basic_tutorial/ # Video content storage
├── record/ # Student recordings (PDF format)
└── templates/ # Django templates
frontend/
├── package.json # Dependencies (50+ packages)
├── webpack.config.js # Build configuration
├── Dockerfile # Container setup
├── public/ # Static assets
│ ├── index.html # App entry point
│ ├── manifest.json # PWA configuration
│ └── *.png # Icons and logos
└── src/ # Source code
├── index.js # App initialization with routing
├── index.css # Global styles
├── assets/ # Images and resources
├── pages/ # 7 main application pages
│ ├── Login.jsx # Authentication
│ ├── CoursesList.jsx # Course listing
│ ├── Exercises.jsx # Exercise navigation
│ ├── Coding.jsx # Code editor (500+ lines)
│ ├── Faculty.jsx # Faculty dashboard
│ ├── Problem.jsx # Problem viewer
│ └── StudentMarkSheet.jsx # Grade reports
├── components/ # 14 reusable components
│ ├── Header.jsx # Navigation bar
│ ├── Question.jsx # Quiz interface (300+ lines)
│ ├── Viva.jsx # Assessment component
│ ├── Tutorial.jsx # Video tutorials
│ ├── FacultyBatch.jsx # Batch management
│ └── *.jsx # Additional components
└── context/ # 5 state providers
├── CoursesContext.js # Course state
├── BatchesContext.js # Batch management
├── ExercisesContext.js # Exercise data
├── QuestionContext.js # Question navigation
└── SideBarContext.jsx # UI state
judge0-v1.13.1/
├── docker-compose.yml # Standard setup
└── judge0.conf # Configuration (350+ lines)
judge0-v1.13.1-extra/
├── docker-compose.yml # Extended setup
├── docker-compose.yaml.bak # Backup configuration
└── judge0.conf # Extended configuration
Doc/
├── API.postman_collection.json # API testing (2606 lines)
├── Deployment.md # Production setup guide
├── Development.md # Development instructions
├── index.html # Documentation portal
└── Note # Additional notes
- Python 3.8+: Backend development
- Node.js v20: Frontend development
- Docker: Judge0 and containerization
- Git: Version control
# Clone repository
git clone https://git.karunya.edu/computer-technology-centre/Codetutor
cd Lab-Tutor
# Set up Judge0
cd judge0-v1.13.1
docker-compose up -d db redis
sleep 10
docker-compose up -d
cd ..
cd backend
python -m venv venv
source ./venv/bin/activate # Linux
pip install -r requirements.txt
# Database setup
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
# Populate initial data
python manage.py populate_judge0
python manage.py populate_course
python manage.py populate_exercise
# Start development server
python manage.py runserver
cd frontend
npm install -f
npm start
- Frontend: http://localhost:3000
- Backend: http://localhost:8000
- Judge0: http://localhost:2358
# Frontend .env
REACT_APP_API_BASE_URL=http://localhost:8000
# Backend .env
DATABASE_URL=sqlite:///db.sqlite3
LDAP_SERVER_URI=ldap://your-server.com
DEBUG=True
# Backend
python manage.py shell # Django shell
python manage.py test # Run tests
python manage.py collectstatic # Static files
# Frontend
npm test # Run tests
npm run build # Production build
npm run eject # Expose configuration
- Create JSON: Use
problems_export.json
format - Import:
python manage.py populate_problem
- Verify: Check Django admin interface
- LDAP Sync:
python manage.py sync_users users.csv
- Department Setup:
python manage.py populate_department
- Batch Creation: Use Faculty interface
# Start SonarQube
docker run -d -p 9000:9000 --name sonarqube sonarqube
# Run analysis
docker run --rm \
-v $(pwd):/usr/src \
-e SONAR_HOST_URL="http://localhost:9000" \
-e SONAR_LOGIN="<TOKEN>" \
sonarsource/sonar-scanner-cli \
-Dsonar.projectKey=CodeTutor \
-Dsonar.sources=/usr/src
- Judge0 Connection: Check Docker containers
- Database Errors: Verify migrations
- Frontend Build: Clear node_modules cache
- LDAP Issues: Check server connectivity
- Django: Console and file logging
- React: Browser console
- Judge0: Docker logs
- LDAP Integration: Secure university authentication
- JWT Tokens: Short-lived access tokens
- Permission Classes: Role-based access control
- Sandboxing: Judge0 isolate containers
- Resource Limits: CPU, memory, time constraints
- Network Restrictions: Isolated execution environment
- HTTPS: SSL/TLS encryption
- Input Validation: Serializer validation
- SQL Injection: Django ORM protection
- Type Validation: File extension checking
- Size Limits: Upload size restrictions
- Virus Scanning: Consider integration
- Indexing: Key foreign key relationships
- Query Optimization: Select_related, prefetch_related
- Connection Pooling: PostgreSQL connections
- Redis: Judge0 queue management
- Django Cache: Session and query caching
- Frontend: React memoization
- Load Balancing: NGINX upstream servers
- Database Scaling: Read replicas
- Judge0 Scaling: Multiple worker instances
- Health Checks: API endpoint monitoring
- Resource Usage: CPU, memory, disk space
- Error Tracking: Exception logging
- Submission Tracking: Success rates
- Performance Metrics: Execution times
- Usage Patterns: Peak hours analysis
- Learning Progress: Exercise completion rates
- Difficulty Analysis: Problem success rates
- Plagiarism Reports: Similarity patterns
This comprehensive documentation covers all aspects of the CodeTutor platform. For specific implementation details, refer to the individual source files and their inline documentation.