# vsion-x/vizgenie architecture

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

- Interactive diagram: https://gitdiagram.com/vsion-x/vizgenie
- Repository: https://github.com/vsion-x/vizgenie

## Overview

1. **What this repository is**
VizGenie is a Streamlit-based AI dashboard generator that turns natural-language requests into Grafana dashboards. The core product is an agentic workflow: user intent goes in, datasource-specific queries and dashboard JSON come out, and the result is deployed to Grafana.

2. **Primary runtime boundary**
The main application lives in `main.py` and is the user-facing entry point. It orchestrates the UI, connection settings, and workflow execution, but the actual decision-making is pushed into the LangGraph agent pipeline under `agents/`.

3. **Agent orchestration layer**
`agents/workflow.py` defines the deterministic multi-step graph, while `agents/vizgenie_agents.py` contains the node logic for each stage. The workflow is sequential with conditional routing: intent extraction, metric discovery, validation, query generation, query validation, dashboard generation, and Grafana deployment.

4. **State as the central contract**
`state/graph_state.py` defines the shared workflow state passed between nodes. This state is the main data bus for the system, holding the user query, extracted metrics, generated queries, dashboard spec, execution log, and error/retry context. It is the key architectural boundary between steps.

5. **LLM and prompt layer**
`llm/prompt.py` holds the task-specific prompts used by the agents. `handlers/groq_handler.py` wraps Groq LLM access, so the LLM is a separate service dependency rather than embedded inside the UI or tools. The repo is designed around a small number of LLM calls per request, with retry logic on validation failures.

6. **Tools versus handlers**
`tools/vizgenie_tools.py` exposes the workflow capabilities as LangChain-style tools, while `handlers/` contains the concrete integration code. This split separates orchestration semantics from I/O concerns. The handlers are the actual adapters to external systems: Prometheus, PostgreSQL, Grafana, ChromaDB, and Groq.

7. **Datasource-specific branches**
The system supports two datasource families: Prometheus for metrics and PostgreSQL for tabular/business data. After metric extraction and validation, the workflow branches into PromQL generation or SQL generation depending on the selected datasource. `handlers/prometheus_handler.py` and `handlers/postgres_handler.py` are the datasource integration points.

8. **Vector search and metadata enrichment**
`handlers/vectordb_handler.py` connects to ChromaDB for semantic metric lookup. The app uses vector search as a discovery layer before validation, which helps map user language to real metric names. For PostgreSQL, `metadata/metadata.yaml` acts as schema knowledge used to ground SQL generation against the sample sales dataset in `sales_db.csv`.

9. **Dashboard creation and deployment**
Once a query is validated, the workflow generates a Grafana dashboard definition and deploys it through `handlers/grafana_handler.py`. Grafana is the final sink of the primary data flow, receiving dashboard JSON through its API rather than through file export. The output of the whole system is therefore a live dashboard URL, not just a query string.

10. **Infrastructure and local stack**
`docker-compose.yaml` wires together the app and its dependencies: Grafana, Prometheus, PostgreSQL, and ChromaDB. The repo also includes Grafana provisioning under `grafana/` and observability configs under `config/` and `demo/config/`, indicating the stack is intended to bootstrap with preloaded dashboards, datasources, and monitoring defaults.

11. **Demo and observability sub-system**
The `demo/` directory is a separate support environment, not the core product path. It includes a demo app, a load generator, and Grafana/Loki/Prometheus config for showcasing the system under synthetic traffic. This suggests the repository has both a product workflow and a packaged demo/monitoring environment.

12. **Important architectural flow to diagram**
A good diagram should show: user request in Streamlit → LangGraph workflow/state → LLM + tools/handlers → datasource lookup/validation → query generation → dashboard JSON generation → Grafana deployment. Around that core, show the supporting services: Groq for inference, ChromaDB for semantic search, Prometheus/PostgreSQL as data sources, and Grafana as the deployment target.

