How anatta-rs/ast-to-mermaid works
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: pipeline.rs Analysis pipeline · parser/mod.rs Language parsers · run Command handlers · render/mod.rs Render dispatcher
Components 29
CLI and Git inputs
- CLI entry
src/bin/a2m.rs - Command dispatch
src/cli/run/mod.rs - Command options
src/cli/flags.rs - Git source
src/git_source.rs - Command handlers
src/cli/run
Code analysis
- Analysis pipeline
src/pipeline.rs - Language parsers
src/parser/mod.rs - Rust frontend
src/parser/rust.rs - Python frontend
src/parser/python.rs - Dart frontend
src/parser/dart.rs - Tree-sitter queries
src/parser/queries.rs - Code graph model
src/model.rs - Memory store
src/graph/memory.rs - Call resolver
src/resolve.rs - Analysis limits
src/limits.rs
Graph views
- Render dispatcher
src/render/mod.rs - Diagram levels
src/render - Call flow view
src/render/flow.rs - Sequence diagrams
src/sequence/mod.rs - Sequence traversal
src/sequence/visit.rs - Sequence language support
src/sequence/lang.rs - Sequence renderer
src/sequence/render.rs
Artifacts and history
- Content cache
src/cache.rs - Artifact emitter
src/artifacts/mod.rs - Structural diff
src/diff.rs - Cache maintenance
src/cli/run/gc.rs
Other components
- Engineer
- Mermaid output
- JSON and diagram bundle
Connections 35
- Engineer → CLI entry: invokes
- CLI entry → Command dispatch: dispatches
- Command dispatch → Command options: uses options
src/cli/run/mod.rs - Command dispatch → Command handlers: routes commands
src/cli/run/mod.rs - Command handlers → Analysis pipeline: analyzes sources
src/cli/run/index.rs - Analysis pipeline → Git source: reads revisions
src/pipeline.rs - Analysis pipeline → Content cache: uses cache
src/pipeline.rs - Analysis pipeline → Language parsers: parses files
src/pipeline.rs - Language parsers → Rust frontend: dispatches Rust
src/parser/mod.rs - Language parsers → Python frontend: dispatches Python
src/parser/mod.rs - Language parsers → Dart frontend: dispatches Dart
src/parser/mod.rs - Rust frontend → Tree-sitter queries: uses queries
src/parser/rust.rs - Python frontend → Tree-sitter queries: uses queries
src/parser/python.rs - Language parsers → Code graph model: produces atoms
src/parser/mod.rs - Analysis pipeline → Memory store: populates store
src/pipeline.rs - Analysis pipeline → Call resolver: resolves calls
src/pipeline.rs - Call resolver → Memory store: updates edges
src/resolve.rs - Language parsers → Memory store: applies parse results
src/parser/mod.rs - Analysis pipeline → Render dispatcher: renders analysis
src/pipeline.rs - Render dispatcher → Diagram levels: dispatches levels
src/render/mod.rs - Render dispatcher → Call flow view: dispatches flow
src/render/mod.rs - Render dispatcher → Mermaid output: returns diagram
src/render/mod.rs - Analysis pipeline → Artifact emitter: emits bundle
src/pipeline.rs - Artifact emitter → Memory store: reads graph
src/artifacts/mod.rs - Artifact emitter → JSON and diagram bundle: writes artifacts
src/artifacts/mod.rs - Artifact emitter → Render dispatcher: renders entities
src/artifacts/mod.rs - Command handlers → Sequence diagrams: extracts sequences
src/cli/run/sequence.rs - Sequence diagrams → Sequence traversal: walks function bodies
src/sequence/mod.rs - Sequence diagrams → Sequence language support: uses language support
src/sequence/mod.rs - Sequence diagrams → Sequence renderer: renders steps
src/sequence/mod.rs - Sequence renderer → Mermaid output: emits sequence
src/sequence/render.rs - Command handlers → Structural diff: compares revisions
src/cli/run/mod.rs - Command handlers → Cache maintenance: maintains cache
src/cli/run/mod.rs - Command handlers → Git source: selects Git ref
src/cli/run/sequence.rs - Language parsers → Analysis limits: applies bounds
src/parser/mod.rs