FastAPI backend service for automatically grading CSCE-247 design pattern individual assignments. This system analyzes student GitHub repositories and provides automated grading based on predefined criteria.
This API service is designed for CSCE-247 Teaching Assistants to automate the grading process for individual design pattern assignments. Students submit their work via GitHub repository links, and the system automatically evaluates their code against established criteria.
- Framework: FastAPI with Python 3.11
- Database: PostgreSQL (shared with Django frontend)
- Authentication: GitHub token-based repository access
- Grading Engine: Automated analysis of design patterns and code structure
- Storage: Persistent grading results and criteria storage
# From project root
docker-compose up --build -d
# API will be available at http://localhost:8001
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_SERVER=localhost
export POSTGRES_DB=postgres
export POSTGRES_PORT=5432
# Run the application
uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload
Create a new assignment configuration.
Request:
{
"assignment_name": "Strategy Pattern Assignment"
}
Response:
{
"message": "Assignment created successfully",
"assignment_name": "Strategy Pattern Assignment"
}
Upload grading criteria for an assignment.
Request:
- Form Data:
criteria_file
(File: .txt, .docx, or .json)
Supported Formats:
- Text (.txt): Plain text grading rubric
- Word (.docx): Formatted grading document
- JSON (.json): Structured criteria with weights
Response:
{
"message": "Criteria uploaded successfully",
"assignment_name": "Strategy Pattern Assignment",
"file_type": "docx"
}
Submit a repository for automated grading.
Request:
{
"assignment_name": "Strategy Pattern Assignment",
"repo_link": "https://github.com/student/csce247-assignment",
"token": "ghp_xxxxxxxxxxxxxxxxxxxx"
}
Response:
{
"student_name": "john_doe",
"assignment_name": "Strategy Pattern Assignment",
"final_grade": 85.5,
"max_points": 100,
"grading_details": {
"pattern_implementation": {
"score": 30,
"max_score": 35,
"feedback": "Strategy pattern correctly implemented with minor issues..."
},
"code_quality": {
"score": 25,
"max_score": 30,
"feedback": "Good code structure and documentation..."
}
},
"submission_time": "2024-09-22T15:30:00Z"
}
Retrieve all grading results.
Response:
[
{
"id": 1,
"student_name": "john_doe",
"assignment_name": "Strategy Pattern Assignment",
"final_grade": 85.5,
"submission_time": "2024-09-22T15:30:00Z"
}
]
Get all grades for a specific student.
Response:
[
{
"id": 1,
"student_name": "john_doe",
"assignment_name": "Strategy Pattern Assignment",
"final_grade": 85.5,
"assignment_details": { /* full grading breakdown */ }
}
]
Health check endpoint.
Response:
{
"message": "FastAPI is connected!"
}
Run the test suite:
# With Docker
docker-compose exec fastapi python -m pytest
# Local development
pytest tests/
id
: Primary keystudent_name
: Extracted from GitHub repositoryassignment_name
: Reference to assignmentrepo_link
: GitHub repository URLfinal_grade
: Calculated final scoremax_points
: Total possible pointsgrading_details
: JSON field with detailed breakdownsubmission_time
: Timestamp of grading requestcreated_at
: Record creation time
id
: Primary keyassignment_name
: Unique assignment identifiercriteria
: JSON field with grading criteriacreated_at
: Assignment creation time
ENV
: Environment (development/production)POSTGRES_USER
: Database usernamePOSTGRES_PASSWORD
: Database passwordPOSTGRES_SERVER
: Database hostPOSTGRES_DB
: Database namePOSTGRES_PORT
: Database portALLOWED_ORIGINS
: CORS allowed origins
The grading engine can be configured through criteria files to evaluate:
- Design pattern implementation correctness
- Code quality and structure
- Documentation completeness
- Test coverage
- Repository organization
The API includes comprehensive logging for:
- Grading requests and results
- Repository access attempts
- Database operations
- Error tracking and debugging
This API integrates seamlessly with the Django frontend service, providing:
- RESTful endpoints for all grading operations
- CORS configuration for web interface access
- Shared PostgreSQL database for data consistency
- Real-time grading status updates
-
Setup New Assignment:
curl -X POST http://localhost:8001/assignments \ -H "Content-Type: application/json" \ -d '{"assignment_name": "Observer Pattern"}'
-
Upload Grading Criteria: Use the web interface at http://localhost:8000/upload-criteria/
-
Batch Grade Submissions: Students submit via web interface, results stored automatically
-
Export Grades: Access via web interface or direct API calls to
/grades
- Repository Access Issues: Verify GitHub token has read access
- Grading Failures: Check criteria file format and assignment name
- Database Connection: Ensure PostgreSQL is running and accessible
- Frontend: Django web interface for TAs and students
- Database: PostgreSQL for persistent storage
- Admin Interface: pgAdmin for database management