An intelligent code analysis tool that uses LLMs to explain and document your codebase. It analyzes function dependencies, builds a call tree, and provides detailed explanations using AI.
- 🔍 Function Discovery: Automatically finds and extracts functions from TypeScript, JavaScript, and Python files
- 🌲 Dependency Tree: Builds and visualizes function call relationships
- 🤖 LLM Analysis: Uses AI models to provide detailed code explanations
- 📝 Markdown Output: Generates comprehensive documentation with code snippets
- 📊 History Viewer: Web UI to browse and review all LLM analyses
- ⚡ Multi-Model Support: Query multiple LLM models simultaneously via OpenRouter
bun install
Set your OpenRouter API key as an environment variable:
export OPENROUTER_API_KEY=your_api_key_here
If you want to use the web viewer:
cd ui
bun install
Run the main script with a function name to analyze:
bun run main.ts <functionName>
Example:
bun run main.ts analyzeCode
This will:
- Search for the function in your codebase
- Build a recursive tree of all subfunctions it calls
- Display the dependency tree
- Ask if you want LLM analysis
- Generate a markdown file with all related functions
- Use LLM to explain the code
- Save results as markdown and JSON
To view past analyses in the web UI:
# Step 1: Aggregate history files
bun run aggregate-history.ts
# Step 2: Start the web viewer
cd ui
bun run dev
Then open your browser to http://localhost:5173 to browse all your code analyses.
code_analysis/
├── main.ts # Main analysis script
├── utils.ts # Code parsing and analysis functions
├── llmcalls.ts # LLM API integration
├── aggregate-history.ts # History aggregation utility
├── ui/ # Web viewer (Svelte)
│ ├── src/
│ │ ├── routes/
│ │ │ └── +page.svelte # Main viewer page
│ │ └── lib/
│ │ └── components/ # UI components
│ ├── static/
│ │ └── history/ # JSON history files
│ ├── package.json
│ └── vite.config.ts
└── package.json
- Function Extraction: The tool scans your codebase for function definitions in
.ts
,.tsx
,.js
,.jsx
, and.py
files - Dependency Analysis: It identifies which functions call which other functions
- Tree Building: Creates a complete call tree showing all relationships
- LLM Query: Sends the code to LLM models for detailed explanation
- Result Storage: Saves both markdown documentation and JSON metadata
- History Tracking: All LLM responses are logged with metrics (tokens, speed, etc.)
The tool uses OpenRouter to access various LLM models. Default models are configured in main.ts
:
const models = ["deepseek/deepseek-chat-v3.1:free", "z-ai/glm-4.5-air:free"];
const temperature = 1.0;
You can modify these to use different models available on OpenRouter.
The web viewer provides:
- List of all code analysis requests
- Full markdown rendering of LLM responses
- Metrics for each request (tokens, speed, temperature)
- Timestamp and model information
- Clean, responsive UI
To build the web viewer for production:
cd ui
bun run build
The built files will be in ui/.svelte-kit/
and can be deployed to any static hosting service.