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