burokku docs plan crate-split.md

Crate split #

Status: step 2, burokku-core and the burokku facade, is built on refactor/burokku-core, and step 3, Registry::on_shutdown and burokku-llrt, on refactor/burokku-llrt above it; see Built. The Decided items were settled on 2026-10-26, except 16, settled on 2026-10-27. The test API in test-api.md changed first, as the user decided on 2026-10-27, and is merged.

Decided marks what the user settled; Proposed marks my recommendations that still need a decision.

Why #

Everything lives in crates/burokku today: the engine, Burokku's own features in src/features/, and the application API. Inside one crate the features can reach any pub(crate) item of the engine, and they do, so "features use the public API" is a review rule the compiler does not check. Nor can anyone tell from the crates which one provides a feature.

The goal is a split of responsibility so clear that a user can tell which crate provides each feature.

Decided #

  1. One crate per feature, under crates/features/.

  2. burokku is the public API; every other crate is internal and unstable. Applications depend on burokku alone.

  3. Burokku's own features use the public API as much as possible. Some may not, the window for one.

  4. The engine never names a feature.

  5. LLRT is not part of the engine. burokku-llrt takes install_llrt_globals, llrt_lifecycle.js, and the llrt_modules and llrt_utils git dependencies, and core drops LLRT.

  6. A public shutdown hook replaces the host's knowledge of LLRT. Registry::on_shutdown takes an async closure over the runtime, and hooks run in reverse registration order, before the runtime is dropped. Every hook runs: one extension's failure does not affect the next. Today prepare_llrt_shutdown (crates/burokku/src/app.rs) evaluates globalThis.__burokkuShutdown() and sleeps 10 ms for LLRT's timer task; that becomes LLRT's own hook:

    registry.on_shutdown(async |runtime: &Runtime| {
        runtime.eval::<()>("globalThis.__burokkuShutdown()").await?;
        // LLRT's timer task releases its callbacks before the context drops.
        tokio::time::sleep(Duration::from_millis(10)).await;
        Ok(())
    });
    

    It is a Registry closure rather than an Extension method because an async trait method cannot be called on Box<dyn Extension>.

  7. llrt is a cargo feature, on by default for now. The React and Solid examples need its timers. It may leave the defaults later; an app without it gets bare QuickJS. burokku forwards llrt-default, llrt-console, and the rest to burokku-llrt.

  8. Text, scroll, and the resize observer get no cargo features. They are too small to split that way, so they are always on.

  9. No feature's own types are public.

  10. LLRT's tests move with it. The tests that hold a setInterval to check cleanup at shutdown move to burokku-llrt or burokku/tests; core keeps a test that a test extension's shutdown hook runs.

  11. div, flex, and grid are declared in a crate of their own, burokku-containers. Builtin<S>, the generic definition that declares them today, is a temporary name and is not made public.

  12. The window's resizeTo, close, and open move into WindowDefinition::define_class.

  13. text and input stay inside core for now, coupled as they are today, and split out as burokku-text once the API they need is defined. Until then that API is simply the current state. They are the one exception to 4.

  14. Scroll leaves core.

  15. The code becomes easier to test, rather than tests being moved around it.

  16. Extension::before orders LLRT ahead of the UI tree. LLRT and the DOM both define a global CustomEvent, and a later plugin's global replaces an earlier one's. Nodes dispatch only the UI tree's, so it must win; LLRT's cannot be reused, since core cannot depend on an optional crate. before lists the extensions that must register after this one, and LLRT names UI_TREE there. Chosen by the user on 2026-10-27.

Proposed #

My recommendations, not decided yet:

  1. The window stays in core, as the engine's own element rather than a feature (see Window).
  2. How 2 and 3 of Decided are enforced (see Rules).
  3. The crate docs of core and of each feature crate say that it is internal, carries no semver promise, and that apps depend on burokku.
  4. A feature crate exports only its extension and its NAME, for the facade to register.
  5. Extension names move to their crates (burokku_llrt::NAME and so on). Core keeps UI_TREE, and TEXT while text lives in core.
  6. The containers are always on too, like text, scroll, and the resize observer.
  7. A failing shutdown hook is still reported, as LLRT's cleanup failure is today.
  8. The style types stay in core and become public in element: CommonStyle, FlexContainer, GridContainer, FlexStyle, GridStyle, ContainerLayout. The layout stage reads them, and a third-party element may then lay out as flex or grid too.
  9. taffy's geometry is re-exported as burokku::geometry. The public API already passes taffy's types (Point, Size, AbsoluteAxis), so the features take them from it instead of depending on taffy. Asked "re-export taffy's types, or define our own?", the user answered "yes"; this reads it as re-export.

Layout #

The crates follow the Decided items; the details rest on the Proposed ones.

Cargo.toml   members = ["crates/burokku", "crates/core", "crates/native", "crates/runtime",
                        "crates/test_macro", "crates/features/*", "example/*"]
             (listed by name: "crates/*" would match crates/features, which has
              no Cargo.toml, and break the workspace)
crates/
├── native/  runtime/  test_macro/        internal, unchanged; test_macro is
│                                     published as burokku-test-macro, since
│                                     burokku::test re-exports ui_tree!
│
├── core/          burokku-core       internal. The engine; its `pub` IS the public API
│   ├── Cargo.toml                    features: internal, test-support, bench (no LLRT)
│   ├── src/
│   │   ├── lib.rs                    #![deny(unreachable_pub)]; pub use runtime;
│   │   │                             `pub mod` only for:
│   │   │   ── public: burokku re-exports these modules whole ──
│   │   ├── app.rs                    CoreBuilder, Backend, NativeBackend, errors;
│   │   │                             runs the shutdown hooks
│   │   ├── extension.rs              Extension, Registry (+ on_shutdown),
│   │   │                             ExtensionError, UI_TREE, TEXT (for now)
│   │   ├── element.rs                ElementDefinition, ElementInstance, PaintList,
│   │   │                             layers, style traits and style types,
│   │   │                             paragraph surface, script helpers
│   │   ├── feature.rs                FeatureSlot, TreeFeature, DispatchStep, give/take
│   │   ├── events.rs + events/       pointer, keyboard, mouse, editing
│   │   ├── view.rs                   TreeView, NodeView, NodeLayout
│   │   ├── geometry.rs               taffy's Point, Size, Rect, AbsoluteAxis…
│   │   ├── test.rs                   cfg(test-support): TestApp, TestBackend
│   │   │   ── for exceptions, never re-exported ──
│   │   ├── internal.rs               cfg(feature = "internal"), #[doc(hidden)]; empty
│   │   │   ── private, pub(crate) only ──
│   │   ├── tree.rs + tree/           UITree, Node, absorb, content, slots, styles
│   │   │   ├── window.rs             <window>, the only element core declares
│   │   │   ├── testing.rs            cfg(test): div/flex/grid for core's unit tests
│   │   │   └── js.rs + js/           DOM API + scripts/
│   │   ├── interaction.rs + interaction/   focus, selection, editing, pointer
│   │   ├── text.rs + text/           the text engine
│   │   ├── layout.rs + layout/       scene.rs + scene/
│   │   ├── request.rs                HostRequest; features push through give
│   │   │                             context methods
│   │   ├── host.rs + host/           one turn: input → dispatch → stages →
│   │   │                             present → drain requests
│   │   │   ── here for now, until burokku-text splits out ──
│   │   └── features.rs + features/
│   │       ├── text.rs + text/       <text>; imports core's public modules only
│   │       └── input.rs              <input>
│   └── tests/                        integration tests on stand-in extensions
│
├── features/                         internal. Each depends on burokku-core without
│   │                                 `internal` and exports its extension + NAME
│   ├── containers/       burokku-containers        <div> <flex> <grid>
│   ├── llrt/             burokku-llrt              LLRT globals, lifecycle.js,
│   │                                               shutdown hook; llrt-* features
│   ├── scroll/           burokku-scroll
│   └── resize_observer/  burokku-resize-observer
│
└── burokku/       burokku            the public API: the only crate apps name
    ├── Cargo.toml                    containers, scroll, resize-observer always on;
    │                                 default = ["llrt"], the only cargo feature;
    │                                 llrt-* forward to burokku-llrt
    ├── src/
    │   ├── lib.rs                    pub use burokku_core::{app items, extension,
    │   │                             element, feature, events, view, geometry,
    │   │                             runtime}; Plugin, RuntimeBuilder at the root
    │   ├── app.rs                    Burokku::builder() = CoreBuilder + built-ins
    │   │                             (+ llrt when on)
    │   └── test.rs                   core's TestApp + native's test types
    └── tests/main.rs + …             cross-feature tests, one binary, burokku:: only

CoreBuilder registers one extension of its own, UI_TREE, which brings the window and the DOM API, and, while it lives in core, text. Everything else comes from the facade. Shared dependency versions (taffy, rquickjs, native) move to [workspace.dependencies].

Rules #

Proposed: how 2 and 3 of Decided are enforced. The crate boundary is what makes "features use the public API" a compile error.

  1. Only burokku is public. Core declares only its public modules as pub mod and denies unreachable_pub, so every pub item in core is reachable from one of them. burokku re-exports those modules whole, never item lists, so the two cannot drift.
  2. Features use the public API. A feature crate depends on burokku-core without internal. CI checks each feature crate on its own with cargo check -p, since a workspace-wide build unifies cargo features and would hide an undeclared use.
  3. An exception is declared in a manifest. A crate that needs internals writes burokku-core = { …, features = ["internal"] }, so every exception is one line to grep for. internal starts empty: no crate needs it today.

Window #

Proposed, except item 2, which is Decided (12).

The window stays in core. The host already reads its own types: window sync (crates/burokku/src/ui/host/window.rs) reads WindowStyle, WindowInstance, and the title, width, and height attributes; layout treats ElementRole::Root specially; the registry refuses Root and Parents::App to any other type. Moving it out would need a public native window API for the host to read windows through.

It still registers as an application's element does:

  1. UI_TREE registers WindowDefinition through the public Registry::element. Registry::builtin_element is deleted.
  2. resizeTo, close, and open move into WindowDefinition::define_class. Core's DOM setup stops creating the Window class and copying them onto it (crates/burokku/src/ui/js_bindings/facade.rs); the generic class setup creates the class from class_name().
  3. ElementTag::WINDOW keeps id 0, and the registry keeps asserting that the window registers first and alone holds the window's place.

Text and input stay in core for now #

That they stay, and split out once their API is defined, is Decided (13). The rest of this section is Proposed.

text and input stay inside core, in core/src/features/, until the engine offers editing to extensions. Today input's value, selectionStart, selectionEnd, and setSelectionRange are core's own code, which reaches selection in Interaction, the native text input context, and script wrapper bookkeeping, and core's DOM setup attaches them to the InputElement class by name. Until the split this stays as it is.

While they live in core:

  1. They import only core's public modules, so the split stays a move, checked by a CI step that greps core/src/features/ for imports of private modules.
  2. CoreBuilder registers them itself, as it registers UI_TREE.
  3. The leaks they have today wait for the split: input.rs reaches ui::events::editing, traits::StyleProperties, and PropertyError, and core's text-engine tests import features::text::testing::paragraph_input.

burokku-text splits out when:

  1. the engine offers editing to extensions through the public API, designed then, so that burokku-text writes the four members itself in InputDefinition::define_class; and
  2. core's text and editing tests no longer need text or input (see Testing).

Testing #

That the code becomes easier to test is Decided (15). How is Proposed:

  1. Core tests the engine's mechanisms on stand-ins. Where a test needs an element or a feature, it uses a minimal stand-in extension instead of a real feature: a slot that records its hooks instead of scroll, a minimal editable leaf instead of input. Core's tests use <text> about 189 times, <input> about 15 times, and overflow: scroll about 42 times today. The stand-ins are written on the public API in core/tests/, where the compiler allows nothing else; tests that need internals stay unit tests, and tree/testing.rs keeps div, flex, and grid for them under cfg(test). A stand-in that cannot be written on the public API marks a gap in it.
  2. Each feature crate tests itself on CoreBuilder and itself alone.
  3. Cross-feature behavior is tested in burokku/tests, one binary.
  4. None of this works on today's test API, which builds fixtures on &mut UITree through TestApp::with_ui_tree and ui_tree!; UITree becomes private to core. test-api.md plans the public tier these tests build on: a Fixture that offers only what script can already do, ui_tree! unchanged on it, a test app from chosen extensions, and fixed fonts.

Core cannot take a feature crate as a dev-dependency: the cycle compiles core twice, and the two copies' traits do not match.

What moves #

