Vineshnayak/CodeSage
0
1---2title: CodeSage3colorFrom: blue4colorTo: green5sdk: streamlit6sdk_version: 1.28.07app_file: ui/app.py8pinned: false9---10 11# CodeSage12 13CodeSage is a codebase analysis tool that combines static analysis and Retrieval-Augmented Generation (RAG) to assist with code exploration and refactoring. It uses Abstract Syntax Tree (AST) parsing, vector embeddings, and dependency graph traversal to answer architectural queries and compute complexity metrics.14 15## Features16 17### 1. Codebase Querying18The system implements a RAG pipeline to process natural language queries about the codebase:19- **Vector Search:** Converts queries into dense vector embeddings and retrieves relevant code segments from a local FAISS index.20- **Graph Context:** Extracts structural relationships (imports, class hierarchies, function calls) using an in-memory `NetworkX` graph.21- **LLM Integration:** Passes the context to a Large Language Model (via Groq) to synthesize responses based on the provided codebase data.22 23### 2. Dependency Graph and Impact Analysis24Constructs a relational dependency graph mapping files, classes, and methods. Users can supply a target module to identify its downstream dependencies and evaluate the potential impact of modifications.25 26### 3. Static Code Analysis27Utilizes Python's native `ast` module to analyze source code complexity. It tracks:28- Cyclomatic complexity.29- Function length and parameter counts.30- Multiple-exit-point control structures.31 32### 4. Assisted Refactoring and Debugging33Integrates LLM-driven tools for code maintenance:34- **Bug Hunter:** Analyzes error tracebacks, locates the failing source file using the vector index, and suggests fixes.35- **Auto-Refactor:** Processes specified code blocks to recommend PEP-8 compliant and structurally improved alternatives.36 37### 5. File System Monitoring38A watchdog daemon monitors the active directory tree for modifications, updating semantic vectors and the AST graph to maintain index consistency.39 40## Technical Architecture41 42* **Analysis:** `ast`, `networkx`43* **Vector Search:** `sentence-transformers` (`all-MiniLM-L6-v2`), `faiss-cpu`44* **LLM API:** Groq (`llama-3.1-8b-instant`)45* **UI Framework:** Streamlit46 47## Setup and Deployment48 49**1. Environment Setup**50Requires Python 3.10 or higher.51```bash52python3 -m venv venv53source venv/bin/activate54pip install -r requirements.txt55```56 57**2. Configuration**58Copy the `.env.example` template to `.env` and configure your API keys:59```ini60GROQ_API_KEY=your_api_key_here61LLM_MODEL=llama-3.1-8b-instant62EMBEDDING_MODEL=all-MiniLM-L6-v263```64 65## Usage66 67The application requires an initial index of the codebase to process queries.68 69**1. Build the Index**70Parse the target directory to generate the required index artifacts:71```bash72python3 main.py index73```74 75**2. Start the Interface**76Launch the Streamlit dashboard locally:77```bash78python3 main.py ui79```80*The Streamlit client runs on `localhost:8501` by default.*81 82**3. Run the File Monitor (Optional)**83Start a background process to update the index upon file modifications:84```bash85python3 main.py watch86```87 