How bruits/satteri works
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: src/lib.rs satteri · src/lib.rs AST · index.ts satteri pkg · plugin.ts Plugin runtime
Components 19
Rust core
Parsing, tree storage, AST, compilation, and native integration.
- satteri · Top-level Rust orchestration crate tying parsing, tree conversion, and compilation together.
crates/satteri/src/lib.rs - Parser · Forked pulldown-cmark front door for tokenization, block/inline parsing, and syntax extensions.
crates/satteri-pulldown-cmark/src/lib.rs - Arena · Compact arena allocator, raw buffers, codecs, and line indexing for parsed tree storage.
crates/satteri-arena/src/lib.rs - AST · MDAST/HAST models, traversal, conversion, text extraction, rebuild logic, and render support.
crates/satteri-ast/src/lib.rs - MDAST · Typed Markdown AST representation and its codec layer.
crates/satteri-ast/src/mdast/mod.rs - HAST · Typed HTML AST representation, codec, and rendering layer.
crates/satteri-ast/src/hast/mod.rs - MDX compiler · Rust MDX-to-JavaScript compilation path built around OXC and HAST conversion.
crates/satteri-mdxjs-rs/src/lib.rs - Plugin API · Rust plugin trait, typed visitors, context/data, command handling, and runner.
crates/satteri-plugin-api/src/lib.rs - N-API binding · 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 · JavaScript-facing package exposing compile, plugin, and runtime entry points.
packages/satteri/src/index.ts - Compile · Top-level JS compile entry point that drives the document pipeline.
packages/satteri/src/compile.ts - Command buffer · JS-side buffer for replaying tree edits and rebuild instructions.
packages/satteri/src/command-buffer.ts - MDAST reader · Reconstructs typed Markdown nodes from Rust-owned storage for JS consumption.
packages/satteri/src/mdast/mdast-reader.ts - HAST reader · Reconstructs typed HTML nodes from Rust-owned storage for JS consumption.
packages/satteri/src/hast/hast-reader.ts - MDAST materializer · Builds ergonomic Markdown node objects and lazy properties for plugins.
packages/satteri/src/mdast/mdast-materializer.ts - HAST materializer · Builds ergonomic HTML node objects and lazy properties for plugins.
packages/satteri/src/hast/hast-materializer.ts - Plugin runtime · TypeScript plugin layer with visitors, typed nodes, and host-facing extension points.
packages/satteri/src/plugin.ts - Browser/WASI · Browser and WASI entrypoints for non-Node execution paths.
packages/satteri/browser.js
Tooling
Benchmarks and validation harnesses.
- Benchmarks · Pipeline, memory, and comparison benchmarks for Rust and JS paths.
packages/satteri/bench/pipeline.bench.ts
Connections 23
- 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.