# bruits/satteri architecture

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

- Interactive diagram: https://gitdiagram.com/bruits/satteri
- Repository: https://github.com/bruits/satteri

## Overview

1. **Overall shape**
   Sätteri is a Rust-first Markdown/MDX processing pipeline with a TypeScript runtime wrapper. The Rust side does the heavy parsing, tree construction, and compilation work; the npm package provides the JavaScript-facing plugin API and the object model that plugins interact with.

2. **Primary end-to-end flow**
   Source text enters the Rust pipeline, is parsed into an internal Markdown/MDX tree, converted into typed ASTs, then either rendered/compiled further or exposed to JavaScript through N-API. The JS layer reconstructs typed node objects, runs plugins, and issues commands back into Rust when tree edits or rebuilds are needed.

3. **Parsing layer**
   `crates/satteri-pulldown-cmark` is the low-level parser. It is a fork of `pulldown-cmark` with MDX and other syntax extensions, backed by spec fixtures for CommonMark, GFM, footnotes, tables, wikilinks, math, and similar extensions. This crate is the front door for Markdown tokenization and block/inline parsing.

4. **Core tree and memory model**
   `crates/satteri-arena` provides the arena allocator and binary buffer primitives used to store parsed nodes efficiently. It includes line indexing, raw buffers, node codecs, and MDX-specific type encoding, which lets the parser and AST layers share compact, offset-based structures instead of heap-heavy object graphs.

5. **AST and tree transformation layer**
   `crates/satteri-ast` defines the typed MDAST and HAST node models, plus codecs, traversal, rebuild logic, text extraction, and conversion between representations. This is the main structural boundary between “parsed Markdown” and “renderable HTML/JS-friendly trees.”

6. **High-level Rust pipeline**
   `crates/satteri` is the top-level Rust API that ties parsing, conversion, and compilation together. If you were drawing the internal Rust architecture, this is the orchestration layer above the parser, arena, AST, and MDX compiler crates.

7. **MDX compilation**
   `crates/satteri-mdxjs-rs` is the Rust MDX-to-JavaScript compiler path. It is a fork of `mdxjs-rs` adapted to use OXC, with utilities for converting HAST into OXC structures and emitting JS/JSX-related transformations. This is the code path that turns MDX content into executable JS output.

8. **Plugin runtime in Rust**
   `crates/satteri-plugin-api` defines a Rust `Plugin` trait, typed visitors, plugin context/data, and a runner. This is the Rust-side extension boundary for running plugins and applying tree commands, with tests covering command handling, rebuild integration, and plugin basics.

9. **Native binding boundary**
   `crates/satteri-napi-binding` exposes the Rust pipeline to JavaScript through N-API. It is the bridge crate that packages the Rust engine for Node-compatible consumption, and its build script indicates it is part of the compiled native delivery path.

10. **TypeScript package architecture**
   `packages/satteri` is the JavaScript-facing layer. It contains the top-level compile entry point, command buffer handling, lazy property support, and separate MDAST/HAST reader, visitor, and materializer implementations. This package is where plugin authors interact with typed JS objects rather than raw Rust buffers.

11. **Rust-to-JS data model**
   The JS package mirrors Rust tree data into readable objects via “reader” and “materializer” layers, then traverses them with visitors. The presence of `command-buffer.ts`, `mdast-reader.ts`, `hast-reader.ts`, and corresponding materializers shows a deliberate split: Rust owns storage and computation, while TypeScript owns ergonomic traversal and plugin-facing APIs.

12. **Browser/WASI support**
   The npm package includes WASI/browser entrypoints such as `satteri_napi.wasi-browser.js`, `satteri_napi.wasi.cjs`, and worker files. That means the runtime boundary is not just Node/native N-API; there is also a WASI-compatible execution path for browser-like or sandboxed environments.

13. **Tests and validation strategy**
   The repo is heavily test-driven across both sides: Rust integration tests for AST behavior, rebuilds, and HTML output; JS tests for compile, visitors, plugin behavior, and materialization; and benchmark suites for pipeline performance. The parser crate additionally validates against upstream specification fixtures, which is important for architecture correctness in a syntax-heavy system.

14. **What to emphasize in a diagram**
   The key boundaries are: input text → Rust parsing/arena → typed ASTs → MDX/HTML compilation, and Rust core → N-API/WASI bridge → TypeScript plugin/runtime objects. The most important architectural idea is that Rust owns performance-critical syntax processing, while JavaScript owns ergonomic plugin composition and host integration.

