# varunshenoy/graphgpt architecture

> Architecture diagram of the GitHub repository varunshenoy/graphgpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varunshenoy/graphgpt
- Repository: https://github.com/varunshenoy/graphgpt

## Overview

##### Main Components
- Frontend Application:
- This is the core of the project, implemented in React (files in the src folder like App.js, index.js) along with public assets (index.html, manifest.json, robots.txt).
- Prompts Module:
- Located in the public/prompts directory, these files contain the instructions (few-shot prompts) guiding GPT-3 on how to format the JSON output for graph rendering.
- External Service – OpenAI API:
- Although not directly represented in the file tree, the README describes using the OpenAI API for interpreting natural language input.
- Graph Visualization:
- The use of react-graph-vis indicates that the output from the AI is rendered as a graph through this library component.
- User Interface Components:
- UI interactions such as inputting text queries, viewing demo GIFs, and receiving feedback from the API.

##### Relationships and Interactions
- User Interaction Layer:
- Users interact with the React frontend (enter text and trigger queries).
- Data flows from user inputs to the core application.
- Application Logic:
- The React app processes the input, triggers a call to the OpenAI API using the provided API key.
- The request payload incorporates one of the predetermined prompts from the public/prompts folder.
- External Communication:
- The application receives the response from the OpenAI API that includes JSON-formatted graph data.
- Graph Rendering:
- The received JSON-fed data is handled by the react-graph-vis component to render the knowledge graph.
- State Management:
- Successive queries either update or create new graph structures, indicating an underlying state management mechanism that tracks the graph's evolution.

##### Architectural Patterns and Technologies
- Single Page Application (SPA) pattern implemented in React.
- External API Consumption:
- Integration with OpenAI API to process natural language.
- Modular Prompt Configuration:
- Storing and organizing prompt files separately to guide behavior of the API calls.
- Graph Rendering:
- Use of react-graph-vis as a library to isolate visualization from business logic.
- Asynchronous Data Flow:
- Handle API latency (noted as up to 20 seconds) with proper asynchronous calls and UI feedback.

##### Additional Elements to Capture
- Configuration points (like environment variables or API key input) that affect the system.
- Where the application deals with network latency and error handling.
- On how state is managed, possibly within the React application, to capture successive modifications on the knowledge graph.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Application"
        UI["User Interface Components"]:::internal
        RF["React Frontend (SPA)"]:::internal
    end

    U["User Input"]:::external
    PM["Prompts Module"]:::internal
    OAI["OpenAI API"]:::external
    GV["Graph Visualization (react-graph-vis)"]:::internal

    U -->|"submit"| UI
    UI -->|"forwards_query"| RF
    RF -->|"fetch_prompt"| PM
    RF -->|"send_request"| OAI
    OAI -->|"return_data"| RF
    RF -->|"render_graph"| GV

    %% Click Events for React Frontend files
    click RF "https://github.com/varunshenoy/graphgpt/blob/main/src/App.js"
    click RF "https://github.com/varunshenoy/graphgpt/blob/main/src/index.js"
    click RF "https://github.com/varunshenoy/graphgpt/blob/main/public/index.html"
    click RF "https://github.com/varunshenoy/graphgpt/blob/main/public/manifest.json"
    click RF "https://github.com/varunshenoy/graphgpt/blob/main/public/robots.txt"

    %% Click Events for User Interface Components files
    click UI "https://github.com/varunshenoy/graphgpt/blob/main/src/App.css"
    click UI "https://github.com/varunshenoy/graphgpt/blob/main/src/index.css"

    %% Click Event for Prompts Module directory
    click PM "https://github.com/varunshenoy/graphgpt/tree/main/public/prompts"

    %% Click Event for Graph Visualization integration
    click GV "https://github.com/varunshenoy/graphgpt/blob/main/src/App.js"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px;
```