Main entry points: [`agents/vizgenie_agents.py`](https://github.com/vsion-x/vizgenie/blob/main/agents/vizgenie_agents.py) (Agent nodes), [`docker-compose.yaml`](https://github.com/vsion-x/vizgenie/blob/main/docker-compose.yaml) (Compose stack), [`agents/workflow.py`](https://github.com/vsion-x/vizgenie/blob/main/agents/workflow.py) (Workflow), [`main.py`](https://github.com/vsion-x/vizgenie/blob/main/main.py) (Main app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core app"]
  node_main_py["Main app<br/>streamlit entrypoint<br/>[main.py]"]
  node_workflow_py{{"Workflow<br/>langgraph pipeline<br/>[workflow.py]"}}
  node_agents_py["Agent nodes<br/>agent logic<br/>[vizgenie_agents.py]"]
  node_state_py[("State model<br/>shared state<br/>[graph_state.py]")]
end

subgraph group_integrations["Integrations"]
  node_tools_py["Workflow tools<br/>langchain tools<br/>[vizgenie_tools.py]"]
  node_prompt_py["Prompts<br/>prompt templates<br/>[prompt.py]"]
  node_groq_py["Groq client<br/>llm adapter<br/>[groq_handler.py]"]
  node_vector_py[("Vector search<br/>chromadb adapter")]
  node_prom_handler[("Prometheus<br/>metrics adapter")]
  node_pg_handler[("PostgreSQL<br/>sql adapter")]
  node_grafana_handler["Grafana API<br/>deployment adapter<br/>[grafana_handler.py]"]
end

subgraph group_support["Support stack"]
  node_metadata_yaml["Schema metadata<br/>dataset metadata<br/>[metadata.yaml]"]
  node_grafana_prov["Grafana provisioning<br/>provisioning assets"]
  node_compose_yaml["Compose stack<br/>local stack"]
  node_config_prom["Prom config<br/>monitoring config<br/>[prometheus.yml]"]
  node_demo_main["Demo app<br/>demo entrypoint<br/>[main.py]"]
  node_demo_load["Load generator<br/>traffic generator<br/>[main.py]"]
  node_demo_config["Demo observability<br/>monitoring config"]
end

node_main_py -->|"runs"| node_workflow_py
node_main_py -->|"uses"| node_tools_py
node_workflow_py -->|"passes state"| node_state_py
node_workflow_py -->|"executes nodes"| node_agents_py
node_agents_py -->|"prompts"| node_prompt_py
node_agents_py -->|"llm calls"| node_groq_py
node_agents_py -->|"lookup"| node_vector_py
node_agents_py -->|"promql path"| node_prom_handler
node_agents_py -->|"sql path"| node_pg_handler
node_agents_py -->|"deploys"| node_grafana_handler
node_vector_py -->|"grounds metrics"| node_prom_handler
node_pg_handler -->|"grounds sql"| node_metadata_yaml
node_workflow_py -->|"final sink"| node_grafana_handler
node_compose_yaml -->|"starts"| node_main_py
node_compose_yaml -->|"boots"| node_grafana_prov
node_compose_yaml -->|"configures"| node_config_prom
node_compose_yaml -->|"packages"| node_demo_config
node_demo_main -->|"showcases"| node_demo_load
node_demo_config -->|"observes"| node_grafana_prov

click node_main_py "https://github.com/vsion-x/vizgenie/blob/main/main.py"
click node_workflow_py "https://github.com/vsion-x/vizgenie/blob/main/agents/workflow.py"
click node_agents_py "https://github.com/vsion-x/vizgenie/blob/main/agents/vizgenie_agents.py"
click node_state_py "https://github.com/vsion-x/vizgenie/blob/main/state/graph_state.py"
click node_tools_py "https://github.com/vsion-x/vizgenie/blob/main/tools/vizgenie_tools.py"
click node_prompt_py "https://github.com/vsion-x/vizgenie/blob/main/llm/prompt.py"
click node_groq_py "https://github.com/vsion-x/vizgenie/blob/main/handlers/groq_handler.py"
click node_vector_py "https://github.com/vsion-x/vizgenie/blob/main/handlers/vectordb_handler.py"
click node_prom_handler "https://github.com/vsion-x/vizgenie/blob/main/handlers/prometheus_handler.py"
click node_pg_handler "https://github.com/vsion-x/vizgenie/blob/main/handlers/postgres_handler.py"
click node_grafana_handler "https://github.com/vsion-x/vizgenie/blob/main/handlers/grafana_handler.py"
click node_metadata_yaml "https://github.com/vsion-x/vizgenie/blob/main/metadata/metadata.yaml"
click node_grafana_prov "https://github.com/vsion-x/vizgenie/tree/main/grafana/provisioning"
click node_compose_yaml "https://github.com/vsion-x/vizgenie/blob/main/docker-compose.yaml"
click node_config_prom "https://github.com/vsion-x/vizgenie/blob/main/config/prometheus.yml"
click node_demo_main "https://github.com/vsion-x/vizgenie/blob/main/demo/app/main.py"
click node_demo_load "https://github.com/vsion-x/vizgenie/blob/main/demo/load-generator/main.py"
click node_demo_config "https://github.com/vsion-x/vizgenie/tree/main/demo/config"

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_main_py,node_workflow_py,node_agents_py,node_state_py toneBlue
class node_tools_py,node_prompt_py,node_groq_py,node_vector_py,node_prom_handler,node_pg_handler,node_grafana_handler toneAmber
class node_metadata_yaml,node_grafana_prov,node_compose_yaml,node_config_prom,node_demo_main,node_demo_load,node_demo_config toneMint
```

## Components

### Core app

Primary Streamlit app and agentic workflow

- [Main app](https://github.com/vsion-x/vizgenie/blob/main/main.py): streamlit entrypoint · User-facing UI entrypoint that orchestrates request handling and workflow execution · `main.py`
- [Workflow](https://github.com/vsion-x/vizgenie/blob/main/agents/workflow.py): langgraph pipeline · Deterministic multi-step agent graph with routing and retries · `agents/workflow.py`
- [Agent nodes](https://github.com/vsion-x/vizgenie/blob/main/agents/vizgenie_agents.py): agent logic · Per-step node logic for intent, metrics, validation, query generation, and deployment · `agents/vizgenie_agents.py`
- [State model](https://github.com/vsion-x/vizgenie/blob/main/state/graph_state.py): shared state · Central workflow contract carrying query, metrics, queries, dashboard spec, logs, and errors · `state/graph_state.py`

### Integrations

LLM, datasource, and deployment adapters

- [Workflow tools](https://github.com/vsion-x/vizgenie/blob/main/tools/vizgenie_tools.py): langchain tools · Tool facade exposing workflow capabilities to the agent layer · `tools/vizgenie_tools.py`
- [Prompts](https://github.com/vsion-x/vizgenie/blob/main/llm/prompt.py): prompt templates · Task-specific prompt definitions used by the agent stages · `llm/prompt.py`
- [Groq client](https://github.com/vsion-x/vizgenie/blob/main/handlers/groq_handler.py): llm adapter · Wrapper for Groq inference access and request handling · `handlers/groq_handler.py`
- [Vector search](https://github.com/vsion-x/vizgenie/blob/main/handlers/vectordb_handler.py): chromadb adapter · Semantic metric lookup and metadata enrichment through ChromaDB · `handlers/vectordb_handler.py`
- [Prometheus](https://github.com/vsion-x/vizgenie/blob/main/handlers/prometheus_handler.py): metrics adapter · Prometheus integration for datasource-specific metric discovery and query execution · `handlers/prometheus_handler.py`
- [PostgreSQL](https://github.com/vsion-x/vizgenie/blob/main/handlers/postgres_handler.py): sql adapter · PostgreSQL integration for schema-grounded SQL generation and execution · `handlers/postgres_handler.py`
- [Grafana API](https://github.com/vsion-x/vizgenie/blob/main/handlers/grafana_handler.py): deployment adapter · Deploys generated dashboard JSON into Grafana and returns the live dashboard target · `handlers/grafana_handler.py`

### Support stack

Provisioning, metadata, and demo environment

- [Schema metadata](https://github.com/vsion-x/vizgenie/blob/main/metadata/metadata.yaml): dataset metadata · YAML knowledge base grounding SQL generation for the sample sales dataset · `metadata/metadata.yaml`
- [Grafana provisioning](https://github.com/vsion-x/vizgenie/tree/main/grafana/provisioning): provisioning assets · Preloaded dashboards and datasource configuration for local Grafana bootstrap · `grafana/provisioning`
- [Compose stack](https://github.com/vsion-x/vizgenie/blob/main/docker-compose.yaml): local stack · Orchestrates the app, Grafana, Prometheus, PostgreSQL, and ChromaDB · `docker-compose.yaml`
- [Prom config](https://github.com/vsion-x/vizgenie/blob/main/config/prometheus.yml): monitoring config · Prometheus configuration used by the local and demo monitoring stack · `config/prometheus.yml`
- [Demo app](https://github.com/vsion-x/vizgenie/blob/main/demo/app/main.py): demo entrypoint · Separate demo Streamlit app for showcasing the workflow under synthetic traffic · `demo/app/main.py`
- [Load generator](https://github.com/vsion-x/vizgenie/blob/main/demo/load-generator/main.py): traffic generator · Synthetic workload generator used by the demo environment · `demo/load-generator/main.py`
- [Demo observability](https://github.com/vsion-x/vizgenie/tree/main/demo/config): monitoring config · Loki, Prometheus, and Promtail configuration for the packaged demo environment · `demo/config`

## Connections

- Main app → Workflow: runs · The UI hands a user request to the deterministic agent workflow
- Main app → Workflow tools: uses · The app exposes workflow capabilities through tool-like interfaces
- Workflow → State model: passes state · Workflow steps read and update the shared graph state
- Workflow → Agent nodes: executes nodes · The graph routes control through the agent node implementations
- Agent nodes → Prompts: prompts · Each stage uses task-specific prompt templates
- Agent nodes → Groq client: llm calls · Agent reasoning and generation are delegated to Groq
- Agent nodes → Vector search: lookup · Metric discovery is enriched by semantic search
- Agent nodes → Prometheus: promql path · Prometheus is used when the workflow targets metrics data
- Agent nodes → PostgreSQL: sql path · PostgreSQL is used when the workflow targets tabular data
- Agent nodes → Grafana API: deploys · Final dashboard JSON is pushed to Grafana
- Vector search → Prometheus: grounds metrics · Vector search helps map user language to real metrics
- PostgreSQL → Schema metadata: grounds sql · Schema metadata constrains query generation against the sample dataset
- Workflow → Grafana API: final sink · Successful runs end with Grafana deployment
- Compose stack → Main app: starts · Compose includes the primary application runtime
- Compose stack → Grafana provisioning: boots · Local stack loads Grafana provisioning assets
- Compose stack → Prom config: configures · Compose wires the monitoring configuration into the stack
- Compose stack → Demo observability: packages · Demo environment includes its own observability configuration
- Demo app → Load generator: showcases · The demo app is paired with synthetic traffic generation
- Demo observability → Grafana provisioning: observes · Demo monitoring stack complements Grafana provisioning
