# ankrutee/nexturn-projectelective architecture

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

- Interactive diagram: https://gitdiagram.com/ankrutee/nexturn-projectelective
- Repository: https://github.com/ankrutee/nexturn-projectelective

## Overview

##### Main Components
- Terminal Application (main.py): Handles user input, SQL query generation, and database connectivity.
- Web Application (app.py): A Streamlit-based interface that offers user-friendly interactive features.
- Database: Represented by bank.sql (the database schema), schemaBank.txt (schema details), and trialQueries.txt (tested queries). This component manages the banking data.
- NLP / GPT Integration: Although not shown as a separate file, both main.py and app.py integrate with OpenAI’s GPT model (and Mistral AI) for processing natural language queries.
- Dependency Management: requirements.txt ensures that all necessary libraries are installed.

##### Relationships and Interactions
- The Terminal and Web interfaces serve as entry points for users. Both collect queries from the user.
- User queries are sent to the query generation component that uses embedded schema details (from schemaBank.txt) and tested SQL samples (trialQueries.txt) to generate analytical SQL queries.
- The generated SQL queries are then executed against the banking database (whose structure is defined in bank.sql).
- NLP components interact with the query generation logic by using OpenAI and Mistral AI APIs to process natural language into SQL.
- Database connectivity is handled within main.py (and potentially in app.py) where the connect_to_mysql() function is updated with relevant credentials.

##### Architectural Patterns and Technologies
- Separation of Concerns: Two distinct frontends (terminal and web) clearly separate user interaction layers from the back-end query generation.
- Integration with External APIs: The project uses external services (OpenAI API, Mistral AI). Their role in enriching the NLP capabilities must also be represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces Subgraph
    subgraph "User Interfaces"
        T["Terminal Application (main.py)"]:::ui
        W["Streamlit Web UI (app.py)"]:::ui
    end

    %% Backend Subgraph
    subgraph "Backend"
        Q["Query Generator & NLP Module"]:::logic
        D["MySQL Database"]:::db
    end

    %% External Services
    E["OpenAI API"]:::api
    M["Mistral AI API"]:::api

    %% Dependency Management
    Dep["Dependency Management (requirements.txt)"]:::dep

    %% Connections from UI to Backend
    T -->|"user_query"| Q
    W -->|"user_query"| Q

    %% Connection from Query Generator to Database
    Q -->|"SQL_query"| D
    D -->|"query_result"| Q

    %% External API integrations
    Q -->|"NLP_call"| E
    Q -->|"NLP_call"| M

    %% Dependency management connection (informational)
    T --- Dep
    W --- Dep

    %% Click Events
    click T "https://github.com/ankrutee/nexturn-projectelective/blob/main/main.py"
    click W "https://github.com/ankrutee/nexturn-projectelective/blob/main/app.py"
    click D "https://github.com/ankrutee/nexturn-projectelective/blob/main/bank.sql"
    click D "https://github.com/ankrutee/nexturn-projectelective/blob/main/schemaBank.txt"
    click D "https://github.com/ankrutee/nexturn-projectelective/blob/main/trialQueries.txt"
    click Dep "https://github.com/ankrutee/nexturn-projectelective/blob/main/requirements.txt"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef logic fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef db fill:#FFE4B5,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef api fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef dep fill:#DDA0DD,stroke:#333,stroke-width:2px;
```
