Language-agnostic High-Level Design generator powered by Tree-sitter + LLM
Project description
HLD Generator
Language-agnostic High-Level Design document generator powered by Tree-sitter + LLM.
Point it at any codebase — Python, JavaScript, TypeScript, Java, Go, Rust, C/C++, Ruby, C#, Kotlin, Swift, and more — and get a complete HLD with architecture diagrams, component breakdowns, and dependency analysis.
How It Works
Codebase → Scanner → Tree-sitter AST Parser → Code Graph → LLM Analysis → HLD Document
↓ (fallback)
Regex Parser
- Scan — Discovers source files, filters out vendor/generated code
- Parse — Extracts classes, functions, imports, endpoints using Tree-sitter (with regex fallback). Parsing runs in parallel using a thread pool
- Graph — Builds a dependency graph with NetworkX, identifies entry points and hub modules
- Analyse — Sends structured context to an LLM (Claude or GPT) for semantic understanding, or runs static fallback analysis with
--provider none - Render — Generates a Markdown HLD report + Mermaid architecture diagram
Installation
# Install directly from GitHub (no clone needed)
pip install git+https://github.com/harsh-vishnoi/hld-generator.git
# Or clone and install for development
git clone https://github.com/harsh-vishnoi/hld-generator.git
cd hld-generator
pip install -e .
Requirements: Python 3.9+
hldnot found after install? pip may install the script to a directory not on your PATH (e.g.~/.local/binor~/Library/Python/3.x/bin). Either add that directory to your PATH:# macOS echo 'export PATH="$PATH:$HOME/Library/Python/3.9/bin"' >> ~/.zshrc && source ~/.zshrc # Linux echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc && source ~/.bashrcOr skip the
hldcommand entirely and run via Python:python -m hld_generator ./my-project --provider none
Updating to latest version:
pip install --upgrade git+https://github.com/harsh-vishnoi/hld-generator.git
Quick Start
# With Anthropic Claude (recommended)
export ANTHROPIC_API_KEY=sk-ant-...
hld ./my-project
# With OpenAI
export OPENAI_API_KEY=sk-...
hld ./my-project --provider openai
# Without LLM (graph-only static analysis, no API key needed)
hld ./my-project --provider none
# Scan a single file
hld ./main.py --provider none
# Custom output directory
hld ./my-project -o ./docs/architecture
# Include test files + verbose logging
hld ./my-project --include-tests -v
# Run as a Python module
python -m hld_generator ./my-project --provider none
Output
The tool generates three files in ./hld_output/ (or your custom output dir):
| File | Description |
|---|---|
hld_report.md |
Complete HLD document with overview, components, data flow, tech stack, and architecture diagram |
architecture.mmd |
Standalone Mermaid diagram file (renderable in GitHub, VS Code, etc.) |
graph_summary.md |
Raw code graph statistics — modules, packages, entry points, hub modules, API endpoints |
CLI Reference
hld <target> [options]
| Flag | Default | Description |
|---|---|---|
target |
(required) | Path to a source file or directory to analyse |
-o, --output |
./hld_output |
Output directory |
--provider |
anthropic |
LLM provider: anthropic, openai, none, or a plugin-registered name |
--model |
auto | LLM model name (defaults: claude-sonnet-4-20250514 / gpt-4o) |
--format |
markdown |
Output format: built-in markdown or a plugin-registered renderer name |
--include-tests |
off | Include test files in the analysis |
--max-files |
500 |
Maximum number of files to scan |
--max-file-size |
512000 |
Maximum file size in bytes |
--plugins-dir |
none | Directory containing plugin .py files to load |
-v, --verbose |
off | Enable debug logging |
--version |
— | Show version |
Exit codes: 0 = success, 1 = no files found, 2 = degraded (LLM failed but fallback output was produced).
API keys: Set via environment variables ANTHROPIC_API_KEY or OPENAI_API_KEY. The --api-key flag is deprecated (visible in process list).
Supported Languages
| Language | Tree-sitter | Regex Fallback | Endpoint Detection |
|---|---|---|---|
| Python | yes | yes | Flask, FastAPI, Django |
| JavaScript | yes | yes | Express |
| TypeScript | yes | yes | Express |
| Java | yes | yes | Spring Boot |
| Go | yes | yes | net/http, Gin, Chi |
| Rust | yes | yes | — |
| C | yes | yes | — |
| C++ | yes | yes | — |
| Ruby | yes | yes | — |
| C# | — | yes | — |
| Kotlin | — | yes | — |
| Swift | — | yes | — |
| PHP | — | yes | — |
| Scala | — | yes | — |
Languages without Tree-sitter grammars automatically use the regex fallback parser. Even completely unknown languages get basic extraction via generic patterns.
Verifying the Application
Two test suites are included:
# Quick smoke test (7 tests) — validates core parsing, no external deps
python test_quick.py
# Comprehensive test suite (141 tests) — covers every module end-to-end
python test_comprehensive.py
You can also run a full end-to-end validation on any codebase:
# Static analysis (no API key needed)
hld ./my-project --provider none -v
# Verify output files were created
ls -la ./hld_output/
# Check exit code (0 = success)
echo $?
What the Tests Cover
| Suite | Tests | Scope |
|---|---|---|
test_quick.py |
7 | Language map, config defaults, regex parser (Python/JS/Go/Java), file scanner |
test_comprehensive.py |
141 | Config, scanner, regex parser, tree-sitter parser, graph builder, LLM fallback, renderer, plugin system, edge cases, entry point detection, section numbering, integration fixes |
Architecture
hld_generator/
├── __init__.py # Package version
├── __main__.py # python -m hld_generator entry point
├── cli.py # CLI entry point & pipeline orchestrator
├── config.py # Configuration, language maps, constants
├── scanner.py # File discovery & filtering
├── parsers/
│ ├── base.py # Data structures (ParsedFile, ParsedEntity, ImportInfo)
│ ├── manager.py # Parser facade (auto-selects tree-sitter or regex, parallel parse_all)
│ ├── tree_sitter_parser.py # Tree-sitter AST parser
│ └── regex_parser.py # Regex fallback parser
├── graph.py # NetworkX dependency graph builder
├── llm.py # LLM client (Anthropic + OpenAI + plugin dispatch)
├── fallback.py # Static fallback analyser (no LLM needed)
├── renderer.py # Markdown + Mermaid output renderer
├── plugins.py # Plugin registry & hook system
└── _networkx_shim/ # Lightweight NetworkX fallback for offline use
└── __init__.py
Plugin System
HLD Generator supports plugins for custom parsers, LLM providers, renderers, and pipeline hooks.
Loading Plugins
Plugins are loaded from:
--plugins-dir <path>— explicitly specified directory.hld_plugins/— auto-discovered next to the target directory
Each .py file in the plugin directory is loaded automatically (files starting with _ are skipped).
Plugin Types
Custom parser — add support for a new language:
from hld_generator.plugins import registry
@registry.register_parser("swift")
class SwiftParser:
def parse_file(self, file_path, language):
# Return a ParsedFile
...
Custom LLM provider — use a different LLM backend:
@registry.register_llm_provider("ollama")
class OllamaProvider:
def call(self, context: str, system_prompt: str) -> str:
# Return raw LLM response text
...
Then use it: hld ./project --provider ollama
Custom renderer — output in a different format:
@registry.register_renderer("html")
class HTMLRenderer:
def render(self, analysis, code_graph, output_dir) -> list[Path]:
# Write files and return their paths
...
Then use it: hld ./project --format html
Pipeline hooks — modify data between pipeline stages:
@registry.register_hook("post_parse")
def enrich(parsed_files):
# Modify and return parsed_files
return parsed_files
Available Hook Points
| Hook | Receives | Returns |
|---|---|---|
pre_scan |
config |
config |
post_scan |
scanned_files |
scanned_files |
pre_parse |
scanned_files |
scanned_files |
post_parse |
parsed_files |
parsed_files |
pre_graph |
parsed_files |
parsed_files |
post_graph |
code_graph |
code_graph |
pre_llm |
code_graph |
code_graph |
post_llm |
analysis |
analysis |
pre_render |
analysis, code_graph |
(analysis, code_graph) |
post_render |
output_files |
output_files |
Other Extension Points
Custom endpoint patterns:
registry.register_endpoint_pattern(
r'@MyFramework\.route\("([^"]+)"\)',
name="MyFramework"
)
Custom language file extensions:
registry.register_language(".hx", "haxe")
Extending (Without Plugins)
Add a new language:
- Add extension mapping in
config.py→LANGUAGE_MAP - Add regex patterns in
parsers/regex_parser.py→_PATTERNS - (Optional) Add tree-sitter grammar to
config.py→TREE_SITTER_GRAMMARSand queries totree_sitter_parser.py→_QUERIES
Add framework endpoint detection:
Add patterns to parsers/regex_parser.py → _ENDPOINT_PATTERNS
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hld_generator-0.2.0.tar.gz.
File metadata
- Download URL: hld_generator-0.2.0.tar.gz
- Upload date:
- Size: 55.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4bc5f0af1b84135d0adcad392701e275c7e74731df4d7c8e57d361f9d3e62ec
|
|
| MD5 |
65116b42a550f0ec6dd38c39d56a4650
|
|
| BLAKE2b-256 |
2d31efe57ac2c13d7cf2afb3fc211da1174170fcb98fcf533ea373a695ed7fa1
|
Provenance
The following attestation bundles were made for hld_generator-0.2.0.tar.gz:
Publisher:
publish.yml on harsh-vishnoi/hld-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hld_generator-0.2.0.tar.gz -
Subject digest:
c4bc5f0af1b84135d0adcad392701e275c7e74731df4d7c8e57d361f9d3e62ec - Sigstore transparency entry: 1018357668
- Sigstore integration time:
-
Permalink:
harsh-vishnoi/hld-generator@75840c32f7d33def0499bc10129c34df9e5f75e4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/harsh-vishnoi
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@75840c32f7d33def0499bc10129c34df9e5f75e4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hld_generator-0.2.0-py3-none-any.whl.
File metadata
- Download URL: hld_generator-0.2.0-py3-none-any.whl
- Upload date:
- Size: 42.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f90430e509a8d1ad8ba6b7e471f644615d476cc13b9f2842dc84ccbda48938f
|
|
| MD5 |
94a5d7f9f35c033f70c3a857f7442905
|
|
| BLAKE2b-256 |
3180ce5230aeb52d8ffe1039dbd684b4dd40d33f3c92c8c96bbded160819c7c9
|
Provenance
The following attestation bundles were made for hld_generator-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on harsh-vishnoi/hld-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hld_generator-0.2.0-py3-none-any.whl -
Subject digest:
2f90430e509a8d1ad8ba6b7e471f644615d476cc13b9f2842dc84ccbda48938f - Sigstore transparency entry: 1018357691
- Sigstore integration time:
-
Permalink:
harsh-vishnoi/hld-generator@75840c32f7d33def0499bc10129c34df9e5f75e4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/harsh-vishnoi
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@75840c32f7d33def0499bc10129c34df9e5f75e4 -
Trigger Event:
push
-
Statement type: