# daudibrahimhasan/skeletree architecture

> Architecture diagram of the GitHub repository daudibrahimhasan/skeletree, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/daudibrahimhasan/skeletree
- Repository: https://github.com/daudibrahimhasan/skeletree

## Overview

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: [`src/skeletree/core.py`](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/core.py) (Core), [`src/skeletree/model.py`](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/model.py) (Model), [`src/skeletree/tokens.py`](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/tokens.py) (Tokens), [`src/skeletree/extractors/base.py`](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/base.py) (Base API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_src["src/skeletree"]
  node_node_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_node_core["Core<br/>orchestrator<br/>[core.py]"]
  node_node_config["Config<br/>settings merge<br/>[config.py]"]
  node_node_walker["Walker<br/>repo scanner<br/>[walker.py]"]
  node_node_cache[("Cache<br/>incremental state<br/>[cache.py]")]
  node_node_model["Model<br/>data contract<br/>[model.py]"]
  node_node_deps["Deps<br/>manifest parser<br/>[deps.py]"]
  node_node_tokens(("Tokens<br/>estimator<br/>[tokens.py]"))
end

subgraph group_group_extractors["extractors"]
  node_node_ext_base["Base API<br/>extractor contract<br/>[base.py]"]
  node_node_py_ast["Python AST<br/>python extractor<br/>[python_ast.py]"]
  node_node_tree_sitter["Tree-sitter<br/>multi-language extractor<br/>[treesitter.py]"]
end

subgraph group_group_render["rendering"]
  node_node_md["Markdown<br/>renderer<br/>[markdown.py]"]
  node_node_json["JSON<br/>renderer<br/>[json_out.py]"]
end

subgraph group_group_tests["tests"]
  node_node_test_walker(("Walker tests<br/>test suite<br/>[test_walker.py]"))
  node_node_test_extract(("Extractor tests<br/>test suite<br/>[test_python_ast.py]"))
  node_node_test_render(("Render tests<br/>test suite<br/>[test_render.py]"))
  node_node_test_cache(("Cache tests<br/>test suite<br/>[test_cache.py]"))
  node_node_test_cli(("CLI tests<br/>test suite<br/>[test_cli.py]"))
end

subgraph group_group_ci["repo ops"]
end

node_node_cli -->|"loads"| node_node_config
node_node_cli -->|"starts"| node_node_core
node_node_core -->|"scans"| node_node_walker
node_node_core -->|"reuses"| node_node_cache
node_node_core -->|"reads"| node_node_deps
node_node_core -->|"dispatches"| node_node_ext_base
node_node_ext_base -->|"implements"| node_node_py_ast
node_node_ext_base -->|"implements"| node_node_tree_sitter
node_node_py_ast -->|"writes"| node_node_model
node_node_tree_sitter -->|"writes"| node_node_model
node_node_deps -->|"adds"| node_node_model
node_node_walker -->|"lists"| node_node_model
node_node_model -->|"sizes"| node_node_tokens
node_node_tokens -->|"reports"| node_node_md
node_node_tokens -->|"reports"| node_node_json
node_node_core -->|"renders"| node_node_md
node_node_core -->|"renders"| node_node_json
node_node_test_walker -.->|"covers"| node_node_walker
node_node_test_extract -.->|"covers"| node_node_py_ast
node_node_test_extract -.->|"covers"| node_node_tree_sitter
node_node_test_render -.->|"covers"| node_node_md
node_node_test_render -.->|"covers"| node_node_json
node_node_test_cache -.->|"covers"| node_node_cache
node_node_test_cli -.->|"covers"| node_node_cli

click node_node_cli "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/cli.py"
click node_node_core "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/core.py"
click node_node_config "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/config.py"
click node_node_walker "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/walker.py"
click node_node_cache "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/cache.py"
click node_node_model "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/model.py"
click node_node_deps "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/deps.py"
click node_node_tokens "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/tokens.py"
click node_node_ext_base "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/base.py"
click node_node_py_ast "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/python_ast.py"
click node_node_tree_sitter "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/treesitter.py"
click node_node_md "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/render/markdown.py"
click node_node_json "https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/render/json_out.py"
click node_node_test_walker "https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_walker.py"
click node_node_test_extract "https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_python_ast.py"
click node_node_test_render "https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_render.py"
click node_node_test_cache "https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_cache.py"
click node_node_test_cli "https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_cli.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_cli,node_node_core,node_node_config,node_node_walker,node_node_cache,node_node_model,node_node_deps,node_node_tokens toneBlue
class node_node_ext_base,node_node_py_ast,node_node_tree_sitter toneAmber
class node_node_md,node_node_json toneMint
class node_node_test_walker,node_node_test_extract,node_node_test_render,node_node_test_cache,node_node_test_cli toneRose
```

## Components

### src/skeletree

Main CLI package and analysis pipeline

- [CLI](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/cli.py): entrypoint · Parses user options and launches the run · `src/skeletree/cli.py`
- [Core](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/core.py): orchestrator · Coordinates scan, extract, and render stages · `src/skeletree/core.py`
- [Config](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/config.py): settings merge · Loads and merges repo and CLI settings · `src/skeletree/config.py`
- [Walker](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/walker.py): repo scanner · Finds files and applies ignore and limit rules · `src/skeletree/walker.py`
- [Cache](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/cache.py): incremental state · Skips unchanged files using local metadata · `src/skeletree/cache.py`
- [Model](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/model.py): data contract · Shared structures for files, symbols, deps, and stats · `src/skeletree/model.py`
- [Deps](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/deps.py): manifest parser · Extracts dependency names from project manifests · `src/skeletree/deps.py`
- [Tokens](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/tokens.py): estimator · Computes approximate token counts for the map · `src/skeletree/tokens.py`

### extractors

Language-specific symbol extraction

- [Base API](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/base.py): extractor contract · Common interface for language extractors · `src/skeletree/extractors/base.py`
- [Python AST](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/python_ast.py): python extractor · Extracts Python symbols with stdlib ast · `src/skeletree/extractors/python_ast.py`
- [Tree-sitter](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/extractors/treesitter.py): multi-language extractor · Parses supported non-Python languages · `src/skeletree/extractors/treesitter.py`

### rendering

Final output formats

- [Markdown](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/render/markdown.py): renderer · Writes the human-readable repo map · `src/skeletree/render/markdown.py`
- [JSON](https://github.com/daudibrahimhasan/skeletree/blob/main/src/skeletree/render/json_out.py): renderer · Writes the machine-readable output · `src/skeletree/render/json_out.py`

### tests

Architecture-mirroring test coverage

- [Walker tests](https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_walker.py): test suite · Covers file discovery and ignore behavior · `tests/test_walker.py`
- [Extractor tests](https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_python_ast.py): test suite · Covers Python and tree-sitter extraction · `tests/test_python_ast.py`
- [Render tests](https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_render.py): test suite · Covers output formatting · `tests/test_render.py`
- [Cache tests](https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_cache.py): test suite · Covers cache reuse behavior · `tests/test_cache.py`
- [CLI tests](https://github.com/daudibrahimhasan/skeletree/blob/main/tests/test_cli.py): test suite · Covers command-line behavior · `tests/test_cli.py`

## Connections

- 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
