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
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.pybut defined inutils.pyis 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
| 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 |
| 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 |
| 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 |
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
- Python 3.10+
- Node.js 18+
- A free Groq API key
git clone https://github.com/manishaagangadevi/dead-code-detector.git
cd dead-code-detector# 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 --reloadBackend will run at: http://127.0.0.1:8000
# Open new terminal, navigate to frontend
cd frontend
# Install dependencies
npm install
# Start development server
npm run devFrontend will run at: http://localhost:5173
- Open
http://localhost:5173 - Paste your Python or JavaScript code in the editor
- Select the language from the dropdown
- Click Analyze
- View issues, call graph, and AI explanations in the right panel
- Click Upload Project button
- Select multiple
.pyor.jsfiles from your project - Click Analyze
- The tool will analyze all files together β functions used across files are correctly identified as alive
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
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
}
}Analyze multiple files together with cross-file awareness.
Request:
{
"files": [
{ "filename": "main.py", "code": "..." },
{ "filename": "utils.py", "code": "..." }
],
"language": "python"
}Health check endpoint.
WebSocket endpoint for real-time analysis. Send JSON:
{ "code": "...", "language": "python" }Full interactive API documentation available at http://127.0.0.1:8000/docs
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)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feat/amazing-feature) - Commit your changes (
git commit -m 'feat: Add amazing feature') - Push to the branch (
git push origin feat/amazing-feature) - Open a Pull Request
Manisha Gangadevi
Made with β€οΈ for the love of clean code
β Star this repo if you found it helpful!