An AI-powered codebase assistant that enables developers to connect a GitHub repository and ask questions about the codebase using natural language. Instead of manually searching through files, developers can ask questions like "Where is authentication implemented?" or "How does the login flow work?" and receive intelligent answers grounded in the actual code.
Live demo : ai-repo-intelligence-agent.vercel.app
backend is running on render free tier so services spin down after 15 minutes without inbound traffic and take about 60 seconds to wake up on the next request
- Smart Code Retrieval: Uses RAG (Retrieval-Augmented Generation) to find relevant code snippets
- Natural Language Queries: Ask questions in plain English without needing to know the codebase
- LangGraph Workflow: Structured reasoning pipeline for consistent, explainable answers
- File References: Every answer includes the specific files used to generate the response
- Modern UI: Clean React + TypeScript interface with Tailwind CSS styling
- GitHub Integration: Clone and index any public GitHub repository
- Vector Search: Semantic search using embeddings for concept-based retrieval
- Code-Aware Chunking: Intelligently splits code into manageable chunks with metadata
- Multi-turn Chat: Maintains conversation context for follow-up questions
- Incremental Updates: Support for updating vector store with Git diff changes
The application follows a modular architecture with clear separation of concerns:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ React + TS │────────▶│ FastAPI │────────▶│ LangGraph │
│ Frontend │ HTTP │ Backend │ Graph │ Workflow │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ GitHub Repo │────────▶│ Code │────────▶│ FAISS │
│ (Clone) │ Files │ Chunking │ Embed │ Vector Store │
└─────────────────┘ └─────────────────┘ └─────────────────┘
-
Repository Cloning (
app/ingestion/github.py):- User provides a GitHub repository URL
- The system clones the repository to a temporary directory
- Supports authentication via GitHub token for private repos
-
File Scanning (
app/ingestion/scanner.py):- Scans the cloned repository for supported file types
- Skips ignored directories (node_modules, .git, pycache, etc.)
- Filters by allowed extensions (.py, .js, .ts, .jsx, .tsx, .json, .yaml, .md)
- Excludes files larger than 1MB
-
Code Chunking (
app/ingestion/chunker.py):- Reads each file and detects the programming language
- Splits code into smaller, semantically meaningful chunks
- Uses RecursiveCharacterTextSplitter with configurable chunk size (default: 1000 chars)
- Adds metadata: file path, language, chunk index
- Creates overlap between chunks (default: 150 chars) to maintain context
-
Embedding Generation (
app/retrieval/embeddings.py):- Converts each chunk into vector representations
- Uses sentence-transformers/all-MiniLM-L6-v2 model
- Captures semantic meaning for concept-based search
-
Vector Storage (
app/retrieval/vectorstore.py):- Stores embeddings in FAISS (Facebook AI Similarity Search)
- Generates deterministic chunk IDs (format:
file_path::chunk_index) - Persists to disk for quick loading
- Supports deletion of chunks by file path for incremental updates
-
Question Analysis (
app/graph/nodes.py-analyze_question):- Transforms contextual follow-up questions into standalone search queries
- Uses LLM to resolve references like "it", "that file", "the second endpoint"
- Maintains conversation context from chat history
- Example: "How does it work?" → "How does the authentication system work?"
-
Code Retrieval (
app/graph/nodes.py-retrieve_code):- Performs semantic search using the reformulated query
- Retrieves top-k relevant chunks (default: k=5)
- Uses FAISS similarity search for fast retrieval
-
Answer Generation (
app/graph/nodes.py-generate_answer):- Passes retrieved code chunks and question to LLM
- Uses a prompt template that enforces strict grounding in context
- Generates accurate answers with file citations
- Includes chat history for multi-turn conversations
- Backend Framework: FastAPI - Modern, fast web framework for building APIs
- Orchestration: LangGraph - Structured agent workflows with state management
- LLM Integration: LangChain - Framework for LLM applications
- LLM Provider: OpenRouter - Access to multiple LLM models via unified API
- Embeddings: HuggingFace sentence-transformers - State-of-the-art text embeddings
- Vector Database: FAISS - Efficient similarity search and clustering
- Frontend: React 19 + TypeScript - Modern UI library with type safety
- Frontend Styling: Tailwind CSS v4 - Utility-first CSS framework
- Build Tool: Vite - Fast build tool and dev server
- HTTP Client: Axios - Promise-based HTTP client for the browser
- Git Operations: GitPython - Python library for Git operations
- Configuration: Pydantic Settings - Type-safe configuration management
# Clone the repository
git clone <your-repo-url>
cd ai-repo-intelligence
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install Python dependencies
pip install -r requirements.txt
# Install root JavaScript dependencies (OpenRouter SDK)
npm install
# Configure environment variables
cp .env.example .env
# Edit .env with your HF_TOKEN and GITHUB_TOKEN (optional)source .venv/bin/activate
uvicorn main:app --reload --host 0.0.0.0 --port 8000The backend API will be available at http://localhost:8000
In a new terminal:
cd frontend
npm install
npm run devThe frontend will be available at http://localhost:5173
- Open the React app in your browser at
http://localhost:5173 - Enter a GitHub repository URL (e.g.,
https://github.com/username/repo) - Wait for the repository to be processed and indexed
- Start asking questions about the codebase:
- "Where is authentication implemented?"
- "How does the login flow work?"
- "Why might this endpoint return 401?"
- "Where is the database connection configured?"
- View answers with referenced file paths for context
The frontend can be configured via environment variables. Copy .env.example to .env in the frontend/ directory:
cd frontend
cp .env.example .envEdit .env to configure the backend URL:
VITE_API_BASE_URL=http://localhost:8000
Upload and index a GitHub repository.
Request Body:
{
"repo_url": "https://github.com/username/repo"
}Response:
{
"message": "Repository successfully processed and indexed.",
"repo_name": "username_repo",
"files_processed": 42,
"chunks_created": 156
}Ask questions about the indexed repository.
Request Body:
{
"question": "Where is authentication implemented?",
"chat_history": [
{"role": "user", "content": "Previous question"},
{"role": "assistant", "content": "Previous answer"}
]
}Response:
{
"question": "Where is authentication implemented?",
"answer": "Authentication is implemented in auth/routes.py...",
"referenced_files": ["auth/routes.py", "auth/middleware.py"]
}Health check endpoint.
Response:
{
"status": "ok",
"message": "AI Repo Intelligence Agent service running."
}ai-repo-intelligence/
├── app/ # Main application package
│ ├── api/ # FastAPI routes and endpoints
│ │ └── routes.py # API route handlers for upload and chat
│ ├── config/ # Configuration management
│ │ └── settings.py # Pydantic settings with environment variables
│ ├── graph/ # LangGraph workflow implementation
│ │ ├── graph.py # Graph construction and compilation
│ │ ├── nodes.py # Individual workflow nodes (analyze, retrieve, generate)
│ │ └── state.py # Agent state definition (TypedDict)
│ ├── ingestion/ # Repository ingestion pipeline
│ │ ├── chunker.py # Code chunking with metadata
│ │ ├── diff_updater.py # Incremental updates using Git diff
│ │ ├── github.py # GitHub repository cloning
│ │ └── scanner.py # File scanning and filtering
│ ├── llm/ # LLM integration
│ │ ├── client.py # HuggingFace LLM client initialization
│ │ └── prompts.py # Prompt templates for RAG
│ └── retrieval/ # Vector storage and retrieval
│ ├── embeddings.py # Embedding model initialization
│ ├── retriever.py # Retrieval interface and helper functions
│ └── vectorstore.py # FAISS vector store management
├── data/ # Data storage directory
│ ├── vectorstore/ # Persisted FAISS index
│ └── temp_repos/ # Temporary cloned repositories
├── frontend/ # React + TypeScript frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── services/ # API service layer
│ │ ├── types/ # TypeScript type definitions
│ │ ├── App.tsx # Main application component
│ │ └── main.tsx # Application entry point
│ ├── .env.example # Environment variables template
│ ├── package.json # Frontend dependencies
│ └── README.md # Frontend documentation
├── tests/ # Test suite
│ └── test_chat_route.py # API route tests
├── .env # Environment variables (not in git)
├── .env.example # Example environment variables
├── .gitignore # Git ignore patterns
├── main.py # FastAPI application entry point
├── package.json # Root dependencies (OpenRouter SDK)
├── requirements.txt # Python dependencies
└── test_script.py # Test script for manual testing
The FastAPI application entry point. It:
- Initializes the FastAPI app with metadata (title, description, version)
- Includes the API router with
/api/v1prefix - Provides a health check endpoint at
/
Connection: This is the starting point for the backend. It imports and mounts the API router from app/api/routes.py.
Defines the REST API endpoints. It:
- Implements
/upload-repoendpoint for repository ingestion - Implements
/chatendpoint for querying the repository - Handles request validation using Pydantic models
- Manages error handling and HTTP status codes
Connections:
- Uses
app/graph/graph.pyfor the LangGraph workflow - Uses
app/ingestion/github.pyfor repository cloning - Uses
app/ingestion/scanner.pyfor file scanning - Uses
app/ingestion/chunker.pyfor code chunking - Uses
app/retrieval/vectorstore.pyfor vector store operations
Centralized configuration management using Pydantic. It:
- Defines all environment variables with types and defaults
- Manages API tokens (HF_TOKEN, GITHUB_TOKEN)
- Configures storage paths (vectorstore, temp directories)
- Sets chunking parameters (chunk size, overlap)
- Defines allowed file extensions and ignored directories
- Provides helper methods to safely read secrets
Connections: Used throughout the application by nearly all modules to access configuration values.
Constructs the LangGraph workflow. It:
- Defines the graph structure with three nodes
- Sets up the execution flow: START → analyze_question → retrieve_code → generate_answer → END
- Compiles the graph into an executable application
Connections:
- Imports state from
app/graph/state.py - Imports node functions from
app/graph/nodes.py - The compiled
graph_appis used byapp/api/routes.py
Implements the individual workflow nodes. It contains three main functions:
- analyze_question: Transforms follow-up questions into standalone queries using LLM
- retrieve_code: Performs semantic search using the vector store
- generate_answer: Generates the final answer using retrieved context
Connections:
- Uses state from
app/graph/state.py - Uses vector store from
app/retrieval/vectorstore.py - Uses retriever from
app/retrieval/retriever.py - Uses LLM client from
app/llm/client.py - Uses prompts from
app/llm/prompts.py
Defines the agent state as a TypedDict. It:
- Specifies the structure of data passed between nodes
- Includes: question, chat_history, search_query, retrieved_documents, answer
Connections: Used by app/graph/graph.py and app/graph/nodes.py to maintain workflow state.
Handles GitHub repository operations. It:
- Validates and parses GitHub repository URLs
- Clones repositories to temporary directories
- Supports authentication via GitHub tokens
- Cleans up temporary directories after processing
Connections:
- Uses settings from
app/config/settings.py - Called by
app/api/routes.pyduring repository upload
Scans cloned repositories for files. It:
- Recursively walks the repository directory
- Filters by allowed file extensions
- Skips ignored directories and large files
- Returns a list of valid file paths
Connections:
- Uses settings from
app/config/settings.py - Called by
app/api/routes.pyafter cloning
Splits code files into chunks. It:
- Reads file contents with encoding fallback
- Detects programming language from file extension
- Splits code using RecursiveCharacterTextSplitter
- Adds metadata (file path, language) to each chunk
- Handles encoding errors gracefully
Connections:
- Uses settings from
app/config/settings.py - Called by
app/api/routes.pyafter scanning - Called by
app/ingestion/diff_updater.pyfor incremental updates
Handles incremental updates using Git diff. It:
- Analyzes Git commits to identify changed files
- Evicts deleted/modified chunks from the vector store
- Re-indexes added/modified files
- Prevents "ghost chunks" (stale embeddings)
Connections:
- Uses scanner from
app/ingestion/scanner.py - Uses chunker from
app/ingestion/chunker.py - Uses vector store functions from
app/retrieval/vectorstore.py
Initializes the HuggingFace LLM client. It:
- Creates a HuggingFaceEndpoint instance
- Configures model parameters (temperature, max tokens)
- Wraps it in ChatHuggingFace for chat interface
Connections:
- Uses settings from
app/config/settings.py - Used by
app/graph/nodes.pyfor question analysis and answer generation
Defines prompt templates. It:
- Contains the system prompt for the RAG assistant
- Defines the user prompt template with context
- Creates a ChatPromptTemplate that supports chat history
- Enforces strict grounding in provided context
Connections:
- Used by
app/graph/nodes.pyin the generate_answer node
Initializes the embedding model. It:
- Creates a HuggingFaceEmbeddings instance
- Uses the all-MiniLM-L6-v2 model for text embeddings
Connections:
- Used by
app/retrieval/vectorstore.pyfor creating and loading the vector store
Provides retrieval interfaces. It:
- Creates a retriever from a FAISS vectorstore
- Implements similarity search with configurable k
- Provides a helper function for direct chunk retrieval
Connections:
- Used by
app/graph/nodes.pyin the retrieve_code node - Works with FAISS vectorstore from
app/retrieval/vectorstore.py
Manages the FAISS vector store. It:
- Generates deterministic chunk IDs (format:
file_path::chunk_index) - Creates the vector store from documents with embeddings
- Persists the vector store to disk
- Loads the vector store from disk
- Deletes chunks by file path for incremental updates
Connections:
- Uses embeddings from
app/retrieval/embeddings.py - Used by
app/api/routes.pyduring repository upload - Used by
app/graph/nodes.pyduring query processing - Used by
app/ingestion/diff_updater.pyfor incremental updates
The React + TypeScript frontend provides a modern, responsive interface for interacting with the backend API.
Main application component that:
- Manages chat state and repository URL input
- Handles API calls to the backend for repository upload and chat queries
- Renders the chat interface with message history
- Displays loading states and error messages
- Uses Lucide React icons for UI elements
API service layer that:
- Encapsulates HTTP requests using Axios
- Provides typed functions for
/api/v1/upload-repoand/api/v1/chatendpoints - Handles request/response formatting
- Manages error handling and timeout configuration
TypeScript type definitions for:
- API request/response structures
- Chat message types
- Repository upload response data
- Clean, modern UI with Tailwind CSS v4 styling
- Real-time chat interface with message history
- Markdown rendering for code blocks and formatted text
- Responsive design for desktop and mobile
- Loading indicators and error handling
- File reference display in responses
User (React UI) → routes.py (/upload-repo)
→ github.py (clone_repository)
→ scanner.py (scan_repository)
→ chunker.py (chunk_files)
→ vectorstore.py (create_vectorstore)
→ github.py (cleanup)
→ Response to User
User (React UI) → routes.py (/chat)
→ graph.py (graph_app.invoke)
→ nodes.py (analyze_question)
→ llm/client.py (query reformulation)
→ nodes.py (retrieve_code)
→ vectorstore.py (load_vectorstore)
→ retriever.py (retrieve_relevant_chunks)
→ nodes.py (generate_answer)
→ llm/prompts.py (get_rag_prompt_template)
→ llm/client.py (generate answer)
→ Response to User with referenced files
Edit .env file to configure:
HF_TOKEN: HuggingFace API token for LLM access (required)HF_MODEL: Model ID (default: zai-org/GLM-5.3)GITHUB_TOKEN: GitHub token for private repositories (optional)VECTORSTORE_DIRECTORY: Directory for vector store persistence (default: data/vectorstore)TEMP_CLONE_DIR: Directory for temporary repository clones (default: data/temp_repos)CHUNK_SIZE: Code chunk size for embeddings (default: 1000)CHUNK_OVERLAP: Overlap between code chunks (default: 150)
- Where is authentication implemented?
- How does the login flow work?
- Why might this endpoint return 401?
- Where is the database connection configured?
- Which files handle user registration?
- What happens after a user submits the login form?
- How is the user session managed?
- Where are API routes defined?
- What database ORM is being used?
- How are errors handled in this application?
pytest tests/python test_script.pyMIT License - See LICENSE file for details