# anatta-rs/ast-to-mermaid architecture

> Architecture diagram of the GitHub repository anatta-rs/ast-to-mermaid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anatta-rs/ast-to-mermaid
- Repository: https://github.com/anatta-rs/ast-to-mermaid

## Overview

ast-to-mermaid is a Rust code-graph analyzer and diagram generator. Its main workflow accepts a source tree or Git ref through the CLI, discovers and parses Rust, Python, and Dart files, stores code entities and call edges in memory, resolves cross-module calls, and produces Mermaid views or JSON artifact bundles. Separate product branches provide function sequence diagrams, cached Git-aware indexing, and structural diffs. The map follows documented and indexed relationships; some CLI handlers and subsystems were not excerpted, so their links are limited to what the README or source index supports.

Main entry points: [`src/pipeline.rs`](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/pipeline.rs) (Analysis pipeline), [`src/parser/mod.rs`](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/mod.rs) (Language parsers), [`src/cli/run`](https://github.com/anatta-rs/ast-to-mermaid/tree/main/src/cli/run) (Command handlers), [`src/render/mod.rs`](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/render/mod.rs) (Render dispatcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and Git inputs"]
  node_cli_entry["CLI entry<br/>[a2m.rs]"]
  node_cli_dispatch["Command dispatch<br/>[mod.rs]"]
  node_cli_flags["Command options<br/>[flags.rs]"]
  node_git_source["Git source<br/>[git_source.rs]"]
  node_run_handlers["Command handlers"]
end

subgraph group_analysis["Code analysis"]
  node_pipeline["Analysis pipeline<br/>[pipeline.rs]"]
  node_parser["Language parsers<br/>[mod.rs]"]
  node_rust_parser["Rust frontend<br/>[rust.rs]"]
  node_python_parser["Python frontend<br/>[python.rs]"]
  node_dart_parser["Dart frontend<br/>[dart.rs]"]
  node_parser_queries["Tree-sitter queries<br/>[queries.rs]"]
  node_domain_model["Code graph model<br/>[model.rs]"]
  node_store[("Memory store<br/>[memory.rs]")]
  node_resolver["Call resolver<br/>[resolve.rs]"]
  node_limits["Analysis limits<br/>[limits.rs]"]
end

subgraph group_views["Graph views"]
  node_render_dispatch["Render dispatcher<br/>[mod.rs]"]
  node_render_levels["Diagram levels"]
  node_flow_view["Call flow view<br/>[flow.rs]"]
  node_sequence["Sequence diagrams<br/>[mod.rs]"]
  node_sequence_visit["Sequence traversal<br/>[visit.rs]"]
  node_sequence_lang["Sequence language support<br/>[lang.rs]"]
  node_sequence_render["Sequence renderer<br/>[render.rs]"]
end

subgraph group_outputs["Artifacts and history"]
  node_cache[("Content cache<br/>[cache.rs]")]
  node_artifact_emitter["Artifact emitter<br/>[mod.rs]"]
  node_diff["Structural diff<br/>[diff.rs]"]
  node_cache_gc["Cache maintenance<br/>[gc.rs]"]
end

node_user(("Engineer"))
node_mermaid_result["Mermaid output"]
node_bundle_result["JSON and diagram bundle"]

node_user -->|"invokes"| node_cli_entry
node_cli_entry -->|"dispatches"| node_cli_dispatch
node_cli_dispatch -->|"uses options"| node_cli_flags
node_cli_dispatch -->|"routes commands"| node_run_handlers
node_run_handlers -.->|"analyzes sources"| node_pipeline
node_pipeline -->|"reads revisions"| node_git_source
node_pipeline -->|"uses cache"| node_cache
node_pipeline -->|"parses files"| node_parser
node_parser -->|"dispatches Rust"| node_rust_parser
node_parser -->|"dispatches Python"| node_python_parser
node_parser -->|"dispatches Dart"| node_dart_parser
node_rust_parser -->|"uses queries"| node_parser_queries
node_python_parser -->|"uses queries"| node_parser_queries
node_parser -->|"produces atoms"| node_domain_model
node_pipeline -->|"populates store"| node_store
node_pipeline -->|"resolves calls"| node_resolver
node_resolver -->|"updates edges"| node_store
node_parser -->|"applies parse results"| node_store
node_pipeline -->|"renders analysis"| node_render_dispatch
node_render_dispatch -->|"dispatches levels"| node_render_levels
node_render_dispatch -->|"dispatches flow"| node_flow_view
node_render_dispatch -->|"returns diagram"| node_mermaid_result
node_pipeline -->|"emits bundle"| node_artifact_emitter
node_artifact_emitter -->|"reads graph"| node_store
node_artifact_emitter -->|"writes artifacts"| node_bundle_result
node_artifact_emitter -->|"renders entities"| node_render_dispatch
node_run_handlers -->|"extracts sequences"| node_sequence
node_sequence -->|"walks function bodies"| node_sequence_visit
node_sequence -->|"uses language support"| node_sequence_lang
node_sequence -->|"renders steps"| node_sequence_render
node_sequence_render -->|"emits sequence"| node_mermaid_result
node_run_handlers -->|"compares revisions"| node_diff
node_run_handlers -->|"maintains cache"| node_cache_gc
node_run_handlers -.->|"selects Git ref"| node_git_source
node_parser -.->|"applies bounds"| node_limits

click node_cli_entry "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/bin/a2m.rs"
click node_cli_dispatch "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cli/run/mod.rs"
click node_cli_flags "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cli/flags.rs"
click node_git_source "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/git_source.rs"
click node_run_handlers "https://github.com/anatta-rs/ast-to-mermaid/tree/main/src/cli/run"
click node_pipeline "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/pipeline.rs"
click node_parser "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/mod.rs"
click node_rust_parser "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/rust.rs"
click node_python_parser "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/python.rs"
click node_dart_parser "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/dart.rs"
click node_parser_queries "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/queries.rs"
click node_domain_model "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/model.rs"
click node_store "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/graph/memory.rs"
click node_resolver "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/resolve.rs"
click node_limits "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/limits.rs"
click node_cache "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cache.rs"
click node_render_dispatch "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/render/mod.rs"
click node_render_levels "https://github.com/anatta-rs/ast-to-mermaid/tree/main/src/render"
click node_flow_view "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/render/flow.rs"
click node_sequence "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/mod.rs"
click node_sequence_visit "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/visit.rs"
click node_sequence_lang "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/lang.rs"
click node_sequence_render "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/render.rs"
click node_artifact_emitter "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/artifacts/mod.rs"
click node_diff "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/diff.rs"
click node_cache_gc "https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cli/run/gc.rs"

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_cli_entry,node_cli_dispatch,node_cli_flags,node_git_source,node_run_handlers toneBlue
class node_pipeline,node_parser,node_rust_parser,node_python_parser,node_dart_parser,node_parser_queries,node_domain_model,node_store,node_resolver,node_limits toneAmber
class node_render_dispatch,node_render_levels,node_flow_view,node_sequence,node_sequence_visit,node_sequence_lang,node_sequence_render toneMint
class node_cache,node_artifact_emitter,node_diff,node_cache_gc toneRose
class node_user,node_mermaid_result,node_bundle_result toneIndigo
```

## Components

### CLI and Git inputs

- [CLI entry](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/bin/a2m.rs): `src/bin/a2m.rs`
- [Command dispatch](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cli/run/mod.rs): `src/cli/run/mod.rs`
- [Command options](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cli/flags.rs): `src/cli/flags.rs`
- [Git source](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/git_source.rs): `src/git_source.rs`
- [Command handlers](https://github.com/anatta-rs/ast-to-mermaid/tree/main/src/cli/run): `src/cli/run`

### Code analysis

- [Analysis pipeline](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/pipeline.rs): `src/pipeline.rs`
- [Language parsers](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/mod.rs): `src/parser/mod.rs`
- [Rust frontend](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/rust.rs): `src/parser/rust.rs`
- [Python frontend](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/python.rs): `src/parser/python.rs`
- [Dart frontend](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/dart.rs): `src/parser/dart.rs`
- [Tree-sitter queries](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/parser/queries.rs): `src/parser/queries.rs`
- [Code graph model](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/model.rs): `src/model.rs`
- [Memory store](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/graph/memory.rs): `src/graph/memory.rs`
- [Call resolver](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/resolve.rs): `src/resolve.rs`
- [Analysis limits](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/limits.rs): `src/limits.rs`

### Graph views

- [Render dispatcher](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/render/mod.rs): `src/render/mod.rs`
- [Diagram levels](https://github.com/anatta-rs/ast-to-mermaid/tree/main/src/render): `src/render`
- [Call flow view](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/render/flow.rs): `src/render/flow.rs`
- [Sequence diagrams](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/mod.rs): `src/sequence/mod.rs`
- [Sequence traversal](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/visit.rs): `src/sequence/visit.rs`
- [Sequence language support](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/lang.rs): `src/sequence/lang.rs`
- [Sequence renderer](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/sequence/render.rs): `src/sequence/render.rs`

### Artifacts and history

- [Content cache](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cache.rs): `src/cache.rs`
- [Artifact emitter](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/artifacts/mod.rs): `src/artifacts/mod.rs`
- [Structural diff](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/diff.rs): `src/diff.rs`
- [Cache maintenance](https://github.com/anatta-rs/ast-to-mermaid/blob/main/src/cli/run/gc.rs): `src/cli/run/gc.rs`

### Other components

- **Engineer**
- **Mermaid output**
- **JSON and diagram bundle**

## Connections

- Engineer → CLI entry: invokes
- CLI entry → Command dispatch: dispatches
- Command dispatch → Command options: uses options (evidence: `src/cli/run/mod.rs`)
- Command dispatch → Command handlers: routes commands (evidence: `src/cli/run/mod.rs`)
- Command handlers → Analysis pipeline: analyzes sources (evidence: `src/cli/run/index.rs`)
- Analysis pipeline → Git source: reads revisions (evidence: `src/pipeline.rs`)
- Analysis pipeline → Content cache: uses cache (evidence: `src/pipeline.rs`)
- Analysis pipeline → Language parsers: parses files (evidence: `src/pipeline.rs`)
- Language parsers → Rust frontend: dispatches Rust (evidence: `src/parser/mod.rs`)
- Language parsers → Python frontend: dispatches Python (evidence: `src/parser/mod.rs`)
- Language parsers → Dart frontend: dispatches Dart (evidence: `src/parser/mod.rs`)
- Rust frontend → Tree-sitter queries: uses queries (evidence: `src/parser/rust.rs`)
- Python frontend → Tree-sitter queries: uses queries (evidence: `src/parser/python.rs`)
- Language parsers → Code graph model: produces atoms (evidence: `src/parser/mod.rs`)
- Analysis pipeline → Memory store: populates store (evidence: `src/pipeline.rs`)
- Analysis pipeline → Call resolver: resolves calls (evidence: `src/pipeline.rs`)
- Call resolver → Memory store: updates edges (evidence: `src/resolve.rs`)
- Language parsers → Memory store: applies parse results (evidence: `src/parser/mod.rs`)
- Analysis pipeline → Render dispatcher: renders analysis (evidence: `src/pipeline.rs`)
- Render dispatcher → Diagram levels: dispatches levels (evidence: `src/render/mod.rs`)
- Render dispatcher → Call flow view: dispatches flow (evidence: `src/render/mod.rs`)
- Render dispatcher → Mermaid output: returns diagram (evidence: `src/render/mod.rs`)
- Analysis pipeline → Artifact emitter: emits bundle (evidence: `src/pipeline.rs`)
- Artifact emitter → Memory store: reads graph (evidence: `src/artifacts/mod.rs`)
- Artifact emitter → JSON and diagram bundle: writes artifacts (evidence: `src/artifacts/mod.rs`)
- Artifact emitter → Render dispatcher: renders entities (evidence: `src/artifacts/mod.rs`)
- Command handlers → Sequence diagrams: extracts sequences (evidence: `src/cli/run/sequence.rs`)
- Sequence diagrams → Sequence traversal: walks function bodies (evidence: `src/sequence/mod.rs`)
- Sequence diagrams → Sequence language support: uses language support (evidence: `src/sequence/mod.rs`)
- Sequence diagrams → Sequence renderer: renders steps (evidence: `src/sequence/mod.rs`)
- Sequence renderer → Mermaid output: emits sequence (evidence: `src/sequence/render.rs`)
- Command handlers → Structural diff: compares revisions (evidence: `src/cli/run/mod.rs`)
- Command handlers → Cache maintenance: maintains cache (evidence: `src/cli/run/mod.rs`)
- Command handlers → Git source: selects Git ref (evidence: `src/cli/run/sequence.rs`)
- Language parsers → Analysis limits: applies bounds (evidence: `src/parser/mod.rs`)
