This is the FastAPI backend for the AI-powered quiz generation platform. It handles user authentication, file uploads, quiz generation using Gemini AI, answer evaluation, history tracking, and more.
π₯οΈ The frontend for this project is built with React.js. Check it out here: quiz-app-frontend
- FastAPI (with Starlette and Pydantic)
- SQLAlchemy (ORM with PostgreSQL)
- Alembic for database migrations
- Google Gemini API for AI-powered quiz generation
- UUID-based models for secure record identification
- JWT Authentication
.
βββ ai_prompts/ # Gemini AI prompts engineering
βββ backend
Β Β βββ alembic/ # Migration scripts
Β Β βββ alembic.ini # Alembic config
Β Β βββ auth/ # Login, password hashing, token generation
Β Β βββ db/ # Database models and session management
Β Β βββ main.py # App entry point
Β Β βββ uploads/ # Uploaded files (PDF, DOCX, TXT)
Β Β βββ Procfile # Deployemnt instructions
Β Β βββ requirements.txt # Backend dependencies
Β Β βββ routes/ # API routes: answers, quizzes, uploads, users
Β Β βββ runtime.txt
Β Β βββ services/ # Gemini AI service logic
Β Β βββ tests/ # Pytest-based test suite- JWT tokens are issued on login via
/auth/login - Token is passed in the header:
Authorization: Bearer <token> - Authenticated endpoints use FastAPI
Dependsto extract and verify tokens
| Method | Path | Description |
|---|---|---|
| POST | /auth/register |
Register a new user |
| POST | /auth/login |
Log in and receive JWT token |
| POST | /upload-db/ |
Upload a document (PDF, DOCX, TXT) |
| POST | /quizzes/generate/ |
Trigger Gemini to generate quiz questions |
| POST | /answers/ |
Submit answers and receive evaluation |
| GET | /dashboard |
Get user-specific uploaded files/quizzes |
| GET | /dashboard/files/{id} |
Get quizzes per uploaded file |
| GET | /history |
View latest attempt for each quiz |
| GET | /history/{quiz_id} |
View all attempts for a quiz |
View the auto-generated Swagger UI at: π https://quiz-backend-nick-4b3aa7c613b0.herokuapp.com/docs
- Uses Google Gemini via
services/gemini_service.py - Prompt engineering done in
ai_prompts/gemini_prompts.py - All quizzes include:
question,options[],correct answer, andexplanation
Tests are located in backend/tests/ and use Pytest
- Auth flows
- Upload validations (
PDF/DOCX/TXTonly) - Quiz submission and scoring
- Dashboard and history fetch
- Edge cases (e.g., empty files, bad JSON, invalid quiz attempts)
cd backend
pytestpython -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windowspip install -r requirements.txtDATABASE_URL=postgresql://user:password@localhost/quizdb
GEMINI_API_KEY=your_google_gemini_key
SECRET_KEY=your_jwt_secret_key
alembic upgrade headuvicorn main:app --reload- Gemini-generated quizzes are stored per file per user
- Each quiz has multiple attempts tracked
- UUIDs ensure secure and unique identification
- CORS enabled for frontend at
http://localhost:3000
See ai_prompts/ for detailed prompt templates sent to Gemini API.
- Overview: High-level description of system components.
- Data Flow: Describes how data moves from upload to evaluation.
- API Design: RESTful endpoints powering the system.
- General System Diagram (PDF): Visual architecture representation.
- User Stories: Features from a user perspective.
- System Architecture: Direct access to all technical documentation related to the system design, architecture, and data flow of the AI-Powered Quiz Web App.
MIT License
Built with π by Nick Efe Oni.
Feel free to fork, star, and share your feedback!
Nick Efe Oni
GitHub β’ LinkedIn
βοΈ efeoni10@gmail.com