DeveloperTemplate Categories Architecture

Template Categories Architecture

This page documents the Template Categories system (SBAI-835). A template’s category decides how an entity type is rendered (structured form vs. rich document editor) and is returned in the tenant entity-type catalog.

Frontmatter

A template declares its category with the template_category frontmatter key. The key is optional; if absent or unrecognized it defaults to entity.

---
entity_type: "screenplay"
template_category: "document"   # entity | document
---
ValuePurpose
entityStructured data with fields, rendered as a form (characters, locations, items)
documentFramework/guide documents with sections, rendered as a rich editor

Parsing is in TemplateCategory::from_str_lossy (core crates/sb-core/src/template.rs): document (case-insensitive) maps to document, everything else to entity. There is no filename-based inference.

Catalog categories

GET /api/tenant/entity-types is served by the entity seam on sb-server-worker (api.studiobrain.ai), backed by the per-project ProjectStore Durable Object. The per-row category in that response is computed by core’s portable tenant module (crates/sb-server/src/portable/tenant.rs, category_for) from a slug map, not read from template frontmatter:

  • assembly, dialogue, quest, timeline resolve to core (system features with dedicated UI pages)
  • A fixed list of document-style slugs (for example style_bible, universe, gdd, story_bible, screenplay, manuscript) resolve to document
  • Every other slug resolves to entity

So the catalog can return core in addition to the frontmatter values entity and document.

Entity type catalog API

MethodPathDescription
GET/api/tenant/entity-typesEntity types activated for the tenant, plus any type that already has entities
GET/api/tenant/entity-types?category=documentFilter rows to one category
GET/api/tenant/entity-types?project_id=...Scope entity_count to a project (the type list stays tenant-wide)

Types come from tenant template activations (template_activations) unioned with types that already have entity data. Built-in types are not injected automatically; installing and activating a template is what adds it (SBAI-8124).

curl -H "Authorization: Bearer {token}" \
  "https://api.studiobrain.ai/api/tenant/entity-types?category=document"

Response shape (fields from EntityTypeInfo):

{
  "entity_types": [
    {
      "type": "screenplay",
      "label": "Screenplay",
      "plural_label": "Screenplays",
      "icon_name": "FileText",
      "entity_count": 3,
      "is_system": false,
      "source": "template",
      "status": "active",
      "supports_custom_ui": false,
      "category": "document",
      "capabilities": {},
      "editable": true,
      "marketplace_eligible": true
    }
  ],
  "plan": "community",
  "max_entity_types": -1
}

Notes on the current implementation: capabilities is always an empty object, supports_custom_ui is always false, plan is the literal community, and max_entity_types is -1 (unlimited). editable is false for dialogue, quest, timeline; marketplace_eligible is false for those plus assembly.

The legacy GET /api/templates/entity-types alias (SBAI-7269) projects the same catalog to a plain list of slugs.

Template reload

POST /api/templates/reload is a reserved path segment on the templates routes; it is never treated as a template named reload. See Template Inheritance for how tenant/project overrides resolve.

See Also