# sanjay-m1512/nl_sql_local_backend architecture

> Architecture diagram of the GitHub repository sanjay-m1512/nl_sql_local_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sanjay-m1512/nl_sql_local_backend
- Repository: https://github.com/sanjay-m1512/nl_sql_local_backend

## Overview

This Flask service provides authenticated, role-aware database management and natural-language SQL querying. A user request enters the application, which resolves the selected database and schema, obtains SQL from the language-model integration, classifies or executes the query, and records audit information. The application also handles company/developer accounts, database registration, and schema synchronization. The README is empty; some routes and their call sites are omitted from the excerpts, so those relationships are not asserted beyond documented imports and visible references.

Main entry points: [`app.py`](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/app.py) (Flask routes), [`db/connection.py`](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/db/connection.py) (MySQL connection), [`llm/nl_to_sql.py`](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/llm/nl_to_sql.py) (NL-to-SQL), [`utils/audit_logger.py`](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/utils/audit_logger.py) (Audit logger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Application API"]
  node_app["Flask routes<br/>[app.py]"]
  node_env["Environment updater<br/>[env_updater.py]"]
end

subgraph group_query["Query Processing"]
  node_nl_sql["NL-to-SQL<br/>[nl_to_sql.py]"]
  node_classifier["SQL classifier<br/>[sql_classifier.py]"]
end

subgraph group_storage["Data Access"]
  node_audit_logger["Audit logger<br/>[audit_logger.py]"]
  node_connection["MySQL connection<br/>[connection.py]"]
  node_config["Environment config<br/>[config.py]"]
  node_mongo[("MongoDB records")]
end

subgraph group_integrations["External Services"]
  node_mysql[("MySQL databases")]
  node_groq{{"Groq API"}}
end

node_user(("API user"))

node_user -->|"sends requests"| node_app
node_app -->|"requests SQL"| node_nl_sql
node_app -->|"classifies SQL"| node_classifier
node_app -->|"uses database helpers"| node_connection
node_app -->|"reads and writes"| node_mongo
node_app -->|"connects for schema"| node_mysql
node_app -->|"logs queries"| node_audit_logger
node_app -.->|"updates settings"| node_env
node_nl_sql -->|"requests completion"| node_groq
node_connection -->|"reads settings"| node_config
node_connection -->|"opens connection"| node_mysql
node_audit_logger -->|"gets connection"| node_connection
node_config -.->|"loads API key"| node_groq

click node_app "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/app.py"
click node_env "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/utils/env_updater.py"
click node_nl_sql "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/llm/nl_to_sql.py"
click node_classifier "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/security/sql_classifier.py"
click node_audit_logger "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/utils/audit_logger.py"
click node_connection "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/db/connection.py"
click node_config "https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_env,node_user toneBlue
class node_nl_sql,node_classifier toneAmber
class node_audit_logger,node_connection,node_config,node_mongo toneMint
class node_mysql,node_groq toneRose
```

## Components

### Application API

- [Flask routes](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/app.py): `app.py`
- [Environment updater](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/utils/env_updater.py): `utils/env_updater.py`

### Query Processing

- [NL-to-SQL](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/llm/nl_to_sql.py): `llm/nl_to_sql.py`
- [SQL classifier](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/security/sql_classifier.py): `security/sql_classifier.py`

### Data Access

- [Audit logger](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/utils/audit_logger.py): `utils/audit_logger.py`
- [MySQL connection](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/db/connection.py): `db/connection.py`
- [Environment config](https://github.com/sanjay-m1512/nl_sql_local_backend/blob/main/config.py): `config.py`
- **MongoDB records**

### External Services

- **MySQL databases**
- **Groq API**

### Other components

- **API user**

## Connections

- API user → Flask routes: sends requests
- Flask routes → NL-to-SQL: requests SQL (evidence: `app.py`)
- Flask routes → SQL classifier: classifies SQL (evidence: `app.py`)
- Flask routes → MySQL connection: uses database helpers (evidence: `app.py`)
- Flask routes → MongoDB records: reads and writes (evidence: `app.py`)
- Flask routes → MySQL databases: connects for schema (evidence: `app.py`)
- Flask routes → Audit logger: logs queries (evidence: `app.py`)
- Flask routes → Environment updater: updates settings (evidence: `app.py`)
- NL-to-SQL → Groq API: requests completion (evidence: `llm/nl_to_sql.py`)
- MySQL connection → Environment config: reads settings (evidence: `db/connection.py`)
- MySQL connection → MySQL databases: opens connection (evidence: `db/connection.py`)
- Audit logger → MySQL connection: gets connection (evidence: `utils/audit_logger.py`)
- Environment config → Groq API: loads API key
