How vsion-x/vizgenie works
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: vizgenie_agents.py Agent nodes · docker-compose.yaml Compose stack · workflow.py Workflow · main.py Main app
Components 18
Core app
Primary Streamlit app and agentic workflow
- Main app · User-facing UI entrypoint that orchestrates request handling and workflow execution
main.py - Workflow · Deterministic multi-step agent graph with routing and retries
agents/workflow.py - Agent nodes · Per-step node logic for intent, metrics, validation, query generation, and deployment
agents/vizgenie_agents.py - State model · Central workflow contract carrying query, metrics, queries, dashboard spec, logs, and errors
state/graph_state.py
Integrations
LLM, datasource, and deployment adapters
- Workflow tools · Tool facade exposing workflow capabilities to the agent layer
tools/vizgenie_tools.py - Prompts · Task-specific prompt definitions used by the agent stages
llm/prompt.py - Groq client · Wrapper for Groq inference access and request handling
handlers/groq_handler.py - Vector search · Semantic metric lookup and metadata enrichment through ChromaDB
handlers/vectordb_handler.py - Prometheus · Prometheus integration for datasource-specific metric discovery and query execution
handlers/prometheus_handler.py - PostgreSQL · PostgreSQL integration for schema-grounded SQL generation and execution
handlers/postgres_handler.py - Grafana API · 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 · YAML knowledge base grounding SQL generation for the sample sales dataset
metadata/metadata.yaml - Grafana provisioning · Preloaded dashboards and datasource configuration for local Grafana bootstrap
grafana/provisioning - Compose stack · Orchestrates the app, Grafana, Prometheus, PostgreSQL, and ChromaDB
docker-compose.yaml - Prom config · Prometheus configuration used by the local and demo monitoring stack
config/prometheus.yml - Demo app · Separate demo Streamlit app for showcasing the workflow under synthetic traffic
demo/app/main.py - Load generator · Synthetic workload generator used by the demo environment
demo/load-generator/main.py - Demo observability · Loki, Prometheus, and Promtail configuration for the packaged demo environment
demo/config
Connections 19
- 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