# minhnghia100402/graduation-thesis-haui-2024 architecture

> Architecture diagram of the GitHub repository minhnghia100402/graduation-thesis-haui-2024, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/minhnghia100402/graduation-thesis-haui-2024
- Repository: https://github.com/minhnghia100402/graduation-thesis-haui-2024

## Overview

##### Project type and purpose
- This is a full-stack research chat application (“HAUI CHAT”) demonstrating Retrieval-Augmented Generation (RAG) with LLMs for an information retrieval graduation project.
- Frontend: Next.js + React + Tailwind UI for user login/signup, chat, sharing sessions.
- Backend: Python FastAPI service exposing chat and prompt endpoints, orchestrating vector retrieval and LLM calls.
- Data layer: a vector store built via ingestion scripts and an external LLM API (e.g. OpenAI).

##### File structure
Top-level
- docker-compose.yaml – orchestrates frontend & backend containers
- backend/ – Python service, models, routers, service layers, ingestion scripts
- frontend/ – Next.js app in the new “app” folder, UI components, hooks, auth config
Backend substructure
- src/routers – chat.py (handles /chat), promt.py (handles /prompt)
- src/services
– chat/ – business logic for LLM orchestration
– loads/ – functions to load embeddings, LLM clients, build/re-rank collections
– vector_stores/ – vector_indexing.py for CRUD on the vector database
– utils/ – data extraction, chunking, logging
- scripts/vector_store.sh + vector_store.py – one-off data ingestion into the vector store
- Dockerfile & .env_example – containerization and configuration
Frontend substructure
- app/ – route groups: (chat), login, signup, new, share
- components/ – UI primitives, layout components, stock demo widgets
- lib/ – shared hooks, types, utils
- auth.ts, auth.config.ts – next-auth config
- Dockerfile, next.config.js, tsconfig.json, tailwind.config.ts

##### README for additional insights
- Describes RAG + LLM focus, Docker-based setup, vector store ingestion step, Docker Compose launch command.
- Emphasizes configuration via `.env` for API keys and local paths.

##### Detail
- Utilities (logging, chunking) as subcomponents or annotations in the service layer.
- Startup & orchestration (Docker Compose) outside the main data flow but connected to both containers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure
    DC["Docker Compose"]:::infra
    DC -->|orchestrates| FE_CONTAINER
    DC -->|orchestrates| BE_CONTAINER

    %% User and Frontend
    UserBrowser["User Browser"]:::external
    UserBrowser -->|HTTP/HTTPS| NextApp

    subgraph FE_CONTAINER["Frontend Container (Next.js)"]
        style FE_CONTAINER stroke:#0366d6,stroke-width:2px
        NextApp["Next.js UI"]:::frontend
        Routes["app/"]:::frontend
        Components["components/"]:::frontend
        Lib["lib/"]:::frontend
        AuthCfg["auth.ts / auth.config.ts"]:::frontend
        BuildCfg["next.config.js / tailwind.config.ts"]:::frontend

        NextApp --> Routes
        NextApp --> Components
        NextApp --> Lib
        NextApp --> AuthCfg
        NextApp --> BuildCfg
    end

    click Routes "https://github.com/minhnghia100402/graduation-thesis-haui-2024/tree/master/frontend/app/"
    click Components "https://github.com/minhnghia100402/graduation-thesis-haui-2024/tree/master/frontend/components/"
    click Lib "https://github.com/minhnghia100402/graduation-thesis-haui-2024/tree/master/frontend/lib/"
    click AuthCfg "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/frontend/auth.ts"
    click AuthCfg "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/frontend/auth.config.ts"
    click BuildCfg "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/frontend/next.config.js"
    click BuildCfg "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/frontend/tailwind.config.ts"
    click FE_CONTAINER "https://github.com/minhnghia100402/graduation-thesis-haui-2024/tree/master/frontend/Dockerfile"

    %% Backend
    subgraph BE_CONTAINER["Backend Container (FastAPI)"]
        style BE_CONTAINER stroke:#22863a,stroke-width:2px
        MainApp["main.py"]:::backend
        subgraph Routers["Routers"]
            ChatRouter["chat.py (/chat)"]:::backend
            PromptRouter["promt.py (/prompt)"]:::backend
        end
        subgraph Services["Service Layer"]
            Orchestrator["chat/prompt.py"]:::backend
            subgraph Loaders["Embeddings & LLM Loaders"]
                Embeddings["embeddings.py"]:::backend
                LLMLoad["llms.py"]:::backend
                Collection["load_collection.py"]:::backend
                Reranker["reranker.py"]:::backend
            end
        end
        subgraph DataAccess["Vector Store Adapter"]
            VectorIndex["vector_indexing.py"]:::backend
        end
        subgraph Utils["Utility Modules"]
            ExtractData["extract_data.py"]:::backend
            DataForVector["data_for_vector.py"]:::backend
            Chunker["segmantic_chunker_chunkSize.py"]:::backend
            Logger["logger.py"]:::backend
        end

        MainApp --> Routers
        Routers --> Services
        Services --> DataAccess
        Services --> Loaders
        Services --> Utils
    end

    click MainApp "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/main.py"
    click ChatRouter "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/routers/chat.py"
    click PromptRouter "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/routers/promt.py"
    click Orchestrator "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/chat/prompt.py"
    click VectorIndex "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/vector_stores/vector_indexing.py"
    click Embeddings "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/loads/embeddings.py"
    click LLMLoad "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/loads/llms.py"
    click Collection "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/loads/load_collection.py"
    click Reranker "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/loads/reranker.py"
    click ExtractData "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/utils/extract_data.py"
    click DataForVector "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/utils/data_for_vector.py"
    click Chunker "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/utils/segmantic_chunker_chunkSize.py"
    click Logger "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/src/services/utils/logger.py"
    click BE_CONTAINER "https://github.com/minhnghia100402/graduation-thesis-haui-2024/tree/master/backend/Dockerfile"
    click BE_CONTAINER "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/.env_example"

    %% Data Ingestion
    subgraph Ingestion["Data Ingestion Pipeline"]
        style Ingestion stroke:#d93f0b,stroke-width:2px
        ShellScript["vector_store.sh"]:::backend
        IngestPy["vector_store.py"]:::backend
    end
    ShellScript --> IngestPy
    IngestPy --> VectorDB

    click ShellScript "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/scripts/vector_store.sh"
    click IngestPy "https://github.com/minhnghia100402/graduation-thesis-haui-2024/blob/master/backend/vector_store.py"

    %% Data Stores and External
    VectorDB["Vector Store (DB)"]:::datastore
    BE_CONTAINER -->|CRUD via SDK| VectorDB
    BE_CONTAINER -->|HTTP JSON| ExternalLLM
    ExternalLLM["External LLM API"]:::external

    %% Flows
    NextApp -->|REST /chat, /prompt| BE_CONTAINER
    BE_CONTAINER -->|retrieve embeddings| VectorDB
    BE_CONTAINER -->|generate response| ExternalLLM
    ExternalLLM -->|LLM response| BE_CONTAINER
    BE_CONTAINER -->|JSON reply| NextApp

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0366d6,color:#0366d6
    classDef backend fill:#d1e7dd,stroke:#22863a,color:#22863a
    classDef datastore fill:#fff3cd,stroke:#bb8b00,color:#bb8b00
    classDef external fill:#fde2e1,stroke:#d6336c,color:#d6336c
    classDef infra fill:#f0f0f0,stroke:#6c757d,color:#6c757d
```
