Skip to content

DanAdewole/Acad-Mini-Assessment-Engine

Repository files navigation

πŸ“š Mini Assessment Engine

A comprehensive, production-ready Django REST API for managing educational assessments, exams, and automated grading with AI support.

Django DRF Python PostgreSQL


πŸ“‹ Table of Contents


✨ Features

Core Functionality

  • πŸŽ“ 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

Technical Excellence

  • πŸš€ 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

πŸ› οΈ Tech Stack

Backend

  • Django 5.2 - Web framework
  • Django REST Framework 3.16+ - API framework
  • drf-spectacular - OpenAPI 3 schema generation
  • PostgreSQL / SQLite - Database

AI & Grading

  • scikit-learn - TF-IDF text similarity (Mock grading)
  • OpenAI GPT - AI-powered grading (optional)
  • Google Gemini - AI-powered grading (optional)

DevOps

  • Poetry - Dependency management
  • Docker & Docker Compose - Containerization
  • Ruff - Linting and formatting

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Poetry (recommended) or pip
  • PostgreSQL 15+ (optional, SQLite works for dev)

1. Clone the Repository

git clone https://github.com/yourusername/mini_assessment_engine.git
cd mini_assessment_engine

2. Install Dependencies

# Using Poetry (recommended)
poetry install

# Or using pip
pip install -r requirements.txt

3. Set Up Environment

# Copy environment template
cp env.example .env

# Edit .env with your settings
# Minimum required:
SECRET_KEY=your-secret-key-here
DEBUG=True
GRADING_SERVICE=mock

4. Run Migrations

poetry run python manage.py migrate

5. Create Superuser

poetry run python manage.py createsuperuser

6. Start Development Server

poetry run python manage.py runserver

7. Access the Application


πŸ“¦ Installation

Option 1: Local Development (Poetry)

  1. Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
  1. Install Dependencies
poetry install
  1. Activate Virtual Environment
poetry shell
  1. 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
  1. Run Server
python manage.py runserver

Option 2: Local Development (pip)

  1. Create Virtual Environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install Dependencies
pip install -r requirements.txt
  1. Follow steps 4-6 from Option 1

🐳 Docker Setup

Quick Start with Docker Compose

  1. Build and Start Services
docker-compose up --build
  1. Run Migrations (first time)
docker-compose exec web python manage.py migrate
  1. Create Superuser
docker-compose exec web python manage.py createsuperuser
  1. Access the Application

Docker Commands

# 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 --build

Production Docker

For production, update docker-compose.yml:

environment:
    - DEBUG=False
    - SECRET_KEY=your-production-secret-key
    - DATABASE_URL=your-production-database-url
    - ALLOWED_HOSTS=yourdomain.com

πŸ“ Project Structure

mini_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

πŸ‘₯ User Roles

The system supports three user roles with distinct permissions:

1. Student πŸ‘¨β€πŸŽ“

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

2. Instructor πŸ‘¨β€πŸ«

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

3. Admin πŸ‘¨β€πŸ’Ό

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

🎯 Grading Methods

The system supports three grading methods that can be switched via configuration:

1. Mock Grading (TF-IDF Based)

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=mock

2. OpenAI GPT Grading

Best 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 performance
  • gpt-4-turbo - Fast and capable
  • gpt-3.5-turbo - Budget option

Configuration:

GRADING_SERVICE=ai
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxx
OPENAI_MODEL=gpt-4o-mini

3. Google Gemini Grading

Best 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 quality
  • gemini-pro - General purpose

Configuration:

GRADING_SERVICE=gemini
GEMINI_API_KEY=AIzaSyxxxxxxxxxxxxx
GEMINI_MODEL=gemini-1.5-flash

Grading Comparison

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

API Documentation can be found in swagger

Authentication

All endpoints except registration and login require authentication:

# Include token in header
Authorization: Token your-auth-token-here

βš™οΈ Configuration

Environment Variables

See env.example for all available options:

Core Settings

SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1

Database

# SQLite (default)
DATABASE_URL=

# PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/dbname

Grading Service

# 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

πŸ“š Documentation

  • 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

About

A comprehensive, production-ready Django REST API for managing educational assessments, exams, and automated grading with AI support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors