# eftimovdaniel/askugd architecture

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

- Interactive diagram: https://gitdiagram.com/eftimovdaniel/askugd
- Repository: https://github.com/eftimovdaniel/askugd

## Overview

AskUGD is a multilingual, document-grounded university assistant. A student asks through the web widget or Gradio UI; the backend guards the request, plans retrieval and generation, then returns a cited answer, optionally as a stream. A separate ingestion workflow prepares official documents for search. The graph also preserves hybrid retrieval, reranking, table-aware extraction, session/cache behavior, and security. Some links rely on README claims or source-index references; unsampled implementation details are not assumed.

Main entry points: [`backend/app/core/pipeline.py`](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/pipeline.py) (Turn planner), [`backend/ingestion/run_ingestion.py`](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/run_ingestion.py) (Ingestion runner), [`backend/app/api/chat.py`](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/api/chat.py) (Chat API), [`backend/app/core/retriever.py`](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/retriever.py) (Hybrid retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Student interfaces"]
  node_widget["Web widget<br/>[ugdAgent.ts]"]
  node_bootstrap["Widget bootstrap<br/>[main.ts]"]
  node_gradio["Gradio UI<br/>[app.py]"]
end

subgraph group_service["Chat service"]
  node_api["Chat API<br/>[chat.py]"]
  node_pipeline["Turn planner<br/>[pipeline.py]"]
  node_backend["FastAPI app<br/>[main.py]"]
end

subgraph group_knowledge["Knowledge ingestion"]
  node_ingest["Ingestion runner<br/>[run_ingestion.py]"]
  node_pdf["PDF loader<br/>[pdf_loader.py]"]
  node_ocr["OCR processing<br/>[ocr.py]"]
  node_tables["Table extraction<br/>[table_extractor.py]"]
  node_html["HTML scraper<br/>[html_scraper.py]"]
  node_chunker["Document chunker<br/>[chunker.py]"]
  node_tablechunk["Table chunker<br/>[chunker_tabeli.py]"]
end

subgraph group_retrieval["Search and answer"]
  node_retriever["Hybrid retrieval<br/>[retriever.py]"]
  node_vectorstore["Vector store<br/>[vectorstore.py]"]
  node_rerank["Cross-encoder reranker<br/>[rerank.py]"]
  node_generator["Answer generator<br/>[generator.py]"]
  node_intents["Intent handling<br/>[intents.py]"]
  node_language["Language handling<br/>[language.py]"]
end

subgraph group_state["State and security"]
  node_cache[("Answer cache<br/>[cache.py]")]
  node_history[("Conversation history<br/>[history.py]")]
  node_sessions["Signed sessions<br/>[sessions.py]"]
  node_security["Request defenses<br/>[security.py]"]
end

node_student(("Student"))
node_qdrant[("Qdrant")]
node_llm(("LLM provider"))
node_redis[("Redis")]
node_official["Official documents"]

node_student -->|"asks via"| node_widget
node_bootstrap -->|"initializes"| node_widget
node_widget -.->|"streams questions"| node_api
node_student -->|"asks via"| node_gradio
node_gradio -->|"starts turn"| node_pipeline
node_backend -->|"mounts routes"| node_api
node_api -->|"guards requests"| node_security
node_api -->|"plans and commits"| node_pipeline
node_pipeline -->|"checks intent"| node_intents
node_pipeline -->|"checks cache"| node_cache
node_pipeline -->|"loads and appends"| node_history
node_pipeline -->|"resolves session"| node_sessions
node_pipeline -->|"retrieves passages"| node_retriever
node_retriever -->|"searches"| node_vectorstore
node_retriever -->|"reranks candidates"| node_rerank
node_retriever -.->|"uses language tools"| node_language
node_api -->|"generates answers"| node_generator
node_generator -->|"requests completion"| node_llm
node_vectorstore -->|"searches and writes"| node_qdrant
node_ingest -->|"reads sources"| node_official
node_ingest -->|"loads PDFs"| node_pdf
node_ingest -->|"scrapes web sources"| node_html
node_pdf -->|"uses OCR"| node_ocr
node_pdf -.->|"extracts tables"| node_tables
node_ingest -->|"chunks documents"| node_chunker
node_ingest -->|"chunks table blocks"| node_tablechunk
node_ingest -->|"writes chunks"| node_vectorstore
node_sessions -.->|"stores session data"| node_redis
node_history -.->|"uses shared storage"| node_redis

click node_widget "https://github.com/eftimovdaniel/askugd/blob/main/frontend/src/ugdAgent.ts"
click node_bootstrap "https://github.com/eftimovdaniel/askugd/blob/main/frontend/src/main.ts"
click node_gradio "https://github.com/eftimovdaniel/askugd/blob/main/app.py"
click node_api "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/api/chat.py"
click node_pipeline "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/pipeline.py"
click node_backend "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/main.py"
click node_ingest "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/run_ingestion.py"
click node_pdf "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/pdf_loader.py"
click node_ocr "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/ocr.py"
click node_tables "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/table_extractor.py"
click node_html "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/html_scraper.py"
click node_chunker "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/chunker.py"
click node_tablechunk "https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/chunker_tabeli.py"
click node_retriever "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/retriever.py"
click node_vectorstore "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/vectorstore.py"
click node_rerank "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/rerank.py"
click node_generator "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/generator.py"
click node_intents "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/intents.py"
click node_language "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/language.py"
click node_cache "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/cache.py"
click node_history "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/history.py"
click node_sessions "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/sessions.py"
click node_security "https://github.com/eftimovdaniel/askugd/blob/main/backend/app/security.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_widget,node_bootstrap,node_gradio toneBlue
class node_api,node_pipeline,node_backend,node_qdrant,node_redis toneAmber
class node_ingest,node_pdf,node_ocr,node_tables,node_html,node_chunker,node_tablechunk toneMint
class node_retriever,node_vectorstore,node_rerank,node_generator,node_intents,node_language toneRose
class node_cache,node_history,node_sessions,node_security,node_student,node_llm,node_official toneIndigo
```

## Components

### Student interfaces

- [Web widget](https://github.com/eftimovdaniel/askugd/blob/main/frontend/src/ugdAgent.ts): `frontend/src/ugdAgent.ts`
- [Widget bootstrap](https://github.com/eftimovdaniel/askugd/blob/main/frontend/src/main.ts): `frontend/src/main.ts`
- [Gradio UI](https://github.com/eftimovdaniel/askugd/blob/main/app.py): `app.py`

### Chat service

- [Chat API](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/api/chat.py): `backend/app/api/chat.py`
- [Turn planner](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/pipeline.py): `backend/app/core/pipeline.py`
- [FastAPI app](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/main.py): `backend/app/main.py`

### Knowledge ingestion

- [Ingestion runner](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/run_ingestion.py): `backend/ingestion/run_ingestion.py`
- [PDF loader](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/pdf_loader.py): `backend/ingestion/pdf_loader.py`
- [OCR processing](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/ocr.py): `backend/ingestion/ocr.py`
- [Table extraction](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/table_extractor.py): `backend/ingestion/table_extractor.py`
- [HTML scraper](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/html_scraper.py): `backend/ingestion/html_scraper.py`
- [Document chunker](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/chunker.py): `backend/ingestion/chunker.py`
- [Table chunker](https://github.com/eftimovdaniel/askugd/blob/main/backend/ingestion/chunker_tabeli.py): `backend/ingestion/chunker_tabeli.py`

### Search and answer

- [Hybrid retrieval](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/retriever.py): `backend/app/core/retriever.py`
- [Vector store](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/vectorstore.py): `backend/app/core/vectorstore.py`
- [Cross-encoder reranker](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/rerank.py): `backend/app/core/rerank.py`
- [Answer generator](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/generator.py): `backend/app/core/generator.py`
- [Intent handling](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/intents.py): `backend/app/core/intents.py`
- [Language handling](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/language.py): `backend/app/core/language.py`

### State and security

- [Answer cache](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/cache.py): `backend/app/core/cache.py`
- [Conversation history](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/history.py): `backend/app/core/history.py`
- [Signed sessions](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/core/sessions.py): `backend/app/core/sessions.py`
- [Request defenses](https://github.com/eftimovdaniel/askugd/blob/main/backend/app/security.py): `backend/app/security.py`

### Other components

- **Student**
- **Qdrant**
- **LLM provider**
- **Redis**
- **Official documents**

## Connections

- Student → Web widget: asks via
- Widget bootstrap → Web widget: initializes (evidence: `frontend/src/main.ts`)
- Web widget → Chat API: streams questions
- Student → Gradio UI: asks via (evidence: `app.py`)
- Gradio UI → Turn planner: starts turn (evidence: `app.py`)
- FastAPI app → Chat API: mounts routes (evidence: `backend/app/main.py`)
- Chat API → Request defenses: guards requests (evidence: `backend/app/api/chat.py`)
- Chat API → Turn planner: plans and commits (evidence: `backend/app/api/chat.py`)
- Turn planner → Intent handling: checks intent (evidence: `backend/app/core/pipeline.py`)
- Turn planner → Answer cache: checks cache (evidence: `backend/app/core/pipeline.py`)
- Turn planner → Conversation history: loads and appends (evidence: `backend/app/core/pipeline.py`)
- Turn planner → Signed sessions: resolves session (evidence: `backend/app/core/pipeline.py`)
- Turn planner → Hybrid retrieval: retrieves passages (evidence: `backend/app/core/pipeline.py`)
- Hybrid retrieval → Vector store: searches (evidence: `backend/app/core/retriever.py`)
- Hybrid retrieval → Cross-encoder reranker: reranks candidates (evidence: `backend/app/core/retriever.py`)
- Hybrid retrieval → Language handling: uses language tools
- Chat API → Answer generator: generates answers (evidence: `backend/app/api/chat.py`)
- Answer generator → LLM provider: requests completion
- Vector store → Qdrant: searches and writes (evidence: `backend/app/core/vectorstore.py`)
- Ingestion runner → Official documents: reads sources (evidence: `backend/ingestion/run_ingestion.py`)
- Ingestion runner → PDF loader: loads PDFs (evidence: `backend/ingestion/run_ingestion.py`)
- Ingestion runner → HTML scraper: scrapes web sources (evidence: `backend/ingestion/run_ingestion.py`)
- PDF loader → OCR processing: uses OCR (evidence: `backend/ingestion/pdf_loader.py`)
- PDF loader → Table extraction: extracts tables
- Ingestion runner → Document chunker: chunks documents (evidence: `backend/ingestion/run_ingestion.py`)
- Ingestion runner → Table chunker: chunks table blocks (evidence: `backend/ingestion/run_ingestion.py`)
- Ingestion runner → Vector store: writes chunks (evidence: `backend/ingestion/run_ingestion.py`)
- Signed sessions → Redis: stores session data
- Conversation history → Redis: uses shared storage
