# prudviraj007/sql-ai-samples architecture

> Architecture diagram of the GitHub repository prudviraj007/sql-ai-samples, 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/prudviraj007/sql-ai-samples
- Repository: https://github.com/prudviraj007/sql-ai-samples

## Overview

##### project type and purpose
- This is a sample repository aimed at educating users through examples. It shows how to integrate an Azure SQL Database with various AI components.
- The samples cover several scenarios: using Azure Cognitive Services for vectorization and search, using T-SQL scripts for content moderation via Azure OpenAI, implementing a natural language to SQL agent via LangChain, and orchestrating an end-to-end workflow with Azure PromptFlow.

##### Main components
- Azure SQL Database – the central data repository where all sample data resides.
- AI/Machine Learning Services:
- Azure Cognitive Services (Cognitive Search for integrated vectorization and recommendation)
- Azure OpenAI (for vector embeddings, content moderation, and chatbot style interactions)
- LangChain (a Python-based NL2SQL agent layer)
- Azure PromptFlow (orchestrating the flow between data, OpenAI, and Azure ML endpoints)
- Sample-specific components:
- Jupyter Notebooks (e.g., the AzureSQL_CogSearch_IntegratedVectorization.ipynb and LangChain notebooks) illustrating prototype workflows.
- T-SQL Scripts (in the ContentModeration folder) that encapsulate the SQL logic to call AI services.
- Deployment and config files (YAML files, .env samples, and configuration JSON files in the PromptFlow section) showing how to deploy/operate these flows, and their integration points.

##### Establish the relationships and interactions
- Data Flow: Begin with the Azure SQL Database as the data center from which data is extracted.
- For the Azure Cognitive Services sample, illustrate how user reviews or text data are pulled from the database into Azure Cognitive Search. Show the flow of the data being automatically chunked and vectorized.
- For Content Moderation, show T-SQL scripts acting as a processing layer that calls out to Azure OpenAI Content Safety and Language AI. Indicate the round-trip where text is analyzed and prior results (e.g., safety scores, redacted content) are returned to the SQL side.
- For the PromptFlow sample, show a comprehensive orchestration layer that connects the SQL Database, Azure Cognitive Search, and Azure OpenAI services. Include additional integration with an Azure ML workspace if required.

##### Architectural patterns and design principles
- Service-oriented design: Emphasize that the microservices (cognitive search, content moderation, NL2SQL via LangChain, and PromptFlow orchestration) each are independent modules that interact with the central database.
- Configuration/Deployment: Indicate areas where environment variables (.env, config JSON files) manage the connectivity and security between services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Azure SQL Database"]:::db

    subgraph "Azure Cognitive Services Sample"
        CS1["Integrated Vectorization Notebook"]:::notebook
        CS2["Cognitive Search Setup Notebook"]:::notebook
    end

    subgraph "Content Moderation Sample"
        CM1["contentSafety.sql"]:::tsql
        CM2["languageAI.sql"]:::tsql
    end

    subgraph "LangChain Integration Sample"
        LC1["LangChain Directory"]:::langchain
        LC2["dbAzureOpenAI.ipynb"]:::notebook
        LC3["dbOpenAI.ipynb"]:::notebook
    end

    subgraph "PromptFlow Orchestration Sample"
        PF1["PromptFlow Directory"]:::promptflow
    end

    %% Data flows from Azure SQL Database to each sample integration
    A -->|"UserReviews"| CS1
    A -->|"UserData"| CM1
    A -->|"SQLQueries"| LC1
    A -->|"DataFlow"| PF1

    %% Content Moderation calls Azure OpenAI endpoints
    CM1 -->|"Calls"| AO1["Azure OpenAI (ContentSafety)"]:::ai
    CM2 -->|"Calls"| AO2["Azure OpenAI (LanguageAI)"]:::ai

    %% LangChain sample uses Azure OpenAI for NL2SQL conversion
    LC1 -->|"NL2SQLRequest"| AO3["Azure OpenAI (LLM)"]:::ai

    %% PromptFlow orchestration integrates multiple services
    PF1 -->|"Orchestrates"| CS1
    PF1 -->|"Orchestrates"| AO4["Azure OpenAI"]:::ai
    PF1 -->|"Orchestrates"| AML["Azure ML Workspace"]:::ml

    %% Click Events
    click A "https://github.com/prudviraj007/sql-ai-samples/tree/main/AzureSQLDatabase"
    click CS1 "https://github.com/prudviraj007/sql-ai-samples/blob/main/AzureSQLACSSamples/src/AzureSQL_CogSearch_IntegratedVectorization.ipynb"
    click CS2 "https://github.com/prudviraj007/sql-ai-samples/blob/main/AzureSQLPromptFlowSamples/src/sql-promptflow-demo/acs/azure_congnitive_search_prepare.ipynb"
    click CM1 "https://github.com/prudviraj007/sql-ai-samples/blob/main/AzureSQLDatabase/ContentModeration/contentSafety.sql"
    click CM2 "https://github.com/prudviraj007/sql-ai-samples/blob/main/AzureSQLDatabase/ContentModeration/languageAI.sql"
    click LC1 "https://github.com/prudviraj007/sql-ai-samples/tree/main/AzureSQLDatabase/LangChain"
    click LC2 "https://github.com/prudviraj007/sql-ai-samples/blob/main/AzureSQLDatabase/LangChain/dbAzureOpenAI.ipynb"
    click LC3 "https://github.com/prudviraj007/sql-ai-samples/blob/main/AzureSQLDatabase/LangChain/dbOpenAI.ipynb"
    click PF1 "https://github.com/prudviraj007/sql-ai-samples/tree/main/AzureSQLPromptFlowSamples"

    %% Styles
    classDef db fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef notebook fill:#aed6f1,stroke:#1f618d,stroke-width:1px;
    classDef tsql fill:#abebc6,stroke:#1e8449,stroke-width:1px;
    classDef langchain fill:#f9caa7,stroke:#d35400,stroke-width:1px;
    classDef promptflow fill:#d7bde2,stroke:#6c3483,stroke-width:1px;
    classDef ai fill:#f5b7b1,stroke:#922b21,stroke-width:1px;
    classDef ml fill:#d1f2eb,stroke:#17a589,stroke-width:1px;
```
