# fasouto/termaid architecture

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

- Interactive diagram: https://gitdiagram.com/fasouto/termaid
- Repository: https://github.com/fasouto/termaid

## Overview

termaid turns Mermaid text into terminal diagrams through its Python API, CLI, and Claude Code integration. The main workflow is input acquisition, diagram-type parsing into diagram data, then layout/routing and character rendering; sequence diagrams use a dedicated renderer. It also offers Markdown extraction, Rich styling, and a Textual widget. The graph reflects documented capabilities and source-index references; unsampled diagram-specific implementations are grouped by directory, and their internal links are omitted where the excerpts do not establish the calls.

Main entry points: [`src/termaid/__init__.py`](https://github.com/fasouto/termaid/blob/main/src/termaid/__init__.py) (Python API), [`src/termaid/renderer/draw.py`](https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/draw.py) (Flowchart renderer), [`src/termaid/cli.py`](https://github.com/fasouto/termaid/blob/main/src/termaid/cli.py) (CLI), [`src/termaid/renderer/sequence.py`](https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/sequence.py) (Sequence renderer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI<br/>[cli.py]"]
  node_api["Python API<br/>[__init__.py]"]
  node_hook["Claude hook<br/>[claude_hook.py]"]
  node_markdown["Markdown ingestion<br/>[markdown.py]"]
  node_ingest["Input ingestion<br/>[ingest.py]"]
end

subgraph group_parse["Parsing and models"]
  node_parser_dispatch["Diagram parsers"]
  node_flow_parser["Flowchart parser<br/>[flowchart.py]"]
  node_sequence_parser["Sequence parser<br/>[sequence.py]"]
  node_diagram_models["Diagram models"]
  node_graph_model["Graph model<br/>[model.py]"]
  node_graph_shapes["Node shapes<br/>[shapes.py]"]
end

subgraph group_layout["Layout and routing"]
  node_grid["Grid layout<br/>[grid.py]"]
  node_layers["Layer ordering<br/>[layers.py]"]
  node_placement["Node placement<br/>[placement.py]"]
  node_notes["Note layout<br/>[notes.py]"]
  node_router["Edge routing<br/>[router.py]"]
end

subgraph group_render["Rendering and output"]
  node_draw["Flowchart renderer<br/>[draw.py]"]
  node_sequence_renderer["Sequence renderer<br/>[sequence.py]"]
  node_renderer_family["Diagram renderers"]
  node_canvas["Character canvas<br/>[canvas.py]"]
  node_charset["Character sets<br/>[charset.py]"]
  node_shape_drawers["Shape drawing"]
  node_rich["Rich output<br/>[rich.py]"]
  node_styled["Styled output<br/>[styled.py]"]
  node_widget["Textual widget<br/>[widget.py]"]
end

node_user(("Diagram author"))

node_user -->|"provides input"| node_cli
node_user -->|"provides diagram"| node_api
node_user -->|"requests diagrams"| node_hook
node_cli -->|"reads input"| node_ingest
node_cli -->|"renders Markdown"| node_markdown
node_cli -->|"calls API"| node_api
node_hook -->|"renders diagrams"| node_api
node_api -->|"selects parser"| node_parser_dispatch
node_api -->|"parses sequence"| node_sequence_parser
node_api -->|"parses flowchart"| node_flow_parser
node_api -->|"renders sequence"| node_sequence_renderer
node_api -->|"renders graph"| node_draw
node_flow_parser -->|"builds graph"| node_graph_model
node_flow_parser -->|"assigns shapes"| node_graph_shapes
node_sequence_parser -->|"builds sequence data"| node_diagram_models
node_sequence_renderer -->|"renders sequence data"| node_diagram_models
node_grid -->|"uses ordering"| node_layers
node_grid -->|"places nodes"| node_placement
node_grid -->|"positions notes"| node_notes
node_draw -->|"computes layout"| node_grid
node_draw -->|"routes edges"| node_router
node_draw -->|"draws onto"| node_canvas
node_draw -->|"draws nodes"| node_shape_drawers
node_sequence_renderer -->|"draws onto"| node_canvas
node_sequence_renderer -->|"uses characters"| node_charset
node_shape_drawers -->|"draws onto"| node_canvas
node_shape_drawers -->|"uses characters"| node_charset
node_api -->|"supports styled rendering"| node_rich
node_api -->|"returns styled chunks"| node_styled
node_api -->|"offers widget"| node_widget
node_renderer_family -.->|"shares drawing surface"| node_canvas

click node_cli "https://github.com/fasouto/termaid/blob/main/src/termaid/cli.py"
click node_api "https://github.com/fasouto/termaid/blob/main/src/termaid/__init__.py"
click node_hook "https://github.com/fasouto/termaid/blob/main/src/termaid/claude_hook.py"
click node_markdown "https://github.com/fasouto/termaid/blob/main/src/termaid/markdown.py"
click node_ingest "https://github.com/fasouto/termaid/blob/main/src/termaid/ingest.py"
click node_parser_dispatch "https://github.com/fasouto/termaid/tree/main/src/termaid/parser"
click node_flow_parser "https://github.com/fasouto/termaid/blob/main/src/termaid/parser/flowchart.py"
click node_sequence_parser "https://github.com/fasouto/termaid/blob/main/src/termaid/parser/sequence.py"
click node_diagram_models "https://github.com/fasouto/termaid/tree/main/src/termaid/model"
click node_graph_model "https://github.com/fasouto/termaid/blob/main/src/termaid/graph/model.py"
click node_graph_shapes "https://github.com/fasouto/termaid/blob/main/src/termaid/graph/shapes.py"
click node_grid "https://github.com/fasouto/termaid/blob/main/src/termaid/layout/grid.py"
click node_layers "https://github.com/fasouto/termaid/blob/main/src/termaid/layout/layers.py"
click node_placement "https://github.com/fasouto/termaid/blob/main/src/termaid/layout/placement.py"
click node_notes "https://github.com/fasouto/termaid/blob/main/src/termaid/layout/notes.py"
click node_router "https://github.com/fasouto/termaid/blob/main/src/termaid/routing/router.py"
click node_draw "https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/draw.py"
click node_sequence_renderer "https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/sequence.py"
click node_renderer_family "https://github.com/fasouto/termaid/tree/main/src/termaid/renderer"
click node_canvas "https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/canvas.py"
click node_charset "https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/charset.py"
click node_shape_drawers "https://github.com/fasouto/termaid/tree/main/src/termaid/renderer/shapes"
click node_rich "https://github.com/fasouto/termaid/blob/main/src/termaid/output/rich.py"
click node_styled "https://github.com/fasouto/termaid/blob/main/src/termaid/output/styled.py"
click node_widget "https://github.com/fasouto/termaid/blob/main/src/termaid/output/widget.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_cli,node_api,node_hook,node_markdown,node_ingest toneBlue
class node_parser_dispatch,node_flow_parser,node_sequence_parser,node_diagram_models,node_graph_model,node_graph_shapes toneAmber
class node_grid,node_layers,node_placement,node_notes,node_router toneMint
class node_draw,node_sequence_renderer,node_renderer_family,node_canvas,node_charset,node_shape_drawers,node_rich,node_styled,node_widget toneRose
class node_user toneIndigo
```

## Components

### Entry points

- [CLI](https://github.com/fasouto/termaid/blob/main/src/termaid/cli.py): `src/termaid/cli.py`
- [Python API](https://github.com/fasouto/termaid/blob/main/src/termaid/__init__.py): `src/termaid/__init__.py`
- [Claude hook](https://github.com/fasouto/termaid/blob/main/src/termaid/claude_hook.py): `src/termaid/claude_hook.py`
- [Markdown ingestion](https://github.com/fasouto/termaid/blob/main/src/termaid/markdown.py): `src/termaid/markdown.py`
- [Input ingestion](https://github.com/fasouto/termaid/blob/main/src/termaid/ingest.py): `src/termaid/ingest.py`

### Parsing and models

- [Diagram parsers](https://github.com/fasouto/termaid/tree/main/src/termaid/parser): `src/termaid/parser`
- [Flowchart parser](https://github.com/fasouto/termaid/blob/main/src/termaid/parser/flowchart.py): `src/termaid/parser/flowchart.py`
- [Sequence parser](https://github.com/fasouto/termaid/blob/main/src/termaid/parser/sequence.py): `src/termaid/parser/sequence.py`
- [Diagram models](https://github.com/fasouto/termaid/tree/main/src/termaid/model): `src/termaid/model`
- [Graph model](https://github.com/fasouto/termaid/blob/main/src/termaid/graph/model.py): `src/termaid/graph/model.py`
- [Node shapes](https://github.com/fasouto/termaid/blob/main/src/termaid/graph/shapes.py): `src/termaid/graph/shapes.py`

### Layout and routing

- [Grid layout](https://github.com/fasouto/termaid/blob/main/src/termaid/layout/grid.py): `src/termaid/layout/grid.py`
- [Layer ordering](https://github.com/fasouto/termaid/blob/main/src/termaid/layout/layers.py): `src/termaid/layout/layers.py`
- [Node placement](https://github.com/fasouto/termaid/blob/main/src/termaid/layout/placement.py): `src/termaid/layout/placement.py`
- [Note layout](https://github.com/fasouto/termaid/blob/main/src/termaid/layout/notes.py): `src/termaid/layout/notes.py`
- [Edge routing](https://github.com/fasouto/termaid/blob/main/src/termaid/routing/router.py): `src/termaid/routing/router.py`

### Rendering and output

- [Flowchart renderer](https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/draw.py): `src/termaid/renderer/draw.py`
- [Sequence renderer](https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/sequence.py): `src/termaid/renderer/sequence.py`
- [Diagram renderers](https://github.com/fasouto/termaid/tree/main/src/termaid/renderer): `src/termaid/renderer`
- [Character canvas](https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/canvas.py): `src/termaid/renderer/canvas.py`
- [Character sets](https://github.com/fasouto/termaid/blob/main/src/termaid/renderer/charset.py): `src/termaid/renderer/charset.py`
- [Shape drawing](https://github.com/fasouto/termaid/tree/main/src/termaid/renderer/shapes): `src/termaid/renderer/shapes`
- [Rich output](https://github.com/fasouto/termaid/blob/main/src/termaid/output/rich.py): `src/termaid/output/rich.py`
- [Styled output](https://github.com/fasouto/termaid/blob/main/src/termaid/output/styled.py): `src/termaid/output/styled.py`
- [Textual widget](https://github.com/fasouto/termaid/blob/main/src/termaid/output/widget.py): `src/termaid/output/widget.py`

### Other components

- **Diagram author**

## Connections

- Diagram author → CLI: provides input (evidence: `README.md`)
- Diagram author → Python API: provides diagram (evidence: `README.md`)
- Diagram author → Claude hook: requests diagrams (evidence: `README.md`)
- CLI → Input ingestion: reads input (evidence: `src/termaid/cli.py`)
- CLI → Markdown ingestion: renders Markdown (evidence: `src/termaid/cli.py`)
- CLI → Python API: calls API (evidence: `src/termaid/cli.py`)
- Claude hook → Python API: renders diagrams (evidence: `src/termaid/claude_hook.py`)
- Python API → Diagram parsers: selects parser (evidence: `src/termaid/__init__.py`)
- Python API → Sequence parser: parses sequence (evidence: `src/termaid/__init__.py`)
- Python API → Flowchart parser: parses flowchart (evidence: `src/termaid/__init__.py`)
- Python API → Sequence renderer: renders sequence (evidence: `src/termaid/__init__.py`)
- Python API → Flowchart renderer: renders graph (evidence: `src/termaid/__init__.py`)
- Flowchart parser → Graph model: builds graph (evidence: `src/termaid/parser/flowchart.py`)
- Flowchart parser → Node shapes: assigns shapes (evidence: `src/termaid/parser/flowchart.py`)
- Sequence parser → Diagram models: builds sequence data (evidence: `src/termaid/parser/sequence.py`)
- Sequence renderer → Diagram models: renders sequence data (evidence: `src/termaid/renderer/sequence.py`)
- Grid layout → Layer ordering: uses ordering (evidence: `src/termaid/layout/grid.py`)
- Grid layout → Node placement: places nodes (evidence: `src/termaid/layout/grid.py`)
- Grid layout → Note layout: positions notes (evidence: `src/termaid/layout/grid.py`)
- Flowchart renderer → Grid layout: computes layout (evidence: `src/termaid/renderer/draw.py`)
- Flowchart renderer → Edge routing: routes edges (evidence: `src/termaid/renderer/draw.py`)
- Flowchart renderer → Character canvas: draws onto (evidence: `src/termaid/renderer/draw.py`)
- Flowchart renderer → Shape drawing: draws nodes (evidence: `src/termaid/renderer/draw.py`)
- Sequence renderer → Character canvas: draws onto (evidence: `src/termaid/renderer/sequence.py`)
- Sequence renderer → Character sets: uses characters (evidence: `src/termaid/renderer/sequence.py`)
- Shape drawing → Character canvas: draws onto (evidence: `src/termaid/renderer/shapes/__init__.py`)
- Shape drawing → Character sets: uses characters (evidence: `src/termaid/renderer/shapes/__init__.py`)
- Python API → Rich output: supports styled rendering (evidence: `README.md`)
- Python API → Styled output: returns styled chunks (evidence: `src/termaid/__init__.py`)
- Python API → Textual widget: offers widget (evidence: `README.md`)
- Diagram renderers → Character canvas: shares drawing surface (evidence: `src/termaid/renderer/sequence.py`)
