Skip to main content

Class File Format

Each class is defined in its own JSON file. The file name corresponds to the class name part of the qualified name (e.g., my-project.employee → employee.json).

Top-level structure​

{
"$schema": "https://api.mosterd.com/schema/definition-v1.schema.json",
"version": 1,
"class": "my-project.employmentAgreement",
"kind": "BASIC",
"inherits": "commons.agreement",
"description": "...",
"nameField": "name",
"customKeyField": "...",
"indexed": true,
"generalSearchClasses": [...],
"fields": [...],
"relations": [...],
"formulas": [...],
"archetypeDefinitions": [...],
"archetypes": [...],
"scripts": [...],
"reports": [...],
"pipeline": {...},
"lists": [...],
"views": [...],
"graphDefinitions": [...],
"layouts": [...],
"groups": [...],
"assets": [...],
"translations": [...],
"accessControl": [...],
"roles": [...],
"data": [...],
"dataUpgrades": [...],
"migration": {...}
}

Only class and kind are required. extends replaces inherits on an EXTENSION, and imports and modules are used in index.json; none of the three is shown above.

PropertyTypeDescription
$schemaURLOptional editor hint: the JSON Schema of the file's format. Ignored by the platform. See Editor support.
versionintegerThe definition format the file is written in. The current format is 1; a file without version is format 0.
classQualifiedNameQualified name of this class.
kindBASIC | ABSTRACT | CONFIG | EXTENSIONThe role of the class. See Class Kinds.
inheritsQualifiedNameThe class this class inherits from. Required for BASIC and ABSTRACT classes.
extendsQualifiedNameFor an EXTENSION: the class being extended. Use instead of inherits.
importsQualifiedName[]Classes to load. Used in index.json.
modulesModule[]Optional bundles of imports. See Modules.
fieldsFieldDefinition[]The class's own fields. See Fields.
descriptionstringOptional English description of the class, for agents and documentation. See Descriptions.
nameFieldstringThe field that holds the object's display name. Defaults to the inherited name field.
customKeyFieldstringA field whose value can be used as an alternative key for objects of this class, for example during an import.
relationsRelationDefinition[]Relation definitions. See Relations.
formulasFormula[]Computed field definitions. See Formulas.
archetypeDefinitionsArchetype[]Semantic archetype declarations (slots). Usually on a CONFIG class. See Archetypes.
archetypesArchetypeBinding[]Bindings mapping this class's fields/relations onto archetype slots. See Archetypes.
scriptsScript[]Action definitions. See Scripts.
reportsReport[]Document generation definitions. See Reports.
pipelinePipelineAutomated processing of new objects. See Pipeline.
listsStandardList[]Named value lists for LIST fields. See Lists.
viewsView[]Table/list view definitions. See Views.
graphDefinitionsGraphDefinition[]Graphs of nodes and edges across classes. Declared on a dedicated CONFIG class. See Graphs.
layoutsLayout[]UI layout definitions. See Layouts.
groupsTabGroup[]Groups that organise the class's tabs on its detail page. See Grouped tabs.
assetsAsset[]Static files (kind LOGO or STYLESHEET) served from the repository. See Assets.
translationsTranslation[]Language-specific labels for this class and its fields. See Translations.
accessControlAccessControlDefinition[]Access-control definitions. Each names the objects that carry its identifier and, optionally, the users who do. See Access Control and the schema reference.
rolesRole[]Roles bundling access-control definitions, referenced from system.userProfile.accessRoles. A separate branch from accessControl, usually declared alongside it on the same class. See the schema reference.
dataDefaultData[]Fixture objects to create when loading default data. See Default Data.
indexedbooleanWhether objects of this class appear in the general search. Default true. See Search.
generalSearchClassesQualifiedName[]The classes the app's general search box searches. See Search.
dataUpgradesDataUpgrade[]Upgrades of stored data for breaking model changes. One section per namespace, on a CONFIG class loaded without modules. See Data Upgrades.
migrationMigrationDefinitionMigration mapping from a legacy system (beta). See Migration.

