How dhruvatreja/datavisualization_langgraph works
Project Type & Purpose
• This is a full-stack application focused on bridging natural language queries to data visualizations using SQL. It integrates a LangGraph-based AI agent that interprets user input, dynamically generates SQL queries, executes them on a SQLite (or CSV-converted) database, and then returns visual visualizations through a streaming API.
• The project uses LangGraph Studio for orchestration and offers two back-end implementations (JavaScript and Python) along with a dedicated SQLite server (handling uploads and query execution).
Analyzing the File Structure
• Top-level components include:
• frontend: A Next.js React-based application that provides the user interface, handles file uploads, and displays visualizations.
• backend_js and backend_py: Two implementations of the back-end logic (node and Python) that define the core LangGraph agent. These folders include key modules/nodes (DataFormatter, DatabaseManager, LLMManager, SQLAgent, WorkflowManager, etc.) that map directly to the steps in the agent workflow.
• sqlite_server: A standalone service responsible for handling database file (SQLite, CSV) uploads, storing files, and providing schema information.
• Config files (like package.json, tsconfig.json, .env.example) across these directories indicate the presence of containerized deployments, dependency management, and environment variable configurations.
Detailed Architecture Breakdown & Key Components
A. Frontend:
• Located in the “frontend” directory with components (e.g., Logo, UploadButton, several graph components).
• It communicates with the LangGraph API via a URL defined in its .env file.
• It fetches visualizations and workflow traces through a streaming API.
• How front-end connects to both the LangGraph backend (for query processing) and indirectly to the SQLite server (for file/data upload).
B. Backend:
• Two implementations: backend_js (JavaScript/TypeScript) and backend_py (Python). Both implement the LangGraph agent.
• Key modules within the my_agent folder correspond to nodes in the agent’s workflow:
• Parse Question: Analyzes the natural language query along with database schema.
• Get Unique Nouns: Extracts specific data values from non-numeric fields to refine the query.
• Generate SQL: Creates SQL based on the question and extracted data.
• Validate and Fix SQL: Ensures correctness of query syntax and table/column names.
• Execute SQL: Carries out the query on a SQLite database.
• Choose Visualization: Uses an LLM to select an appropriate chart type (bar, line, scatter, etc.).
• Format Results & Format Data for Visualization: Prepares the data both in textual and graphical formats.
• The LangGraph agent architecture is containerized via LangGraph Studio, which packages these modules and provides a URL for API access.
C. SQLite Server:
• This component handles file uploads (under 1MB) and manages the SQLite databases.
• It includes routing (see ProjectRoutes.js) and maintains storage (sqlite_server/uploads) for user-uploaded databases.
• It acts as an intermediary, allowing the backend to execute queries on the appropriate database instance.
D. External/Orchestration Components:
• LangGraph Studio: Acts as the orchestration layer to run the LangGraph API in a containerized environment. It manages environment variables (e.g., OPENAI_API_KEY, DB_ENDPOINT_URL), connects the backend agent with the SQLite server, and provides a visual interface for monitoring agent state.