# dummycodertech/campusbrain_chatbot architecture

> Architecture diagram of the GitHub repository dummycodertech/campusbrain_chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dummycodertech/campusbrain_chatbot
- Repository: https://github.com/dummycodertech/campusbrain_chatbot

## Overview

Campus Brain is a Streamlit PYQ study assistant: students provide a paper by upload or URL, the app extracts and caches its text, then offers revision materials, predictions, and question answering. The graph preserves the README’s major capabilities and the source-indexed call relationships. Some feature internals and app wiring are unsampled; those relationships are shown only where the README or source index supports them.

Main entry points: [`components/action_buttons.py`](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/action_buttons.py) (Study controls), [`app.py`](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/app.py) (Streamlit app), [`storage/cache_store.py`](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/storage/cache_store.py) (SQLite cache), [`components/chat_box.py`](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/chat_box.py) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["App and interface"]
  node_app["Streamlit app<br/>[app.py]"]
  node_buttons["Study controls<br/>[action_buttons.py]"]
  node_chat["Chat interface<br/>[chat_box.py]"]
  node_theme["Theme<br/>[theme.py]"]
  node_meter["Usage meter<br/>[usage_meter.py]"]
end

subgraph group_ingest["Paper ingestion"]
  node_ingest["Ingestion coordinator<br/>[cache_writer.py]"]
  node_pdfpages["PDF page extraction<br/>[pdf_to_images.py]"]
  node_ocr["OCR and subject tagging<br/>[ocr_tagger.py]"]
  node_fetch["Safe PDF fetch<br/>[safe_fetch.py]"]
  node_subjects["Subject reference"]
end

subgraph group_study["Study features"]
  node_summary["Paper summaries<br/>[summary.py]"]
  node_quiz["MCQ quizzes<br/>[quiz.py]"]
  node_flashcards["Flashcards<br/>[flashcards.py]"]
  node_answercheck["Answer checker<br/>[answer_checker.py]"]
  node_topics["Topic tagging<br/>[topic_tagger.py]"]
  node_topicprep["Question preparation<br/>[question_prep.py]"]
  node_heatmap["Topic heatmap<br/>[topic_heatmap.py]"]
  node_topquestions["Top questions<br/>[topic_questions.py]"]
  node_predictor["Exam predictor<br/>[predictor.py]"]
  node_mock["Mock paper generator<br/>[mock_paper.py]"]
  node_qa["Paper and syllabus Q&amp;A<br/>[qa.py]"]
  node_router["Intent router<br/>[intent_router.py]"]
end

subgraph group_data["Retrieval and cache"]
  node_paperlookup["Paper lookup<br/>[paper_lookup.py]"]
  node_subjectlookup["Subject lookup<br/>[subject_lookup.py]"]
  node_cache[("SQLite cache<br/>[cache_store.py]")]
end

subgraph group_external["AI and web services"]
  node_llm["Groq model service<br/>[llm_client.py]"]
  node_web["Tavily search<br/>[web_search.py]"]
end

node_student(("Student"))
node_host(("Embedding host"))
node_pdf["PDF source"]
node_tavily{{"Tavily API"}}

node_student -->|"uses"| node_app
node_host -->|"passes paper parameters"| node_app
node_student -->|"uploads PDF"| node_app
node_app -->|"starts ingestion"| node_ingest
node_app -->|"applies theme"| node_theme
node_app -->|"renders controls"| node_buttons
node_app -->|"renders chat"| node_chat
node_app -->|"looks up paper"| node_paperlookup
node_app -->|"reads paper state"| node_cache
node_app -->|"shows usage"| node_meter
node_ingest -->|"fetches PDF"| node_fetch
node_pdf -.->|"provides bytes"| node_fetch
node_ingest -->|"splits pages"| node_pdfpages
node_ingest -->|"extracts and tags"| node_ocr
node_ingest -->|"loads subject list"| node_subjects
node_ingest -->|"writes page text"| node_cache
node_buttons -->|"generates"| node_summary
node_buttons -->|"generates"| node_quiz
node_buttons -->|"generates"| node_flashcards
node_buttons -->|"checks answers"| node_answercheck
node_buttons -->|"tags topics"| node_topics
node_buttons -->|"renders heatmap"| node_heatmap
node_buttons -->|"shows recurring questions"| node_topquestions
node_buttons -->|"predicts topics"| node_predictor
node_buttons -->|"builds mock paper"| node_mock
node_buttons -->|"loads papers"| node_cache
node_chat -->|"routes free text"| node_router
node_chat -->|"answers questions"| node_qa
node_chat -->|"handles summary intent"| node_summary
node_chat -->|"handles quiz intent"| node_quiz
node_chat -->|"handles flashcard intent"| node_flashcards
node_topics -->|"prepares questions"| node_topicprep
node_predictor -->|"uses topic frequencies"| node_heatmap
node_predictor -->|"uses question history"| node_topquestions
node_paperlookup -->|"reads papers"| node_cache
node_subjectlookup -->|"reads subjects"| node_cache
node_summary -->|"uses output cache"| node_cache
node_quiz -->|"uses output cache"| node_cache
node_flashcards -->|"uses output cache"| node_cache
node_topics -->|"reads and saves tags"| node_cache
node_summary -->|"generates text"| node_llm
node_quiz -->|"generates questions"| node_llm
node_flashcards -->|"generates cards"| node_llm
node_answercheck -->|"evaluates answer"| node_llm
node_topics -->|"assigns topic tags"| node_llm
node_qa -->|"answers with model"| node_llm
node_qa -->|"searches knowledge"| node_web
node_web -->|"searches web"| node_tavily

click node_app "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/app.py"
click node_buttons "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/action_buttons.py"
click node_chat "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/chat_box.py"
click node_theme "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/theme.py"
click node_meter "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/usage_meter.py"
click node_ingest "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/cache_writer.py"
click node_pdfpages "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/pdf_to_images.py"
click node_ocr "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/ocr_tagger.py"
click node_fetch "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/safe_fetch.py"
click node_subjects "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/subject_reference.py"
click node_summary "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/summary.py"
click node_quiz "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/quiz.py"
click node_flashcards "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/flashcards.py"
click node_answercheck "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/answer_checker.py"
click node_topics "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/topic_tagger.py"
click node_topicprep "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/question_prep.py"
click node_heatmap "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/topic_heatmap.py"
click node_topquestions "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/topic_questions.py"
click node_predictor "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/predictor.py"
click node_mock "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/mock_paper.py"
click node_qa "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/qa.py"
click node_router "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/router/intent_router.py"
click node_paperlookup "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/retrieval/paper_lookup.py"
click node_subjectlookup "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/retrieval/subject_lookup.py"
click node_cache "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/storage/cache_store.py"
click node_llm "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/services/llm_client.py"
click node_web "https://github.com/dummycodertech/campusbrain_chatbot/blob/main/services/web_search.py"

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_app,node_buttons,node_chat,node_theme,node_meter toneBlue
class node_ingest,node_pdfpages,node_ocr,node_fetch,node_subjects toneAmber
class node_summary,node_quiz,node_flashcards,node_answercheck,node_topics,node_topicprep,node_heatmap,node_topquestions,node_predictor,node_mock,node_qa,node_router,node_tavily toneMint
class node_paperlookup,node_subjectlookup,node_cache toneRose
class node_llm,node_web,node_student,node_host,node_pdf toneIndigo
```

## Components

### App and interface

- [Streamlit app](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/app.py): `app.py`
- [Study controls](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/action_buttons.py): `components/action_buttons.py`
- [Chat interface](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/chat_box.py): `components/chat_box.py`
- [Theme](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/theme.py): `components/theme.py`
- [Usage meter](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/components/usage_meter.py): `components/usage_meter.py`

### Paper ingestion

- [Ingestion coordinator](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/cache_writer.py): `ingestion/cache_writer.py`
- [PDF page extraction](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/pdf_to_images.py): `ingestion/pdf_to_images.py`
- [OCR and subject tagging](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/ocr_tagger.py): `ingestion/ocr_tagger.py`
- [Safe PDF fetch](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/safe_fetch.py): `ingestion/safe_fetch.py`
- [Subject reference](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/ingestion/subject_reference.py): `ingestion/subject_reference.py`

### Study features

- [Paper summaries](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/summary.py): `generation/summary.py`
- [MCQ quizzes](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/quiz.py): `generation/quiz.py`
- [Flashcards](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/flashcards.py): `generation/flashcards.py`
- [Answer checker](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/answer_checker.py): `generation/answer_checker.py`
- [Topic tagging](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/topic_tagger.py): `generation/topic_tagger.py`
- [Question preparation](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/question_prep.py): `generation/question_prep.py`
- [Topic heatmap](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/topic_heatmap.py): `generation/topic_heatmap.py`
- [Top questions](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/topic_questions.py): `generation/topic_questions.py`
- [Exam predictor](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/predictor.py): `generation/predictor.py`
- [Mock paper generator](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/mock_paper.py): `generation/mock_paper.py`
- [Paper and syllabus Q&A](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/generation/qa.py): `generation/qa.py`
- [Intent router](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/router/intent_router.py): `router/intent_router.py`

### Retrieval and cache

- [Paper lookup](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/retrieval/paper_lookup.py): `retrieval/paper_lookup.py`
- [Subject lookup](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/retrieval/subject_lookup.py): `retrieval/subject_lookup.py`
- [SQLite cache](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/storage/cache_store.py): `storage/cache_store.py`

### AI and web services

- [Groq model service](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/services/llm_client.py): `services/llm_client.py`
- [Tavily search](https://github.com/dummycodertech/campusbrain_chatbot/blob/main/services/web_search.py): `services/web_search.py`

### Other components

- **Student**
- **Embedding host**
- **PDF source**
- **Tavily API**

## Connections

- Student → Streamlit app: uses (evidence: `README.md`)
- Embedding host → Streamlit app: passes paper parameters (evidence: `README.md`)
- Student → Streamlit app: uploads PDF (evidence: `README.md`)
- Streamlit app → Ingestion coordinator: starts ingestion (evidence: `app.py`)
- Streamlit app → Theme: applies theme (evidence: `app.py`)
- Streamlit app → Study controls: renders controls (evidence: `app.py`)
- Streamlit app → Chat interface: renders chat (evidence: `app.py`)
- Streamlit app → Paper lookup: looks up paper (evidence: `app.py`)
- Streamlit app → SQLite cache: reads paper state (evidence: `app.py`)
- Streamlit app → Usage meter: shows usage (evidence: `app.py`)
- Ingestion coordinator → Safe PDF fetch: fetches PDF (evidence: `ingestion/cache_writer.py`)
- PDF source → Safe PDF fetch: provides bytes (evidence: `README.md`)
- Ingestion coordinator → PDF page extraction: splits pages (evidence: `ingestion/cache_writer.py`)
- Ingestion coordinator → OCR and subject tagging: extracts and tags (evidence: `ingestion/cache_writer.py`)
- Ingestion coordinator → Subject reference: loads subject list (evidence: `ingestion/cache_writer.py`)
- Ingestion coordinator → SQLite cache: writes page text (evidence: `ingestion/cache_writer.py`)
- Study controls → Paper summaries: generates (evidence: `components/action_buttons.py`)
- Study controls → MCQ quizzes: generates (evidence: `components/action_buttons.py`)
- Study controls → Flashcards: generates (evidence: `components/action_buttons.py`)
- Study controls → Answer checker: checks answers (evidence: `components/action_buttons.py`)
- Study controls → Topic tagging: tags topics (evidence: `components/action_buttons.py`)
- Study controls → Topic heatmap: renders heatmap (evidence: `components/action_buttons.py`)
- Study controls → Top questions: shows recurring questions (evidence: `components/action_buttons.py`)
- Study controls → Exam predictor: predicts topics (evidence: `components/action_buttons.py`)
- Study controls → Mock paper generator: builds mock paper (evidence: `components/action_buttons.py`)
- Study controls → SQLite cache: loads papers (evidence: `components/action_buttons.py`)
- Chat interface → Intent router: routes free text (evidence: `components/chat_box.py`)
- Chat interface → Paper and syllabus Q&A: answers questions (evidence: `components/chat_box.py`)
- Chat interface → Paper summaries: handles summary intent (evidence: `components/chat_box.py`)
- Chat interface → MCQ quizzes: handles quiz intent (evidence: `components/chat_box.py`)
- Chat interface → Flashcards: handles flashcard intent (evidence: `components/chat_box.py`)
- Topic tagging → Question preparation: prepares questions (evidence: `generation/topic_tagger.py`)
- Exam predictor → Topic heatmap: uses topic frequencies (evidence: `generation/predictor.py`)
- Exam predictor → Top questions: uses question history (evidence: `generation/predictor.py`)
- Paper lookup → SQLite cache: reads papers (evidence: `retrieval/paper_lookup.py`)
- Subject lookup → SQLite cache: reads subjects (evidence: `retrieval/subject_lookup.py`)
- Paper summaries → SQLite cache: uses output cache (evidence: `generation/summary.py`)
- MCQ quizzes → SQLite cache: uses output cache (evidence: `generation/quiz.py`)
- Flashcards → SQLite cache: uses output cache (evidence: `generation/flashcards.py`)
- Topic tagging → SQLite cache: reads and saves tags (evidence: `generation/topic_tagger.py`)
- Paper summaries → Groq model service: generates text (evidence: `README.md`)
- MCQ quizzes → Groq model service: generates questions (evidence: `README.md`)
- Flashcards → Groq model service: generates cards (evidence: `README.md`)
- Answer checker → Groq model service: evaluates answer (evidence: `generation/answer_checker.py`)
- Topic tagging → Groq model service: assigns topic tags (evidence: `generation/topic_tagger.py`)
- Paper and syllabus Q&A → Groq model service: answers with model (evidence: `generation/qa.py`)
- Paper and syllabus Q&A → Tavily search: searches knowledge (evidence: `generation/qa.py`)
- Tavily search → Tavily API: searches web (evidence: `services/web_search.py`)
