# bhargavaalapati/ai-wiki-quiz-generator architecture

> Architecture diagram of the GitHub repository bhargavaalapati/ai-wiki-quiz-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhargavaalapati/ai-wiki-quiz-generator
- Repository: https://github.com/bhargavaalapati/ai-wiki-quiz-generator

## Overview

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: [`backend/main.py`](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/main.py) (API routes), [`backend/database.py`](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/database.py) (Database), [`frontend/src/services/api.js`](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/services/api.js) (API client), [`frontend/src/tabs/GenerateQuizTab.jsx`](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/tabs/GenerateQuizTab.jsx) (Generate Quiz)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui_shell["App shell<br/>SPA entry<br/>[App.jsx]"]
  node_generate_tab["Generate Quiz<br/>view"]
  node_history_tab["History<br/>view<br/>[HistoryTab.jsx]"]
  node_quiz_display["Quiz UI<br/>[QuizDisplay.jsx]"]
  node_active_quiz["Active Quiz<br/>[ActiveQuiz.jsx]"]
  node_ui_feedback["UI states<br/>components<br/>[Loader.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_url_validation["URL checks<br/>utils<br/>[validation.js]"]
end

subgraph group_backend["Backend"]
  node_api_routes["API routes<br/>FastAPI app<br/>[main.py]"]
  node_request_guard["Validation guard<br/>request layer<br/>[main.py]"]
  node_scraper["Scraper<br/>ingestion<br/>[scraper.py]"]
  node_rag_pipeline["RAG pipeline<br/>retrieval<br/>[rag_pipeline.py]"]
  node_llm_generator["Quiz generator<br/>llm"]
  node_db_layer[("Database<br/>persistence<br/>[database.py]")]
  node_schema_models["Models<br/>schema/orm<br/>[models.py]"]
end

subgraph group_data["Data"]
  node_test_db[("test.db<br/>sqlite db<br/>[test.db]")]
  node_sample_data["Sample data<br/>fixtures<br/>[Alan_Turing.json]"]
  node_external_sources{{"External services<br/>runtime deps"}}
end

node_ui_shell -->|"switches to"| node_generate_tab
node_ui_shell -->|"switches to"| node_history_tab
node_generate_tab -->|"checks URL"| node_url_validation
node_generate_tab -->|"requests quiz"| node_api_client
node_history_tab -->|"loads history"| node_api_client
node_api_client -->|"POST/GET"| node_api_routes
node_api_routes -->|"validates"| node_request_guard
node_request_guard -->|"scrapes"| node_scraper
node_scraper -->|"passes text"| node_rag_pipeline
node_rag_pipeline -->|"selects context"| node_llm_generator
node_llm_generator -->|"stores quiz"| node_db_layer
node_api_routes -->|"reads history"| node_db_layer
node_db_layer -->|"uses schema"| node_schema_models
node_db_layer -->|"backed by"| node_test_db
node_scraper -->|"Wikipedia"| node_external_sources
node_llm_generator -->|"Gemini"| node_external_sources
node_rag_pipeline -->|"pgvector"| node_external_sources
node_api_routes -.->|"fixtures"| node_sample_data
node_ui_feedback -->|"shows errors"| node_api_client
node_quiz_display -->|"renders"| node_active_quiz

click node_ui_shell "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/App.jsx"
click node_generate_tab "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/tabs/GenerateQuizTab.jsx"
click node_history_tab "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/tabs/HistoryTab.jsx"
click node_quiz_display "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/components/QuizDisplay.jsx"
click node_active_quiz "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/components/ActiveQuiz.jsx"
click node_ui_feedback "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/components/Loader.jsx"
click node_api_client "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/services/api.js"
click node_url_validation "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/utils/validation.js"
click node_api_routes "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/main.py"
click node_request_guard "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/main.py"
click node_scraper "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/scraper.py"
click node_rag_pipeline "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/rag_pipeline.py"
click node_llm_generator "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/llm_quiz_generator.py"
click node_db_layer "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/database.py"
click node_schema_models "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/models.py"
click node_test_db "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/test.db"
click node_sample_data "https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/sample_data/Alan_Turing.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui_shell,node_generate_tab,node_history_tab,node_quiz_display,node_active_quiz,node_ui_feedback,node_api_client,node_url_validation toneBlue
class node_api_routes,node_request_guard,node_scraper,node_rag_pipeline,node_llm_generator,node_db_layer,node_schema_models toneAmber
class node_test_db,node_sample_data,node_external_sources toneMint
```

## Components

### Frontend

React/Vite single-page app for quiz generation and history browsing

- [App shell](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/App.jsx): SPA entry · Top-level frontend composition and tab switching · `frontend/src/App.jsx`
- [Generate Quiz](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/tabs/GenerateQuizTab.jsx): view · URL input and quiz creation flow · `frontend/src/tabs/GenerateQuizTab.jsx`
- [History](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/tabs/HistoryTab.jsx): view · Saved quiz history and prior runs · `frontend/src/tabs/HistoryTab.jsx`
- [Quiz UI](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/components/QuizDisplay.jsx): Renders questions, answers, and quiz content · `frontend/src/components/QuizDisplay.jsx`
- [Active Quiz](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/components/ActiveQuiz.jsx): Interactive quiz-taking state · `frontend/src/components/ActiveQuiz.jsx`
- [UI states](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/components/Loader.jsx): components · Loading, modal, skeleton, and rate-limit feedback · `frontend/src/components/Loader.jsx`
- [API client](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/services/api.js): service · Frontend boundary to backend endpoints · `frontend/src/services/api.js`
- [URL checks](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/frontend/src/utils/validation.js): utils · Client-side input validation before submit · `frontend/src/utils/validation.js`

### Backend

FastAPI service for scraping, retrieval, generation, and persistence

- [API routes](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/main.py): FastAPI app · HTTP entrypoint and request orchestration · `backend/main.py`
- [Validation guard](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/main.py): request layer · Validates inputs and enforces rate limits · `backend/main.py`
- [Scraper](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/scraper.py): ingestion · Fetches and cleans Wikipedia article text · `backend/scraper.py`
- [RAG pipeline](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/rag_pipeline.py): retrieval · Dense retrieval, BM25, and reranking for context selection · `backend/rag_pipeline.py`
- [Quiz generator](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/llm_quiz_generator.py): llm · Builds prompts and generates quiz output · `backend/llm_quiz_generator.py`
- [Database](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/database.py): persistence · Quiz cache, history store, and record access · `backend/database.py`
- [Models](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/models.py): schema/orm · Quiz records and database schema objects · `backend/models.py`

### Data

Local fixtures and persisted quiz records

- [test.db](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/backend/test.db): sqlite db · Local SQLite database used for development and tests · `backend/test.db`
- [Sample data](https://github.com/bhargavaalapati/ai-wiki-quiz-generator/blob/main/sample_data/Alan_Turing.json): fixtures · Offline example payloads and tested URLs · `sample_data/Alan_Turing.json`
- **External services**: runtime deps · Wikipedia, Gemini, and production vector datastore

## Connections

- 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
