Templates and plugins
Templates package a complete content model. Plugins add behaviour. Both work without changing the platform's core code.
Templates
A template is a folder with a template.json manifest in the server's templates directory (TEMPLATES_DIR, which is templates/ in the repository). Installed definitions are marked as owned by the template, so they can be upgraded later.
Manifest
{
"id": "events",
"name": "Events",
"version": "1.0.0",
"description": "Event listings with venues.",
"platformVersion": "1.0.0",
"changelog": { "1.0.0": "Initial release." },
"entities": [
{ "key": "venue", "name": "Venue", "fields": [ { "key": "name", "label": "Name", "type": "text", "required": true } ] },
{
"key": "event",
"name": "Event",
"fields": [
{ "key": "title", "label": "Title", "type": "text", "required": true },
{ "key": "startsAt", "label": "Starts at", "type": "datetime" },
{ "key": "venue", "label": "Venue", "type": "relation", "config": { "targetEntity": "venue" } }
]
}
],
"sampleData": {
"venue": [ { "name": "Main hall" } ],
"event": [ { "title": "Launch party", "venue": "@venue:0" } ]
}
}Entities use the same format as schema files. In sampleData, "@entity:index" references an earlier sample record. Restart the API (or just call the list endpoint again) to see new templates.
Template upgrades
When a newer version of an installed template is available, Templates & plugins shows Upgrade available. Click Review upgrade to see the plan before anything changes.
| Plan item | Meaning |
|---|---|
| New entity / New field | Will be created |
| Update | A template-managed definition will be updated |
| Kept (customized) | You changed this definition, so it is left exactly as it is |
| Deprecated | Removed from the template. It is kept, with its data |
| Conflict | Can't be applied automatically (type change, key used by your own field or entity). Blocks the upgrade |
Guarantees: your own entities, fields and all records are never modified. Breaking changes (a new required field, a field becoming unique) need explicit acceptance. The upgrade runs in one transaction: if anything fails, nothing changes, and the failed attempt is recorded in the upgrade history.
GET /api/v1/admin/templates/{id}/upgrade-plan
POST /api/v1/admin/templates/{id}/upgrade {"acceptBreaking": true}
GET /api/v1/admin/templates/{id}/upgrades # history, including failuresPlugins
Plugins are trusted code installed on the server by an administrator, in a folder inside PLUGINS_DIR (plugins/ in the repository). They are never uploaded through the UI. Each workspace enables the plugins it wants under Templates & plugins.
Manifest: plugin.json
{
"id": "word-count",
"name": "Word count",
"version": "1.0.0",
"description": "Stores the number of words of an article body.",
"capabilities": ["records:modify"],
"entities": ["article"],
"main": "index.js"
}| Capability | Allows |
|---|---|
records:modify | record.beforeCreate, record.beforeUpdate: return field changes |
records:observe | record.afterCreate, record.afterUpdate, record.afterDelete: react to changes |
Module: index.js
'use strict';
function register(api) {
api.on('record.beforeCreate', count);
api.on('record.beforeUpdate', count);
}
function count({ fields, data }) {
if (!fields.includes('wordCount') || typeof data.body !== 'string') return {};
return { wordCount: data.body.trim().split(/\s+/).filter(Boolean).length };
}
module.exports = { register };How hooks behave
- Before-hooks receive
{ tenantId, entity, fields, data, previous }and may return field changes. The changes are validated against the schema like user input, then saved in the same transaction. - Throwing an error rejects the change with
422 PLUGIN_REJECTEDand your message. - Hooks have a time limit (
PLUGIN_HOOK_TIMEOUT_MS, default 2 s). A slow hook returns503 PLUGIN_TIMEOUT. - After-hooks run after the change is saved. Their errors are logged and never affect the request.
- Plugins only receive record data. They get no database access and never see other workspaces.
Plugin code runs inside the API process. Install only plugins you have reviewed.
Example: CMS publishing helpers
The bundled cms-publishing plugin sets publishedAt when an article or page is first published, and fills an empty seoTitle from the title. Its source is in plugins/cms-publishing.