Skip to main content

Markdown dependency analyzer โ€” extract all dependencies, generate diagrams and charts

Project description

mdflow

AI Cost Tracking

PyPI Version Python License AI Cost Human Time Model

  • ๐Ÿค– LLM usage: $0.6000 (4 commits)
  • ๐Ÿ‘ค Human dev: ~$200 (2.0h @ $100/h, 30min dedup)

Generated on 2026-05-03 using openrouter/qwen/qwen3-coder-next


Markdown dependency analyzer โ€” extract all dependencies, generate diagrams and charts.

mdflow parses Markdown files and extracts every possible structural element: headings, links, fenced code blocks (including markpact:* embedded file references), list items, TOON/YAML quality sections, and document metadata. It then generates Mermaid diagrams, HTML reports, and Markdown summaries.


What it extracts

Element Details
Headings Full H1โ€“H6 hierarchy, anchor slugs
Links [text](href) โ€” classified as internal / external / anchor / image
Code blocks Language, content, line range, markpact:type path=... metadata
List items Depth, parent heading, clean text
TOON sections ALERTS, REFACTOR, HOTSPOTS, HEALTH, NEXT, RISKS, PIPELINESโ€ฆ
Document metadata ## Metadata key/value lists
Cross-doc dependencies Links between files, markpact embedded file paths

Generated outputs

Output Description
{stem}_report.html Self-contained HTML report with all diagrams (Mermaid.js)
{stem}_report.md Markdown summary with inline Mermaid
{stem}_heading_mindmap.mermaid Mindmap of heading hierarchy
{stem}_section_flow.mermaid Section flowchart with code/link annotations
{stem}_code_pie.mermaid Pie chart of code blocks by language
{stem}_markpact_graph.mermaid Graph of embedded file references
{stem}_alerts_graph.mermaid TOON alerts & refactor tasks flowchart
{stem}_workflow.mermaid DOQL workflow steps diagram
dependency_graph.html Cross-document dependency graph (directory scan)

Installation

# Clone or copy the mdflow/ directory, then:
pip install -e .
# No mandatory dependencies โ€” pure stdlib.

Usage

Python API

from mdflow import MdFlow

flow = MdFlow()

# โ”€โ”€ Single file โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
doc = flow.parse("SUMR.md")

print(doc.title)                        # "Ze ลบrรณdeล‚"
print(len(doc.headings))               # 24
print([ts.name for ts in doc.toon_sections])  # ['HEALTH', 'REFACTOR', ...]
print(doc.metadata)                    # {'name': 'redsl', 'version': '1.2.45', ...}

# Access markpact embedded file references
for cb in doc.markpact_blocks:
    print(f"markpact:{cb.markpact_type}  path={cb.markpact_path}")

# Get TOON quality metrics
metrics = flow.toon_metrics(doc)
print(metrics["health"])               # {'cc_mean': 20.0, 'critical': 7}
print(metrics["refactors"][:3])        # list of refactor tasks

# Get all Mermaid diagrams as strings (no files written)
diagrams = flow.diagrams(doc)
print(diagrams["section_flow"])        # flowchart TD ...

# Generate reports to disk
flow.report(doc, "output/")            # writes HTML + MD + .mermaid files

# โ”€โ”€ Directory scan โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
docs, graph = flow.scan("docs/", "output/")
print(f"{len(docs)} files, {len(graph.edges)} dependency edges")

CLI

# Analyze a single file
mdflow analyze SUMR.md --output output/

# Select formats
mdflow analyze SUMR.md --format html,md

# Scan a directory
mdflow scan docs/ --output output/

# Print a specific Mermaid diagram to stdout
mdflow diagram SUMR.md --diagram section_flow
mdflow diagram SUMR.md --diagram list        # list available diagrams

# Write diagram to file
mdflow diagram SUMR.md --diagram alerts_graph -o alerts.mermaid

Examples

The examples/ directory is organized by complexity and use case:

Basic

  • 01_parse_single_file.py โ€” Parse and inspect a single document
  • 02_generate_reports.py โ€” Generate HTML, Markdown, and Mermaid reports
  • 03_diagrams_as_strings.py โ€” Get diagrams as strings (no file I/O)
  • 04_cli_basics.sh โ€” CLI commands: analyze, scan, diagram

Advanced

  • 01_directory_scan.py โ€” Scan a directory and build dependency graphs
  • 02_toon_analysis.py โ€” Extract TOON quality metrics (HEALTH, ALERTS, REFACTOR, ...)
  • 03_custom_diagram_pipeline.py โ€” Build custom HTML with selected diagrams

API / Extensibility

  • 01_low_level_parser.py โ€” Use MdParser directly for fine-grained control
  • 02_custom_analyzer.py โ€” Build your own analyzer on top of MdDocument

Sample data files in examples/data/ are cross-linked so directory-scan examples produce realistic dependency graphs.

Run any example from the project root:

python examples/basic/01_parse_single_file.py
python examples/advanced/01_directory_scan.py
python examples/api/02_custom_analyzer.py

See examples/README.md for full details.


Architecture

mdflow/
โ”œโ”€โ”€ __init__.py         โ† MdFlow faรงade (high-level API)
โ”œโ”€โ”€ models.py           โ† Data classes: MdDocument, DependencyGraph, โ€ฆ
โ”œโ”€โ”€ parser.py           โ† Core Markdown parser (stdlib only)
โ”œโ”€โ”€ analyzers/
โ”‚   โ””โ”€โ”€ __init__.py     โ† DependencyAnalyzer, StructureAnalyzer,
โ”‚                          CodeInventoryAnalyzer, ToonAnalyzer
โ”œโ”€โ”€ generators/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ mermaid.py      โ† All Mermaid diagram generators
โ”‚   โ”œโ”€โ”€ html.py         โ† Self-contained HTML report
โ”‚   โ””โ”€โ”€ markdown.py     โ† Markdown summary report
โ””โ”€โ”€ cli.py              โ† argparse CLI entry point

Supported TOON sections

mdflow recognises these TOON section names inside toon / yaml code blocks and in blocks tagged markpact:analysis:

ALERTS ยท REFACTOR ยท HOTSPOTS ยท HEALTH ยท NEXT ยท RISKS ยท PIPELINES ยท DUPLICATES ยท WARNINGS ยท MODULES ยท EVOLUTION ยท COUPLING


Extension points

  • Custom extractor: subclass or monkey-patch MdParser
  • Custom diagram: call flow.diagrams(doc) and extend the mermaid module
  • Graphviz output: install graphviz Python package and use DependencyGraph data directly

License

Licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdflow-0.1.5.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdflow-0.1.5-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file mdflow-0.1.5.tar.gz.

File metadata

  • Download URL: mdflow-0.1.5.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mdflow-0.1.5.tar.gz
Algorithm Hash digest
SHA256 2f2aeb449115ee5049a9b9ce4699f0c22e0339367cf6b2720d49c6fee1d17b67
MD5 ac38bea8d34feceda840147afd014db6
BLAKE2b-256 fd7b72357fe38defc73a11a103d90d9a7375499a0d5892a442b4bb3129a63a55

See more details on using hashes here.

File details

Details for the file mdflow-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mdflow-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mdflow-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 33ab4271ec3eedc6b0b8b43e806d63bd5cc9b82b4adc64da9b0ec51e7e4eec4b
MD5 3afebba9290279abf250851e8cd5cab8
BLAKE2b-256 271a1ce584a746a7ee50844312ebc2775c9acff1e8745b2b899e35e795d8b331

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page