Proposed: what each move takes, beyond what Decided says.

  1. burokku-llrt. install_llrt_globals and llrt_lifecycle.js from crates/burokku/src/extension/builtin.rs; the LLRT git dependencies and the llrt-* cargo features; the two shutdown tests that hold a setInterval (shutdown_stops_runtime_and_driver in app.rs, and the test in ui/host/test/tests.rs that cleans up LLRT before a panicking test body unwinds). Core keeps a test that a stand-in extension's shutdown hook runs. builder_options_present_layers_and_input_reaches_js in the same file runs text, ResizeObserver, and a setInterval together, so it moves to burokku/tests.
  2. burokku-containers. The div, flex, and grid declarations, written on public items (ContentModel's fields are already public). ElementTag::DIV, FLEX, GRID, and BUILTINS go; every use is in a test. default_definitions() shrinks to the window, and text and input while they live in core. Core's DOM setup stops creating Div, Flex, and Grid.
  3. burokku-scroll. Scroll's code reaches nothing private outside one test helper, scroll_to, which takes &mut UITree and is rewritten on TestApp. It does import native::compositor's layer types and taffy's geometry directly; it takes them from element and geometry instead (see 7). Core's scene tests that import features::scroll move with it; core tests whose result depends on scrolling move to burokku/tests; tests that only mention overflow: scroll stay in core, where it is a style value that does not scroll. Its helpers on core's SlotGive are methods of a private trait first (extension-traits.md), so they move unchanged.
  4. burokku-resize-observer. Uses taffy's Size through burokku::geometry.
  5. TestApp::with_ui_tree (ui/host/test.rs) leaves the public API: it hands out &mut UITree, which becomes private. It stays pub(crate) for core's unit tests, and the public tier builds fixtures through Fixture instead (test-api.md).
  6. AGENTS.md and the reference docs follow the new paths.
  7. Feature crates depend on no internal crate but core. They take native's layer types from element, which re-exports them already, rquickjs from runtime, which core re-exports as burokku does today, and taffy's types from geometry. A crate's own private dependencies, such as the resize observer's slotmap, stay its own.

Rejected #

Rejected by the user on 2026-10-26, with why:

  1. A public installer for input's members (a define_editing_methods(context, prototype) that copies core's methods onto a class). It hands core's implementation of a feature's surface to the feature through the public API: rule 3 holds only on paper, and the members' semantics become a stable promise. Public API is capabilities an extension builds on.
  2. Keeping scroll in core because core's tests use it. Test coupling is what the split removes, by moving tests; it is never a reason to keep a feature in core. Text stays only for a gap in the API.
  3. A cargo feature per built-in for text, scroll, the resize observer, and the containers. They are too small to split that way.
  4. Making Builtin<S> public as a ContainerDefinition<S>. Builtin<S> is a temporary name, not a design; it survives only in core's cfg(test) helper.
  5. Public feature types, such as reading a node's scroll state from another extension.
  6. LLRT inside core. It registers through the public API already; only the host's shutdown call tied it to the engine.

Steps #

Proposed order, after the test API in test-api.md:

  1. Core's tests on stand-ins, independent of text, input, and scroll where they test the engine's mechanisms.
  2. burokku-core and the burokku facade: core's public modules, geometry, the rules and CI checks.
  3. Registry::on_shutdown and burokku-llrt.
  4. burokku-containers, with the window's methods moving into its define_class.
  5. burokku-scroll.
  6. burokku-resize-observer.
  7. Later, once the engine offers editing: burokku-text.

Built #

Proposed: what I chose while building, beyond the items above, for review. Each pull request adds its own rows.

Pull request on refactor/burokku-core (step 2):

