How boundaryml/baml works
Major Components
• Core Engine & Libraries: Use the “engine” directory as the heart of the system. Within it, there are multiple submodules such as:
– baml-lib (which includes baml-core, baml-log, baml-types, parser-database, jinja-runtime, jsonish, etc.)
– baml-runtime (handles prompt execution, CLI commands, streaming, IR processing, retry policies, LLM client orchestration)
– baml-rpc (facilitates remote procedure calls/debugging, trace events)
– CLI (simple command line interface to trigger operations)
• Language Clients & Code Generation: The “language_client_*” directories (for Python, Ruby, TypeScript, etc.) show that the project supports auto-generated client libraries for different ecosystems. In addition, there is the “language_client_codegen” component and associated templates (for Python, Ruby, TypeScript) that drive this code generation.
• Frontend & Interactive Tools:
– The TypeScript “fiddle-frontend” and “fiddle-proxy” directories provide a web playground for testing prompts.
– VSCode integration exists in the “typescript/vscode-ext” folder to give developers interactive tools (such as viewing full prompt code, network request previews, etc.).
• Documentation & Developer Tools:
– “fern” – a large documentation and guide corpus primarily written in Markdown.
– “docs” folder and integration tests under “integ-tests” add test harnesses and example projects.
• External LLM Providers:
Relationships and Interactions
• The client libraries (language_client_*) rely on the core engine to generate the necessary bindings which are produced by the code generation tools. Represent them as consumers of engine APIs.
• The CLI tools in the engine and additional integration tests show how developers interact with the system to run prompts and observe streaming responses.
• Frontend components (Fiddle-frontend, VSCode Extension) serve as the user interface layer that communicates (via APIs or workspaces) with the underlying engine and runtime components.
• Documentation (“fern”, “docs”) is linked to all major components as an aid to both usage and developer onboarding.
Architectural Patterns and Design Principles
• Modularity: The engine is split into clear libraries (parsing, runtime, diagnostics, LLM client orchestration, codegen) that are largely independent.
• Layered Architecture: The design separates low-level processing (parsing, IR generation, validation) from high-level client and presentation layers (language clients, web interface, IDE extensions).
• Extensibility & Interoperability: The language client design and code generation indicate that BAML is intended to be integrated into many development environments in a plug-and-play fashion.
• Separation of Concern: Prompts (functions) are separated from language-specific bindings and from the logic needed to handle streaming, retries, and fallback strategies.
• Use of open standards and clear interfacing (e.g., via file-based prompts, JSON-friendly schemas, streaming APIs).