# phothinmg/peisar architecture

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

- Interactive diagram: https://gitdiagram.com/phothinmg/peisar
- Repository: https://github.com/phothinmg/peisar

## Overview

Peisar is a Rust Markdown parser with Rust and Node.js surfaces. Its main workflow accepts Markdown, extracts frontmatter, builds a span-aware AST, optionally applies parser hooks and AST visitors, and can render HTML; it also exposes standalone YAML/TOML parsing capabilities. Edges are limited to relationships shown in the excerpts, SOURCE INDEX references, or README. Some implementation details—notably the YAML and frontmatter internals—were not sampled.

Main entry points: [`src/peisar_core/mod.rs`](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/mod.rs) (Document API), [`src/peisar_core/parsers/block.rs`](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/block.rs) (Block Parser), [`src/lib.rs`](https://github.com/phothinmg/peisar/blob/main/src/lib.rs) (Rust and N-API), [`src/peisar_core/parsers/mod.rs`](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/mod.rs) (AST Parse Orchestrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public APIs"]
  node_api_surface["Rust and N-API<br/>[lib.rs]"]
  node_core_entry["Document API<br/>[mod.rs]"]
end

subgraph group_parse["Markdown Parsing"]
  node_options["Parser Options<br/>[options.rs]"]
  node_config["Parser Configuration<br/>[config.rs]"]
  node_frontmatter["Frontmatter Extraction"]
  node_parser_entry["AST Parse Orchestrator<br/>[mod.rs]"]
  node_block_parser["Block Parser<br/>[block.rs]"]
  node_inline_parser["Inline Parser<br/>[inline.rs]"]
  node_table_parser["GFM Tables<br/>[table.rs]"]
  node_attribute_parser["Kramdown Attributes<br/>[attrs.rs]"]
end

subgraph group_ast["AST Extensions"]
  node_ast_tokens["AST Node Types<br/>[token.rs]"]
  node_source_spans["Source Spans<br/>[span.rs]"]
  node_token_attributes["Attribute Types<br/>[attrs.rs]"]
  node_parser_hooks["Parser Hooks<br/>[plugin.rs]"]
  node_visitor_control["Visitor Interop<br/>[control.rs]"]
end

subgraph group_render["Rendering"]
  node_html_renderer["HTML Renderer<br/>[html.rs]"]
  node_render_cache["Render Cache<br/>[render_cache.rs]"]
end

subgraph group_formats["Data Formats"]
  node_yaml_parser["YAML Parser<br/>[mod.rs]"]
  node_toml_parser["TOML Parser<br/>[mod.rs]"]
  node_toml_lexer["TOML Lexer<br/>[lexer.rs]"]
  node_toml_datetime["TOML Date-Time<br/>[date_time.rs]"]
end

node_rust_user(("Rust Consumer"))
node_node_user(("Node.js Consumer"))

node_rust_user -->|"uses Rust API"| node_api_surface
node_node_user -->|"uses Node API"| node_api_surface
node_api_surface -->|"exposes"| node_core_entry
node_core_entry -->|"extracts first"| node_frontmatter
node_core_entry -->|"parses body"| node_parser_entry
node_core_entry -->|"renders HTML"| node_html_renderer
node_core_entry -->|"caches output"| node_render_cache
node_parser_entry -->|"parses blocks"| node_block_parser
node_block_parser -->|"parses inline content"| node_inline_parser
node_block_parser -->|"builds tables"| node_table_parser
node_block_parser -->|"uses attributes"| node_attribute_parser
node_block_parser -->|"tries hooks"| node_parser_hooks
node_inline_parser -->|"tries hooks"| node_parser_hooks
node_table_parser -->|"parses cells"| node_inline_parser
node_parser_entry -->|"tracks positions"| node_source_spans
node_parser_entry -->|"builds AST"| node_ast_tokens
node_core_entry -->|"registers plugins"| node_visitor_control
node_visitor_control -->|"bridges callbacks"| node_parser_hooks
node_html_renderer -->|"uses configuration"| node_config
node_ast_tokens -->|"contains attributes"| node_token_attributes
node_api_surface -->|"exposes parser"| node_yaml_parser
node_api_surface -->|"exposes parser"| node_toml_parser
node_toml_parser -->|"uses lexer"| node_toml_lexer
node_toml_parser -->|"parses date-times"| node_toml_datetime

click node_api_surface "https://github.com/phothinmg/peisar/blob/main/src/lib.rs"
click node_core_entry "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/mod.rs"
click node_options "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/options.rs"
click node_config "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/config.rs"
click node_frontmatter "https://github.com/phothinmg/peisar/tree/main/src/peisar_core/frontmatter"
click node_parser_entry "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/mod.rs"
click node_block_parser "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/block.rs"
click node_inline_parser "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/inline.rs"
click node_table_parser "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/table.rs"
click node_attribute_parser "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/attrs.rs"
click node_ast_tokens "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/tokens/token.rs"
click node_source_spans "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/tokens/span.rs"
click node_token_attributes "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/tokens/attrs.rs"
click node_parser_hooks "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/plugin.rs"
click node_visitor_control "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/control.rs"
click node_html_renderer "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/html.rs"
click node_render_cache "https://github.com/phothinmg/peisar/blob/main/src/peisar_core/render_cache.rs"
click node_yaml_parser "https://github.com/phothinmg/peisar/blob/main/src/yaml/mod.rs"
click node_toml_parser "https://github.com/phothinmg/peisar/blob/main/src/toml/mod.rs"
click node_toml_lexer "https://github.com/phothinmg/peisar/blob/main/src/toml/lexer.rs"
click node_toml_datetime "https://github.com/phothinmg/peisar/blob/main/src/toml/date_time.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_api_surface,node_core_entry toneBlue
class node_options,node_config,node_frontmatter,node_parser_entry,node_block_parser,node_inline_parser,node_table_parser,node_attribute_parser toneAmber
class node_ast_tokens,node_source_spans,node_token_attributes,node_parser_hooks,node_visitor_control toneMint
class node_html_renderer,node_render_cache toneRose
class node_yaml_parser,node_toml_parser,node_toml_lexer,node_toml_datetime,node_rust_user,node_node_user toneIndigo
```

## Components

### Public APIs

- [Rust and N-API](https://github.com/phothinmg/peisar/blob/main/src/lib.rs): `src/lib.rs`
- [Document API](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/mod.rs): `src/peisar_core/mod.rs`

### Markdown Parsing

- [Parser Options](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/options.rs): `src/peisar_core/options.rs`
- [Parser Configuration](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/config.rs): `src/peisar_core/config.rs`
- [Frontmatter Extraction](https://github.com/phothinmg/peisar/tree/main/src/peisar_core/frontmatter): `src/peisar_core/frontmatter`
- [AST Parse Orchestrator](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/mod.rs): `src/peisar_core/parsers/mod.rs`
- [Block Parser](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/block.rs): `src/peisar_core/parsers/block.rs`
- [Inline Parser](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/inline.rs): `src/peisar_core/parsers/inline.rs`
- [GFM Tables](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/table.rs): `src/peisar_core/parsers/table.rs`
- [Kramdown Attributes](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/attrs.rs): `src/peisar_core/parsers/attrs.rs`

### AST Extensions

- [AST Node Types](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/tokens/token.rs): `src/peisar_core/tokens/token.rs`
- [Source Spans](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/tokens/span.rs): `src/peisar_core/tokens/span.rs`
- [Attribute Types](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/tokens/attrs.rs): `src/peisar_core/tokens/attrs.rs`
- [Parser Hooks](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/parsers/plugin.rs): `src/peisar_core/parsers/plugin.rs`
- [Visitor Interop](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/control.rs): `src/peisar_core/control.rs`

### Rendering

- [HTML Renderer](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/html.rs): `src/peisar_core/html.rs`
- [Render Cache](https://github.com/phothinmg/peisar/blob/main/src/peisar_core/render_cache.rs): `src/peisar_core/render_cache.rs`

### Data Formats

- [YAML Parser](https://github.com/phothinmg/peisar/blob/main/src/yaml/mod.rs): `src/yaml/mod.rs`
- [TOML Parser](https://github.com/phothinmg/peisar/blob/main/src/toml/mod.rs): `src/toml/mod.rs`
- [TOML Lexer](https://github.com/phothinmg/peisar/blob/main/src/toml/lexer.rs): `src/toml/lexer.rs`
- [TOML Date-Time](https://github.com/phothinmg/peisar/blob/main/src/toml/date_time.rs): `src/toml/date_time.rs`

### Other components

- **Rust Consumer**
- **Node.js Consumer**

## Connections

- Rust Consumer → Rust and N-API: uses Rust API (evidence: `README.md`)
- Node.js Consumer → Rust and N-API: uses Node API (evidence: `README.md`)
- Rust and N-API → Document API: exposes (evidence: `src/lib.rs`)
- Document API → Frontmatter Extraction: extracts first (evidence: `src/peisar_core/mod.rs`)
- Document API → AST Parse Orchestrator: parses body (evidence: `src/peisar_core/mod.rs`)
- Document API → HTML Renderer: renders HTML (evidence: `src/peisar_core/mod.rs`)
- Document API → Render Cache: caches output (evidence: `src/peisar_core/mod.rs`)
- AST Parse Orchestrator → Block Parser: parses blocks (evidence: `src/peisar_core/parsers/mod.rs`)
- Block Parser → Inline Parser: parses inline content (evidence: `src/peisar_core/parsers/block.rs`)
- Block Parser → GFM Tables: builds tables (evidence: `src/peisar_core/parsers/block.rs`)
- Block Parser → Kramdown Attributes: uses attributes (evidence: `src/peisar_core/parsers/block.rs`)
- Block Parser → Parser Hooks: tries hooks (evidence: `src/peisar_core/parsers/block.rs`)
- Inline Parser → Parser Hooks: tries hooks (evidence: `src/peisar_core/parsers/inline.rs`)
- GFM Tables → Inline Parser: parses cells (evidence: `src/peisar_core/parsers/table.rs`)
- AST Parse Orchestrator → Source Spans: tracks positions (evidence: `src/peisar_core/parsers/mod.rs`)
- AST Parse Orchestrator → AST Node Types: builds AST (evidence: `src/peisar_core/parsers/mod.rs`)
- Document API → Visitor Interop: registers plugins (evidence: `src/peisar_core/mod.rs`)
- Visitor Interop → Parser Hooks: bridges callbacks (evidence: `src/peisar_core/control.rs`)
- HTML Renderer → Parser Configuration: uses configuration (evidence: `src/peisar_core/html.rs`)
- AST Node Types → Attribute Types: contains attributes (evidence: `src/peisar_core/tokens/mod.rs`)
- Rust and N-API → YAML Parser: exposes parser (evidence: `src/lib.rs`)
- Rust and N-API → TOML Parser: exposes parser (evidence: `src/lib.rs`)
- TOML Parser → TOML Lexer: uses lexer (evidence: `src/toml/mod.rs`)
- TOML Parser → TOML Date-Time: parses date-times (evidence: `src/toml/mod.rs`)
