Skip to content

Latest commit

Β 

History

50 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 GraphRAG Digital Twin & Interactive Portfolio

Production Monorepo: Next.js 15 (React 19, Turbopack, Tailwind CSS v4, Motion) + FastAPI Agentic GraphRAG Backend (LangGraph, Knowledge Graph, Pinecone Vector Search, LLM Guardrails).

Created by Ahmed Bargady β€” PhD Student in AI & Cybersecurity at UM6P (Mohammed VI Polytechnic University).


image

🌟 Architecture Overview

This monorepo powers an AI-driven digital twin designed to answer complex technical, research, and career inquiries in real-time. Unlike standard RAG systems, it combines Agentic Corrective RAG (LangGraph), structured Knowledge Graphs, and AI Security Guardrails.

image
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚              Next.js 15 Frontend (App Router)          β”‚
               β”‚   Chat Interface β€’ Knowledge Graph Viz β€’ Security Hub   β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚ SSE / Stream
                                           β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚             FastAPI GraphRAG Server Endpoint           β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β–Ό                                     β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚   AI Security Shield   β”‚            β”‚   LangGraph State Engineβ”‚
           β”‚ Prompt Leak & Injectionβ”‚            β”‚  Adaptive Routing Node β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                             β”‚
                                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                        β–Ό                                         β–Ό
                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                           β”‚   Knowledge Graph      β”‚                β”‚   Pinecone Vector DB   β”‚
                           β”‚ Multi-Hop Entity Facts β”‚                β”‚  Semantic Document RAG β”‚
                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Core Technical Highlights

1. πŸ€– Agentic GraphRAG (LangGraph)

  • Adaptive Routing: Automatically detects query intent (Smalltalk, General Knowledge, Entity-Grounded, or Multi-hop Complex).
  • Corrective Retrieval Loop: Grades retrieved facts; if context is insufficient, it rewrites the query dynamically and re-retrieves before generation.
  • Hybrid Retrieval: Fuses deterministic Knowledge Graph subgraphs with high-dimensional vector embeddings for max recall and precision.
image

2. πŸ•Έ Interactive Knowledge Graph

  • Entity Linking: Maps research domains (APT Detection, Provenance Graphs, GNNs, Transformers) to papers, projects, and skills.
  • Live Traversal Stream: Emits active graph paths alongside response streams, rendering interactive node topologies in the UI.
image

3. πŸ›‘ AI Security Showcase & Red-Teaming Guardrails

  • Prompt Injection Defense: Pre-execution input classification blocking adversarial jailbreaks.
  • System Prompt Leak Guard: Output stream monitoring to prevent sensitive context disclosure.
  • Rate Limiting & Red-Teaming Suite: Built-in endpoints for automated security evaluation.
  • Data Privacy & Open-Source Audit: All biography, research, and project knowledge base files stored under backend/data/ are 100% sanitized, public-ready, and clean of private credentials, SSH keys, or confidential secrets.
image

πŸ“ Repository Layout

GraphRAGPortfolio/
β”œβ”€β”€ frontend/             # Next.js 15 (React 19, Turbopack, Tailwind CSS v4, Motion, Lucide)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/          # App router pages (Home, Chat, Security Showcase)
β”‚   β”‚   β”œβ”€β”€ components/   # Interactive Graph, Chat UI, Reasoning Trace, Terminal components
β”‚   β”‚   └── store/        # Zustand state management
β”‚   └── package.json
β”‚
β”œβ”€β”€ backend/              # FastAPI Python Backend
β”‚   β”œβ”€β”€ agent/            # LangGraph state machine & Corrective RAG pipeline
β”‚   β”œβ”€β”€ kg/               # Knowledge graph schema, networkx, & store
β”‚   β”œβ”€β”€ security/         # Red-teaming scripts, guardrails, & rate limiters
β”‚   β”œβ”€β”€ data/             # Research documents, papers, & bio knowledge base
β”‚   β”œβ”€β”€ config.py         # Centralized model & server configuration
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ package.json          # Root npm workspace & script orchestration
β”œβ”€β”€ turbo.json            # Turborepo task pipeline configuration
β”œβ”€β”€ .gitignore
└── .env.example

πŸš€ Quick Start

Prerequisites

  • Node.js: v20+
  • npm or pnpm
  • Python: v3.10+

1. Installation

Clone the repository and install root workspace dependencies:

git clone https://github.com/AhmedCoolProjects/GraphRAGPortfolio.git
cd GraphRAGPortfolio

# Install Node dependencies for all workspaces
npm install

Set up Python virtual environment for the backend:

cd backend
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cd ..

2. Environment Configuration

Copy .env.example to set up environment variables:

cp .env.example .env

Configure your environment variables:

  • GROQ_API_KEY: Groq API Key for fast LLM inference.
  • PINECONE_API_KEY: Pinecone Vector Store API Key.
  • NEXT_PUBLIC_CHAT_API_URL: Backend URL (e.g. http://localhost:8000).

3. Local Development

Run both Frontend and Backend concurrently with Turborepo:

npm run dev
  • Frontend: http://localhost:3000
  • Backend API: http://localhost:8000
  • Swagger Docs: http://localhost:8000/docs

πŸ“œ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ‘¨β€πŸ’» Connect & Follow

Ahmed Bargady

PhD Student in AI & Cybersecurity @ UM6P

Portfolio GitHub LinkedIn HuggingFace X / Twitter

About

🧠 Production-grade GraphRAG monorepo powering an AI digital twin. Features Next.js 15, FastAPI, LangGraph agentic corrective retrieval, Knowledge Graph traversal, and AI security guardrails.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages