Bonsai is a UI library developed by Jane Street for constructing performant, reactive web applications in OCaml, partly inspired by Elm. According to the source documentation, it is used to build almost all web applications inside Jane Street, ranging from the corporate directory to tools that monitor and interact with trading systems.

The framework implements components as purely functional state machines that are easily composable. A key feature is incrementalization—values don’t get recomputed until necessary. This applies not just to rendering but to every computed value within the framework.
Unlike many web frameworks that combine state, incrementality, and rendering into a single abstraction, Bonsai allows developers to compose these primitives independently. The source explains that “if you’re used to React, imagine if everything used something very similar to hooks, and state was managed outside of the component hierarchy.” State is decoupled from explicit components, enabling extensive lifecycle and scoping management as users interact with the page. For example, Bonsai automatically handles state management for collections of stateful UI components in interfaces like tabs, rather than requiring manual state hoisting.
Because Bonsai is written in OCaml, the same language and types can be used on both backend and frontend. The source notes this is particularly impactful for legibility and maintaining large web application codebases, especially when leveraging OCaml’s type system to reduce errors. At Jane Street, many internal systems previously had only terminal UIs, and the framework has made it straightforward to port existing types and business logic to the web.
Bonsai includes a powerful templating language, component-specific stylesheets, and whole-app automated testing capabilities. The testing system allows developers to programmatically manipulate UI elements and observe DOM changes. Tests can include mock server calls and changes to both the UI and underlying state, enabling component development without opening a browser.
The Bonsai ecosystem extends beyond web applications. Bonsai itself is generic for building incremental, composable state machines. Bonsai_web specializes this for interactive browser-based UIs, while Bonsai_term targets interactive terminal-based UIs. The source mentions a prototype called Bonsai_vr for reactive virtual-reality UIs was created for April Fools’ Day.
Documentation includes a quick start guide, composition comparisons, how-to articles, podcast episodes on UI framework design and tools for traders, a library of example websites, and API documentation.
Key facts
- Bonsai is Jane Street’s UI library written in OCaml for building performant, reactive web applications
- Components are implemented as purely functional state machines with incremental rendering and composability
- State management is decoupled from component hierarchy, enabling lifecycle and scoping control
- The same language and types can be used on both backend and frontend
- Bonsai includes a testing system allowing programmatic UI manipulation without opening a browser
- The framework also supports Bonsai_web for browser UIs, Bonsai_term for terminal UIs, and experimental Bonsai_vr for virtual-reality UIs
