<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://systemprompt.io/files/images/logo.svg">
<source media="(prefers-color-scheme: light)" srcset="https://systemprompt.io/files/images/logo-dark.svg">
<img src="https://systemprompt.io/files/images/logo.svg" alt="systemprompt.io" width="180">
</picture>
### Production infrastructure for AI agents
[**Website**](https://systemprompt.io) · [**Documentation**](https://systemprompt.io/documentation/) · [**Guides**](https://systemprompt.io/guides) · [**Core**](https://github.com/systempromptio/systemprompt-core) · [**Template**](https://github.com/systempromptio/systemprompt-template) · [**Discord**](https://discord.gg/wkAbSuPWpr)
</div>
---
# systemprompt-templates
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/systempromptio/systemprompt-core/main/assets/readme/terminals/dark/domain-templates.svg">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/systempromptio/systemprompt-core/main/assets/readme/terminals/light/domain-templates.svg">
<img alt="systemprompt-templates terminal demo" src="https://raw.githubusercontent.com/systempromptio/systemprompt-core/main/assets/readme/terminals/dark/domain-templates.svg" width="100%">
</picture>
</div>
[](https://crates.io/crates/systemprompt-templates)
[](https://docs.rs/systemprompt-templates)
[](https://github.com/systempromptio/systemprompt-core/blob/main/LICENSE)
[](https://codecov.io/gh/systempromptio/systemprompt-core)
The rendering layer for config-as-code deployments you own. A Handlebars template registry with provider plugins, priority resolution, and filesystem discovery, so the HTML your deployment serves is defined in your tree, not a hosted theme.
**Layer**: Domain — business-logic modules that implement systemprompt.io features. Part of the [systemprompt-core](https://github.com/systempromptio/systemprompt-core) workspace.
## Overview
**Integrations** · [Extensible Architecture](https://systemprompt.io/features/extensible-architecture)
This crate provides the core template system for discovering, loading, and rendering HTML templates using Handlebars. It supports a plugin architecture with providers, loaders, extenders, and component renderers.
## Usage
```toml
[dependencies]
systemprompt-templates = "0.32"
```
```rust
use std::sync::Arc;
use systemprompt_templates::{
CoreTemplateProvider, FileSystemLoader, TemplateRegistryBuilder,
};
async fn setup_templates() -> Result<(), Box<dyn std::error::Error>> {
let provider = CoreTemplateProvider::discover_from("./templates").await?;
let loader = FileSystemLoader::new(vec!["./templates".into()]);
let registry = TemplateRegistryBuilder::new()
.with_provider(Arc::new(provider))
.with_loader(Arc::new(loader))
.build_and_init()
.await?;
let html = registry.render("page", &serde_json::json!({
"title": "Hello"
}))?;
Ok(())
}
```
## Module Layout
| `builder` | `TemplateRegistryBuilder` for fluent registry construction. |
| `core_provider` | `CoreTemplateProvider` for filesystem template discovery. |
| `embedded_defaults` | `EmbeddedDefaultsProvider` bundling the in-tree `defaults/templates/`. |
| `registry/` | `TemplateRegistry` and Handlebars wiring: lifecycle, render/lookup queries, and stats. |
## Modules
### `builder`
Provides `TemplateRegistryBuilder` for fluent construction of `TemplateRegistry` instances. Supports chaining `with_provider()`, `with_loader()`, `with_extender()`, `with_component()`, and `with_page_provider()` methods.
### `core_provider`
Implements `CoreTemplateProvider` which discovers HTML templates from a filesystem directory. Reads optional `templates.yaml` manifests for metadata and infers content types from template name suffixes (`-post`, `-list`).
### `embedded_defaults`
`EmbeddedDefaultsProvider` exposes the in-tree `defaults/templates/` bundle so consumers get a working engine without filesystem access.
### `error`
Defines `TemplateError` with variants for common failure modes (`NotFound`, `LoadError`, `CompileError`, `RenderError`, `NoLoader`, `NotInitialized`) plus the `TemplateResult` alias.
### `registry`
Core `TemplateRegistry` that coordinates providers, loaders, extenders, and component renderers. Uses Handlebars for compilation and rendering, registers a `json` helper for JSON-LD safe serialisation, and resolves template conflicts by priority (lower values win). Split into `lifecycle`, `queries`, and `stats` submodules.
## Priority System
Templates are resolved by priority where lower values take precedence:
| `EXTENSION_PRIORITY` | 500 | Override default templates |
| `DEFAULT_PRIORITY` | 1000 | Standard templates |
## License
BSL-1.1 (Business Source License). Source-available for evaluation, testing, and non-production use. Production use requires a commercial license. Each version converts to Apache 2.0 four years after publication. See [LICENSE](https://github.com/systempromptio/systemprompt-core/blob/main/LICENSE).
---
<div align="center">
**[systemprompt.io](https://systemprompt.io)** · **[Documentation](https://systemprompt.io/documentation/)** · **[Guides](https://systemprompt.io/guides)** · **[Live Demo](https://systemprompt.io/features/demo)** · **[Template](https://github.com/systempromptio/systemprompt-template)** · **[crates.io](https://crates.io/crates/systemprompt-templates)** · **[docs.rs](https://docs.rs/systemprompt-templates)** · **[Discord](https://discord.gg/wkAbSuPWpr)**
<sub>Domain layer · Own how your organization uses AI.</sub>
</div>