# phatjkk/nttu-chatbot architecture

> Architecture diagram of the GitHub repository phatjkk/nttu-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phatjkk/nttu-chatbot
- Repository: https://github.com/phatjkk/nttu-chatbot

## Overview

##### Main Components
- Front-end: Located in the “front-end” directory, it contains the UI code (HTML, CSS, JavaScript/React—using Vite, Tailwind CSS, etc.). This is the interactive user layer where students interact with the chatbot.
- Back-end: Found in the “back-end” folder (e.g., RAG_SERVER_GPU.ipynb) which likely handles the server-side logic, managing chatbot queries and possibly coordinating with the language model.
- Vector Database: The “vector_database” directory holds the notebook for creating the vector database (VECTOR_DATABASE_CREATE.ipynb) that stores document embeddings used for retrieval.
- Model Training: The “training_model” directory includes notebooks like Fine_tuning_Zephyr_generator.ipynb for fine-tuning the generator models, a key aspect of the chatbot’s language generation capability.
- Data Analysis: The “data_analysis” directory contains notebooks to analyze data; useful for optimizing the RAG or for further insights.
- Evaluation: The “eval_rag” directory splits into subfolders for automated metric evaluation (BERT score evaluation notebooks) and human evaluation (user feedback and visualizations). These components are essential for continuously assessing chatbot performance.
- Dataset: The “dataset” directory holds raw data files (Excel, PDFs, text files) that serve as the source documents for the RAG system.

##### Relationships and Interactions
- User Interaction Flow:
- The user accesses the Chatbot via the Front-end web interface.
- User requests are sent (via API calls or similar mechanisms) from the Front-end to the Back-end.
- Back-end Processing:
- The Back-end (RAG server) accepts the query and interacts with the LLM to generate a response.
- This process likely involves querying the Vector Database for relevant document embeddings.
- The RAG design implies that document retrieval serves as a supporting module to provide context to the language model.
- Continuous Improvement Pipeline:
- The Training Model notebooks allow for fine-tuning on specific data (e.g., Zephyr generator adjustments) to improve response quality.
- Data Analysis notebooks help diagnose performance issues whereas Evaluation notebooks (both automated and human) validate system output.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each component (UI, API/server logic, data processing/training, and evaluation) is developed and maintained separately.
- Modular Design: The clear categorization (frontend, backend, vector database, training, evaluation) supports modularity, allowing updates or improvements to specific parts independently.
- Pipelines for Improvement: There is an evident design for continuously iterating on the model performance via training, testing, and evaluation pipelines.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    User("User (Student)"):::user
    FE("Front-end (React/Vite)"):::frontend
    BE("RAG Back-end (LLM+Doc Retriever)"):::backend
    VDB("Vector Database (Embeddings)"):::database
    MT("Model Training/Fine-tuning"):::training
    EV("Evaluation (BERT&Human Eval)"):::evaluation
    DA("Data Analysis (Performance Monitoring)"):::analysis
    DS("Dataset (Raw Source Documents)"):::dataset

    %% User Interaction Flow
    User -->|"submitsQuery"| FE
    FE -->|"callsAPI"| BE

    %% Back-end Processing with Retrieval
    BE -->|"queries"| VDB
    VDB -->|"returnsContext"| BE

    %% Continuous Improvement Pipeline
    BE -->|"updates"| MT
    BE -->|"feedback"| EV
    DA -->|"monitors"| MT
    DA -->|"monitors"| EV

    %% Data Provision from Dataset
    DS -->|"providesDocs"| VDB
    DS -->|"providesDocs"| MT
    DS -->|"providesDocs"| EV

    %% Click Events
    click FE "https://github.com/phatjkk/nttu-chatbot/tree/main/front-end/"
    click BE "https://github.com/phatjkk/nttu-chatbot/blob/main/back-end/RAG_SERVER_GPU.ipynb"
    click VDB "https://github.com/phatjkk/nttu-chatbot/blob/main/vector_database/VECTOR_DATABASE_CREATE.ipynb"
    click MT "https://github.com/phatjkk/nttu-chatbot/blob/main/training_model/Fine_tuning_Zephyr_generator.ipynb"
    click DA "https://github.com/phatjkk/nttu-chatbot/blob/main/data_analysis/DATA_Analysis.ipynb"
    click EV "https://github.com/phatjkk/nttu-chatbot/tree/main/eval_rag/"
    click DS "https://github.com/phatjkk/nttu-chatbot/tree/main/dataset/"

    %% Styles
    classDef user fill:#B2EBF2,stroke:#00796B,stroke-width:2px;
    classDef frontend fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef backend fill:#FFECB3,stroke:#FFA000,stroke-width:2px;
    classDef database fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef training fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef evaluation fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef analysis fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef dataset fill:#E0F7FA,stroke:#00838F,stroke-width:2px;
```