Item Choice Why
the move crates/burokku moves to crates/core in a commit of its own; the facade comes in the next git follows every file's history across the move
core's modules element, feature, events, view, geometry, and extension; test with test-support; bench and internal hidden the Layout's list
NodeId, ScrollExtent in view a feature reads them from the tree; neither defines an element or a feature
script helpers with_slot, with_tree_feature, with_instance, node_id, node_layout, reveal, and element_promise stay in element the Layout puts them there; an element's script class calls them
events one file: the input a slot or tree feature hears, such as PointerInput, KeyInput, and CaptureInput, and native's WheelPhase the DOM events in ui/events are the engine's, not an extension's
the private tree ui/ keeps its layout; the Layout's tree/, interaction/, text/, layout/, and host/ wait this pull request changes what is public, not where private code lives
core's test and bench stay inline in lib.rs, as on main they only re-export
the style types public in element (Proposed 8), flat beside CommonStyle: the containers' styles, their value types such as Dimension, RgbaColor, and the align, flex, and grid types, the Justify* and AlignSelf aliases, StyleProperties, and PropertyError with ui private, nothing outside core could name the types CommonStyle's fields and ElementStyle name, so no crate could write a style of its own; on main, burokku::ui was public and named them
ElementRegistryError, StyleRevisions, Line in extension, view, and geometry ExtensionError::Elements, NodeRevisions::style, and ItemStyle's grid lines name them
Node::kind, Element::tag pub(crate) NodeKind is how the tree stores a node, and ElementTag names div, flex, and grid; nothing outside the engine read them, and Node::element and Node::text remain
what stays unnameable the sealed traits, DispatchInstance and the two Sealeds, and what only they reach: UITree, InstanceCall, the lent types an outside crate can neither implement nor call them; -W unnameable_types lists only these
bench's re-exports ElementTag and UITree carry cfg_attr(not(feature = "bench"), allow(unreachable_pub)) only the hidden bench module re-exports them, so without bench nothing reaches them
doc tests core's start with a hidden # extern crate burokku_core as burokku; they read as an app's code does, burokku::…
core's crate doc says core is internal, carries no semver promise, and that apps depend on burokku (Proposed 3)
the facade only lib.rs: pub use burokku_core::{element, events, extension, feature, geometry, runtime, view}, the app types and Plugin and RuntimeBuilder at the root, and test, TestApp, and TestBackend with test-support; no app.rs yet Burokku::builder() stays core's until LLRT and the containers move out, in steps 3 and 4
the facade's features default = ["llrt-default"], test-support, llrt-default, and llrt-console, each forwarding to core, which keeps them LLRT leaves core in step 3
[workspace.dependencies] only what two or more crates share: llrt_modules, llrt_utils, native, rquickjs, runtime, thiserror, and tokio taffy is core's alone until scroll moves out, since FeatureSlot::style takes taffy's Style; the examples keep their own burokku path, since each sets its own default features
the CI check a step in the clippy job runs cargo check --locked --manifest-path on core's, burokku's, and each crates/features/* manifest, before the JavaScript build Rule 2 says cargo check -p; checking one package either way unifies no other crate's features, and a manifest glob checks each feature crate once it exists, without naming it in CI; no library crate embeds an example's bundle
burokku-native's dev-dependency still burokku, now the facade nothing in native uses it, as on main; removing it is not this step's

Pull request on refactor/burokku-llrt (step 3):

Item Choice Why
Extension::before names that must register after this one; a name no extension has is not an error, unlike requires; a name several extensions share places this one before all of them; a cycle through requires or before is the existing RequirementCycle an extension that is absent orders nothing; RequirementCycle already says "the order cannot be satisfied"
Registry::on_shutdown takes impl AsyncFnOnce(&Runtime) -> runtime::Result<()> + 'static, erased through a private RunOnShutdown trait Decided 6's async closure, stored without a public boxed-future type
a failing hook reported as shutdown hook of extension "<name>" failed: <error>; several failures are joined with ; into the one RuntimeStatus::Failed (Proposed 7) names the extension, as LLRT's cleanup failure did; every hook still runs (Decided 6)
hooks on a script failure run too, and their failures are dropped LLRT's timers must still be released; the script's error is the one reported
core's builder core keeps Burokku::builder() with the extensions it holds; BurokkuBuilder::new, Default, build, run, and Burokku<TestBackend>::run_test become pub(crate) the Layout's CoreBuilder would rename a type about 290 call sites name; new and Default equal core's builder(), which lacks LLRT, and an app runs through BurokkuBuilder::run alone
the facade's Burokku a type of its own in app.rs: builder() calls core's and adds burokku_llrt::LlrtExtension with the llrt feature the Layout's app.rs
the facade's features default = ["llrt-default"]; llrt gates the dependency, and llrt-default and llrt-console turn it on and forward the Layout says default = ["llrt"], which would drop the LLRT modules main has on by default
burokku-llrt's exports NAME and LlrtExtension (Proposed 4, 5); extension::LLRT leaves core the facade registers it by type
burokku-llrt's features default = ["llrt-default"] of its own; the facade depends on it with default-features = false its own tests run with main's modules; the facade's features decide for apps
burokku-llrt's tests on BurokkuBuilder::core() and LlrtExtension alone: the two shutdown tests, the panicking test body, and that a node dispatches the DOM's CustomEvent beside LLRT's Testing 2; the last fails without before
BurokkuBuilder::core() no longer has LLRT's globals, so no timers Decided 5
cross-feature tests builder_options_present_layers_and_input_reaches_js and settling_shows_what_an_observer_changed_after_the_layout move to burokku/tests/main.rs; the facade dev-depends on itself with test-support the second also needs setTimeout and the resize observer; a self dev-dependency is how an integration test turns on a feature of its own crate
core's shutdown tests a stand-in hook reads the runtime before it stops; hooks run last-registered first and a failure is reported; a panicking test body runs them before unwinding Testing 1, Decided 10
a_script_queued_before_shutdown_never_runs counts the scripts run in Rust instead of evaluating after shutdown it evaluated in the 10 ms LLRT's hook sleeps, so it failed once core lost LLRT
workspace members crates/features/* is listed the Layout's list
[workspace.dependencies] unchanged; llrt_modules and llrt_utils are now shared by native and burokku-llrt