# mostafahikal/uniguide architecture

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

- Interactive diagram: https://gitdiagram.com/mostafahikal/uniguide
- Repository: https://github.com/mostafahikal/uniguide

## Overview

#### Purpose and entry points
UniGuide is a Python university-assistant chatbot for college-document questions and timetable queries. Its interactive entry point is `app/ui.py`; application orchestration is centered in `app/main.py`. The UI requires the user to select a query mode, making routing an explicit user-controlled boundary rather than an inferred classifier.

#### Presentation and chat orchestration
The Gradio layer collects a question and mode, invokes the chat pipeline, and displays the generated answer. `app/ui.py` is the runtime-facing interface; `app/main.py` coordinates request handling across routing, retrieval, and response generation. This is an application service, not a web/API server architecture.

#### Mode router
`app/router.py` dispatches requests into one of two retrieval paths:
- Structured retrieval for lectures, exams, and other tabular schedules.
- RAG retrieval for college information and PDF-backed general questions.

The selected mode controls which persistence system is accessed, isolating schedule data from unstructured document search.

#### Structured schedule path
For schedule/exam questions, the system extracts searchable constraints from the question and queries normalized JSON records. `app/retrieval.py` implements retrieval behavior, while `data/tables.json` is the structured data store and `data/Tables/exams` is source material for timetable content. Retrieved records are passed as grounding context to response generation rather than sent directly to the UI.

#### Document RAG path
For college-information questions, the system semantically searches a FAISS vector store built from institutional PDFs such as `data/College/General_Bsc.pdf`. `app/retrieval.py` owns the retrieval boundary; embeddings use the multilingual `paraphrase-multilingual-MiniLM-L12-v2` model, supporting Arabic and other multilingual queries. The README describes a `vector_store/` artifact, but it is not present in the supplied tree and must be generated/provided at deployment.

#### Ingestion and normalization
`app/ingestion.py` contains distinct source-to-store pipelines:
- PDF ingestion applies Tesseract OCR, normalization, chunking, embeddings, and FAISS indexing.
- Image/table ingestion uses Groq Vision to extract schedule records, then writes structured JSON.

`app/normalizer.py` standardizes extracted schedule records before storage, protecting structured retrieval from OCR/vision format variability. Raw data lives beneath `data/`; normalized structured output is `data/tables.json`.

#### Answer generation and external dependencies
`app/responder.py` turns retrieved context into the final natural-language response using Groq LLM inference, with templates/instructions centralized in `app/prompts.py`. Groq is therefore an external generation dependency on both retrieval paths; Groq Vision is additionally required during image ingestion. Runtime configuration, including API key, chat model, vision model, and embedding model, is centralized in `app/config.py` and sourced through `.env` conventions shown by `.env.example`.

#### Key runtime boundaries
Core infrastructure is local Python + Gradio, FAISS for vector persistence/search, JSON for schedules, and Tesseract for PDF OCR. Sensitive remote access is limited to Groq services via `GROQ_API_KEY`; model names are configurable. The principal flow is: UI mode/question → `app/main.py`/`app/router.py` → appropriate retrieval store → `app/responder.py` → UI answer.

