Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Dead Code Detector

Live Demo

AI-Powered Static Analysis Tool for Python & JavaScript

FastAPI React Groq Python License

Detect unused functions, dead variables, and unreachable code blocks across your entire codebase β€” with AI-powered explanations and fix suggestions.

Features β€’ Tech Stack β€’ Setup β€’ Usage β€’ API Docs


πŸš€ What is Dead Code Detector?

Dead Code Detector is a full-stack AI-powered static analysis tool that goes beyond simple linting. It parses your code into an Abstract Syntax Tree (AST), builds a cross-file call graph, and uses a Large Language Model (LLM) to explain why each piece of code is dead and how to fix it.

Unlike basic linters, this tool:

  • Analyzes multiple files together β€” a function used in main.py but defined in utils.py is correctly identified as alive
  • Uses AI to explain dead code in plain English, not just flag line numbers
  • Visualizes your entire function call graph interactively
  • Provides real-time analysis as you type via WebSocket

✨ Features

Feature Description
🧠 AI Explanations Groq LLaMA3 explains why each dead code block exists and how to fix it
🌐 Cross-File Analysis Upload entire projects β€” detects functions unused across ALL files
πŸ“Š Interactive Call Graph Force-directed graph showing function relationships with dead nodes highlighted in red
⚑ Live WebSocket Analysis Real-time dead code detection as you type in the editor
🎨 Monaco Editor VS Code's editor embedded in the browser with syntax highlighting
πŸ“„ PDF Export Generate professional dark-themed reports with AI explanations
🐍 Multi-Language Full support for Python and JavaScript/TypeScript
πŸ“ File Upload Upload single files or entire project folders
πŸ’Š Health Score Codebase health percentage based on dead code ratio

πŸ› οΈ Tech Stack

Backend

Technology Purpose
FastAPI High-performance REST API and WebSocket server
Python AST Built-in Python abstract syntax tree parser
Esprima JavaScript AST parser for JS/TS analysis
Groq (LLaMA 3.3-70B) Free LLM API for AI-powered code explanations
Uvicorn ASGI server for async request handling
WebSockets Real-time bidirectional communication

Frontend

Technology Purpose
React 18 Component-based UI framework
Vite Lightning-fast build tool and dev server
Monaco Editor VS Code's editor for in-browser code editing
Cytoscape.js Interactive call graph visualization
Axios HTTP client for API communication
jsPDF Client-side PDF generation
Lucide React Modern icon library

πŸ“ Project Structure

dead-code-detector/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ analyzers/
β”‚   β”‚   β”‚   β”œβ”€β”€ ast_analyzer.py        # Python & JS AST analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ llm_analyzer.py        # Groq LLM integration
β”‚   β”‚   β”‚   β”œβ”€β”€ call_graph.py          # Call graph builder
β”‚   β”‚   β”‚   └── cross_file_analyzer.py # Multi-file analysis engine
β”‚   β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   β”‚   β”œβ”€β”€ analyze.py             # REST API endpoints
β”‚   β”‚   β”‚   └── websocket.py           # WebSocket endpoint
β”‚   β”‚   └── main.py                    # FastAPI app entry point
β”‚   β”œβ”€β”€ .env                           # Environment variables (not committed)
β”‚   β”œβ”€β”€ .env.example                   # Example environment file
β”‚   └── requirements.txt               # Python dependencies
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx                    # Main React component
β”‚   β”‚   β”œβ”€β”€ main.jsx                   # React entry point
β”‚   β”‚   └── index.css                  # Global dark theme styles
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
└── README.md

βš™οΈ Setup

Prerequisites

1. Clone the repository

git clone https://github.com/manishaagangadevi/dead-code-detector.git
cd dead-code-detector

2. Backend Setup

# Navigate to backend
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
cp .env.example .env

# Add your Groq API key to .env
# GROQ_API_KEY=your_key_here

# Start the backend server
uvicorn app.main:app --reload

Backend will run at: http://127.0.0.1:8000

3. Frontend Setup

# Open new terminal, navigate to frontend
cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

Frontend will run at: http://localhost:5173


πŸ“– Usage

Single File Analysis

  1. Open http://localhost:5173
  2. Paste your Python or JavaScript code in the editor
  3. Select the language from the dropdown
  4. Click Analyze
  5. View issues, call graph, and AI explanations in the right panel

Multi-File Project Analysis

  1. Click Upload Project button
  2. Select multiple .py or .js files from your project
  3. Click Analyze
  4. The tool will analyze all files together β€” functions used across files are correctly identified as alive

Export Report

After analysis, click Export PDF to download a detailed dark-themed report including:

  • Summary statistics
  • All dead code issues with line numbers
  • AI explanations for each issue
  • Fix suggestions

πŸ”Œ API Reference

POST /api/analyze

Analyze a single file for dead code.

Request:

{
  "code": "def unused_func():\n    pass\n",
  "language": "python"
}

Response:

{
  "success": true,
  "language": "python",
  "total_lines": 2,
  "dead_count": 1,
  "dead_code_items": [
    {
      "type": "dead_function",
      "name": "unused_func",
      "line_start": 1,
      "line_end": 2,
      "severity": "high",
      "message": "Function 'unused_func' is defined but never called",
      "ai_explanation": "...",
      "fix_suggestion": "..."
    }
  ],
  "call_graph": { "nodes": [], "edges": [] },
  "summary": {
    "dead_functions": 1,
    "dead_variables": 0,
    "unreachable_blocks": 0
  }
}

POST /api/analyze-project

Analyze multiple files together with cross-file awareness.

Request:

{
  "files": [
    { "filename": "main.py", "code": "..." },
    { "filename": "utils.py", "code": "..." }
  ],
  "language": "python"
}

GET /api/health

Health check endpoint.

WS /ws/analyze

WebSocket endpoint for real-time analysis. Send JSON:

{ "code": "...", "language": "python" }

Full interactive API documentation available at http://127.0.0.1:8000/docs


🧠 How It Works

Code Input
    β”‚
    β–Ό
AST Parser (Python AST / Esprima)
    β”‚
    β–Ό
Symbol Table Builder
β”œβ”€β”€ Collect all defined functions
β”œβ”€β”€ Collect all defined variables
└── Collect all function calls & usages
    β”‚
    β–Ό
Cross-File Reference Resolver
β”œβ”€β”€ Build global symbol table across all files
β”œβ”€β”€ Resolve imports and exports
└── Mark functions used in any file as alive
    β”‚
    β–Ό
Dead Code Detector
β”œβ”€β”€ Functions defined but never called = dead
β”œβ”€β”€ Variables assigned but never used = dead
└── Code after return statements = unreachable
    β”‚
    β–Ό
LLM Analyzer (Groq LLaMA 3.3-70B)
β”œβ”€β”€ Explain why each block is dead
└── Suggest specific fixes
    β”‚
    β–Ό
Call Graph Builder
└── Visualize function relationships
    β”‚
    β–Ό
Results (UI + PDF Export)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes (git commit -m 'feat: Add amazing feature')
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

πŸ‘©β€πŸ’» Author

Manisha Gangadevi


Made with ❀️ for the love of clean code

⭐ Star this repo if you found it helpful!

Releases

Packages

Contributors

Languages