Loading repository data…
Loading repository data…
furyfist / repository
A secure, role-based REST API built with FastAPI to power a full-stack quiz platform. This backend uses SQLAlchemy for ORM, Alembic for database migrations, and Pydantic for data validation.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This document outlines the final state of the FastAPI backend. We successfully pivoted from the initial "Question Bank" concept to a simpler, more direct "Quiz-Centric" model. The backend is now complete and fully functional, supporting the entire workflow for both Admins and Students.
The first phase involved completely replacing the old 6-table database schema with a new, more efficient 5-table schema.
app/models/)We created a new 5-table model that is simpler and better for analytics:
app/models/user.py: (Unchanged)
usersadmin, teacher, student). This is the foundation for our authentication.app/models/quiz.py: (New File)
quizzesusers table to track who created it.app/models/question.py: (Modified)
questionsquiz_id foreign key, meaning every question belongs directly to one quiz. This was the most important change.app/models/quiz_assignment.py: (New File)
quiz_assignmentsstudent_id is assigned to which quiz_id. We also added score (Float) and submitted_at (Timestamp) columns to store the student's final results.app/models/response.py: (New File)
responsesTo apply this new schema to our PostgreSQL database:
nta_test database to clear the old, conflicting Alembic history. We ran the SQL commands DROP SCHEMA public CASCADE; and CREATE SCHEMA public; directly in psql.alembic revision --autogenerate -m "..." to create a new migration script that built the 5 new tables. We applied this with alembic upgrade head.score and submitted_at columns to the quiz_assignments model, we ran alembic revision --autogenerate ... and alembic upgrade head a second time to apply this change.__init__.py)To ensure our new models and schemas could be imported correctly by other parts of the app, we created two new files:
app/models/__init__.py: This file imports all 5 of our SQLAlchemy models (User, Quiz, Question, etc.) and makes them available to the application.app/schemas/__init__.py: This file does the same for all our Pydantic schemas.This structure fixed all AttributeError problems and is now stable.
With the database in place, we built the API endpoints. We created one new router (quiz.router) to hold all the new logic, which we then included in app/main.py.
All endpoints that perform "create" or "view results" actions are protected and require an Admin/Teacher token. All endpoints for "taking" a quiz require a Student token. This security is handled by the existing get_current_user dependency from app/routers/auth.py.
app/routers/quiz.py)POST /quizzes/
{ "title": "New Quiz Title" }POST /quizzes/{quiz_id}/questions
{ "text": "...", "options_json": {...}, "correct_answer": "A", "marks": 5 }POST /quizzes/{quiz_id}/assign
{ "student_id": 2 }GET /quizzes/{quiz_id}/results
app/routers/quiz.py)GET /quizzes/assigned/me
GET /quizzes/assigned/{assignment_id}
correct_answer field is omitted for security.POST /quizzes/assigned/{assignment_id}/submit
{ "answers": [ { "question_id": 1, "selected_answer": "A" }, ... ] }Bug Fix: We also fixed a bug in this endpoint, changing datetime.utcnow() to datetime.now(timezone.utc) to ensure the submitted_at timestamp saves correctly to the database.
The backend is 100% complete and tested. The API fully supports the entire MVP workflow. Ready to begin Phase 3: Build Frontend (React).