# veryfastlearner/salesgenius architecture

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

- Interactive diagram: https://gitdiagram.com/veryfastlearner/salesgenius
- Repository: https://github.com/veryfastlearner/salesgenius

## Overview

1. **Repo shape**
   This repository is a two-surface product: a React/Vite web shell in `frontend/`, plus two Python/Gradio applications for AI-driven workflows. The Python side is split into a sales intelligence assistant and a data-visualization assistant.

2. **Top-level user entry points**
   The main user-facing paths are:
   - `app_gui.py` for the SalesGenius chat experience
   - `smart_dashboard.py` for the PlotSense / dashboard experience
   - `frontend/` as the browser-based launcher and navigation layer
   The React UI appears to act as the primary portal into the two Gradio apps.

3. **Frontend boundary**
   `frontend/src/App.jsx` and its components (`ChatPanel`, `TracePanel`, `ProfileCard`, `PlotSensePanel`, `HeroSection`) compose the browser UX. The `frontend/src/api/` adapters (`salesGenius.js`, `plotSense.js`) isolate the UI from the Python services, which is the main client/server boundary in the repo.

4. **SalesGenius backend architecture**
   The sales assistant is orchestrated as a sequential multi-agent pipeline described in the README and implemented across `sales_agent.py` and likely exposed through `final_api.py`. The chain is:
   Analyzer/Gatekeeper → Validator/Strategist → Sales Agent/Expert.
   Each stage narrows or reformats the request before the final response is returned to the UI.

5. **Multi-agent data flow**
   The first agent filters irrelevant input and decides whether to stop early. If the request is relevant, the second agent turns the raw chat into structured intent and profile updates. The final agent uses that validated context to produce the user-facing answer plus hidden recommendation/next-step data for the interface.

6. **Model and service dependencies**
   The architecture relies on Groq-hosted LLMs, with smaller models used for gating and formatting and a larger model used for the final reasoning step. The sales pipeline also pulls in Tavily for live company/news context and a local CSV dataset, `sme_financial_decision.csv`, for sector/financial benchmark grounding.

7. **State handling and output normalization**
   A notable architectural concern is output hardening: the system normalizes LLM responses into strict dictionary/list shapes before sending them back to the UI. This indicates the backend is stateful across chat turns and is designed to avoid crashes from malformed model output.

8. **PlotSense / Smart Dashboard subsystem**
   `smart_dashboard.py` is a separate Gradio app for CSV-driven analysis. Its workflow is: user uploads a dataset → the DataFrame is analyzed → chart recommendations are generated → the best recommendation drives plot generation → a separate explanation step turns the chart into plain-language insights.

9. **PlotSense internal boundaries**
   The PlotSense flow combines three distinct responsibilities: recommendation, chart generation, and explanation. That is a clear pipeline boundary between AI suggestion, visualization rendering, and narrative interpretation, all mediated through Pandas and Matplotlib in memory.

10. **Testing and validation**
   `test_sales_agent.py` and `test_output.txt` indicate at least one backend test path focused on the sales orchestration layer. The presence of tests and captured output suggests the backend behavior is important to keep deterministic enough for multi-turn interactions and UI state updates.

11. **Deployment/runtime split**
   The repo mixes a Python runtime for AI services and a Node/Vite runtime for the frontend. The React app is built and served separately from the Gradio/Python services, which means the architecture is effectively a browser client plus one or more local or remote AI-backed Python servers.

12. **Architecture summary for diagramming**
   If you’re drawing this system, model it as three major boxes: a React portal, a SalesGenius AI service with a 3-agent LLM pipeline and live/external data sources, and a PlotSense analytics service that turns uploaded CSVs into chart recommendations, plots, and explanations. The important boundaries are the UI-to-Python API boundary and the internal multi-agent/data-processing stages inside each Python service.

