# minhcspro/chatbot-for-tax-and-law-llm architecture

> Architecture diagram of the GitHub repository minhcspro/chatbot-for-tax-and-law-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/minhcspro/chatbot-for-tax-and-law-llm
- Repository: https://github.com/minhcspro/chatbot-for-tax-and-law-llm

## Overview

##### Project type and purpose
- From the file tree and README, this is a collection of Jupyter notebooks that implement a Retrieval-Augmented Generation (RAG) pipeline for tax and law documents.
- Key steps: • scrape_thue_baohiem.ipynb – scrape insurance/tax regulations • llama_indexing.ipynb – build a vector index over scraped text • test_llama_index.ipynb – query the index + LLM to answer questions

##### File structure
- No traditional “src/” or “frontend/” folders: everything lives in notebooks.
- Each notebook corresponds to a logical stage in the data pipeline: ingestion, indexing, query/testing.
- Configuration (e.g. API keys, model settings) will be embedded in notebooks or environment variables.

##### README insights
- README only contains an image reference, which likely depicts the high-level RAG flow.

a. Main components
1. Web Scraper: scrapes tax/law documents (scrape_thue_baohiem.ipynb)
2. Data Store: raw HTML/text storage (could be local files or a simple DB)
3. Preprocessing & Embedding: text cleaning, chunking, embedding via LLM API (llama_indexing.ipynb)
4. Vector Index: stores embeddings (e.g., FAISS, Weaviate, Chroma)
5. Retrieval API: given a user query, retrieve top-k relevant chunks
6. LLM Engine: prompts the language model with retrieved context to generate answers
7. Client Interface / Tester: Jupyter notebook or simple CLI that submits queries (test_llama_index.ipynb)

b. Relationships and interactions
- Scraper → Data Store (writes raw text)
- Data Store → Preprocessor → Embedding → Vector Index (build phase)
- Client Interface → Retrieval API → Vector Index (reads) → LLM Engine → Client Interface (response)

c. Architectural patterns & design principles
- Pipeline stages: clear separation of ingestion, processing, indexing, and serving
- Modular: each notebook/ component can be replaced or extended (e.g., swap in a different vector DB)
- RAG pattern: decouple retrieval (vector similarity) from generation (LLM), ensuring only relevant context is sent to the model

d. Key technologies & libraries
- Python & Jupyter for orchestration
- Requests/BeautifulSoup (or similar) in the scraper
- LangChain or llama-index for embeddings & index abstraction
- FAISS/Chroma/Weaviate for vector index
- OpenAI / Anthropic / local LLM for embeddings & generation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Documentation
    Doc["Project Documentation\n(README.md)"]:::doc
    click Doc "https://github.com/minhcspro/chatbot-for-tax-and-law-llm/blob/main/README.md"

    %% Ingestion
    WebScraper["Web Scraper\n(scrape_thue_baohiem.ipynb)"]:::process
    click WebScraper "https://github.com/minhcspro/chatbot-for-tax-and-law-llm/blob/main/scrape_thue_baohiem.ipynb"

    %% Raw data store
    RawStore[(Raw Data Store)]:::store

    %% Preprocessing & Embedding
    Embedder["Embedder & Preprocessor\n(llama_indexing.ipynb)"]:::process
    click Embedder "https://github.com/minhcspro/chatbot-for-tax-and-law-llm/blob/main/llama_indexing.ipynb"

    %% Vector database
    VectorDB[(Vector DB)]:::store

    %% Client and RAG engine
    Client(("Client/Test Notebook\n(test_llama_index.ipynb)")):::terminal
    click Client "https://github.com/minhcspro/chatbot-for-tax-and-law-llm/blob/main/test_llama_index.ipynb"
    RAGEngine["Retrieval + RAG Engine"]:::process
    click RAGEngine "https://github.com/minhcspro/chatbot-for-tax-and-law-llm/blob/main/test_llama_index.ipynb"

    %% External LLM
    LLM(("LLM API")):::external

    %% Data flow
    Doc --> WebScraper
    WebScraper -->|"writes raw text"| RawStore
    RawStore -->|"loads for processing"| Embedder
    Embedder -->|"builds embeddings"| VectorDB

    Client -->|"query"| RAGEngine
    RAGEngine -->|"search top-k"| VectorDB
    RAGEngine -->|"prompt with context"| LLM
    LLM -->|"response"| RAGEngine
    RAGEngine -->|"answer"| Client

    %% Styles
    classDef store fill:#FFDDAA,stroke:#CC6600,stroke-width:2px;
    classDef process fill:#CCE5FF,stroke:#3377CC,stroke-width:2px;
    classDef external fill:#E5FFCC,stroke:#66AA33,stroke-width:2px;
    classDef terminal fill:#FFCCFF,stroke:#CC33AA,stroke-width:2px;
    classDef doc fill:#F0F0F0,stroke:#999999,stroke-width:1px,stroke-dasharray: 5 5;
```
