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",
"fields": [...],
"relations": [...],
"formulas": [...],
"archetypeDefinitions": [...],
"archetypes": [...],
"scripts": [...],
"reports": [...],
"lists": [...],
"views": [...],
"layouts": [...],
"assets": [...],
"translations": [...],
"accessControl": [...],
"roles": [...],
"data": [...],
"migration": {...}
}
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.
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.
layoutsLayout[]UI layout definitions. See Layouts.
assetsAsset[]Static files (kind LOGO or STYLESHEET) served from the repository.
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.
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" }
]
}

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).