# lzayou/md-toc architecture

> Architecture diagram of the GitHub repository lzayou/md-toc, 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/lzayou/md-toc
- Repository: https://github.com/lzayou/md-toc

## Overview

md-toc is a small, dependency-free Markdown TOC generator. Its main workflow is a user invoking the CLI with a file or piped input; the CLI parses and filters headings, derives GitHub-style anchors, renders a nested or flat list, and writes it to standard output. The core module also exposes these operations as a Python API. The source excerpts show the CLI-to-core calls and internal parsing stages; README usage documents the user-facing modes and options.

Main entry points: [`md_toc/cli.py`](https://github.com/lzayou/md-toc/blob/main/md_toc/cli.py) (CLI), [`md_toc/core.py`](https://github.com/lzayou/md-toc/blob/main/md_toc/core.py) (Heading parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_user(("User"))
node_markdown["Markdown input"]
node_cli["CLI<br/>[cli.py]"]
node_parser["Heading parser<br/>[core.py]"]
node_anchors["Anchor generation<br/>[core.py]"]
node_renderer["TOC renderer<br/>[core.py]"]
node_stdout["Standard output"]

node_user -->|"invokes"| node_cli
node_cli -->|"reads"| node_markdown
node_cli -->|"parses headings"| node_parser
node_parser -->|"derives anchors"| node_anchors
node_cli -->|"renders headings"| node_renderer
node_cli -->|"prints TOC"| node_stdout

click node_cli "https://github.com/lzayou/md-toc/blob/main/md_toc/cli.py"
click node_parser "https://github.com/lzayou/md-toc/blob/main/md_toc/core.py"
click node_anchors "https://github.com/lzayou/md-toc/blob/main/md_toc/core.py"
click node_renderer "https://github.com/lzayou/md-toc/blob/main/md_toc/core.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_user toneBlue
class node_markdown,node_stdout toneIndigo
class node_cli,node_parser,node_anchors,node_renderer toneTeal
```

## Components

### Other components

- **User**
- **Markdown input**
- [CLI](https://github.com/lzayou/md-toc/blob/main/md_toc/cli.py): `md_toc/cli.py`
- [Heading parser](https://github.com/lzayou/md-toc/blob/main/md_toc/core.py): `md_toc/core.py`
- [Anchor generation](https://github.com/lzayou/md-toc/blob/main/md_toc/core.py): `md_toc/core.py`
- [TOC renderer](https://github.com/lzayou/md-toc/blob/main/md_toc/core.py): `md_toc/core.py`
- **Standard output**

## Connections

- User → CLI: invokes (evidence: `README.md`)
- CLI → Markdown input: reads (evidence: `md_toc/cli.py`)
- CLI → Heading parser: parses headings (evidence: `md_toc/cli.py`)
- Heading parser → Anchor generation: derives anchors (evidence: `md_toc/core.py`)
- CLI → TOC renderer: renders headings (evidence: `md_toc/cli.py`)
- CLI → Standard output: prints TOC (evidence: `md_toc/cli.py`)
