Skip to content

The app block

The app block declares the identity of an application: its name, its language and time zone, its roles, its sign-in rules, its scope and its menus. It holds no data and no pages.

app sports_club "Sampletown Sports Club" {
locale: en
timezone: Europe/Berlin
theme { accent: #1f6f43 }
roles {
board "Board"
trainer "Trainer"
member "Member"
}
auth {
methods: [password]
profile member of members "Member" { for: member }
lockout {
after: 5
for: 15min
}
session {
lifetime: 30d
idle_timeout: 12h
}
}
nav main "Club" {
members
}
}

The profile line needs a table members, and the nav needs a page members. Everything else in this example is complete. Each line in it has a section below.

app <name> "<Label>" {
<properties and statements>
}

An application has exactly one app block. By convention it is in app.mtd, in the root directory of the application. The compiler refuses a set of sources with no app block, and it refuses a second app block at the name of the second one.

The name is an identifier in snake_case. It cannot contain a dot or a hyphen. The name has two jobs:

  • Storage. Every table of the application is stored as <name>__<table>, so table members in app sports_club is sports_club__members. This version refuses to rename an application that is installed.
  • The default address. An application with no mount: is served under its name, so the name must then also be a valid mount. See mount.

The compiler refuses these names:

Name Reason
matterdata, in any case the engine stores the organization’s administration roles under this name
mtd, or a name that starts with mtd_ the stored table names would be in the engine’s own mtd_ namespace
a name that is not a valid mount, when there is no mount: the default address would be invalid, for example app Club has an upper-case letter

The label is optional. The engine shows it in the page header, in the title of the browser tab, and in the organization’s list of applications. A calendar feed uses it as the name of the calendar. With no label, the header and the list show the organization’s subdomain instead.

The properties and statements can be in any order. A property can be written once per block. The compiler refuses a second locale: line, for example, and names the line of the first one.

locale: de

locale: sets the language of the text that the engine draws: buttons, messages, empty states, and the notation of dates, numbers and money.

Value Language
en English. This is the default.
de German
fr French
es Spanish
pt Portuguese, in its Brazilian spelling and wording
tr Turkish

The compiler refuses every other value, and its message names the six values. Your own labels are not translated. The locale changes no stored value. For the full list of what changes, read Set the language.

locale: en
locales: [en, de]

locales: lists the languages the application has translations for. locale: stays the language the source is written in, and it must be in the list. Without locales:, the list is just locale:.

The compiler refuses a value that is not en, de, fr, es, pt or tr, a value listed twice, and a list without the locale: language. A language that is listed and has no i18n/<locale>.mtd file gives a warning.

i18n de {
app.title "Gymnasium Musterstadt" was "Sampletown Grammar School"
page.course.title "{:course.name}"
page.course.list.enrolments.label "Einschreibungen" was "Enrolments"
}

An i18n <locale> block is a translation. It lives in its own file, i18n/<locale>.mtd, next to app.mtd. The file is named after its locale, and the locale must be in locales: and must not be the locale: of the application. You never change a page or a table to add a language.

Each entry is a key, the translation in quotes, and was with the source text that the translator saw. The compiler works out the key from where the text is written. You do not choose it. An entry with no was gives a warning: the compiler cannot tell when it goes stale.

A label you leave out is also a text to translate. The engine draws the name in its place (a column price with no label shows price), so the key exists, and its source text is that name. This holds for a column, an enum value, a lifecycle state, a table, a page, a role, a right, the scope and a transition. Write was "price" for such an entry. When no translation exists, the engine draws the name as before.

Text Key
the application’s label app.title
a role, right, scope, profile or job label role.<name>, right.<name>, scope.<name>, profile.<name>, job.<name>
a nav label, an entry, a group nav.<nav>, nav.<nav>.item.<page>, nav.<nav>.group.<group>
a table’s label <table>
a column’s label, help: and empty_label: <table>.<column>, <table>.<column>.help, <table>.<column>.empty_label
an enum value or a lifecycle state <table>.<column>.<value>
a lifecycle transition <table>.<transition>
a check, require or unique message <table>.check.<n>, <table>.require.<column>, <table>.unique.<column>+<column>
a page’s label page.<page>.title
a note page.<page>.note.label, .text, .button and .link.<n>
a region’s text page.<page>.<kind>.<table>.label, .empty, .submit, .success (a region with no table: page.<page>.<kind>.label)
a button or link of a region page.<page>.<kind>.<table>.button.<n>, .row.<n>, .row_action.<n>
a message declared in messages message.<name>

A second region of the same kind over the same table on one page gets #2 after the table name. The full list of keys is in the language specification, section 5.6.

The text inside an expression is not translated. In status = "open" the string "open" is an expression value, and it has no key. Put the word in a caption instead, for example an enum value, and translate that.

Text that goes to a recipient other than the reader on screen is drawn in the language of the sender or of the application (locale:), not in the language of the person who receives it. This covers the invitation mail, the text a scheduled job writes and the text a hook sends with SendMail. The engine does not promise a language for each recipient.

The compiler checks each file against the application:

Situation Result
a key that names no text error, with the closest key
a translation without the {:value} placeholders of its source, or with others error
an empty translation, or a key written twice error
a file for a language that locales: does not list, or for the locale: language error
a text with no translation, or an entry marked todo warning. The source text is used.
was differs from the source text now warning. The translation is still used.
an entry with no was warning. No source is recorded, so the compiler cannot tell when the entry goes stale.
a listed language with no file warning

An entry that ends in the word todo is a placeholder that matterdata i18n sync wrote: its text is a copy of the source. The compiler counts it as a text with no translation, so the engine draws the source text and a strict compile refuses it. A translator writes the translation and deletes todo. The word stands on the same line as the text or as was, and after them:

i18n de {
page.course.list.enrolments.label "Enrolments" was "Enrolments" todo
}
messages {
paid_item_not_deleted "A paid item is not deleted but cancelled."
basket_in_use "This basket is in use by {:name}, {:count} times."
}

messages declares the sentences that a hook refuses a write with. Each line is a name and the sentence in quotes, written in the language of locale:. A hook refers to a message by its name:

throw ctx.error("paid_item_not_deleted");
throw ctx.error("basket_in_use", { name: basket.name, count: n });

The engine draws the sentence in the language of the request, as it draws every other text of the application. A message is a text to translate like any other: its key is message.<name>, and it is written in i18n/<locale>.mtd (see i18n).

The name is a lower-case identifier: letters, digits and underscores, starting with a letter. The compiler refuses a name declared twice and an empty sentence.

Placeholders. {:name} in the sentence is filled with the value of the property name of the second argument. The name is a plain lower-case name. It has the same braces as a value on a page ({:course.name}), but a message is not on a page, so a dotted name is an error, and so is {name} without the colon. Write {{ and }} for a literal brace. A translation must have exactly the placeholders of its source sentence.

What a hook may pass. The values are text and nothing else. A string, a number or a boolean is written into the sentence. An object, an array, null, undefined or a function is ignored. The engine keeps at most 16 values, a name of at most 64 bytes, and a value of at most 512 bytes, and it draws the sentence as text: <b> in a value is shown as the characters <b>. A value that contains {:name} is not expanded. A placeholder with no value is drawn as an empty string, and a value with no placeholder is ignored. Both are written in the engine’s log.

What the compiler checks in the hooks. The compiler reads each ctx.error( call of the modules in logic/. It skips comments, strings, template literals and regular expressions, and it reads calls of ctx.error where ctx is the first parameter of the function given to defineHook. It does not follow an alias (const fail = ctx.error) or a call made in another module.

The call Result
a first argument that is a lower-case identifier and is not declared error, with the closest name
a declared name, and an object literal whose keys differ from the placeholders error. It says what to add and what to remove.
a declared name, and a second argument that is not an object literal (a variable, a spread, a computed key) not checked
a sentence such as ctx.error("Not allowed here."), in an application that lists more than one language warning. The sentence is shown as written, and a translator cannot reach it.
a first argument that is not a string constant, in an application that lists more than one language warning
a declared message that no call names, when no call has a computed first argument warning

An application that lists one language gets no warning for a sentence or a computed first argument: there is nothing to translate. A sentence that is not a declared name is still shown as written, as it was before messages existed. The two warnings for a second language are errors in a strict compile (matterdata validate <dir> -strict). The compiler makes these checks only when it is given the hook modules. Without them nothing about a hook is checked.

A hook that refuses with a name that the application does not declare at run time (for example a computed name) is shown as the text of that name. A job, or any hook that runs with no page, draws nothing to a reader. Its log line names the message.

mount: club

mount: is the first path segment that every page of the application is served under. The default is the application’s name. mount: / serves the application at the root of its organization. A mount is lower-case letters, digits, _ and -, starts with a letter, and has at most 40 characters. The values, the root mount and every refusal are on App mount.

timezone: Europe/Berlin

timezone: is the time zone that the application is written in. It decides which instant a submitted time with no offset means, which wall-clock time a page shows, and which day today is. Stored datetime values are always UTC, and a change to timezone: rewrites none of them.

Value Effect
an IANA name in the form Area/Location that time zone, for example Europe/Berlin or America/New_York
UTC UTC. This is the default.

The compiler refuses these values in the app block:

  • an abbreviation such as CET or EST. It is ambiguous, and EST, MST and HST never change to summer time.
  • a name that is shaped correctly but is not in the IANA database, such as Europe/Sampletown.
  • user and app. These are values of a page’s timezone:. The application has one time zone, and nothing to follow.

A page can deviate from the application time zone, and a page can follow the reader’s time zone. Read Set the time zone.

theme { accent: #1f6f43 }

theme is a block with one property.

accent: is the colour of the organization’s identity. Write it as # and six hexadecimal digits. The engine paints it in four places only: a 2 px stripe at the top of the page, the small square beside the application name, and the underline under the current menu entry and under the current menu group. No text, state or control depends on it, so every colour is legible.

When there is no accent:, the colour is #1d5b3a.

The compiler does not check the value yet. The engine uses a value of the form #rrggbb, and it draws #1d5b3a for any other value.

The stylesheet with the accent belongs to the organization, not to one application. It uses the accent of the root application, or of the only application. In an organization with several applications and no root application, the engine draws #1d5b3a.

roles {
board "Board"
trainer "Trainer"
member "Member"
}

roles declares the roles of the application, one per line: a name in snake_case and an optional label. The administration page shows the label beside the role, and the organization’s list of applications shows it for the roles a person holds.

A login can hold any number of roles in each application. An access rule admits a login that holds any role the rule names. Anything no rule names is denied. For the rules, read Access rules and rights and Control who sees what. To give a person a role, read Manage logins.

The compiler refuses seven reserved names:

Name Reason
public always available in a rule: a visitor with no sign-in
authenticated always available in a rule: a login that holds a role in this application
anonymous the engine’s name for a visitor with no session. Write public in a rule.
owner reserved for row ownership
tenant_admin the administration of the organization is the engine’s, and no application declares it
job, system the engine’s own scheduled work acts as these, and the audit log must tell it apart from a person

The engine’s roles administrator, login_manager and auditor are not reserved. An application can declare a role with one of these names, and it is a different role.

auth {
methods: [password]
lockout {
after: 5
for: 15min
}
session {
lifetime: 30d
idle_timeout: 12h
}
}

auth sets how a person signs in and how long a session lasts. An application with no auth block gets every default in this section. The sign-in page, the password storage and the session cookie are the engine’s. No .mtd file can declare them. For the protection that every request gets, read Security.

All applications of an organization share one session. The lockout and session values that apply are those of the root application. If there is no root application, they are those of the application whose mount sorts first.

The durations in lockout and session are a whole number with one unit and no space: min, h or d, for example 15min, 12h or 30d.

methods: lists the sign-in methods. The only value is password, and it is the default. The compiler refuses every other value. A password is stored as an Argon2id hash.

lockout sets how many failed sign-ins lock a login, and for how long. The counter belongs to the login and is stored in the organization’s file. A successful sign-in sets it back to zero.

The number of failed sign-ins that locks the login. The default is 5. A value of 0 or less keeps the default.

How long the login stays locked, as a duration. The default is 15min.

session sets when a session ends. A session ends at the first of its two limits. The engine then deletes the session, and the person signs in again.

The time from sign-in to the end of the session, as a duration. Activity does not extend it. The default is 30d. The session cookie carries the same lifetime.

The time without a request after which the session ends, as a duration. Each request moves this limit forward. The default is 12h.

profile <name> of <table> "<Label>" { for: <role>, <role> }

A profile connects a login to one row of one table. :user.<name>_id in an access rule is the id of that row. profile member of members gives :user.member_id. The label and the block are optional. An auth block can declare several profiles, for example teachers, students and guardians in a school application.

auth {
profile teacher of teachers "Teacher" { for: teacher, class_teacher }
profile student of students "Student" { for: student }
profile guardian of guardians "Guardian" { for: guardian }
}

A login has at most one row per profile. :user.<name>_id has a value only while the login holds a role that the profile serves. Otherwise it is empty, and a rule that compares with it admits no row. A teacher who is also a guardian has a row for each of the two profiles.

The compiler refuses a profile whose table is not declared.

A login gets its profile rows in two ways. matterdata install binds them when it creates the login, with -profile <name>=<row id> or with -login <email>:<role>:<profile>=<row id>, which you can repeat for several logins. A tenant administrator binds, changes or removes one on the login’s card. See Load demo data and bind logins to records and Bind a login to a record.

The roles that the profile serves. When for: is omitted, the profile serves every role. The compiler refuses a role that is not declared in roles, and a role that another profile already serves.

scope <name> ref(<table>) "<Label>" { default: <bool column> }

A scope puts every page of a request in one row of one table: one term, one season or one class. An application declares at most one scope. The compiler refuses a second scope statement.

scope season ref(seasons) "Season" { default: current }

The type is always ref(<table>). The rows of that table are the values of the scope. The compiler refuses any other type and a table that is not declared.

A table joins the scope with its own scope: property, which names the path to the scope’s table. The engine then adds the scope’s condition to every read and write of that table. A table with no scope: is not filtered.

The engine draws a selector in the page header. A signed-in person can choose any value. The choice is kept in the session, for each application separately, and each change is written to the audit log. A scope decides which records a page is about. It gives no access. For the security rules, read Security.

default: names a bool column of the scope’s table. A session that has not chosen a value starts at a row where this column is true. If several rows are true, the engine takes the last one in display: order. If no row is true, or there is no default:, the engine takes the last row in display: order.

The compiler refuses a column that the table does not have, and a column that is not bool.

A new organization has no row in the scope’s table. Until somebody creates one, every page that reads a scoped table answers with status 503. Pages that read no scoped table work as usual. The page that creates the first row is one of them, because the scope’s own table is never scoped.

A signed-in person sees the application’s header and menu, one sentence that names the scope’s label, and one of these:

  • a button to the page that creates the first row, if the application has such a page and this person may open it;
  • “Ask an administrator …”, if such a page exists but this person may not open it;
  • a sentence that the application has no such page, if none exists.

The engine finds the page itself. You write nothing for it. A page qualifies when all of these are true:

  • it has a new_route: with no {parameter} in it;
  • it holds a form of the scope’s table;
  • it reads no scoped table;
  • its access: and the form’s access: admit the person.

If several pages qualify, the engine takes the one whose page name comes first in alphabetical order. After the save, the person returns to the page they first asked for, and that page now shows the new row’s records.

The form can need other rows first. For example, a term needs a school year, and the button does not lead to the school year’s page. Give that ref field an add_via:, or put the page in a menu. The school example does the first: its term form has field school_year { add_via: school_year }, so the head creates the first school year in a dialog and then saves the first term on the same form.

A visitor who is not signed in, an export and a dialog get a short error page with the same sentence and no button.

nav main "Club" {
members
events
}

nav declares a menu: a name, an optional label and the pages in menu order. A group inside a nav puts some of its pages under one label. The engine leaves out every entry that the reader cannot open. The syntax, the rendering and the refusals are on Navigation.

job reminders every day at 06:00 -> logic/reminders.ts "Reminders"

job names a script and a schedule that calls it, without a request. The four schedule shapes, the name rules and the refusals are on Jobs and retention.

Status: the engine records each occurrence of a job, but it runs no script yet.

retention comments.ip_hash !destructive "GDPR: IP hashes after seven days."

In the app block, retention is an acknowledgement. A new retention rule, or a shorter window, deletes stored records, and the migration refuses it until the app block acknowledges it. The rule itself is written in the table. Read Declaring or shortening a retention needs an acknowledgement.

drop table <table> !destructive "<Reason>"

In the app block, drop acknowledges that a whole table and all of its rows are deleted. A table that is gone from the sources has no declaration left to hold the acknowledgement, so it is written here. To remove one column, write drop <column> !destructive in the table instead.

drop table past_events !destructive "Replaced by events with a status."

The migration deletes a table only when its drop table line is present. Without it, the migration is refused, and the message names the line to write. The table’s multi junction tables and its history table go with it.

The compiler refuses these forms:

  • drop <name> without table. In the app block, drop removes only whole tables.
  • a drop table line without !destructive.
  • a drop table line for a table that the sources still declare. Delete the table declaration too.

matterdata upgrade applies the migration to an organization that holds data. For a destructive step it also needs -allow-destructive <app>.<table>.

The line can stay in the source after the table is gone. When it matches nothing, the migration plan reports it as unused and continues. A misspelled name is also reported as unused, and the real table then stays unacknowledged.

Website privacy policy