Workspace Templates
Reusable industry-specific packs that pre-configure entity types, views, sample data, and navigation for a tenant.
Overview
Workspace templates are pre-built configurations that bootstrap a tenant with entity types, views, sample entities, and navigation in a single operation. They serve two purposes:
- Onboarding acceleration -- New tenants can start with a fully configured workspace instead of building from scratch
- Industry packs -- Domain-specific configurations (PE, manufacturing, consulting) provide best-practice data models
Key Concepts
Template Categories
Templates are organized into categories:
| Category | Label | Description |
|---|---|---|
pe | Private Equity | Portfolio companies, deals, value creation |
manufacturing | Manufacturing | Production lines, equipment, improvement projects |
legal | Legal | Reserved for future legal workflow templates |
consulting | Consulting | Engagements, deliverables, findings |
general | General | Flexible project/task/note workspaces |
Template Scope
- Global templates (
tenant_id = NULL) -- Platform-provided, read-only, visible to all tenants - Tenant templates (
tenant_id = <uuid>) -- Created by tenant admins, editable, visible only within the tenant
Template Contents
Each template contains JSON snapshots of:
- Entity types -- Schema definitions including
json_schema,config, icon, color - Views -- Block configurations and layouts linked to entity types
- Sample entities -- Demo data pre-populated into the created entity types
- Navigation -- Sidebar configuration overrides (reserved for future use)
How It Works
Applying a Template
When a user applies a template:
- Entity types are created sequentially. If a slug already exists, that type is skipped (duplicate-safe).
- Views are created and linked to the newly created entity types via a slug-to-ID mapping.
- Sample entities are optionally created. Only entities whose parent type was successfully created are included.
- The operation is additive -- existing data is never modified or deleted.
Architecture
Admin UI (templates-admin.tsx)
-> REST API (/api/workspace-templates/*)
-> Server Actions (features/templates/server/actions.ts)
-> Supabase (workspace_templates table)
-> Entity Type Actions (createEntityType)
-> View Actions (createView)
-> Entity Actions (createEntity)API Reference
Server Actions
| Function | Description |
|---|---|
listTemplates() | Returns global + tenant templates, ordered by featured status then name |
getTemplate(id) | Returns a single template by ID, or null |
createTemplate(input) | Creates a tenant-scoped template |
updateTemplate(id, input) | Updates a tenant-owned template (global templates are immutable) |
deleteTemplate(id) | Deletes a tenant-owned template |
applyWorkspaceTemplate(id, options?) | Applies a template to the current tenant |
REST API
| Method | Path | Auth | Description |
|---|---|---|---|
GET | /api/workspace-templates | Admin | List templates |
POST | /api/workspace-templates | Admin | Create template |
PATCH | /api/workspace-templates/[id] | Admin | Update template |
DELETE | /api/workspace-templates/[id] | Admin | Delete template |
POST | /api/workspace-templates/[id]/apply | Admin | Apply template |
Types
TemplateCategory-- Union of category string literalsTemplateEntityType-- Entity type snapshot embedded in a templateTemplateView-- View snapshot with block configsTemplateSampleEntity-- Sample entity with typeSlug, title, contentWorkspaceTemplateRecord-- Full database row typeCreateWorkspaceTemplateInput-- Input for creating a templateApplyTemplateResult-- Result counts from applying a template
Database
workspace_templates table
| Column | Type | Description |
|---|---|---|
id | uuid | Primary key |
tenant_id | uuid (nullable) | NULL for global templates, tenant UUID for tenant-scoped |
name | text | Display name |
slug | text | URL-safe identifier, unique per tenant scope |
description | text | Optional description |
icon | text | Lucide icon name |
category | text | Template category |
entity_types | jsonb | Array of entity type snapshots |
views | jsonb | Array of view snapshots |
sample_entities | jsonb | Array of sample entity snapshots |
navigation | jsonb | Navigation config overrides |
is_featured | boolean | Whether to show prominently |
created_by | uuid | User who created the template |
RLS Policies
- Global templates are readable by anyone
- Tenant templates are readable/writable by tenant members
- Service role has full access for seeding
For Agents
Agents do not currently have direct tool access to workspace templates. Template management is an admin-only operation performed through the UI or API.
Design Decisions
- Additive-only apply -- Templates never modify existing data. This prevents accidental overwrites and makes the operation safe to retry.
- Slug-based dedup -- Entity types are matched by slug during apply. If a slug already exists, it is skipped rather than throwing an error.
- Global templates are immutable -- Platform-provided templates cannot be modified by tenants. This ensures consistency across deployments.
- JSON snapshots over references -- Templates store full entity type definitions as JSON rather than referencing live entity types. This makes templates portable and version-independent.
Related Modules
- Entity System -- Entity types created by templates
- View System -- Views created by templates
- Multi-Tenant -- Tenant scoping for templates
- Admin -- Template management UI