# udayrajjhala/contextify architecture

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

- Interactive diagram: https://gitdiagram.com/udayrajjhala/contextify
- Repository: https://github.com/udayrajjhala/contextify

## Overview

##### Main Components for SQL RAG Flow
- Frontend Interface (Streamlit UI): This is where users input a natural language SQL query, provide MySQL database connection details, and view query results.
- Natural Language Query Processor: A module (powered by Google’s Gemini model) receives the natural language query and “translates” it into a valid SQL query.
- (Optional) Context Retriever: In many RAG setups, content is preprocessed and indexed using tools like FAISS. For SQL, this could involve retrieving context such as database schema details or previous query history to fine-tune the conversion process.
- SQL Query Generator (NL2SQL Translator): This critical component takes the processed natural language and outputs a valid SQL statement.
- SQL Executor / Database Connector: Using MySQL Connector (as noted in the README), this module sends the generated SQL statement to the connected MySQL database and receives the raw results.
- Post-Processing & Result Formatter: After executing the SQL query, the results are optionally re-processed (possibly via the Gemini LLM) to generate a human-friendly response before presentation on the UI.

##### Out the Flow and Relationships
- If a context retrieval step is used:

##### Architectural Patterns & Technologies
- Retrieval-augmented generation (RAG) architecture—even if only partially, by noting that context retrieval (via FAISS) and natural language understanding (Google Gemini) are key parts of the workflow.
- That this flow implements the common separation of concerns: the UI is separate from the processing/transformation logic (NL2SQL conversion) and further isolated from direct database access.
- External systems like MySQL and any dependencies such as the Chrome WebDriver, which though primarily used for website scraping, indicate the broader tech ecosystem.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    UI["Streamlit UI"]:::frontend

    %% Backend Processing Modules
    NLQP["NL Query Processor (Gemini)"]:::backend
    CR["Context Retriever (FAISS)"]:::external
    NL2SQL["NL2SQL Translator"]:::backend
    SQLEx["SQL Executor (MySQL Connector)"]:::backend
    RF["Result Formatter"]:::backend

    %% External Database
    DB["MySQL Database"]:::external

    %% Data Flow
    UI -->|"NLQuery"| NLQP
    NLQP -->|"fetchContext"| CR
    CR -->|"contextData"| NLQP
    NLQP -->|"convert"| NL2SQL
    NL2SQL -->|"generatedSQL"| SQLEx
    SQLEx -->|"sendQuery"| DB
    DB -->|"returnResults"| SQLEx
    SQLEx -->|"rawResults"| RF
    RF -->|"displayResults"| UI

    %% Click Events
    click UI "https://github.com/udayrajjhala/contextify/blob/main/app.py"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef external fill:#ffa500,stroke:#000,stroke-width:2px;
```