Main entry points: [`app/retrieval.py`](https://github.com/mostafahikal/uniguide/blob/main/app/retrieval.py) (Retrieval Service), [`app/config.py`](https://github.com/mostafahikal/uniguide/blob/main/app/config.py) (Runtime Configuration), [`app/ingestion.py`](https://github.com/mostafahikal/uniguide/blob/main/app/ingestion.py) (PDF Ingestion), [`app/responder.py`](https://github.com/mostafahikal/uniguide/blob/main/app/responder.py) (Response Generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Chat Runtime"]
  node_ui["Gradio UI<br/>presentation<br/>[ui.py]"]
  node_main["Chat Orchestrator<br/>application service<br/>[main.py]"]
  node_router{{"Mode Router<br/>request router<br/>[router.py]"}}
  node_responder["Response Generator<br/>generation service<br/>[responder.py]"]
  node_prompts["Prompt Templates<br/>prompt definitions<br/>[prompts.py]"]
  node_config["Runtime Configuration<br/>[config.py]"]
  node_env_example["Environment Contract<br/>environment template<br/>[.env.example]"]
end

subgraph group_retrieval["Retrieval Stores"]
  node_retrieval_service["Retrieval Service<br/>retrieval boundary<br/>[retrieval.py]"]
  node_schedule_store[("Normalized Schedules<br/>JSON store<br/>[tables.json]")]
  node_vector_store[("FAISS Vector Store<br/>vector index")]
  node_college_pdf["College PDFs<br/>document source<br/>[General_Bsc.pdf]"]
end

subgraph group_ingestion["Ingestion Pipelines"]
  node_pdf_ingestion["PDF Ingestion<br/>ingestion pipeline<br/>[ingestion.py]"]
  node_table_ingestion["Table Image Ingestion<br/>ingestion pipeline<br/>[ingestion.py]"]
  node_normalizer["Schedule Normalizer<br/>normalization service<br/>[normalizer.py]"]
  node_exam_sources["Exam Source Tables<br/>table source"]
end

subgraph group_external["External Services"]
  node_tesseract{{"Tesseract OCR<br/>OCR dependency"}}
  node_embedding_model{{"Multilingual Embeddings<br/>embedding model"}}
  node_groq_llm{{"Groq LLM<br/>generation API"}}
  node_groq_vision{{"Groq Vision<br/>vision API"}}
end

node_ui -->|"question + mode"| node_main
node_main -->|"dispatch request"| node_router
node_router -->|"selected retrieval path"| node_retrieval_service
node_retrieval_service -->|"structured schedule lookup"| node_schedule_store
node_retrieval_service -->|"semantic document search"| node_vector_store
node_vector_store -->|"relevant chunks"| node_retrieval_service
node_schedule_store -->|"matching records"| node_retrieval_service
node_retrieval_service -->|"grounding context"| node_main
node_main -->|"question + context"| node_responder
node_prompts -->|"instructions"| node_responder
node_responder -->|"generate answer"| node_groq_llm
node_responder -->|"final answer"| node_ui
node_college_pdf -->|"source PDFs"| node_pdf_ingestion
node_pdf_ingestion -->|"OCR"| node_tesseract
node_pdf_ingestion -->|"embed chunks"| node_embedding_model
node_pdf_ingestion -->|"build index"| node_vector_store
node_exam_sources -->|"source tables"| node_table_ingestion
node_table_ingestion -->|"extract records"| node_groq_vision
node_table_ingestion -->|"extracted records"| node_normalizer
node_normalizer -->|"normalized JSON"| node_schedule_store
node_env_example -.->|"documents variables"| node_config
node_config -.->|"embedding settings"| node_retrieval_service
node_config -.->|"LLM settings"| node_responder
node_config -.->|"embedding settings"| node_pdf_ingestion
node_config -.->|"vision settings"| node_table_ingestion

click node_ui "https://github.com/mostafahikal/uniguide/blob/main/app/ui.py"
click node_main "https://github.com/mostafahikal/uniguide/blob/main/app/main.py"
click node_router "https://github.com/mostafahikal/uniguide/blob/main/app/router.py"
click node_retrieval_service "https://github.com/mostafahikal/uniguide/blob/main/app/retrieval.py"
click node_schedule_store "https://github.com/mostafahikal/uniguide/blob/main/data/tables.json"
click node_college_pdf "https://github.com/mostafahikal/uniguide/blob/main/data/College/General_Bsc.pdf"
click node_responder "https://github.com/mostafahikal/uniguide/blob/main/app/responder.py"
click node_prompts "https://github.com/mostafahikal/uniguide/blob/main/app/prompts.py"
click node_config "https://github.com/mostafahikal/uniguide/blob/main/app/config.py"
click node_env_example "https://github.com/mostafahikal/uniguide/blob/main/.env.example"
click node_pdf_ingestion "https://github.com/mostafahikal/uniguide/blob/main/app/ingestion.py"
click node_table_ingestion "https://github.com/mostafahikal/uniguide/blob/main/app/ingestion.py"
click node_normalizer "https://github.com/mostafahikal/uniguide/blob/main/app/normalizer.py"
click node_exam_sources "https://github.com/mostafahikal/uniguide/tree/main/data/Tables/exams"

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,node_main,node_router,node_responder,node_prompts,node_config,node_env_example toneBlue
class node_retrieval_service,node_schedule_store,node_vector_store,node_college_pdf toneAmber
class node_pdf_ingestion,node_table_ingestion,node_normalizer,node_exam_sources toneMint
class node_tesseract,node_embedding_model,node_groq_llm,node_groq_vision toneRose
```

## Components

### Chat Runtime

- [Gradio UI](https://github.com/mostafahikal/uniguide/blob/main/app/ui.py): presentation · Collects question and user-selected mode, then displays the answer. · `app/ui.py`
- [Chat Orchestrator](https://github.com/mostafahikal/uniguide/blob/main/app/main.py): application service · Coordinates routing, retrieval, and response generation. · `app/main.py`
- [Mode Router](https://github.com/mostafahikal/uniguide/blob/main/app/router.py): request router · Selects schedule or document retrieval from the explicit UI mode. · `app/router.py`
- [Response Generator](https://github.com/mostafahikal/uniguide/blob/main/app/responder.py): generation service · Builds grounded natural-language answers from retrieved context. · `app/responder.py`
- [Prompt Templates](https://github.com/mostafahikal/uniguide/blob/main/app/prompts.py): prompt definitions · `app/prompts.py`
- [Runtime Configuration](https://github.com/mostafahikal/uniguide/blob/main/app/config.py): configuration · Centralizes model settings and API-key configuration. · `app/config.py`
- [Environment Contract](https://github.com/mostafahikal/uniguide/blob/main/.env.example): environment template · Documents required environment variables including GROQ_API_KEY. · `.env.example`

### Retrieval Stores

- [Retrieval Service](https://github.com/mostafahikal/uniguide/blob/main/app/retrieval.py): retrieval boundary · Implements both structured and semantic retrieval. · `app/retrieval.py`
- [Normalized Schedules](https://github.com/mostafahikal/uniguide/blob/main/data/tables.json): JSON store · Normalized timetable and exam records. · `data/tables.json`
- **FAISS Vector Store**: vector index · Deployment-generated index for institutional document chunks.
- [College PDFs](https://github.com/mostafahikal/uniguide/blob/main/data/College/General_Bsc.pdf): document source · Institutional source documents for RAG. · `data/College/General_Bsc.pdf`

### Ingestion Pipelines

- [PDF Ingestion](https://github.com/mostafahikal/uniguide/blob/main/app/ingestion.py): ingestion pipeline · OCRs, normalizes, chunks, embeds, and indexes PDFs. · `app/ingestion.py`
- [Table Image Ingestion](https://github.com/mostafahikal/uniguide/blob/main/app/ingestion.py): ingestion pipeline · Extracts schedule records from timetable images. · `app/ingestion.py`
- [Schedule Normalizer](https://github.com/mostafahikal/uniguide/blob/main/app/normalizer.py): normalization service · Standardizes extracted records before JSON storage. · `app/normalizer.py`
- [Exam Source Tables](https://github.com/mostafahikal/uniguide/tree/main/data/Tables/exams): table source · Raw timetable content used for schedule ingestion. · `data/Tables/exams`

### External Services

- **Tesseract OCR**: OCR dependency
- **Multilingual Embeddings**: embedding model · paraphrase-multilingual-MiniLM-L12-v2 supports multilingual semantic search.
- **Groq LLM**: generation API · Remote inference for final answers.
- **Groq Vision**: vision API · Remote extraction for timetable images.

## Connections

- Gradio UI → Chat Orchestrator: question + mode
- Chat Orchestrator → Mode Router: dispatch request
- Mode Router → Retrieval Service: selected retrieval path
- Retrieval Service → Normalized Schedules: structured schedule lookup
- Retrieval Service → FAISS Vector Store: semantic document search
- FAISS Vector Store → Retrieval Service: relevant chunks
- Normalized Schedules → Retrieval Service: matching records
- Retrieval Service → Chat Orchestrator: grounding context
- Chat Orchestrator → Response Generator: question + context
- Prompt Templates → Response Generator: instructions
- Response Generator → Groq LLM: generate answer
- Response Generator → Gradio UI: final answer
- College PDFs → PDF Ingestion: source PDFs
- PDF Ingestion → Tesseract OCR: OCR
- PDF Ingestion → Multilingual Embeddings: embed chunks
- PDF Ingestion → FAISS Vector Store: build index
- Exam Source Tables → Table Image Ingestion: source tables
- Table Image Ingestion → Groq Vision: extract records
- Table Image Ingestion → Schedule Normalizer: extracted records
- Schedule Normalizer → Normalized Schedules: normalized JSON
- Environment Contract → Runtime Configuration: documents variables
- Runtime Configuration → Retrieval Service: embedding settings
- Runtime Configuration → Response Generator: LLM settings
- Runtime Configuration → PDF Ingestion: embedding settings
- Runtime Configuration → Table Image Ingestion: vision settings
