Templates

Template System Overview

StudioBrain is a schema-driven platform. Every entity type — characters, locations, items, recipes, plants, tracks, episodes — is defined by a template: a Markdown file with YAML frontmatter that declares the entity’s fields, validation rules, and rendering behavior. Templates are the nouns of StudioBrain; plugins are the verbs that operate on them.

What Is a Template?

A template is a Markdown file (typically *_TEMPLATE.md) whose YAML frontmatter declares:

  • entity_type — the machine name (e.g. character, biome, recipe)
  • template_category — how the template renders (entity, document, map, rule, skill)
  • fields — frontmatter keys with default values, plus optional field_config hints (type, options, widget, reference_type, validation)
  • display_name, description, icon — optional presentation metadata
  • folder_name, file_prefix — where instances of this entity are stored on disk
  • template_version — version string for update notifications

The body of the Markdown file (below the frontmatter) provides default content, documentation, or generation prompts for AI.

Minimal Example

Entity templates declare fields as plain frontmatter keys whose values are the defaults. Types, options, widgets, and reference targets are optional hints in field_config; without a hint the type is inferred from the default value and the field name.

---
entity_type: recipe
template_category: entity
folder_name: Recipes
file_prefix: RECIPE
template_version: "1.0"
cuisine: Italian
prep_time: ""
ingredients: ""
steps: ""
field_config:
  cuisine:
    type: enum
    options: [Italian, Mexican, Japanese, French, Indian, American, Thai, Other]
---
 
# Recipe Template
 
Use this template for cooking recipes. The AI will generate ingredients
and step-by-step instructions based on the cuisine and any notes you provide.

When a user creates a new Recipe entity, StudioBrain derives a schema from this template and renders a form with the declared fields. The entity instance is saved as a Markdown file in the Recipes/ folder with RECIPE_ as the filename prefix. Document templates (template_category: document) instead declare sections and a fields: map keyed by field name (for example title: { type: string, required: true }).

Template Categories

The template_category field determines how StudioBrain renders and interacts with entities of that type. There are five categories:

CategoryRenderingDirectoryExample Types
entitySchema-driven form with typed fields_Templates/Standard/Character, Location, Item, Biome, Recipe
documentRich text editor with structured sections_Templates/Standard/Documents/Style Bible, GDD, Screenplay, Lore Bible
mapSpatial renderer with markers and layers_Templates/Standard/Maps/World Map, Dungeon Map, Floor Plan
ruleConstraint definitions for AI generation_Rules/Character Rules, World Consistency
skillAI capability with prompts and parameters_Skills/Character Voice, Narrative Helper

Entity types are fully dynamic. Users can create new types by adding a template file — no code changes required. StudioBrain is not limited to game development; templates exist for film/TV, books, music, cooking, gardening, and any other structured content domain.

Project Directory Structure

A StudioBrain project is a regular folder on disk. Directories prefixed with an underscore (_) are system directories managed by the application. Directories without the underscore prefix contain user entity data. A hidden .studiobrain/ directory holds local metadata that is not synced or version-controlled.

MyProject/
  .studiobrain/          # Hidden local metadata (gitignored, not synced)
    content.db           # SQLite entity index cache
    settings.json        # Per-project settings
    cache/               # Sync and scan state (offline_cache.rs; the old cache_state.db is retired)
  _Templates/
    Core/               # Built-in base templates (read-only, auto-updated)
    Standard/           # Templates from catalog, packs, or marketplace
      CHARACTER_TEMPLATE.md
      LOCATION_TEMPLATE.md
      BIOME_TEMPLATE.md
      Documents/        # Document templates
        STYLE_GUIDE_TEMPLATE.md
        GDD_TEMPLATE.md
      Maps/             # Map templates
        WORLD_MAP_MAP_TEMPLATE.md
        DUNGEON_MAP_MAP_TEMPLATE.md
    Custom/             # User overrides (highest priority)
    Packs/              # Installable template packs
    Layouts/            # UI layout definitions (JSON)
  _Rules/
    Core/               # Built-in rules (read-only)
    Standard/           # Structured YAML rules from catalog
    Custom/             # User rule overrides (highest priority)
  _Skills/
    Core/               # Built-in skills (read-only)
    Standard/           # AI skill definitions from catalog
    Custom/             # User skill overrides (highest priority)
  _Plugins/             # Installed plugins
  _Archive/             # Archived entities
  _Generated/           # AI-generated output staging area
  Characters/           # Entity data folder (matches folder_name from template)
  Locations/
  Biomes/
  Recipes/

Override Priority

For templates, rules, and skills, StudioBrain resolves files using a layered priority system. The last match wins:

Core → Standard → Custom
  • _Templates/Core/ contains built-in base templates that ship with StudioBrain. These are read-only and updated automatically.
  • _Templates/Standard/ contains templates installed from packs, the catalog, or the marketplace. These can be updated via CatalogSync.
  • _Templates/Custom/ contains your project-specific overrides. A Custom file with the same entity_type completely replaces the Standard or Core version.

The same pattern applies to _Rules/ and _Skills/. See Inheritance & Overrides for the full resolution algorithm.

Naming Conventions

  • Template files: {ENTITY_TYPE}_TEMPLATE.md (e.g. CHARACTER_TEMPLATE.md)
  • Document templates: {TYPE}_TEMPLATE.md in Standard/Documents/
  • Map templates: {TYPE}_MAP_TEMPLATE.md in Standard/Maps/
  • Entity data files: {FILE_PREFIX}_{entity_name}.md in {folder_name}/
  • Layout files: {entity_type}.layout.json in Layouts/

How Templates Drive Entity Types

The entity_type field in a template’s frontmatter is the primary key that connects templates to the entity system:

  1. Discovery — On startup, StudioBrain scans _Templates/ directories (and the catalog cache) for *_TEMPLATE.md files. Each file’s entity_type is registered.
  2. Schema generation — The fields list in frontmatter is parsed into a typed schema. Field types map to UI components: string to text input, select to dropdown, text to textarea, relation to entity picker, etc.
  3. Form rendering — When a user creates or edits an entity, the schema drives the form layout. If a layout definition exists for that entity type, it controls section ordering, tabs, and component blocks.
  4. Storage — Entity instances are saved as Markdown files in the directory specified by folder_name, with filenames prefixed by file_prefix.
  5. AI generation — When generating content for an entity, StudioBrain passes the template’s body text and any applicable rules and skills to the AI.

Field Types

A field’s type comes from field_config.<name>.type or is inferred. The types the core schema derivation recognizes:

Field TypeDescription
stringSingle-line text
textMulti-line text
markdownInline Markdown content
integerWhole numbers
float / numberDecimal numbers
ratingInteger rating
booleanTrue/false
enumSingle choice from options
date / datetimeDate or timestamp (stored as strings)
url, email, colorValidated-shape strings
imageImage reference
galleryList of image references
tagsList of strings
reference / referencesLink(s) to other entities (reference_type names the target type)
array, object, jsonStructured values

Unknown types are accepted and left unconstrained, so a template can declare a field this version does not model. Numeric and string fields honor validation (min, max, pattern).

Auto-Built Views

A custom entity type needs no layout to be browsable. The core SDK view model (packages/sdk/src/views) infers a card title, image, badges, facets, and board columns from the template’s fields, and offers cards, list, table, gallery, carousel, board, and calendar views (cloud adds map and timeline). An optional views key in the template frontmatter or a layout overrides the inferred defaults key by key.

Next Steps