Template Authoring
Templates define the schema for every entity type in StudioBrain. Each template is a markdown file with YAML frontmatter that declares all fields, their types, defaults, and structure. Creating a new template automatically creates a new entity type — no code changes required. Custom types get an edit form, a detail page and browse views (cards, list, table and so on) generated from the template alone.
Template File Format
Template files are named {UPPERCASE_TYPE}_TEMPLATE.md (for example CHARACTER_TEMPLATE.md). The shipped set lives in the open studiobrain-templates repo under templates/Standard/ (documents under templates/Standard/Documents/, maps under templates/Standard/Maps/) and is installed into a project’s _Templates/ folder. Your own templates go under _Templates/Custom/.
A template has two parts:
- YAML frontmatter (between
---delimiters): Declares all fields with their types and default values, plus metadata such astemplate_category,entity_type,folder_nameandfile_prefix. - Markdown body (below the frontmatter): Provides the default markdown content structure with section headings and placeholder text that serves as instructions for both human authors and AI generation.
entity_type is any slug matching ^[a-z0-9][a-z0-9_]*$. template_category is one of entity, document, map, rule, skill.
Template Walkthrough: CHARACTER_TEMPLATE
Here is a simplified excerpt from the Character template showing the key patterns (the real file also carries field_config, views, workflow, associated rules and more):
---
# METADATA
template_version: "2.0"
template_category: "entity"
id: "[snake_case_name]"
entity_type: "character"
folder_name: "Characters"
file_prefix: "CH_"
created_date: "[YYYY-MM-DD]"
last_updated: "[YYYY-MM-DD]"
status: "active"
# PRODUCTION STATUS TRACKING
production_status:
general: "concept"
game_uefn: "none"
tv_showrunner: "none"
notes: ""
# PRIMARY IMAGE
primary_image: ""
# BASIC IDENTITY
name: "[Generate Full Name]"
nickname: "[Generate Nickname]"
age: "18"
gender: "[male/female/non-binary]"
species: "human"
# TEMPORAL INFORMATION
birth_year: null
death_year: null
key_dates: []
current_age_reference_year: 1998
# PHYSICAL DESCRIPTION
height: "[Height in feet/inches]"
build: "[slim/average/muscular/heavyset]"
hair_color:
name: ""
hex: ""
eye_color:
name: ""
hex: ""
distinguishing_features:
- "[Unique physical feature 1]"
- "[Unique physical feature 2]"
# LOCATION & MOVEMENT
primary_location: "[Reference existing location ID]"
secondary_locations:
- "[Secondary location 1]"
# RELATIONSHIPS
faction: "[Faction affiliation or independent]"
family:
- "[Relationship]: [Person name/description]"
friends:
- "[Friend name/description]": "[relationship_type]"
enemies: []
# PERSONALITY & PSYCHOLOGY
personality_traits:
- "[Core trait 1]"
- "[Core trait 2]"
fears:
- "[Primary fear]"
motivations:
- "[Primary motivation]"
secrets:
- "[Hidden secret 1]"
defining_moment_summary: "[Brief summary of pivotal life event]"
# SKILLS & ABILITIES
primary_skills:
- "[Main skill 1]"
secondary_skills:
- "[Secondary skill 1]"
special_abilities: []
# STORY INTEGRATION
story_function:
- "[Role in narrative]"
inventory_items:
- "[Item 1]"
associated_brands:
- "[Brand name 1]"
job:
- "[Reference existing Job name 1]"
narrative_importance: "[main/major/minor]"
# AI GENERATION HELPERS
ai_profile_description: "[Visual description for AI]"
ai_voice_style: "[Speaking style description]"
ai_bio_summary: "[2-3 sentence bio]"
dialogue_samples:
- "[Example line 1]"
- "[Example line 2]"
---
# [Character Full Name]
## Background
[2-3 paragraphs describing the character's background...]
## Personality
[1-2 paragraphs describing personality...]
## Defining Moment
[1-2 paragraphs describing the pivotal life event...]
## Dialogue & Speech Patterns
[Description of how they speak...]
### Example Dialogue
> "[Greeting line]"
> "[Emotional response line]"
## Relationships
**[Category]**: [Description...]
## Story Role
[Function in the narrative...]field_config: Widget Configuration
The field_config section in template frontmatter lets you declare which widget renders each field and what options it receives. This is the recommended way to control field rendering — it replaces the old system where widget behavior was inferred from field names.
Syntax
Add field_config as a metadata field in your template frontmatter, after associated_skills and before entity data fields:
---
template_version: "2.0"
entity_type: "character"
associated_skills: []
field_config:
hair_color:
widget: color-palette
options:
- { label: "Black", hex: "#1A1A1A" }
- { label: "Blonde", hex: "#E8D44D" }
birth_year:
widget: year
min: 1900
max: 1998
family:
widget: entity-selector
reference_type: character
max_selections: 10
relationship_types:
- { value: "parent", label: "Parent" }
- { value: "sibling", label: "Sibling" }
# Entity data fields below
name: "[Generate Full Name]"
hair_color:
name: ""
hex: ""
birth_year: null
---How It Works
field_configis metadata — it’s excluded from entity data (liketemplate_versionorentity_type)- Each key in
field_configmaps to a field name in your template - The
widgetproperty selects which UI widget renders the field - Additional properties (options, min/max, reference_type, etc.) configure that widget
Common Patterns
Color palette from predefined options:
field_config:
eye_color:
widget: color-palette
options:
- { label: "Blue", hex: "#4A90D9" }
- { label: "Green", hex: "#2E8B57" }
- { label: "Brown", hex: "#6B4226" }Entity reference with relationship types:
field_config:
allies:
widget: entity-selector
reference_type: faction
max_selections: 10
relationship_types:
- { value: "allied", label: "Allied" }
- { value: "vassal", label: "Vassal" }Constrained selection:
field_config:
rarity:
widget: radio-group
options:
- { value: "common", label: "Common" }
- { value: "rare", label: "Rare" }
- { value: "legendary", label: "Legendary" }
layout: horizontalNumeric with range:
field_config:
power_level:
widget: range
min: 0
max: 100
step: 5
show_value: trueUse canonical widget ids: the template validator rejects aliases and unknown ids. For the complete list of widgets and their options, see the Field Widgets Reference.
Field Types
Core derives each field’s type from its default value in the template frontmatter when the template is saved or installed. An explicit field_config widget takes precedence over value inference.
| YAML Default | Inferred Type |
|---|---|
"" or "placeholder" | string |
0 or 42 | integer |
1.5 | number |
true or false | boolean |
null | string (nullable) |
[] or ["item1", "item2"] | array of strings |
Nested object (key: value) | object |
String Fields
name: "[Generate Full Name]" # String with placeholder instruction
gender: "[male/female/non-binary]" # String with allowed values hint
status: "active" # String with default valueNumber Fields
age: "18" # Stored as string, parsed as needed
founded: 1987 # Integer
population: 0 # Integer with zero defaultBoolean Fields
is_active: true
is_deceased: falseArray Fields
# Simple string array
personality_traits:
- "[Core trait 1]"
- "[Core trait 2]"
# Empty array (items added by user)
special_abilities: []
enemies: []Nested Objects
# Object with named sub-fields
production_status:
general: "concept"
game_uefn: "none"
tv_showrunner: "none"
notes: ""
# Object with color data
hair_color:
name: ""
hex: ""
# Object with multiple sub-objects
skin_tone:
palette: ""
base: ""
midtone: ""
shadow: ""
highlight: ""Reference Fields
Fields that reference other entities use the target entity’s ID as a string value. The cross-reference system recognizes these patterns:
# Single reference
primary_location: "[Reference existing location ID]"
faction: "[Faction affiliation]"
# Array of references
secondary_locations:
- "[Secondary location 1]"
- "[Secondary location 2]"
associated_brands:
- "[Brand name 1]"
job:
- "[Reference existing Job name 1]"Entity Types Reference
StudioBrain ships 16 entity templates in templates/Standard/, plus document, map and export-profile templates in subfolders (for example style_bible is in Documents/). The folder name and file prefix come from each template’s folder_name and file_prefix frontmatter.
| Entity Type | Template File | Prefix |
|---|---|---|
| assembly | ASSEMBLY_TEMPLATE.md | ASM_ |
| biome | BIOME_TEMPLATE.md | BIO_ |
| brand | BRAND_TEMPLATE.md | BR_ |
| campaign | CAMPAIGN_TEMPLATE.md | CAMP_ |
| character | CHARACTER_TEMPLATE.md | CH_ |
| dialogue | DIALOGUE_TEMPLATE.md | DLG_ |
| district | DISTRICT_TEMPLATE.md | DIST_ |
| event | EVENT_TEMPLATE.md | EVENT_ |
| faction | FACTION_TEMPLATE.md | FAC_ |
| item | ITEM_TEMPLATE.md | ITEM_ |
| job | JOB_TEMPLATE.md | JOB_ |
| location | LOCATION_TEMPLATE.md | LOC_ |
| prompt | PROMPT_TEMPLATE.md | PROMPT_ |
| quest | QUEST_TEMPLATE.md | QST_ |
| timeline | TIMELINE_TEMPLATE.md | TL_ |
| universe | UNIVERSE_TEMPLATE.md | UNIV_ |
File and Folder Structure
Entities are stored in folders named after their entity ID:
Characters/
rex_marshall/
CH_rex_marshall.md # Main entity file
images/
portrait.png
concept_art.jpg
audio/
voice_sample.mp3
data/
stats.json
Locations/
downtown_plaza/
LOC_downtown_plaza.md
images/
aerial_view.png
Brands/
double_dip_dog_sauce/
BR_double_dip_dog_sauce.md
images/
logo.pngThe file prefix (CH_, LOC_, BR_, etc.) and folder name are read from the template’s file_prefix and folder_name frontmatter.
Required Metadata Fields
Every template should include these metadata fields:
template_version: "2.0" # Template format version
template_category: "entity" # entity, document, map, rule, skill
id: "[snake_case_name]" # Unique entity identifier
entity_type: "character" # Must match template type
folder_name: "Characters" # Entity folder
file_prefix: "CH_" # Entity file prefix
created_date: "[YYYY-MM-DD]" # ISO date
last_updated: "[YYYY-MM-DD]" # ISO date
status: "active" # active, archived, draftThe production_status block is optional but recommended for tracking workflow:
production_status:
general: "concept" # concept, in_progress, needs_work, narrative_done, art_done, complete
game_uefn: "none" # none, planned, in_progress, review, published, live
tv_showrunner: "none" # none, planned, in_progress, review, episode, current, archived
notes: ""AI Generation Sections
Templates can include fields specifically for AI context:
# AI GENERATION HELPERS
ai_profile_description: "[Visual description from profile image]"
ai_voice_style: "[Speaking style/vocal characteristics]"
ai_bio_summary: "[Concise 2-3 sentence bio for AI context]"
dialogue_samples:
- "[Example line showing personality]"These fields are included in the context used for AI generation so the output matches the entity’s established characteristics.
Rules Files
Rules files at _Rules/{TYPE}_RULES.md define validation and generation rules for each entity type. They use the same YAML frontmatter + markdown format.
Rule Structure
Each rule file has frontmatter (system_prompt, entity_type, template_reference, priority) and a rules list. Shipped example (CHARACTER_RULES.md):
rules:
- id: char_001
category: identity
priority: critical
rule: Every character MUST have a primary_location
validation_type: error
applies_to: [character]
- id: char_003
category: relationships
priority: high
rule: Friends always use nicknames when available
validation_type: warning
applies_to: [character]Rule Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique rule identifier |
category | string | Free-form grouping (identity, naming, relationships, tone, …) |
priority | string | critical, high, medium, low |
rule | string | The rule text (also used in AI generation prompts) |
validation_type | string | Severity, error or warning (defaults to error when added through the API) |
applies_to | list | Entity types the rule applies to |
Available Rule Files
The studiobrain-templates repo ships {TYPE}_RULES.md for assembly, biome, brand, character, dialogue, district, faction, item, job, location, timeline and universe, plus general files: CONTENT_RULES.md, GENERATION_RULES.md, IMAGE_GENERATION_RULES.md, STORY_RULES.md, VOICE_GENERATION_RULES.md, WORLD_LORE_RULES.md, PROMPT_ENGINE_RULES.md, WORKFLOW_RULES.md and RULES_INDEX.md.
Rules API
Rules are managed through the REST API (sb-server routes):
GET /api/rules # List all rule files
GET /api/rules/index # Rules index
GET /api/rules/{type} # Get parsed rules
PUT /api/rules/{type} # Upsert the full ruleset
DELETE /api/rules/{type} # Delete tenant rules
GET /api/rules/{type}/markdown # Raw markdown (PUT to update)
GET /api/rules/{type}/prompt # Generated system prompt
POST /api/rules/{type}/add # Add one rule
PUT /api/rules/{type}/{rule_id} # Update one rule
DELETE /api/rules/{type}/{rule_id} # Delete one rule
POST /api/rules/validate/{type} # Validate against rules
POST /api/rules/{type}/validate-entity # Validate an entityPer-rule add, update and delete are only supported for local tenants; cloud tenants must upsert the full ruleset with PUT /api/rules/{type}.
TypeScript Types for Shipped Entity Types
Types you create yourself need no code generation: core derives a schema from the template when it is saved or installed and validates entity writes against it.
For the shipped types, core’s frontend has generated TypeScript interfaces and Zod schemas. npm run generate:types (also run by npm run dev and npm run build) reads the JSON Schemas in the studiobrain-templates repo’s schemas/ directory and writes frontend/src/types/generated/:
entities.ts— TypeScript interfacesschemas.ts— Zod validation schemasmappings.ts—EntityTypeMap,EntityTypeNameand type guardsfield-metadata.ts— field metadata for dynamic editors
The generator only regenerates from a templates checkout at the pinned revision (scripts/templates-schema-ref.txt); otherwise it skips. These files are not generated from your template frontmatter.
Importing Generated Types
Import from the barrel export:
// Correct
import { Character, Location, CharacterSchema } from '@/types';
// Wrong -- don't import from generated/ directly
import { Character } from '@/types/generated/entities';Adding a New Entity Type
Creating a new entity type requires only one step: create the template file.
- Create
_Templates/Custom/MYENTITY_TEMPLATE.md:
---
template_version: "2.0"
template_category: "entity"
id: "[snake_case_name]"
entity_type: "myentity"
folder_name: "My Entities"
file_prefix: "MYE_"
created_date: "[YYYY-MM-DD]"
last_updated: "[YYYY-MM-DD]"
status: "active"
primary_image: ""
name: "[Entity Name]"
custom_field_one: ""
custom_field_two: []
custom_nested:
sub_field_a: ""
sub_field_b: 0
---
# [Entity Name]
## Description
[Describe this entity...]
## Details
[Additional details...]-
Save or install the template. Core derives the entity schema from it.
-
The new entity type is immediately available:
GET /api/entity/myentitylists entitiesPOST /api/entity/myentitycreates entitiesGET /api/entity/myentity/schemareturns the derived schema- The frontend renders edit forms, the detail page and browse views from the template schema; add an optional
viewsblock to the frontmatter to tune the browse views
No backend code changes, no database migrations, no frontend component creation.
Template Versioning
The template_version field tracks the template format. When you update a template (add fields, change structure), bump the version. The backend’s FrontmatterValidator normalizes entity frontmatter (for example injecting a missing template_version).
template_version: "2.0" # Current format versionExisting entities with older template versions continue to work. Missing fields get default values from the template. Removed fields are preserved in the entity’s fields JSON but not validated.