# sandesh-hase/sales_ai_project architecture

> Architecture diagram of the GitHub repository sandesh-hase/sales_ai_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sandesh-hase/sales_ai_project
- Repository: https://github.com/sandesh-hase/sales_ai_project

## Overview

Sales AI combines a Databricks retail-sales ML pipeline with a FastAPI service and React decision-support UI. Users inspect forecasts and KPIs, request forecast explanations or analytics chat, and can upload data or retrain before monitoring the run. The Databricks workflow covers setup, Bronze ingestion, Silver transformation, analysis, Gold preparation, training, and batch inference. Backend and frontend links reflect shown calls and matching API routes; unsampled runtime wiring is omitted.

Main entry points: [`backend/main.py`](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/main.py) (HTTP routes), [`frontend/src/pages/DashboardPage.tsx`](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/pages/DashboardPage.tsx) (Forecast dashboard), [`backend/src/data/db.py`](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/db.py) (Databricks queries), [`frontend/src/api/forecast.ts`](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/forecast.ts) (Forecast API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Decision Support UI"]
  node_app["App routing<br/>[App.tsx]"]
  node_dashboard["Forecast dashboard<br/>[DashboardPage.tsx]"]
  node_chat_page["Analytics chat page"]
  node_forecast_ui["Forecast views<br/>[ForecastChart.tsx]"]
  node_kpi_ui["KPI display<br/>[KPIBar.tsx]"]
  node_pipeline_ui["Pipeline controls"]
  node_chat_ui["Chat panel<br/>[ChatPanel.tsx]"]
  node_explanation_ui["Explanation panel"]
  node_forecast_api["Forecast API client<br/>[forecast.ts]"]
  node_chat_api["Chat API client<br/>[chat.ts]"]
  node_pipeline_api["Pipeline API client<br/>[pipeline.ts]"]
  node_http_client["HTTP client<br/>[client.ts]"]
end

subgraph group_api["Forecast API"]
  node_fastapi["HTTP routes<br/>[main.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_data["Analytics Data"]
  node_analytics["Business analytics<br/>[analytics.py]"]
  node_sql_queries["Databricks queries<br/>[db.py]"]
  node_db_client["SQL connection"]
  node_forecast_loader["Forecast loader"]
  node_jobs["Job management<br/>[databricks_jobs.py]"]
end

subgraph group_genai["GenAI Support"]
  node_chatbot["Analytics chatbot<br/>[chatbot.py]"]
  node_context_builder["Forecast context<br/>[explain_context.py]"]
  node_explainer["Forecast explainer"]
  node_llm_client["LLM client<br/>[llm_client.py]"]
end

subgraph group_ml["Databricks ML Pipeline"]
  node_setup["Workspace setup"]
  node_bronze["Bronze ingestion"]
  node_silver["Silver transformation"]
  node_eda["Exploratory analysis"]
  node_gold["Gold transformation"]
  node_training["Model training"]
  node_inference["Batch inference"]
end

node_retail_user(("Retail user"))
node_databricks[("Databricks workspace")]
node_azure_openai["Azure OpenAI"]

node_retail_user -->|"opens"| node_app
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_chat_page
node_dashboard -->|"renders"| node_forecast_ui
node_dashboard -->|"renders"| node_kpi_ui
node_dashboard -->|"renders"| node_pipeline_ui
node_dashboard -->|"renders"| node_explanation_ui
node_dashboard -->|"loads selections"| node_forecast_api
node_forecast_ui -->|"loads trends"| node_forecast_api
node_explanation_ui -->|"requests explanation"| node_forecast_api
node_pipeline_ui -->|"triggers and polls"| node_pipeline_api
node_chat_page -->|"renders"| node_chat_ui
node_chat_ui -->|"sends messages"| node_chat_api
node_forecast_api -->|"sends requests"| node_http_client
node_chat_api -->|"sends requests"| node_http_client
node_pipeline_api -->|"sends requests"| node_http_client
node_http_client -->|"calls routes"| node_fastapi
node_fastapi -->|"queries KPIs"| node_analytics
node_fastapi -->|"handles chat"| node_chatbot
node_fastapi -->|"builds context"| node_context_builder
node_fastapi -->|"requests explanation"| node_explainer
node_fastapi -->|"fetches forecast data"| node_sql_queries
node_fastapi -->|"starts and checks runs"| node_jobs
node_fastapi -->|"validates responses"| node_schemas
node_analytics -->|"runs queries"| node_sql_queries
node_sql_queries -->|"opens connection"| node_db_client
node_db_client -->|"connects to"| node_databricks
node_sql_queries -->|"reads tables"| node_databricks
node_chatbot -->|"uses analytics"| node_analytics
node_chatbot -->|"calls model"| node_llm_client
node_explainer -->|"requests narrative"| node_llm_client
node_llm_client -->|"sends completions"| node_azure_openai
node_fastapi -.->|"loads forecast results"| node_forecast_loader
node_setup -.->|"prepares ingestion"| node_bronze
node_bronze -->|"transforms data"| node_silver
node_silver -.->|"analyzes data"| node_eda
node_eda -.->|"informs preparation"| node_gold
node_gold -.->|"feeds training"| node_training
node_training -.->|"produces model"| node_inference
node_inference -.->|"writes forecasts"| node_databricks
node_jobs -.->|"dispatches runs"| node_databricks

click node_app "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/App.tsx"
click node_dashboard "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/pages/DashboardPage.tsx"
click node_chat_page "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/pages/AnalyticsChatPage.tsx"
click node_forecast_ui "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/ForecastChart.tsx"
click node_kpi_ui "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/KPIBar.tsx"
click node_pipeline_ui "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/PipelineControl.tsx"
click node_chat_ui "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/ChatPanel.tsx"
click node_explanation_ui "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/ExplanationPanel.tsx"
click node_forecast_api "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/forecast.ts"
click node_chat_api "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/chat.ts"
click node_pipeline_api "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/pipeline.ts"
click node_http_client "https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/client.ts"
click node_fastapi "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/main.py"
click node_schemas "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/models/schemas.py"
click node_analytics "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/analytics.py"
click node_sql_queries "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/db.py"
click node_db_client "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/databricks_client.py"
click node_forecast_loader "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/forecast_results_loader.py"
click node_chatbot "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/chatbot.py"
click node_context_builder "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/explain_context.py"
click node_explainer "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/forecast_explainer.py"
click node_llm_client "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/llm_client.py"
click node_setup "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/01_setup_sales_ai.py"
click node_bronze "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/02_bronze_ingestion.py"
click node_silver "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/03_silver_transformation.py"
click node_eda "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/04_exploratory_data_analysis.py"
click node_gold "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/05_gold_transformation.py"
click node_training "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/06_model_training.py"
click node_inference "https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/07_batch_inference.py"
click node_jobs "https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/databricks_jobs.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_dashboard,node_chat_page,node_forecast_ui,node_kpi_ui,node_pipeline_ui,node_chat_ui,node_explanation_ui,node_forecast_api,node_chat_api,node_pipeline_api,node_http_client,node_retail_user toneBlue
class node_fastapi,node_schemas,node_databricks toneAmber
class node_analytics,node_sql_queries,node_db_client,node_forecast_loader,node_jobs toneMint
class node_chatbot,node_context_builder,node_explainer,node_llm_client toneRose
class node_setup,node_bronze,node_silver,node_eda,node_gold,node_training,node_inference,node_azure_openai toneIndigo
```

## Components

### Decision Support UI

- [App routing](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Forecast dashboard](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [Analytics chat page](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/pages/AnalyticsChatPage.tsx): `frontend/src/pages/AnalyticsChatPage.tsx`
- [Forecast views](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/ForecastChart.tsx): `frontend/src/components/ForecastChart.tsx`
- [KPI display](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/KPIBar.tsx): `frontend/src/components/KPIBar.tsx`
- [Pipeline controls](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/PipelineControl.tsx): `frontend/src/components/PipelineControl.tsx`
- [Chat panel](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/ChatPanel.tsx): `frontend/src/components/ChatPanel.tsx`
- [Explanation panel](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/components/ExplanationPanel.tsx): `frontend/src/components/ExplanationPanel.tsx`
- [Forecast API client](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/forecast.ts): `frontend/src/api/forecast.ts`
- [Chat API client](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/chat.ts): `frontend/src/api/chat.ts`
- [Pipeline API client](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/pipeline.ts): `frontend/src/api/pipeline.ts`
- [HTTP client](https://github.com/sandesh-hase/sales_ai_project/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`

### Forecast API

- [HTTP routes](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/main.py): `backend/main.py`
- [API schemas](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/models/schemas.py): `backend/src/models/schemas.py`

### Analytics Data

- [Business analytics](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/analytics.py): `backend/src/data/analytics.py`
- [Databricks queries](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/db.py): `backend/src/data/db.py`
- [SQL connection](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/databricks_client.py): `backend/src/data/databricks_client.py`
- [Forecast loader](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/forecast_results_loader.py): `backend/src/data/forecast_results_loader.py`
- [Job management](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/data/databricks_jobs.py): `backend/src/data/databricks_jobs.py`

### GenAI Support

- [Analytics chatbot](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/chatbot.py): `backend/src/genai/chatbot.py`
- [Forecast context](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/explain_context.py): `backend/src/genai/explain_context.py`
- [Forecast explainer](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/forecast_explainer.py): `backend/src/genai/forecast_explainer.py`
- [LLM client](https://github.com/sandesh-hase/sales_ai_project/blob/main/backend/src/genai/llm_client.py): `backend/src/genai/llm_client.py`

### Databricks ML Pipeline

- [Workspace setup](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/01_setup_sales_ai.py): `Databricks/Sales_ai/src/01_setup_sales_ai.py`
- [Bronze ingestion](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/02_bronze_ingestion.py): `Databricks/Sales_ai/src/02_bronze_ingestion.py`
- [Silver transformation](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/03_silver_transformation.py): `Databricks/Sales_ai/src/03_silver_transformation.py`
- [Exploratory analysis](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/04_exploratory_data_analysis.py): `Databricks/Sales_ai/src/04_exploratory_data_analysis.py`
- [Gold transformation](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/05_gold_transformation.py): `Databricks/Sales_ai/src/05_gold_transformation.py`
- [Model training](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/06_model_training.py): `Databricks/Sales_ai/src/06_model_training.py`
- [Batch inference](https://github.com/sandesh-hase/sales_ai_project/blob/main/Databricks/Sales_ai/src/07_batch_inference.py): `Databricks/Sales_ai/src/07_batch_inference.py`

### Other components

- **Retail user**
- **Databricks workspace**
- **Azure OpenAI**

## Connections

- Retail user → App routing: opens (evidence: `frontend/src/App.tsx`)
- App routing → Forecast dashboard: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Analytics chat page: routes to (evidence: `frontend/src/App.tsx`)
- Forecast dashboard → Forecast views: renders (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Forecast dashboard → KPI display: renders (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Forecast dashboard → Pipeline controls: renders (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Forecast dashboard → Explanation panel: renders (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Forecast dashboard → Forecast API client: loads selections (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Forecast views → Forecast API client: loads trends (evidence: `frontend/src/components/ForecastChart.tsx`)
- Explanation panel → Forecast API client: requests explanation (evidence: `frontend/src/components/ExplanationPanel.tsx`)
- Pipeline controls → Pipeline API client: triggers and polls (evidence: `frontend/src/components/PipelineControl.tsx`)
- Analytics chat page → Chat panel: renders (evidence: `frontend/src/pages/AnalyticsChatPage.tsx`)
- Chat panel → Chat API client: sends messages (evidence: `frontend/src/components/ChatPanel.tsx`)
- Forecast API client → HTTP client: sends requests (evidence: `frontend/src/api/forecast.ts`)
- Chat API client → HTTP client: sends requests (evidence: `frontend/src/api/chat.ts`)
- Pipeline API client → HTTP client: sends requests (evidence: `frontend/src/api/pipeline.ts`)
- HTTP client → HTTP routes: calls routes
- HTTP routes → Business analytics: queries KPIs (evidence: `backend/main.py`)
- HTTP routes → Analytics chatbot: handles chat (evidence: `backend/main.py`)
- HTTP routes → Forecast context: builds context (evidence: `backend/main.py`)
- HTTP routes → Forecast explainer: requests explanation (evidence: `backend/main.py`)
- HTTP routes → Databricks queries: fetches forecast data (evidence: `backend/main.py`)
- HTTP routes → Job management: starts and checks runs (evidence: `backend/main.py`)
- HTTP routes → API schemas: validates responses (evidence: `backend/main.py`)
- Business analytics → Databricks queries: runs queries (evidence: `backend/src/data/analytics.py`)
- Databricks queries → SQL connection: opens connection (evidence: `backend/src/data/db.py`)
- SQL connection → Databricks workspace: connects to (evidence: `backend/src/data/databricks_client.py`)
- Databricks queries → Databricks workspace: reads tables (evidence: `backend/src/data/db.py`)
- Analytics chatbot → Business analytics: uses analytics (evidence: `backend/src/genai/chatbot.py`)
- Analytics chatbot → LLM client: calls model (evidence: `backend/src/genai/chatbot.py`)
- Forecast explainer → LLM client: requests narrative (evidence: `backend/src/genai/forecast_explainer.py`)
- LLM client → Azure OpenAI: sends completions (evidence: `backend/src/genai/llm_client.py`)
- HTTP routes → Forecast loader: loads forecast results
- Workspace setup → Bronze ingestion: prepares ingestion
- Bronze ingestion → Silver transformation: transforms data (evidence: `README.md`)
- Silver transformation → Exploratory analysis: analyzes data
- Exploratory analysis → Gold transformation: informs preparation
- Gold transformation → Model training: feeds training
- Model training → Batch inference: produces model
- Batch inference → Databricks workspace: writes forecasts
- Job management → Databricks workspace: dispatches runs
