# shettysach/imdb-knowledge-graph-rag architecture

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

- Interactive diagram: https://gitdiagram.com/shettysach/imdb-knowledge-graph-rag
- Repository: https://github.com/shettysach/imdb-knowledge-graph-rag

## Overview

##### Project type and purpose
- This is a full-stack knowledge-graph application with a Retrieval-Augmented Generation (RAG) pipeline.
- It ingests the IMDb Top 250 dataset, builds a Neo4j knowledge graph (nodes: Movie, Genre, Person; relationships: ACTED_IN, DIRECTED, WROTE, BELONGS_TO), then exposes a Streamlit front-end that lets users ask natural-language questions. Questions are processed by LangChain + Gemini to generate Cypher, query Neo4j, and return answers.

##### File structure
- Top level:
- `.env_template` / `.gitignore` / `requirements.txt` – environment and dependencies
- `assets/` – static visuals (graph screenshots)
- `data/` – raw CSV (`imdb.csv`)
- `src/` – core Python and notebooks
– `Knowledge_Graph.ipynb` – offline graph-construction pipeline
– `Graph_RAG.ipynb` – RAG pipeline demonstration
– `App.py` – Streamlit application

##### Key insights from the README
- Components: Neo4j database, LangChain + Gemini API, Streamlit UI
- Workflow: data ingestion → graph construction → RAG query pipeline → UI presentation
- External dependencies: Neo4j server, Gemini API key

##### Main components & interactions
a. Data Ingestion & Graph Construction (batch/offline)
- Component: “CSV Dataset” (data/imdb.csv)
- Component: “Graph Builder Notebook” (`Knowledge_Graph.ipynb`)
b. Runtime RAG Pipeline
- Component: “User Interface (Streamlit App)” (`App.py`)
- Component: “RAG Engine” (LangChain orchestrator)
- Component: “LLM Service” (Gemini API)
- Component: “Graph Database” (Neo4j)
- Flow: User enters prompt → Streamlit App → RAG Engine
→ (1) send prompt to Gemini → receive LLM response (Cypher query)
→ (2) send Cypher to Neo4j → get JSON result
→ (3) RAG Engine processes JSON → returns natural-language answer
→ Streamlit displays answer
c. Supporting components
- Component: “Environment & Config” (`.env`) – contains Neo4j credentials and Gemini API key
- Component: “Dependencies” (`requirements.txt`)

##### Architectural patterns & design principles
- Layered architecture:
- Presentation layer (Streamlit UI)
- Application/service layer (RAG Engine orchestrating LLM + DB calls)
- Data layer (Neo4j)
- Batch vs. real-time separation: graph build offline, query pipeline online
- Use of external microservice (Gemini API) and managed graph store (Neo4j)
- Clear separation of concerns: data ingestion, graph storage, LLM orchestration, UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Offline Graph Construction
    subgraph "Offline Graph Construction"
        data[(CSV Dataset)]:::storage
        builder[/Graph Builder Notebook/]:::doc
        ragNb[/RAG Pipeline Notebook/]:::doc
        envRect["Environment & Config (.env)"]:::external
        requirements["Dependencies (requirements.txt)"]:::external
        assets["Static Assets"]:::external

        data --> builder
        envRect --> builder
        requirements --> builder
        builder --> db[(Neo4j Graph DB)]:::storage

        %% Demo notebook for RAG pipeline
        builder --> ragNb
    end

    %% Online RAG Query Pipeline
    subgraph "Online RAG Query Pipeline"
        user>Users]:::ui
        app["Streamlit App"]:::ui
        rag["LangChain RAG Engine"]:::service
        gemini(["Gemini API"]):::external
        db2[(Neo4j Graph DB)]:::storage

        user --> app
        envRect --> app
        requirements --> app
        app --> rag
        rag --> gemini
        rag --> db2
        gemini --> rag
        db2 --> rag
        rag --> app
        app --> user
    end

    %% Common Database
    db[(Neo4j Graph DB)]:::storage
    db2 --> db
    db --> db2

    %% Click Events
    click data "https://github.com/shettysach/imdb-knowledge-graph-rag/tree/main/data/"
    click builder "https://github.com/shettysach/imdb-knowledge-graph-rag/blob/main/src/Knowledge_Graph.ipynb"
    click ragNb "https://github.com/shettysach/imdb-knowledge-graph-rag/blob/main/src/Graph_RAG.ipynb"
    click app "https://github.com/shettysach/imdb-knowledge-graph-rag/blob/main/src/App.py"
    click envRect "https://github.com/shettysach/imdb-knowledge-graph-rag/blob/main/.env_template"
    click requirements "https://github.com/shettysach/imdb-knowledge-graph-rag/blob/main/requirements.txt"
    click assets "https://github.com/shettysach/imdb-knowledge-graph-rag/tree/main/assets/"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px
    classDef storage fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef doc fill:#EEE8AA,stroke:#000,stroke-width:1px
```