Main entry points: [`crates/satteri/src/lib.rs`](https://github.com/bruits/satteri/blob/main/crates/satteri/src/lib.rs) (satteri), [`crates/satteri-ast/src/lib.rs`](https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/lib.rs) (AST), [`packages/satteri/src/index.ts`](https://github.com/bruits/satteri/blob/main/packages/satteri/src/index.ts) (satteri pkg), [`packages/satteri/src/plugin.ts`](https://github.com/bruits/satteri/blob/main/packages/satteri/src/plugin.ts) (Plugin runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rust["Rust core"]
  node_satteri_root["satteri<br/>Rust API<br/>[lib.rs]"]
  node_pulldown["Parser<br/>[lib.rs]"]
  node_arena[("Arena<br/>Memory model<br/>[lib.rs]")]
  node_ast["AST<br/>Typed trees<br/>[lib.rs]"]
  node_mdast_node["MDAST<br/>Markdown tree<br/>[mod.rs]"]
  node_hast_node["HAST<br/>HTML tree<br/>[mod.rs]"]
  node_mdxjs["MDX compiler<br/>JSX emit<br/>[lib.rs]"]
  node_plugin_api["Plugin API<br/>Plugin runtime<br/>[lib.rs]"]
  node_napi["N-API binding<br/>Native bridge<br/>[lib.rs]"]
end

subgraph group_js["TypeScript runtime"]
  node_satteri_js["satteri pkg<br/>TypeScript package<br/>[index.ts]"]
  node_compile["Compile<br/>Pipeline entry<br/>[compile.ts]"]
  node_command_buffer["Command buffer<br/>Edit commands<br/>[command-buffer.ts]"]
  node_mdast_reader["MDAST reader<br/>Rust buffer reader<br/>[mdast-reader.ts]"]
  node_hast_reader["HAST reader<br/>Rust buffer reader<br/>[hast-reader.ts]"]
  node_mdast_materializer["MDAST materializer<br/>JS objects"]
  node_hast_materializer["HAST materializer<br/>JS objects"]
  node_plugin_ts["Plugin runtime<br/>JS plugin API<br/>[plugin.ts]"]
  node_browser_entry["Browser/WASI<br/>Runtime targets<br/>[browser.js]"]
end

subgraph group_tooling["Tooling"]
  node_bench["Benchmarks<br/>Perf suite<br/>[pipeline.bench.ts]"]
end

node_satteri_root -->|"parse"| node_pulldown
node_satteri_root -->|"store"| node_arena
node_satteri_root -->|"convert"| node_ast
node_satteri_root -->|"compile"| node_mdxjs
node_ast -->|"defines"| node_mdast_node
node_ast -->|"defines"| node_hast_node
node_pulldown -->|"emit"| node_arena
node_pulldown -->|"seed"| node_ast
node_ast -->|"visit"| node_plugin_api
node_plugin_api -->|"commands"| node_command_buffer
node_plugin_api -->|"host bridge"| node_napi
node_napi -->|"load"| node_satteri_js
node_satteri_js -->|"entry"| node_compile
node_satteri_js -->|"plugins"| node_plugin_ts
node_compile -->|"read"| node_mdast_reader
node_compile -->|"read"| node_hast_reader
node_mdast_reader -->|"materialize"| node_mdast_materializer
node_hast_reader -->|"materialize"| node_hast_materializer
node_mdast_materializer -->|"traverse"| node_plugin_ts
node_hast_materializer -->|"traverse"| node_plugin_ts
node_plugin_ts -->|"edit"| node_command_buffer
node_satteri_js -->|"targets"| node_browser_entry
node_satteri_root -.->|"measured by"| node_bench

click node_satteri_root "https://github.com/bruits/satteri/blob/main/crates/satteri/src/lib.rs"
click node_pulldown "https://github.com/bruits/satteri/blob/main/crates/satteri-pulldown-cmark/src/lib.rs"
click node_arena "https://github.com/bruits/satteri/blob/main/crates/satteri-arena/src/lib.rs"
click node_ast "https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/lib.rs"
click node_mdast_node "https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/mdast/mod.rs"
click node_hast_node "https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/hast/mod.rs"
click node_mdxjs "https://github.com/bruits/satteri/blob/main/crates/satteri-mdxjs-rs/src/lib.rs"
click node_plugin_api "https://github.com/bruits/satteri/blob/main/crates/satteri-plugin-api/src/lib.rs"
click node_napi "https://github.com/bruits/satteri/blob/main/crates/satteri-napi-binding/src/lib.rs"
click node_satteri_js "https://github.com/bruits/satteri/blob/main/packages/satteri/src/index.ts"
click node_compile "https://github.com/bruits/satteri/blob/main/packages/satteri/src/compile.ts"
click node_command_buffer "https://github.com/bruits/satteri/blob/main/packages/satteri/src/command-buffer.ts"
click node_mdast_reader "https://github.com/bruits/satteri/blob/main/packages/satteri/src/mdast/mdast-reader.ts"
click node_hast_reader "https://github.com/bruits/satteri/blob/main/packages/satteri/src/hast/hast-reader.ts"
click node_mdast_materializer "https://github.com/bruits/satteri/blob/main/packages/satteri/src/mdast/mdast-materializer.ts"
click node_hast_materializer "https://github.com/bruits/satteri/blob/main/packages/satteri/src/hast/hast-materializer.ts"
click node_plugin_ts "https://github.com/bruits/satteri/blob/main/packages/satteri/src/plugin.ts"
click node_browser_entry "https://github.com/bruits/satteri/blob/main/packages/satteri/browser.js"
click node_bench "https://github.com/bruits/satteri/blob/main/packages/satteri/bench/pipeline.bench.ts"

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_satteri_root,node_pulldown,node_arena,node_ast,node_mdast_node,node_hast_node,node_mdxjs,node_plugin_api,node_napi toneBlue
class node_satteri_js,node_compile,node_command_buffer,node_mdast_reader,node_hast_reader,node_mdast_materializer,node_hast_materializer,node_plugin_ts,node_browser_entry toneAmber
class node_bench toneMint
```

## Components

### Rust core

Parsing, tree storage, AST, compilation, and native integration.

- [satteri](https://github.com/bruits/satteri/blob/main/crates/satteri/src/lib.rs): Rust API · Top-level Rust orchestration crate tying parsing, tree conversion, and compilation together. · `crates/satteri/src/lib.rs`
- [Parser](https://github.com/bruits/satteri/blob/main/crates/satteri-pulldown-cmark/src/lib.rs): Markdown/MDX parser · Forked pulldown-cmark front door for tokenization, block/inline parsing, and syntax extensions. · `crates/satteri-pulldown-cmark/src/lib.rs`
- [Arena](https://github.com/bruits/satteri/blob/main/crates/satteri-arena/src/lib.rs): Memory model · Compact arena allocator, raw buffers, codecs, and line indexing for parsed tree storage. · `crates/satteri-arena/src/lib.rs`
- [AST](https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/lib.rs): Typed trees · MDAST/HAST models, traversal, conversion, text extraction, rebuild logic, and render support. · `crates/satteri-ast/src/lib.rs`
- [MDAST](https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/mdast/mod.rs): Markdown tree · Typed Markdown AST representation and its codec layer. · `crates/satteri-ast/src/mdast/mod.rs`
- [HAST](https://github.com/bruits/satteri/blob/main/crates/satteri-ast/src/hast/mod.rs): HTML tree · Typed HTML AST representation, codec, and rendering layer. · `crates/satteri-ast/src/hast/mod.rs`
- [MDX compiler](https://github.com/bruits/satteri/blob/main/crates/satteri-mdxjs-rs/src/lib.rs): JSX emit · Rust MDX-to-JavaScript compilation path built around OXC and HAST conversion. · `crates/satteri-mdxjs-rs/src/lib.rs`
- [Plugin API](https://github.com/bruits/satteri/blob/main/crates/satteri-plugin-api/src/lib.rs): Plugin runtime · Rust plugin trait, typed visitors, context/data, command handling, and runner. · `crates/satteri-plugin-api/src/lib.rs`
- [N-API binding](https://github.com/bruits/satteri/blob/main/crates/satteri-napi-binding/src/lib.rs): Native bridge · Native boundary that exposes the Rust pipeline to JavaScript through N-API. · `crates/satteri-napi-binding/src/lib.rs`

### TypeScript runtime

Plugin-facing object model and host integration in the npm package.

- [satteri pkg](https://github.com/bruits/satteri/blob/main/packages/satteri/src/index.ts): TypeScript package · JavaScript-facing package exposing compile, plugin, and runtime entry points. · `packages/satteri/src/index.ts`
- [Compile](https://github.com/bruits/satteri/blob/main/packages/satteri/src/compile.ts): Pipeline entry · Top-level JS compile entry point that drives the document pipeline. · `packages/satteri/src/compile.ts`
- [Command buffer](https://github.com/bruits/satteri/blob/main/packages/satteri/src/command-buffer.ts): Edit commands · JS-side buffer for replaying tree edits and rebuild instructions. · `packages/satteri/src/command-buffer.ts`
- [MDAST reader](https://github.com/bruits/satteri/blob/main/packages/satteri/src/mdast/mdast-reader.ts): Rust buffer reader · Reconstructs typed Markdown nodes from Rust-owned storage for JS consumption. · `packages/satteri/src/mdast/mdast-reader.ts`
- [HAST reader](https://github.com/bruits/satteri/blob/main/packages/satteri/src/hast/hast-reader.ts): Rust buffer reader · Reconstructs typed HTML nodes from Rust-owned storage for JS consumption. · `packages/satteri/src/hast/hast-reader.ts`
- [MDAST materializer](https://github.com/bruits/satteri/blob/main/packages/satteri/src/mdast/mdast-materializer.ts): JS objects · Builds ergonomic Markdown node objects and lazy properties for plugins. · `packages/satteri/src/mdast/mdast-materializer.ts`
- [HAST materializer](https://github.com/bruits/satteri/blob/main/packages/satteri/src/hast/hast-materializer.ts): JS objects · Builds ergonomic HTML node objects and lazy properties for plugins. · `packages/satteri/src/hast/hast-materializer.ts`
- [Plugin runtime](https://github.com/bruits/satteri/blob/main/packages/satteri/src/plugin.ts): JS plugin API · TypeScript plugin layer with visitors, typed nodes, and host-facing extension points. · `packages/satteri/src/plugin.ts`
- [Browser/WASI](https://github.com/bruits/satteri/blob/main/packages/satteri/browser.js): Runtime targets · Browser and WASI entrypoints for non-Node execution paths. · `packages/satteri/browser.js`

### Tooling

Benchmarks and validation harnesses.

- [Benchmarks](https://github.com/bruits/satteri/blob/main/packages/satteri/bench/pipeline.bench.ts): Perf suite · Pipeline, memory, and comparison benchmarks for Rust and JS paths. · `packages/satteri/bench/pipeline.bench.ts`

## Connections

- satteri → Parser: parse · Orchestrates Markdown/MDX parsing.
- satteri → Arena: store · Uses compact arena-backed storage for parsed data.
- satteri → AST: convert · Builds typed trees and traversal structures.
- satteri → MDX compiler: compile · Runs MDX-to-JS compilation when needed.
- AST → MDAST: defines · Provides the Markdown AST model and codec.
- AST → HAST: defines · Provides the HTML AST model and codec.
- Parser → Arena: emit · Parses into compact arena-backed structures.
- Parser → AST: seed · Supplies parsed content for AST construction.
- AST → Plugin API: visit · Tree traversal and rebuild logic feed plugin execution.
- Plugin API → Command buffer: commands · Produces tree edit commands for replay in JS.
- Plugin API → N-API binding: host bridge · Exposes plugin/runtime hooks across the native boundary.
- N-API binding → satteri pkg: load · Delivers the native engine to the JS package.
- satteri pkg → Compile: entry · Public package entry dispatches into compilation.
- satteri pkg → Plugin runtime: plugins · Exports the plugin-facing TypeScript API.
- Compile → MDAST reader: read · Reads typed Markdown structures from Rust buffers.
- Compile → HAST reader: read · Reads typed HTML structures from Rust buffers.
- MDAST reader → MDAST materializer: materialize · Turns compact node data into JS objects.
- HAST reader → HAST materializer: materialize · Turns compact node data into JS objects.
- MDAST materializer → Plugin runtime: traverse · Feeds Markdown visitor APIs.
- HAST materializer → Plugin runtime: traverse · Feeds HTML visitor APIs.
- Plugin runtime → Command buffer: edit · Plugin actions are translated into command buffers.
- satteri pkg → Browser/WASI: targets · Provides browser and WASI-compatible execution paths.
- satteri → Benchmarks: measured by · Pipeline performance is exercised by benchmark tooling.
