How bhargavaalapati/ai-wiki-quiz-generator works
1. Repository shape
- This is a two-tier app: a React/Vite frontend in frontend/ and a FastAPI backend in backend/.
- The backend owns the AI workflow, scraping, persistence, and quiz generation; the frontend is mostly an interactive UI over the backend API.
2. Primary user flow
- The core flow is: Wikipedia URL input → backend scrape/clean → cache lookup → quiz generation if needed → store result → return quiz to UI.
- The README’s API contract shows the main backend surfaces: POST /generate_quiz, GET /history, GET /quiz/{id}, and POST /recommend_path.
3. Frontend subsystem
- frontend/src/App.jsx and the tabs/ directory indicate a small SPA with at least two main views: Generate Quiz and History.
- Components like QuizDisplay, ActiveQuiz, Modal, Loader, SkeletonCard, and RateLimitCard suggest the UI supports loading states, quiz interaction, dialogs, and API error/rate-limit feedback.
- services/api.js is the client boundary to the backend, while utils/validation.js handles input checks before submitting URLs.
4. Backend API layer
- backend/main.py is the FastAPI entrypoint and likely the orchestration point for request validation, routing, background work, and response shaping.
- backend/test_main.py indicates the API contract is tested at the route level, which matters because the frontend depends on stable quiz/history response shapes.
5. Scraping and content normalization
- backend/scraper.py is the ingestion boundary for Wikipedia pages.
- Its role is to extract article text and clean/normalize it before any AI processing, which is important because the readme emphasizes token reduction and “clean + optimize text” before generation.
6. RAG and retrieval layer
- backend/rag_pipeline.py is the retrieval/recommendation subsystem.
- Based on the README, this layer combines dense retrieval, sparse retrieval (BM25), and re-ranking to support quiz generation or learning-path recommendations.
- This is the main architecture boundary between raw scraped content and AI-produced output.
7. LLM generation layer
- backend/llm_quiz_generator.py is the generation boundary that turns retrieved/cleaned article context into quiz questions, explanations, and summary content.
- The README ties this to Gemini and LangChain, so this module is likely where prompt construction and model invocation live.
8. Persistence and cache
- backend/database.py, backend/models.py, and backend/test.db show a persistence layer with a local SQLite test database in the repo and a production PostgreSQL/Supabase setup described in the README.
- The architecture uses the database as a cache-first store for generated quizzes and as the source for history lookup, supporting the “O(1) cache lookup” claim.
9. Data model boundary
- backend/models.py likely defines the quiz record structure, associated metadata, and any ORM/schema objects used by FastAPI and the database layer.
- The stored data probably includes the source URL, generated questions, explanations, summary/topics/entities, and timestamps for the history view.
10. Asynchronous and production-oriented behavior
- The README calls out async ingestion/background tasks, which means the backend likely offloads slower generation/indexing work so the request path stays responsive.
- Rate limiting and validation are explicit product concerns, and the frontend’s RateLimitCard suggests the API can return a dedicated “try again later” state.
11. External services and infrastructure
- The system depends on Wikipedia as the content source, Gemini as the LLM, and Supabase PostgreSQL + pgvector as the production datastore/vector index.
- The README also references Vercel for frontend hosting and Render for backend deployment, so the runtime is split across separate hosting environments.
12. Sample data and test assets
- sample_data/Alan_Turing.json, sample_data/Independence.json, and sample_data/tested_urls.txt are fixtures for offline validation/demoing.
- These files suggest the project supports reproducible testing or demo scenarios without relying entirely on live Wikipedia calls.
13. Important architectural boundary
- The clean separation is: frontend = presentation and interaction, backend = ingestion, RAG, generation, persistence.
- For a diagram, the key internal backend pipeline is: router → validation/rate limit → scraper → retrieval/rerank → LLM generator → database write/read → response.
Main entry points: main.py API routes · database.py Database · api.js API client · GenerateQuizTab.jsx Generate Quiz
Components 18
Frontend
React/Vite single-page app for quiz generation and history browsing
- App shell · Top-level frontend composition and tab switching
frontend/src/App.jsx - Generate Quiz · URL input and quiz creation flow
frontend/src/tabs/GenerateQuizTab.jsx - History · Saved quiz history and prior runs
frontend/src/tabs/HistoryTab.jsx - Quiz UI · Renders questions, answers, and quiz content
frontend/src/components/QuizDisplay.jsx - Active Quiz · Interactive quiz-taking state
frontend/src/components/ActiveQuiz.jsx - UI states · Loading, modal, skeleton, and rate-limit feedback
frontend/src/components/Loader.jsx - API client · Frontend boundary to backend endpoints
frontend/src/services/api.js - URL checks · Client-side input validation before submit
frontend/src/utils/validation.js
Backend
FastAPI service for scraping, retrieval, generation, and persistence
- API routes · HTTP entrypoint and request orchestration
backend/main.py - Validation guard · Validates inputs and enforces rate limits
backend/main.py - Scraper · Fetches and cleans Wikipedia article text
backend/scraper.py - RAG pipeline · Dense retrieval, BM25, and reranking for context selection
backend/rag_pipeline.py - Quiz generator · Builds prompts and generates quiz output
backend/llm_quiz_generator.py - Database · Quiz cache, history store, and record access
backend/database.py - Models · Quiz records and database schema objects
backend/models.py
Data
Local fixtures and persisted quiz records
- test.db · Local SQLite database used for development and tests
backend/test.db - Sample data · Offline example payloads and tested URLs
sample_data/Alan_Turing.json - External services · Wikipedia, Gemini, and production vector datastore
Connections 20
- App shell → Generate Quiz: switches to · Main tabbed flow for creating quizzes
- App shell → History: switches to · Main tabbed flow for browsing history
- Generate Quiz → URL checks: checks URL · Pre-submission client validation
- Generate Quiz → API client: requests quiz · Sends generate request to backend
- History → API client: loads history · Fetches prior quiz records
- API client → API routes: POST/GET · Calls quiz, history, and recommendation endpoints
- API routes → Validation guard: validates · Route-level validation and response control
- Validation guard → Scraper: scrapes · Fetches and cleans article content
- Scraper → RAG pipeline: passes text · Normalized article content becomes retrieval input
- RAG pipeline → Quiz generator: selects context · Produces ranked context for quiz generation
- Quiz generator → Database: stores quiz · Persists generated quiz and metadata
- API routes → Database: reads history · Serves cached quiz and history lookup
- Database → Models: uses schema · ORM and record definitions
- Database → test.db: backed by · Local SQLite persistence for development
- Scraper → External services: Wikipedia · Content source for article ingestion
- Quiz generator → External services: Gemini · LLM generation dependency
- RAG pipeline → External services: pgvector · Production retrieval datastore and vector index
- API routes → Sample data: fixtures · Offline demo and validation assets
- UI states → API client: shows errors · Loading, empty, and rate-limit states reflect API outcomes
- Quiz UI → Active Quiz: renders · Quiz presentation and interaction work together