# jimmy-jung/richmarkdown architecture

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

- Interactive diagram: https://gitdiagram.com/jimmy-jung/richmarkdown
- Repository: https://github.com/jimmy-jung/richmarkdown

## Overview

RichMarkdown is a Swift package for native iOS Markdown rendering, with optional code highlighting, Mermaid diagrams, and a separate block editor. The main workflow accepts Markdown in SwiftUI or UIKit, parses it into a document, then renders text, tables, code, and equations; streaming updates use latest-wins work and cached parsing. The graph also preserves documented optional products and editing capabilities. Some implementation files were not sampled, so uncertain links are omitted; README-backed product relationships are cited to the README.

Main entry points: [`Sources/RichMarkdown/RichMarkdownUIView.swift`](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownUIView.swift) (UIKit view), [`Sources/RichMarkdown/RichMarkdownView.swift`](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownView.swift) (SwiftUI view), [`Sources/RichMarkdown/RichMarkdownRenderModel.swift`](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownRenderModel.swift) (Render model), [`Sources/RichMarkdownCore/DocumentBuilder.swift`](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/DocumentBuilder.swift) (Markdown parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_render["Native rendering"]
  node_swiftui["SwiftUI view"]
  node_uikit["UIKit view"]
  node_model["Render model"]
  node_theme["Theme and fonts"]
  node_inlinecode["Inline code decoration"]
end

subgraph group_core["Parsing and streaming"]
  node_builder["Markdown parser"]
  node_parsed["Parsed document"]
  node_limits["Input limits<br/>[InputLimits.swift]"]
  node_scanner["Math scanner<br/>[MathScanner.swift]"]
  node_tail["Streaming tail"]
  node_worker["Coalescing worker"]
  node_cache[("Parse cache<br/>[ParseCache.swift]")]
end

subgraph group_math["Equation rendering"]
  node_mathoptions["Dollar math options"]
  node_inlinemath["Inline math scanner"]
  node_mathservice["Math render service"]
  node_equation["Equation attachment"]
end

subgraph group_editor["Block editor"]
  node_editorui["Block text editor"]
  node_editormodel["Editor model"]
  node_blocks["Editor blocks<br/>[EditorBlock.swift]"]
  node_styler["Markdown styler"]
end

subgraph group_extensions["Optional code extensions"]
  node_highlight["Prism highlighter"]
  node_mermaidrenderer["Mermaid renderer"]
  node_mermaidview["Mermaid diagram view"]
  node_webview["Mermaid web renderer"]
end

node_caller(("App"))

node_caller -->|"supplies Markdown"| node_swiftui
node_caller -->|"supplies Markdown"| node_uikit
node_swiftui -->|"submits render"| node_model
node_uikit -->|"submits render"| node_model
node_model -->|"submits jobs"| node_worker
node_model -->|"reads and stores"| node_cache
node_model -->|"requests rasters"| node_mathservice
node_swiftui -->|"uses shared parser"| node_builder
node_uikit -->|"uses shared parser"| node_builder
node_builder -->|"builds document"| node_parsed
node_builder -->|"bounds input"| node_limits
node_builder -->|"scans math"| node_scanner
node_swiftui -->|"trims streaming text"| node_tail
node_uikit -->|"trims streaming text"| node_tail
node_model -->|"publishes parsed content"| node_parsed
node_mathservice -->|"checks render limits"| node_limits
node_inlinemath -->|"uses options"| node_mathoptions
node_builder -->|"accepts dollar options"| node_mathoptions
node_swiftui -->|"renders equations"| node_equation
node_uikit -->|"renders equations"| node_equation
node_editorui -->|"dispatches edits"| node_editormodel
node_editorui -->|"displays blocks"| node_blocks
node_editormodel -->|"manages blocks"| node_blocks
node_styler -->|"styles blocks"| node_blocks
node_editorui -->|"uses styling"| node_styler
node_caller -->|"edits documents"| node_editorui
node_uikit -->|"highlights code"| node_highlight
node_uikit -->|"replaces diagram blocks"| node_mermaidrenderer
node_mermaidrenderer -->|"creates diagram view"| node_mermaidview
node_mermaidview -->|"requests rendering"| node_webview
node_swiftui -->|"uses theme"| node_theme
node_uikit -->|"uses theme"| node_theme
node_editorui -->|"uses theme"| node_theme

click node_swiftui "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownView.swift"
click node_uikit "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownUIView.swift"
click node_model "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownRenderModel.swift"
click node_theme "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownTheme.swift"
click node_inlinecode "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/InlineCodeDecorationView.swift"
click node_builder "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/DocumentBuilder.swift"
click node_parsed "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/ParsedDocument.swift"
click node_limits "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/InputLimits.swift"
click node_scanner "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/MathScanner.swift"
click node_tail "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/StreamingTail.swift"
click node_worker "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/CoalescingWorker.swift"
click node_cache "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/ParseCache.swift"
click node_mathoptions "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/LatexDollarMathOptions.swift"
click node_inlinemath "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/LatexInlineMathScanner.swift"
click node_mathservice "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/MathRenderService.swift"
click node_equation "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/EquationTextAttachment.swift"
click node_editorui "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift"
click node_editormodel "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/BlockEditorModel.swift"
click node_blocks "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/EditorBlock.swift"
click node_styler "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/MarkdownStyler.swift"
click node_highlight "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownHighlight/PrismHighlighter.swift"
click node_mermaidrenderer "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownMermaid/MermaidDiagramRenderer.swift"
click node_mermaidview "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownMermaid/MermaidDiagramUIView.swift"
click node_webview "https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownMermaid/MermaidWebRenderer.swift"

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_swiftui,node_uikit,node_model,node_theme,node_inlinecode toneBlue
class node_builder,node_parsed,node_limits,node_scanner,node_tail,node_worker,node_cache toneAmber
class node_mathoptions,node_inlinemath,node_mathservice,node_equation toneMint
class node_editorui,node_editormodel,node_blocks,node_styler toneRose
class node_highlight,node_mermaidrenderer,node_mermaidview,node_webview,node_caller toneIndigo
```

## Components

### Native rendering

- [SwiftUI view](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownView.swift): `Sources/RichMarkdown/RichMarkdownView.swift`
- [UIKit view](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownUIView.swift): `Sources/RichMarkdown/RichMarkdownUIView.swift`
- [Render model](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownRenderModel.swift): `Sources/RichMarkdown/RichMarkdownRenderModel.swift`
- [Theme and fonts](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/RichMarkdownTheme.swift): `Sources/RichMarkdown/RichMarkdownTheme.swift`
- [Inline code decoration](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/InlineCodeDecorationView.swift): `Sources/RichMarkdown/InlineCodeDecorationView.swift`

### Parsing and streaming

- [Markdown parser](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/DocumentBuilder.swift): `Sources/RichMarkdownCore/DocumentBuilder.swift`
- [Parsed document](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/ParsedDocument.swift): `Sources/RichMarkdownCore/ParsedDocument.swift`
- [Input limits](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/InputLimits.swift): `Sources/RichMarkdownCore/InputLimits.swift`
- [Math scanner](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/MathScanner.swift): `Sources/RichMarkdownCore/MathScanner.swift`
- [Streaming tail](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/StreamingTail.swift): `Sources/RichMarkdownCore/StreamingTail.swift`
- [Coalescing worker](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownCore/CoalescingWorker.swift): `Sources/RichMarkdownCore/CoalescingWorker.swift`
- [Parse cache](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/ParseCache.swift): `Sources/RichMarkdown/ParseCache.swift`

### Equation rendering

- [Dollar math options](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/LatexDollarMathOptions.swift): `Sources/RichMarkdown/LatexDollarMathOptions.swift`
- [Inline math scanner](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/LatexInlineMathScanner.swift): `Sources/RichMarkdown/LatexInlineMathScanner.swift`
- [Math render service](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/MathRenderService.swift): `Sources/RichMarkdown/MathRenderService.swift`
- [Equation attachment](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdown/EquationTextAttachment.swift): `Sources/RichMarkdown/EquationTextAttachment.swift`

### Block editor

- [Block text editor](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift): `Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift`
- [Editor model](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/BlockEditorModel.swift): `Sources/RichMarkdownBlockEditor/BlockEditorModel.swift`
- [Editor blocks](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/EditorBlock.swift): `Sources/RichMarkdownBlockEditor/EditorBlock.swift`
- [Markdown styler](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownBlockEditor/MarkdownStyler.swift): `Sources/RichMarkdownBlockEditor/MarkdownStyler.swift`

### Optional code extensions

- [Prism highlighter](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownHighlight/PrismHighlighter.swift): `Sources/RichMarkdownHighlight/PrismHighlighter.swift`
- [Mermaid renderer](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownMermaid/MermaidDiagramRenderer.swift): `Sources/RichMarkdownMermaid/MermaidDiagramRenderer.swift`
- [Mermaid diagram view](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownMermaid/MermaidDiagramUIView.swift): `Sources/RichMarkdownMermaid/MermaidDiagramUIView.swift`
- [Mermaid web renderer](https://github.com/jimmy-jung/richmarkdown/blob/main/Sources/RichMarkdownMermaid/MermaidWebRenderer.swift): `Sources/RichMarkdownMermaid/MermaidWebRenderer.swift`

### Other components

- **App**

## Connections

- App → SwiftUI view: supplies Markdown
- App → UIKit view: supplies Markdown
- SwiftUI view → Render model: submits render (evidence: `Sources/RichMarkdown/RichMarkdownView.swift`)
- UIKit view → Render model: submits render (evidence: `Sources/RichMarkdown/RichMarkdownUIView.swift`)
- Render model → Coalescing worker: submits jobs (evidence: `Sources/RichMarkdown/RichMarkdownRenderModel.swift`)
- Render model → Parse cache: reads and stores (evidence: `Sources/RichMarkdown/RichMarkdownRenderModel.swift`)
- Render model → Math render service: requests rasters (evidence: `Sources/RichMarkdown/RichMarkdownRenderModel.swift`)
- SwiftUI view → Markdown parser: uses shared parser
- UIKit view → Markdown parser: uses shared parser
- Markdown parser → Parsed document: builds document (evidence: `Sources/RichMarkdownCore/DocumentBuilder.swift`)
- Markdown parser → Input limits: bounds input (evidence: `Sources/RichMarkdownCore/DocumentBuilder.swift`)
- Markdown parser → Math scanner: scans math (evidence: `Sources/RichMarkdownCore/DocumentBuilder.swift`)
- SwiftUI view → Streaming tail: trims streaming text (evidence: `Sources/RichMarkdown/RichMarkdownView.swift`)
- UIKit view → Streaming tail: trims streaming text (evidence: `Sources/RichMarkdown/RichMarkdownUIView.swift`)
- Render model → Parsed document: publishes parsed content (evidence: `Sources/RichMarkdown/RichMarkdownRenderModel.swift`)
- Math render service → Input limits: checks render limits (evidence: `Sources/RichMarkdown/MathRenderService.swift`)
- Inline math scanner → Dollar math options: uses options (evidence: `Sources/RichMarkdown/LatexInlineMathScanner.swift`)
- Markdown parser → Dollar math options: accepts dollar options (evidence: `Sources/RichMarkdownCore/DocumentBuilder.swift`)
- SwiftUI view → Equation attachment: renders equations (evidence: `Sources/RichMarkdown/EquationTextAttachment.swift`)
- UIKit view → Equation attachment: renders equations (evidence: `Sources/RichMarkdown/EquationTextAttachment.swift`)
- Block text editor → Editor model: dispatches edits (evidence: `Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift`)
- Block text editor → Editor blocks: displays blocks (evidence: `Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift`)
- Editor model → Editor blocks: manages blocks (evidence: `Sources/RichMarkdownBlockEditor/BlockEditorModel.swift`)
- Markdown styler → Editor blocks: styles blocks (evidence: `Sources/RichMarkdownBlockEditor/MarkdownStyler.swift`)
- Block text editor → Markdown styler: uses styling (evidence: `Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift`)
- App → Block text editor: edits documents
- UIKit view → Prism highlighter: highlights code
- UIKit view → Mermaid renderer: replaces diagram blocks
- Mermaid renderer → Mermaid diagram view: creates diagram view (evidence: `Sources/RichMarkdownMermaid/MermaidDiagramRenderer.swift`)
- Mermaid diagram view → Mermaid web renderer: requests rendering (evidence: `Sources/RichMarkdownMermaid/MermaidDiagramUIView.swift`)
- SwiftUI view → Theme and fonts: uses theme (evidence: `Sources/RichMarkdown/RichMarkdownView.swift`)
- UIKit view → Theme and fonts: uses theme (evidence: `Sources/RichMarkdown/RichMarkdownUIView.swift`)
- Block text editor → Theme and fonts: uses theme (evidence: `Sources/RichMarkdownBlockEditor/BlockDocumentTextEditor.swift`)
