{"id":30840960,"url":"https://github.com/zapier/stubtree","last_synced_at":"2025-09-06T19:49:55.886Z","repository":{"id":296378342,"uuid":"990382900","full_name":"zapier/stubtree","owner":"zapier","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-02T20:30:52.000Z","size":85,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-29T20:05:29.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zapier.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-26T03:17:31.000Z","updated_at":"2025-06-22T10:12:53.000Z","dependencies_parsed_at":"2025-06-03T04:48:12.646Z","dependency_job_id":null,"html_url":"https://github.com/zapier/stubtree","commit_stats":null,"previous_names":["zapier/stubtree"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zapier/stubtree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapier%2Fstubtree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapier%2Fstubtree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapier%2Fstubtree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapier%2Fstubtree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zapier","download_url":"https://codeload.github.com/zapier/stubtree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapier%2Fstubtree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273955766,"owners_count":25197579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-06T19:49:49.147Z","updated_at":"2025-09-06T19:49:55.875Z","avatar_url":"https://github.com/zapier.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stubtree\n\nGenerate a bird's-eye view of your codebase with all the important symbols (functions, classes, methods) shown inline. Perfect for documentation, code reviews, or understanding new projects.\n\n```bash\n$ stubtree --root ./src --lang ts\n\nsrc/\n├── index.ts\n│   ├── class FileProcessor\n│   │   ├── constructor(options: ProcessorOptions)\n│   │   ├── processDirectory(dirPath: string): Promise\u003cTreeNode\u003e\n│   │   └── shouldIgnoreFile(filePath: string): boolean\n├── parser.ts\n│   ├── parseTags(input: string): Promise\u003cTag[]\u003e\n│   └── interface Tag\n│       ├── name: string\n│       ├── path: string\n│       └── kind: string\n└── renderer.ts\n    ├── renderTree(node: TreeNode, options?: RenderOptions): string\n    └── formatSymbol(tag: Tag): string\n```\n\n## What is stubtree?\n\nstubtree is a CLI tool that combines the power of ctags with a clean tree visualization to help you quickly understand any codebase. Unlike regular tree commands that only show files and folders, stubtree extracts and displays the actual code structure - classes, methods, functions, and more - giving you instant insight into how a project is organized.\n\n**Perfect for AI coding assistants:** Tools like Claude, GitHub Copilot, and Cursor can better understand your codebase when provided with stubtree's structured output, leading to more accurate suggestions and refactoring.\n\n## Installation\n\n```bash\n# Install globally\nnpm install -g @zapier/stubtree\n\n# Or with yarn\nyarn global add @zapier/stubtree\n\n# Or use directly with npx\nnpx @zapier/stubtree\n```\n\n### Prerequisites\n\nstubtree requires `ctags`:\n\n```bash\n# macOS\nbrew install ctags\n\n# Ubuntu/Debian\nsudo apt-get install ctags\n```\n\n## Getting Started\n\n```bash\n# Scan current directory\nstubtree\n\n# Scan specific directory with TypeScript files\nstubtree --root ./src --lang ts,tsx\n\n# Limit depth for large projects\nstubtree --depth 3\n\n# Export as JSON for processing\nstubtree --json \u003e structure.json\n```\n\n## Options\n\n- `--root \u003cdir\u003e` - Root directory to scan (default: current directory)\n- `--lang \u003cglobs\u003e` - Comma-separated file extensions to include (e.g., `py,ts,tsx`)\n- `--depth \u003cn\u003e` - Maximum directory depth to traverse\n- `--json` - Output raw JSON instead of ASCII tree\n\n### Examples\n\n#### TypeScript/JavaScript project\n\n```bash\nstubtree --root ./src --lang ts,tsx,js,jsx\n```\n\nOutput:\n```\nsrc/\n├── main.ts\n│   ├── init_app() -\u003e void\n│   └── class Service\n│       ├── start() -\u003e Promise\u003cvoid\u003e\n│       └── stop() -\u003e Promise\u003cvoid\u003e\n└── utils/\n    └── io.ts\n        ├── read(path: string) -\u003e string\n        └── write(path: string, data: string) -\u003e void\n```\n\n#### Python project with depth limit\n\n```bash\nstubtree --root ./myproject --lang py --depth 2\n```\n\n#### JSON output\n\n```bash\nstubtree --json \u003e project-structure.json\n```\n\n## Features\n\n- Fast parsing using ctags JSON output with advanced pattern extraction\n- Extracts function signatures, return types, and async modifiers\n- Shows class inheritance and property type annotations\n- Respects file order as encountered (no sorting)\n- Colorized output when outputting to TTY\n- Ignores common directories (.git, node_modules, etc.) and test files\n- Supports multiple programming languages through ctags\n- Smart filtering to show only relevant symbols (classes, functions, methods, not internal variables)\n\n## How it Works\n\n### Behind the Scenes\n\nstubtree combines the power of ctags with Node.js's streaming capabilities to efficiently parse and render your codebase:\n\n1. **Symbol Extraction**: We spawn `ctags` as a child process with specific flags:\n   ```bash\n   ctags --output-format=json --fields=+neKStr --extras=+q --sort=no -R .\n   ```\n   - `--output-format=json`: Outputs newline-delimited JSON, one symbol per line\n   - `--fields=+neKStr`: Includes line numbers, end lines, kind info, scope, type refs, and roles\n   - `--extras=+q`: Includes extra tag information like signatures\n   - `--sort=no`: Preserves file discovery order\n   - `-R`: Recursively scans directories\n\n2. **Streaming JSON Parser**: Instead of loading all ctags output into memory, we use Node's `readline` interface to process the JSON stream line-by-line. Each line contains a symbol like:\n   ```json\n   {\"name\":\"readFile\",\"path\":\"/project/src/io.ts\",\"kind\":\"function\",\"signature\":\"(path: string): Promise\u003cstring\u003e\"}\n   ```\n\n3. **Tree Building**: We build the tree structure in two passes:\n   - First, we group all tags by their file paths\n   - Then, we walk the actual filesystem to build the directory structure, attaching the relevant tags to each file node\n\n4. **Smart Filtering**: \n   - Language filtering happens at the tag parsing stage based on file extensions\n   - Directory traversal respects `--depth` limits and ignores common non-source directories\n   - Empty directories are automatically pruned from the output\n\n5. **ASCII Rendering**: The tree renderer uses a recursive algorithm with careful prefix tracking:\n   - `├──` for non-last items\n   - `└──` for last items\n   - `│   ` for continuation lines\n   - Tags are indented one level deeper than their containing file\n\n6. **Color Support**: We detect TTY output using Node's `isatty()` and apply colors via chalk:\n   - Blue for directories\n   - Green for files\n   - Gray for symbols\n\n### Performance Optimizations\n\n- **Streaming**: We never load the entire ctags output into memory\n- **Lazy Directory Walking**: We only traverse directories that contain matching files\n- **Early Filtering**: Language filters are applied during tag parsing, not after\n- **Minimal Dependencies**: Just `commander` for CLI parsing and `chalk` for colors\n\n## Performance\n\nstubtree is designed to be fast, typically scanning and rendering a project tree in under 1 second on a typical laptop.\n\n## Limitations\n\n- Symbol information is limited to what ctags provides\n- No language-specific type inference beyond ctags capabilities\n- Requires ctags to be installed separately\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run in development mode\nnpm run dev\n\n# Run tests\nnpm test\n\n# Build\nnpm run build\n\n# Lint\nnpm run lint\n\n# Type check\nnpm run typecheck\n```\n\n### Known Issues\n\n- The tool gracefully handles broken symlinks and files that can't be accessed by skipping them during directory traversal\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapier%2Fstubtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzapier%2Fstubtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapier%2Fstubtree/lists"}