Main entry points: [`frontend/src/App.jsx`](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/App.jsx) (App shell), [`sales_agent.py`](https://github.com/veryfastlearner/salesgenius/blob/main/sales_agent.py) (Agent pipeline), [`frontend/src/components/ChatPanel.jsx`](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/ChatPanel.jsx) (Chat panel), [`frontend/src/components/PlotSensePanel.jsx`](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/PlotSensePanel.jsx) (Plot panel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend portal"]
  node_frontend_entry(("Main entry<br/>React bootstrap<br/>[main.jsx]"))
  node_frontend_shell["App shell<br/>React portal<br/>[App.jsx]"]
  node_frontend_chat["Chat panel<br/>UI component<br/>[ChatPanel.jsx]"]
  node_frontend_trace["Trace panel<br/>UI component<br/>[TracePanel.jsx]"]
  node_frontend_profile["Profile card<br/>UI component<br/>[ProfileCard.jsx]"]
  node_frontend_plotpanel["Plot panel<br/>UI component<br/>[PlotSensePanel.jsx]"]
  node_frontend_hero["Hero section<br/>UI component<br/>[HeroSection.jsx]"]
  node_frontend_sales_api["Sales API<br/>client adapter<br/>[salesGenius.js]"]
  node_frontend_plot_api["Plot API<br/>client adapter<br/>[plotSense.js]"]
end

subgraph group_sales["SalesGenius service"]
  node_sales_entry(("Gradio app<br/>Python entry<br/>[app_gui.py]"))
  node_sales_api["Service API<br/>backend API<br/>[final_api.py]"]
  node_sales_pipeline{{"Agent pipeline<br/>LLM orchestration<br/>[sales_agent.py]"}}
  node_sales_llm[("Groq models<br/>model runtime")]
  node_sales_web[("Live context<br/>external search")]
  node_sales_data[("Benchmark CSV<br/>reference data")]
  node_sales_state["Output guard<br/>normalizer"]
end

subgraph group_plot["PlotSense service"]
  node_plot_entry(("Dashboard app<br/>Python entry<br/>[smart_dashboard.py]"))
  node_plot_upload["Upload data<br/>pipeline stage"]
  node_plot_analysis["Data analysis<br/>pandas stage"]
  node_plot_recommend{{"Recommend chart<br/>LLM stage"}}
  node_plot_render["Render plot<br/>matplotlib stage"]
  node_plot_explain["Explain chart<br/>narration stage"]
end

node_frontend_entry -->|"bootstraps"| node_frontend_shell
node_frontend_shell -->|"navigates"| node_frontend_hero
node_frontend_shell -->|"shows"| node_frontend_chat
node_frontend_shell -->|"shows"| node_frontend_trace
node_frontend_shell -->|"shows"| node_frontend_profile
node_frontend_shell -->|"shows"| node_frontend_plotpanel
node_frontend_chat -->|"calls"| node_frontend_sales_api
node_frontend_plotpanel -->|"calls"| node_frontend_plot_api
node_frontend_sales_api -->|"requests"| node_sales_entry
node_frontend_plot_api -->|"requests"| node_plot_entry
node_sales_entry -->|"exposes"| node_sales_api
node_sales_api -->|"orchestrates"| node_sales_pipeline
node_sales_pipeline -->|"uses"| node_sales_llm
node_sales_pipeline -->|"enriches"| node_sales_web
node_sales_pipeline -->|"grounds"| node_sales_data
node_sales_pipeline -->|"normalizes"| node_sales_state
node_plot_entry -->|"starts"| node_plot_upload
node_plot_upload -->|"prepares"| node_plot_analysis
node_plot_analysis -->|"feeds"| node_plot_recommend
node_plot_recommend -->|"selects"| node_plot_render
node_plot_render -->|"describes"| node_plot_explain

click node_frontend_entry "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/main.jsx"
click node_frontend_shell "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/App.jsx"
click node_frontend_chat "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/ChatPanel.jsx"
click node_frontend_trace "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/TracePanel.jsx"
click node_frontend_profile "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/ProfileCard.jsx"
click node_frontend_plotpanel "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/PlotSensePanel.jsx"
click node_frontend_hero "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/HeroSection.jsx"
click node_frontend_sales_api "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/api/salesGenius.js"
click node_frontend_plot_api "https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/api/plotSense.js"
click node_sales_entry "https://github.com/veryfastlearner/salesgenius/blob/main/app_gui.py"
click node_sales_api "https://github.com/veryfastlearner/salesgenius/blob/main/final_api.py"
click node_sales_pipeline "https://github.com/veryfastlearner/salesgenius/blob/main/sales_agent.py"
click node_sales_data "https://github.com/veryfastlearner/salesgenius/blob/main/sme_financial_decision.csv"
click node_plot_entry "https://github.com/veryfastlearner/salesgenius/blob/main/smart_dashboard.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_frontend_entry,node_frontend_shell,node_frontend_chat,node_frontend_trace,node_frontend_profile,node_frontend_plotpanel,node_frontend_hero,node_frontend_sales_api,node_frontend_plot_api toneBlue
class node_sales_entry,node_sales_api,node_sales_pipeline,node_sales_llm,node_sales_web,node_sales_data,node_sales_state toneAmber
class node_plot_entry,node_plot_upload,node_plot_analysis,node_plot_recommend,node_plot_render,node_plot_explain toneMint
```

## Components

### Frontend portal

React/Vite browser UI and API bridge

- [Main entry](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/main.jsx): React bootstrap · Vite/React application entry point · `frontend/src/main.jsx`
- [App shell](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/App.jsx): React portal · Top-level browser experience that routes users into the two assistant surfaces · `frontend/src/App.jsx`
- [Chat panel](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/ChatPanel.jsx): UI component · SalesGenius conversation interface · `frontend/src/components/ChatPanel.jsx`
- [Trace panel](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/TracePanel.jsx): UI component · Shows reasoning or execution trace for the sales workflow · `frontend/src/components/TracePanel.jsx`
- [Profile card](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/ProfileCard.jsx): UI component · Displays customer or account context · `frontend/src/components/ProfileCard.jsx`
- [Plot panel](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/PlotSensePanel.jsx): UI component · Dashboard surface for PlotSense interactions · `frontend/src/components/PlotSensePanel.jsx`
- [Hero section](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/components/HeroSection.jsx): UI component · Landing and navigation header · `frontend/src/components/HeroSection.jsx`
- [Sales API](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/api/salesGenius.js): client adapter · Frontend adapter for the sales intelligence backend · `frontend/src/api/salesGenius.js`
- [Plot API](https://github.com/veryfastlearner/salesgenius/blob/main/frontend/src/api/plotSense.js): client adapter · Frontend adapter for the PlotSense backend · `frontend/src/api/plotSense.js`

### SalesGenius service

Gradio-backed sales intelligence pipeline

- [Gradio app](https://github.com/veryfastlearner/salesgenius/blob/main/app_gui.py): Python entry · SalesGenius chat application entry point · `app_gui.py`
- [Service API](https://github.com/veryfastlearner/salesgenius/blob/main/final_api.py): backend API · Backend surface exposing the sales workflow to the UI · `final_api.py`
- [Agent pipeline](https://github.com/veryfastlearner/salesgenius/blob/main/sales_agent.py): LLM orchestration · Sequential analyzer, validator, strategist, and expert stages · `sales_agent.py`
- **Groq models**: model runtime · Small and large hosted LLMs used across the sales stages
- **Live context**: external search · Tavily-backed company and news lookup
- [Benchmark CSV](https://github.com/veryfastlearner/salesgenius/blob/main/sme_financial_decision.csv): reference data · Local sector and financial grounding dataset · `sme_financial_decision.csv`
- **Output guard**: normalizer · Hardened response shaping for chat state and UI safety

### PlotSense service

CSV-driven analytics and visualization flow

- [Dashboard app](https://github.com/veryfastlearner/salesgenius/blob/main/smart_dashboard.py): Python entry · PlotSense CSV analysis application entry point · `smart_dashboard.py`
- **Upload data**: pipeline stage · Ingests the user-provided dataset
- **Data analysis**: pandas stage · Inspects and prepares the dataframe for visualization
- **Recommend chart**: LLM stage · Chooses the most suitable chart from candidate options
- **Render plot**: matplotlib stage · Builds the selected chart in memory
- **Explain chart**: narration stage · Turns the visualization into plain-language insights

## Connections

- Main entry → App shell: bootstraps · React entry mounts the main portal
- App shell → Hero section: navigates · Landing area frames the product surfaces
- App shell → Chat panel: shows · Primary sales conversation UI
- App shell → Trace panel: shows · Trace and reasoning view
- App shell → Profile card: shows · Customer context pane
- App shell → Plot panel: shows · PlotSense dashboard surface
- Chat panel → Sales API: calls · Sales chat exchanges go through the client adapter
- Plot panel → Plot API: calls · Dashboard actions go through the plot adapter
- Sales API → Gradio app: requests · Browser client reaches the sales app/service boundary
- Plot API → Dashboard app: requests · Browser client reaches the PlotSense service boundary
- Gradio app → Service API: exposes · Gradio app surfaces the backend workflow
- Service API → Agent pipeline: orchestrates · Service delegates to the multi-agent sales flow
- Agent pipeline → Groq models: uses · Multiple Groq-hosted models power gating and final reasoning
- Agent pipeline → Live context: enriches · Fetches live context for company and market grounding
- Agent pipeline → Benchmark CSV: grounds · Uses the local benchmark dataset for validation and context
- Agent pipeline → Output guard: normalizes · Shapes model output into safe structured responses
- Dashboard app → Upload data: starts · Dashboard begins with dataset ingestion
- Upload data → Data analysis: prepares · Uploaded data is inspected and transformed
- Data analysis → Recommend chart: feeds · Analysis context informs chart selection
- Recommend chart → Render plot: selects · Chosen visualization is rendered
- Render plot → Explain chart: describes · Rendered chart is translated into insights
