A Django-based REST API for managing academic assessments with automated grading capabilities.
- Secure Authentication: Token-based authentication with role-based access control
- Exam Management: Create and manage exams with multiple question types
- Automated Grading: Built-in grading engine supporting:
- Multiple Choice Questions (exact match)
- True/False (exact match)
- Short Answer (keyword matching with partial credit)
- Essay (keyword matching with partial credit)
- Student Portal: Dashboard with performance analytics
- Instructor Tools: Statistics and result management
- API Documentation: Comprehensive Swagger/OpenAPI documentation or link to postman collection
- Python 3.8+
- Django 4.2+
- Django REST Framework 3.14+
- SQLite (default) or PostgreSQL (production)
# Create project directory
mkdir acad_ai_assessment
cd acad_ai_assessment
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate
# Install dependencies
pip install django djangorestframework django-filter drf-yasg
pip freeze > requirements.txt# Create project
django-admin startproject assessment_engine .
# Create apps
python manage.py startapp exams
python manage.py startapp accountsCopy the settings.py configuration provided in the artifacts and update:
SECRET_KEY(generate a new one for production)DEBUG = Falsefor productionALLOWED_HOSTSto include your domain
Copy all model files into their respective locations:
accounts/models.py- User modelexams/models.py- Exam, Question, Submission, Answer models
# Create migrations
python manage.py makemigrations accounts
python manage.py makemigrations exams
# Apply migrations
python manage.py migratemkdir -p exams/management/commands
touch exams/management/__init__.py
touch exams/management/commands/__init__.pyCopy the create_sample_data.py management command.
python manage.py create_sample_dataThis creates:
- Instructor account:
username=instructor1, password=password123 - Student account:
username=student1, password=password123 - Sample course and exam with questions
python manage.py createsuperuserpython manage.py runserverOnce the server is running, access the API documentation:
- Swagger UI: http://localhost:8000/swagger/
- ReDoc: http://localhost:8000/redoc/
- Admin Panel: http://localhost:8000/admin/
curl -X POST http://localhost:8000/api/auth/register/ \
-H "Content-Type: application/json" \
-d '{
"username": "newstudent",
"email": "student@example.com",
"password": "securepass123",
"role": "STUDENT",
"first_name": "John",
"last_name": "Doe"
}'curl -X POST http://localhost:8000/api/auth/login/ \
-H "Content-Type: application/json" \
-d '{
"username": "student1",
"password": "password123"
}'Response:
{
"token": "9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}Include the token in the Authorization header:
Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b
POST /api/auth/register/- Register new userPOST /api/auth/login/- Login and get tokenPOST /api/auth/logout/- Logout (delete token)GET /api/auth/profile/- View profilePUT /api/auth/profile/- Update profile
GET /api/courses/- List all coursesGET /api/courses/{id}/- Get course details
GET /api/exams/- List available examsGET /api/exams/{id}/- Get exam details with questionsGET /api/exams/{id}/my_submissions/- Get my submissions for this examGET /api/exams/{id}/statistics/- Get exam statistics (instructors only)
POST /api/exams/{id}/submit/- Submit exam answersGET /api/submissions/- List submissionsGET /api/submissions/{id}/- Get submission detailsGET /api/submissions/my_results/- Get all my results
GET /api/dashboard/- Student dashboard with analytics
curl -X GET http://localhost:8000/api/exams/ \
-H "Authorization: Token YOUR_TOKEN"curl -X GET http://localhost:8000/api/exams/1/ \
-H "Authorization: Token YOUR_TOKEN"curl -X POST http://localhost:8000/api/exams/1/submit/ \
-H "Authorization: Token YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"answers": [
{
"question_id": 1,
"answer_text": "C"
},
{
"question_id": 2,
"answer_text": "False"
},
{
"question_id": 3,
"answer_text": {
"text": "A stack is LIFO while queue is FIFO"
}
}
]
}'Response includes:
- Submission details
- Grading results
- Score and feedback
- Individual answer grades
curl -X GET http://localhost:8000/api/submissions/my_results/ \
-H "Authorization: Token YOUR_TOKEN"curl -X GET http://localhost:8000/api/dashboard/ \
-H "Authorization: Token YOUR_TOKEN"# Run all tests
python manage.py test
# Run specific test class
python manage.py test exams.tests.GradingServiceTest
# Run with verbose output
python manage.py test --verbosity=2Users (Custom User Model)
├── id (PK)
├── username
├── email
├── role (STUDENT/INSTRUCTOR/ADMIN)
└── student_id
Courses
├── id (PK)
├── code
├── name
├── instructor_id (FK → Users)
└── timestamps
Exams
├── id (PK)
├── title
├── course_id (FK → Courses)
├── duration_minutes
├── start_time
├── end_time
├── status (DRAFT/PUBLISHED/ARCHIVED)
├── passing_score
├── max_attempts
└── timestamps
Questions
├── id (PK)
├── exam_id (FK → Exams)
├── question_type (MCQ/SHORT/ESSAY/TF)
├── question_text
├── order
├── marks
├── expected_answer (JSON)
└── options (JSON)
Submissions
├── id (PK)
├── student_id (FK → Users)
├── exam_id (FK → Exams)
├── attempt_number
├── status (IN_PROGRESS/SUBMITTED/GRADING/GRADED)
├── score
├── marks_obtained
└── timestamps
Answers
├── id (PK)
├── submission_id (FK → Submissions)
├── question_id (FK → Questions)
├── answer_text (JSON)
├── marks_awarded
├── is_correct
└── feedback
-
Indexing Strategy:
- Composite indexes on frequently queried fields
- Index on (student, submitted_at) for fast result retrieval
- Index on (exam, status) for filtering
-
Query Optimization:
select_related()for foreign keysprefetch_related()for reverse relations- Minimal queries using annotations and aggregations
-
Security:
- Token authentication
- Role-based permissions
- Students can only access their own data
- Input validation at serializer level
- Atomic transactions for submissions
-
Grading Service:
- Strategy pattern for different question types
- Keyword matching algorithm for open-ended questions
- Partial credit support
- Modular design for easy extension
For production deployment:
- Use PostgreSQL:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'assessment_db',
'USER': 'db_user',
'PASSWORD': 'db_password',
'HOST': 'localhost',
'PORT': '5432',
}
}- Security Settings:
DEBUG = False
SECRET_KEY = config('SECRET_KEY')
ALLOWED_HOSTS = ['yourdomain.com']
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True- Static Files:
python manage.py collectstatic-
Database Optimization:
- Strategic indexing on frequently queried fields
- Composite indexes for multi-column queries
- Query optimization using select_related and prefetch_related
-
Caching (can be added):
- Cache exam details
- Cache submission results
- Redis integration for session storage
-
Pagination:
- Default page size: 20 items
- Configurable per endpoint
- Exact match comparison
- All or nothing scoring
-
Text Preprocessing:
- Lowercase conversion
- Punctuation removal
- Whitespace normalization
-
Keyword Extraction:
- Remove stop words
- Extract meaningful terms
-
Similarity Calculation:
- Jaccard similarity:
|A ∩ B| / |A ∪ B| - Keyword coverage:
|student ∩ expected| / |expected| - Weighted combination:
0.4 × jaccard + 0.6 × coverage
- Jaccard similarity:
-
Scoring:
- ≥90% similarity: Excellent (full marks)
- ≥70% similarity: Good (70-90% marks)
- ≥50% similarity: Partial (50-70% marks)
- <50% similarity: Insufficient (<50% marks)
-
LLM Integration:
- OpenAI/Claude integration for advanced grading
- Contextual understanding of answers
- Detailed feedback generation
-
Real-time Features:
- WebSocket support for live exams
- Proctoring capabilities
- Live grading updates
-
Analytics:
- Advanced performance metrics
- Question difficulty analysis
- Learning outcome tracking
-
Additional Question Types:
- File upload questions
- Code evaluation
- Matching questions
- Fill-in-the-blank
For issues or questions:
- Review the Swagger documentation
- Check test cases for examples
- Examine the grading service implementation
MIT License - Feel free to use for academic purposes.