Strict checking​

The platform checks every file when it loads the model. An unknown or misspelled property, a reference to a field, script or file that does not exist, or a field name that is not lowerCamelCase refuses the model, with a message per file and JSON pointer. The previously loaded model keeps serving the tenant until the errors are fixed. See Loading a model.

Complete example​

A custom EmploymentAgreement class that inherits from commons.dossier:

{
"$schema": "https://api.mosterd.com/schema/definition-v1.schema.json",
"version": 1,
"class": "my-project.employmentAgreement",
"kind": "BASIC",
"inherits": "commons.dossier",

"fields": [
{ "name": "jobTitle", "required": true },
{ "name": "salary", "dataType": "CURRENCY" },
{ "name": "hoursPerWeek", "dataType": "INTEGER" }
],

"formulas": [
{
"field": "name",
"template": "{{jobTitle}}"
}
],

"relations": [
{ "class": "commons.company", "required": true, "multiple": false },
{ "class": "commons.employee", "required": true, "multiple": false }
],

"scripts": [
{
"name": "extractFromDocument",
"type": "FUNCTION_GATEWAY",
"scope": "OBJECT",
"trigger": ["MANUAL"],
"gateway": "Ai",
"parameters": [
{
"name": "documents",
"templateFile": "templates/dossierAndDocuments.hbs"
},
{
"name": "jobTitle",
"value": "The job title if mentioned"
},
{
"name": "salary",
"value": "The monthly gross salary"
}
],
"targets": [
{ "name": "jobTitle", "actionType": "OVERWRITE" },
{ "name": "salary", "actionType": "OVERWRITE" }
]
}
],

"lists": [
{
"name": "my-project.contractType",
"items": [
{ "key": "permanent", "color": "#1a7f37", "backgroundColor": "#dafbe1" },
{ "key": "fixedTerm", "color": "#9a6700", "backgroundColor": "#fff8c5" },
{ "key": "freelance", "color": "#0969da", "backgroundColor": "#ddf4ff" }
]
}
]
}

EXTENSION class example​

Add a custom field to commons.person without creating a new class:

{
"version": 1,
"class": "my-project.person",
"kind": "EXTENSION",
"extends": "commons.person",
"fields": [
{ "name": "employeeNumber" },
{ "name": "department" }
]
}

After loading, every commons.person in the tenant has the extra fields employeeNumber and department.

ABSTRACT class example​

An abstract Shareholder class that can be applied to both persons and companies:

{
"version": 1,
"class": "my-project.shareholder",
"kind": "ABSTRACT",
"inherits": "commons.entity",
"fields": [
{ "name": "sharePercentage", "dataType": "PERCENTAGE" }
]
}

Assets​

An asset points to a static file in the repository that the app serves for the tenant. Declare it in assets on any class; a CONFIG class is the usual place.

"assets": [
{ "kind": "LOGO", "fileName": "acme-logo.png", "contentType": "image/png" },
{ "kind": "STYLESHEET", "fileName": "acme.css", "contentType": "text/css" }
]
PropertyTypeDescription
kindLOGO | STYLESHEETLOGO is the main logo the app shows for the tenant. STYLESHEET is a CSS file loaded while the tenant is active, to override the default look.
fileNamestringThe file's name in the repository, next to the class files.
contentTypestringThe MIME type of the file, for example image/png or text/css.

All three properties are required.

File naming​

File names are derived from the class name portion of the qualified name:

QualifiedNameFile
my-project.employeeemployee.json
my-project.employmentAgreementemploymentAgreement.json
my-project.taxDossiertaxDossier.json

All class files of a repository are in the same directory as its index.json: the repository root, or the directory configured for the tenant. Files that a class refers to — scripts, templates, prompts — may be organized in subdirectories; they are referenced by their path relative to the repository root, including the extension (scripts/logNoteChange.js).