# viswadarshan-024/thirukkural-ai architecture

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

- Interactive diagram: https://gitdiagram.com/viswadarshan-024/thirukkural-ai
- Repository: https://github.com/viswadarshan-024/thirukkural-ai

## Overview

##### Main Components
- User Interface (Frontend): This is primarily handled by Streamlit through files such as app.py and about_page.py. It presents the UI, takes user input (questions), and displays outputs (Thirukkural verses and AI-generated advice).
- Data Storage & Resources: Several static files are used to store the core data, including:
- thirukkural_data.pkl – A pickled dataset containing the text of all Thirukkural verses and their metadata.
- data.json – Likely holds additional metadata or configuration.
- Pre-built vector database files (thirukkural_english_index.faiss and thirukkural_tamil_index.faiss).
- Vector Database & Embeddings Module: Managed by vector_db.py, this component uses a multilingual sentence transformer to create vector embeddings of the dataset and/or initialize/update the FAISS vector databases.
- Query Processing & Semantic Search: When a user query is received, the system converts it into the same vector space as the stored embeddings and performs a similarity search using FAISS to retrieve the most semantically similar couplets.
- LLM Integration & Response Generation: After retrieving candidate matches, the system passes them to the Groq API (model: Llama-3.3-70b-versatile) to rank relevance and generate personalized explanations and advice.

##### Interactions and Data Flow
- A user submits a question via the Streamlit interface.
- The query processing module transforms the query into an embedding.
- The application then queries the FAISS vector database (using pre-computed indices for both Tamil and English) to retrieve candidate verses.
- The retrieved results are passed to the LLM integration module which, via the Groq API, generates a tailored explanation and advice.
- The result is then returned to the user interface for display.

##### Architectural Patterns & Design Principles
- Modularity by clearly delineating components (Frontend, Data Management, Vector Search, LLM Integration).
- Notice the separation of concerns: the UI is separate from the data processing and indexing, and both are decoupled from the LLM service.
- The bilingual support is integrated within the vector search, meaning both Tamil and English indices are maintained and queried as needed.

##### Technologies & Components to Highlight
- Frontend: Streamlit (files: app.py, about_page.py).
- Vector Database: FAISS indexes (thirukkural_english_index.faiss & thirukkural_tamil_index.faiss).
- Embedding Generation: Sentence Transformers.
- LLM Integration: Groq API (using their Llama-3.3-70b-versatile model).
- Data Processing Libraries: Pandas and NumPy.
- Data Sources: thirukkural_data.pkl and data.json.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["app.py"]:::frontend
        B["about_page.py"]:::frontend
        J["Result Display (UI)"]:::frontend
    end

    %% Core Processing
    subgraph "Core Processing"
        C["Query Processor (Embeds user query)"]:::processor
        D["Vector DB & Embeddings Module"]:::processor
        E["LLM Service via Groq API (Llama-3.3-70b-versatile)"]:::external
    end

    %% Data Storage & Resources
    subgraph "Data Storage & Resources"
        F["thirukkural_data.pkl"]:::storage
        G["data.json"]:::storage
        H["thirukkural_english_index.faiss"]:::storage
        I["thirukkural_tamil_index.faiss"]:::storage
    end

    %% Data Flow Edges
    A -->|"submitsQuery"| C
    B -->|"submitsQuery"| C
    C -->|"generatesEmbedding"| D
    D -->|"fetchesData"| F
    D -->|"fetchesData"| G
    D -->|"searchesIndex"| H
    D -->|"searchesIndex"| I
    D -->|"retrievesCandidates"| E
    E -->|"returnsExplanation"| J

    %% Click Events
    click A "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/app.py"
    click B "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/about_page.py"
    click F "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/thirukkural_data.pkl"
    click G "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/data.json"
    click H "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/thirukkural_english_index.faiss"
    click I "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/thirukkural_tamil_index.faiss"
    click D "https://github.com/viswadarshan-024/thirukkural-ai/blob/main/vector_db.py"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#007bff,stroke-width:2px
    classDef processor fill:#d4edda,stroke:#155724,stroke-width:2px
    classDef storage fill:#fff3cd,stroke:#856404,stroke-width:2px
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px
```
