# neo4j-labs/llm-graph-builder architecture

> Architecture diagram of the GitHub repository neo4j-labs/llm-graph-builder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neo4j-labs/llm-graph-builder
- Repository: https://github.com/neo4j-labs/llm-graph-builder

## Overview

##### Main Components

a. Frontend Layer:
- React-based UI (TypeScript)
- Key modules:
- Authentication Component
- File Upload Components (Local, S3, GCS, Web)
- Graph Visualization Component
- Chat Interface
- Settings Management

b. Backend Layer:
- FastAPI Server
- Document Processing Pipeline
- LLM Integration Services
- Multiple Data Source Handlers

c. External Services:
- Neo4j Database (v5.15+)
- Various LLM Services (OpenAI, Gemini, etc.)
- Cloud Storage (S3, GCS)
- Authentication Services (Auth0/Okta)

##### Component Relationships

**User Interface Layer**
**↓↑**
**API Gateway (FastAPI)**
**↓↑**
**Core Processing Layer:**
- Document Processing
- LLM Processing
- Graph Generation
- Embedding Generation
**↓↑**
**Storage Layer:**
- Neo4j Database
- Vector Store
**↔**
**External Services Layer**

##### Specific Implementation Details

a. Document Processing Flow:
**Input Sources → Document Chunking → LLM Processing → Entity Extraction → Relationship Creation → Graph Storage**

b. Query Flow:
**User Query → Chat Interface → Query Processing → Graph/Vector Search → LLM Response Generation → UI Response**

##### Key Technical Elements

- Support for multiple LLM models
- Vector embedding integration
- Different chat modes (vector, graph, hybrid)
- File processing pipeline
- Authentication flow
- Monitoring and logging systems

##### Important Architectural Patterns

- Microservices architecture
- Event-driven processing
- Pipeline pattern for document processing
- Repository pattern for data access
- Factory pattern for LLM model selection

##### Integration Points

Clearly mark:
- API endpoints
- Database connections
- External service connections
- Authentication boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        Auth["Authentication"]:::frontend
        FileUpload["File Upload Components"]:::frontend
        GraphVis["Graph Visualization"]:::frontend
        ChatInt["Chat Interface"]:::frontend
        Settings["Settings Management"]:::frontend
    end

    subgraph API["API Gateway Layer"]
        FastAPI["FastAPI Server"]:::backend
        FrontAPI["Frontend API Integration"]:::backend
        BackAPI["Backend API Response"]:::backend
    end

    subgraph Process["Core Processing Layer"]
        DocProcess["Document Processing"]:::process
        LLMInt["LLM Integration"]:::process
        GraphGen["Graph Generation"]:::process
        EntityProc["Entity Processing"]:::process
        RelCreate["Relationship Creation"]:::process
        QueryProc["Query Processing"]:::process
        QAInt["QA Integration"]:::process
    end

    subgraph Storage["Storage Layer"]
        Neo4j[(Neo4j Database)]:::database
        VectorStore[(Vector Store)]:::database
    end

    subgraph External["External Services Layer"]
        LLMServices["LLM Services<br>(OpenAI, Gemini)"]:::external
        CloudStorage["Cloud Storage<br>(S3, GCS)"]:::external
        AuthService["Authentication<br>Services"]:::external
    end

    subgraph Utils["Utility Layer"]
        Logger["Logger"]:::utility
        Common["Common Functions"]:::utility
        Constants["Constants"]:::utility
        ExHandler["Exception Handling"]:::utility
    end

    %% Relationships
    Auth --> FastAPI
    FileUpload --> FastAPI
    GraphVis --> FastAPI
    ChatInt --> FastAPI
    Settings --> FastAPI

    FastAPI --> DocProcess
    FastAPI --> LLMInt
    FastAPI --> QueryProc

    DocProcess --> GraphGen
    LLMInt --> GraphGen
    GraphGen --> EntityProc
    EntityProc --> RelCreate
    RelCreate --> Neo4j
    QueryProc --> Neo4j
    QueryProc --> VectorStore
    QAInt --> LLMServices

    Process --> External
    Process --> Storage

    %% Click Events
    click Auth "https://github.com/neo4j-labs/llm-graph-builder/blob/main/frontend/src/components/Auth/Auth.tsx"
    click GraphVis "https://github.com/neo4j-labs/llm-graph-builder/blob/main/frontend/src/components/Graph/GraphViewModal.tsx"
    click ChatInt "https://github.com/neo4j-labs/llm-graph-builder/blob/main/frontend/src/components/ChatBot/Chatbot.tsx"
    click Settings "https://github.com/neo4j-labs/llm-graph-builder/blob/main/frontend/src/components/Popups/Settings/SchemaFromText.tsx"
    click FastAPI "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/main.py"
    click DocProcess "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/create_chunks.py"
    click LLMInt "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/llm.py"
    click EntityProc "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/entities/source_node.py"
    click RelCreate "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/make_relationships.py"
    click QueryProc "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/graph_query.py"
    click QAInt "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/QA_integration.py"
    click FrontAPI "https://github.com/neo4j-labs/llm-graph-builder/blob/main/frontend/src/API/Index.ts"
    click BackAPI "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/api_response.py"
    click Logger "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/logger.py"
    click Common "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/shared/common_fn.py"
    click Constants "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/shared/constants.py"
    click ExHandler "https://github.com/neo4j-labs/llm-graph-builder/blob/main/backend/src/shared/llm_graph_builder_exception.py"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef process fill:#e67e22,stroke:#d35400,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef utility fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        Backend["Backend"]:::backend
        Processing["Processing"]:::process
        Database["Database"]:::database
        ExternalServ["External Services"]:::external
        Utilities["Utilities"]:::utility
    end
```
