How daudibrahimhasan/skeletree works
1. Overall shape
- skeletree is a local, single-purpose Python CLI package that turns a repository into a compact “repo map” file.
- The architecture is a pipeline: discover files → apply ignore rules → reuse cache → extract symbols/deps → estimate tokens → render Markdown or JSON.
2. Entry points and orchestration
- src/skeletree/cli.py is the user-facing boundary: it parses CLI options like output path, format, max files, cache control, and init behavior.
- src/skeletree/core.py likely coordinates the full scan-and-render workflow and is the central orchestration layer between scanning, extraction, and output.
3. Repository scanning and file selection
- src/skeletree/walker.py is the discovery layer for traversing the target repo.
- It is responsible for applying .gitignore, built-in noise exclusions, configured ignored directories/patterns, and file-count limits.
- This is the first major boundary: it decides what will be analyzed versus merely listed in the tree.
4. Incremental cache boundary
- src/skeletree/cache.py stores scan metadata in a local cache file, keyed by file path plus mtime and size.
- On reruns, unchanged files are skipped and only modified files are re-parsed.
- Architecturally, this separates filesystem discovery from expensive syntax extraction, making repeated runs cheap.
5. Configuration system
- src/skeletree/config.py loads repo-local and/or project-level settings, including output name, format, file limits, collapse thresholds, and ignore lists.
- The README indicates config can come from pyproject.toml under [tool.skeletree] or from a standalone .skeletree.toml.
- CLI flags override or complement this config, so configuration is a merge point rather than a separate mode.
6. Language extraction subsystem
- src/skeletree/extractors/ is the language-analysis layer.
- extractors/base.py defines the common contract; python_ast.py handles Python via the stdlib ast module; treesitter.py handles non-Python languages via tree-sitter.
- The boundary here is important: Python gets richer extraction without external parsers, while other supported languages use a shared syntax-parsing path.
7. Supported symbol model
- src/skeletree/model.py defines the structured data that flows through the system: project metadata, dependency lists, tree nodes, file symbols, and signatures/docstring snippets.
- This model is the internal contract between extraction and rendering.
- For unknown file types, the system still records the file in the tree even if no symbol breakdown is available.
8. Dependency detection
- src/skeletree/deps.py is a separate manifest-reading subsystem that extracts only library names, not version pins.
- It supports common manifests such as pyproject.toml, requirements*.txt, package.json, Cargo.toml, and go.mod.
- This is intentionally independent from source parsing, because dependency metadata comes from manifests rather than code files.
9. Token estimation
- src/skeletree/tokens.py computes the approximate token count using the chars / 4 heuristic.
- This is not a real tokenizer; it exists to make the map’s “how much smaller is this than reading the repo?” metric cheap and deterministic.
- Token estimation is part of the reporting layer, not the extraction layer.
10. Rendering/output
- src/skeletree/render/markdown.py and src/skeletree/render/json_out.py are the final presentation layer.
- The package can emit a human-readable markdown map or machine-readable JSON, and can write to a file or stdout.
- This renderer boundary keeps the analysis pipeline format-agnostic until the end.
11. Primary data flow
- Input is a local repository path.
- The scanner builds a file set, cache filters unchanged files, extractors populate the model with symbols and dependencies, token stats are computed, and a renderer emits the final artifact.
- The final artifact is typically skeletree.md, which is designed to be the only file an AI agent needs to read.
12. Operational model
- The project is explicitly offline and has no API dependency or telemetry path.
- Its main runtime dependency is Python 3.10+, with optional tree-sitter-based language coverage for non-Python files.
- Tests in tests/ cover the cache, CLI, config, extractors, renderers, tokens, and walker, mirroring the main architectural boundaries.
Main entry points: core.py Core · model.py Model · tokens.py Tokens · base.py Base API
Components 18
src/skeletree
Main CLI package and analysis pipeline
- CLI · Parses user options and launches the run
src/skeletree/cli.py - Core · Coordinates scan, extract, and render stages
src/skeletree/core.py - Config · Loads and merges repo and CLI settings
src/skeletree/config.py - Walker · Finds files and applies ignore and limit rules
src/skeletree/walker.py - Cache · Skips unchanged files using local metadata
src/skeletree/cache.py - Model · Shared structures for files, symbols, deps, and stats
src/skeletree/model.py - Deps · Extracts dependency names from project manifests
src/skeletree/deps.py - Tokens · Computes approximate token counts for the map
src/skeletree/tokens.py
extractors
Language-specific symbol extraction
- Base API · Common interface for language extractors
src/skeletree/extractors/base.py - Python AST · Extracts Python symbols with stdlib ast
src/skeletree/extractors/python_ast.py - Tree-sitter · Parses supported non-Python languages
src/skeletree/extractors/treesitter.py
rendering
Final output formats
tests
Architecture-mirroring test coverage
- Walker tests · Covers file discovery and ignore behavior
tests/test_walker.py - Extractor tests · Covers Python and tree-sitter extraction
tests/test_python_ast.py - Render tests · Covers output formatting
tests/test_render.py - Cache tests · Covers cache reuse behavior
tests/test_cache.py - CLI tests · Covers command-line behavior
tests/test_cli.py
Connections 24
- CLI → Config: loads · CLI inputs are merged with configuration
- CLI → Core: starts · CLI hands execution to the orchestrator
- Core → Walker: scans · Core asks walker for the file set
- Core → Cache: reuses · Cache filters unchanged files
- Core → Deps: reads · Dependency manifests are parsed separately
- Core → Base API: dispatches · Core uses the extractor contract to analyze files
- Base API → Python AST: implements · Python extractor follows the shared interface
- Base API → Tree-sitter: implements · Tree-sitter extractor follows the shared interface
- Python AST → Model: writes · Extraction results populate the shared model
- Tree-sitter → Model: writes · Extraction results populate the shared model
- Deps → Model: adds · Detected dependencies flow into the model
- Walker → Model: lists · Discovered files become tree nodes
- Model → Tokens: sizes · Token estimation is computed from assembled content
- Tokens → Markdown: reports · Markdown output includes token stats
- Tokens → JSON: reports · JSON output includes token stats
- Core → Markdown: renders · Core can emit markdown directly
- Core → JSON: renders · Core can emit JSON directly
- Walker tests → Walker: covers · Walker behavior is validated by tests
- Extractor tests → Python AST: covers · Python extraction behavior is validated by tests
- Extractor tests → Tree-sitter: covers · Tree-sitter extraction behavior is validated by tests
- Render tests → Markdown: covers · Markdown rendering is validated by tests
- Render tests → JSON: covers · JSON rendering is validated by tests
- Cache tests → Cache: covers · Cache behavior is validated by tests
- CLI tests → CLI: covers · CLI behavior is validated by tests