A comprehensive, production-ready Django REST API for managing educational assessments, exams, and automated grading with AI support.
- Features
- Tech Stack
- Quick Start
- Installation
- Docker Setup
- Project Structure
- User Roles
- Grading Methods
- API Documentation
- Configuration
- Documentation
- π Multi-tenant Course Management - Courses, exams, questions
- π 4 Question Types - Multiple choice, True/False, Short answer, Essay
- β‘ Automatic Grading - Instant grading with multiple AI options
- π€ AI-Powered - Support for OpenAI GPT and Google Gemini
- π₯ Role-Based Access - Students, Instructors, Admins
- π Secure Authentication - Token-based auth with email/password
- π Rich Analytics - Detailed submission statistics and insights
- π Regrade Support - Instructors can regrade submissions
- β±οΈ Timed Exams - Configurable start/end times and duration
- π RESTful API - Clean, well-documented endpoints
- π OpenAPI/Swagger - Interactive API documentation
- π Advanced Filtering - Search, filter, and sort all resources
- β‘ Query Optimization - N+1 query prevention with select_related/prefetch_related
- π‘οΈ Custom Permissions - Granular access control
- π¦ Modular Architecture - Reusable components and mixins
- π¨ Consistent Responses - Standardized success/error formatting
- π³ Docker Ready - Complete containerization support
- Django 5.2 - Web framework
- Django REST Framework 3.16+ - API framework
- drf-spectacular - OpenAPI 3 schema generation
- PostgreSQL / SQLite - Database
- scikit-learn - TF-IDF text similarity (Mock grading)
- OpenAI GPT - AI-powered grading (optional)
- Google Gemini - AI-powered grading (optional)
- Poetry - Dependency management
- Docker & Docker Compose - Containerization
- Ruff - Linting and formatting
- Python 3.11+
- Poetry (recommended) or pip
- PostgreSQL 15+ (optional, SQLite works for dev)
git clone https://github.com/yourusername/mini_assessment_engine.git
cd mini_assessment_engine# Using Poetry (recommended)
poetry install
# Or using pip
pip install -r requirements.txt# Copy environment template
cp env.example .env
# Edit .env with your settings
# Minimum required:
SECRET_KEY=your-secret-key-here
DEBUG=True
GRADING_SERVICE=mockpoetry run python manage.py migratepoetry run python manage.py createsuperuserpoetry run python manage.py runserver- API: http://127.0.0.1:8000/api/
- Swagger UI: http://127.0.0.1:8000/api/docs/
- ReDoc: http://127.0.0.1:8000/api/redoc/
- Django Admin: http://127.0.0.1:8000/admin/
- Install Poetry
curl -sSL https://install.python-poetry.org | python3 -- Install Dependencies
poetry install- Activate Virtual Environment
poetry shell- Set Up Database
# SQLite (default - no setup needed)
python manage.py migrate
# PostgreSQL
# 1. Create database: createdb assessment_engine
# 2. Update DATABASE_URL in .env
# 3. Run migrations: python manage.py migrate- Run Server
python manage.py runserver- Create Virtual Environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install Dependencies
pip install -r requirements.txt- Follow steps 4-6 from Option 1
- Build and Start Services
docker-compose up --build- Run Migrations (first time)
docker-compose exec web python manage.py migrate- Create Superuser
docker-compose exec web python manage.py createsuperuser- Access the Application
# Start services
docker-compose up
# Start in background
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs -f web
# Run commands in container
docker-compose exec web python manage.py <command>
# Rebuild after code changes
docker-compose up --buildFor production, update docker-compose.yml:
environment:
- DEBUG=False
- SECRET_KEY=your-production-secret-key
- DATABASE_URL=your-production-database-url
- ALLOWED_HOSTS=yourdomain.commini_assessment_engine/
β
βββ assessment_engine/ # Main project configuration
β βββ settings.py # Django settings
β βββ urls.py # Main URL routing
β βββ responses.py # Standardized API responses
β βββ permissions.py # Custom permission classes
β βββ exceptions.py # Custom exception handling
β βββ mixins.py # Reusable view mixins
β βββ base_views.py # Base ViewSet classes
β βββ grading/ # Grading service modules
β βββ base.py # Abstract grading interface
β βββ mock_grading.py # TF-IDF based grading
β βββ ai_grading.py # OpenAI GPT grading
β βββ gemini_grading.py # Google Gemini grading
β
βββ users/ # User management app
β βββ models.py # Custom User model
β βββ serializers.py # User serializers
β βββ views.py # Authentication views
β βββ urls.py # User endpoints
β
βββ courses/ # Course management app
β βββ models.py # Course model
β βββ serializers.py # Course serializers
β βββ views.py # Course views
β βββ urls.py # Course endpoints
β
βββ exams/ # Exam management app
β βββ models.py # Exam & Question models
β βββ serializers.py # Exam serializers
β βββ views.py # Exam views
β βββ urls.py # Exam endpoints
β
βββ submissions/ # Submission management app
β βββ models.py # Submission & Answer models
β βββ serializers.py # Submission serializers
β βββ views.py # Submission views
β βββ utils.py # Grading service factory
β βββ urls.py # Submission endpoints
β
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Docker image definition
βββ pyproject.toml # Poetry dependencies
βββ .env.example # Environment variables template
βββ ERD.md # Database schema documentation
βββ README.md # This file
The system supports three user roles with distinct permissions:
Capabilities:
- View published courses and active exams
- Submit exam answers
- View their own submissions and grades
- View detailed feedback on answers
Restrictions:
- Cannot create or edit courses/exams
- Cannot view other students' submissions
- Cannot access admin features
Capabilities:
- All Student capabilities
- Create and manage courses
- Create and manage exams and questions
- View all student submissions for their courses
- Regrade submissions
- View submission statistics
- Publish/unpublish courses and exams
Restrictions:
- Cannot access system-wide admin features
- Cannot manage users
- Limited to their own courses
Capabilities:
- All Instructor capabilities
- Full system access
- Manage all users
- Access all courses and exams
- System configuration
- Delete submissions (for data cleanup)
- Update/delete any resource
Use Cases:
- System administration
- User management
- Data cleanup
- Technical support
The system supports three grading methods that can be switched via configuration:
Best For: Development, testing, cost-sensitive deployments
Features:
- β Free - No API costs
- β Fast - ~10ms per answer
- β Offline - No internet required
- β Consistent - Deterministic results
How It Works:
- Uses TF-IDF (Term Frequency-Inverse Document Frequency)
- Calculates cosine similarity between student and expected answers
- Good for exact matches and keyword-based grading
- ~70-80% accuracy for objective questions
Configuration:
GRADING_SERVICE=mockBest For: High-stakes assessments, detailed feedback
Features:
- π― Accurate - ~90-95% accuracy
- π Detailed Feedback - Comprehensive analysis
- π€ Context-Aware - Understands nuance
- π° Paid - API costs apply
Supported Models:
gpt-4o-mini- Most cost-effective ($0.15/1M tokens)gpt-4o- Balanced performancegpt-4-turbo- Fast and capablegpt-3.5-turbo- Budget option
Configuration:
GRADING_SERVICE=ai
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxx
OPENAI_MODEL=gpt-4o-miniBest For: Most use cases, best free tier
Features:
- π― Accurate - ~90-95% accuracy
- π Fast - Especially with gemini-1.5-flash
- πΈ Free Tier - 1500 requests/day
- π Detailed Feedback - Comprehensive analysis
Supported Models:
gemini-1.5-flash- Fast and efficient (recommended)gemini-1.5-pro- Best qualitygemini-pro- General purpose
Configuration:
GRADING_SERVICE=gemini
GEMINI_API_KEY=AIzaSyxxxxxxxxxxxxx
GEMINI_MODEL=gemini-1.5-flash| Feature | Mock | OpenAI | Gemini |
|---|---|---|---|
| Cost | Free | Paid | Free tier available |
| Speed | ~10ms | ~1-3s | ~500ms-2s |
| Accuracy | 70-80% | 90-95% | 90-95% |
| Feedback Quality | Basic | Excellent | Excellent |
| Setup Complexity | None | API key | API key |
| Best For | Dev/Testing | Production | Production |
API Documentation can be found in swagger
All endpoints except registration and login require authentication:
# Include token in header
Authorization: Token your-auth-token-hereSee env.example for all available options:
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1# SQLite (default)
DATABASE_URL=
# PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/dbname# Mock (free, default)
GRADING_SERVICE=mock
# OpenAI
GRADING_SERVICE=ai
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxx
OPENAI_MODEL=gpt-4o-mini
# Gemini
GRADING_SERVICE=gemini
GEMINI_API_KEY=AIzaSyxxxxxxxxxxxxx
GEMINI_MODEL=gemini-1.5-flash- ERD.md - Complete database schema and relationships
- env.example - Environment configuration reference
- Swagger UI - Interactive API documentation at
/api/schema/swagger-ui/ - Model Documentation - Inline docstrings in model files
- API Endpoint Documentation - Auto-generated from docstrings