Docs · Concepts
One seed, three realms.
Everything in a FrontierJS app derives from one file, db/schema.lite. The rest grows outward from it, and every part can be traced back. This page is the handful of ideas that make that true. Read it before anything else; the guides assume it.
The schema is the seed
A schema states what is true about the data for its whole life: the fields and their rules, the relations, who may touch it, and how it may change. Here is one model. Every section below points back at a line of it.
enum LeadStatus { new contacted won lost }
model Lead {
id Int
name String (1, 120)
email String
phone String?
status LeadStatus (new)
ownerId Int
(2.4.4.5)
(read, ownerId == auth().id)
(status,
contact: new -> contacted,
win: contacted -> won,
lose: [new, contacted] -> lost)
}From those lines, without anyone writing them again:
- The table and every migration after it.
- Validation: a bad email is refused before it reaches the database, on the server and in the browser, with the same rule.
- Access: who may read, create, update and delete, and which rows each person sees.
- The lifecycle: the only ways
statuscan change. - Types, a JSON Schema, a default form and an agent's tools, each a projection of the same model.
What the schema never holds is UI behavior or business logic. It says what is true, not what to do about it, and that limit is what keeps everything derived from it predictable.
See it: Derived, one model and everything the schema produces.
Three realms, three nouns
An app has three realms, and each has one noun. Learn the three and you can predict how a feature works before reading its docs.
| Realm | Noun | What it is | For a lead |
|---|---|---|---|
| Data | Model | What the app knows, and the rules that govern it | model Lead, reached as db.lead |
| API | Service | What the outside world may ask for, and how | leads.service.ts, served at /api/leads |
| UI | Resource | How a screen binds to a service | Lead.mesa, exporting leads |
The Service and the Resource for Lead are each a few lines, because everything they could say is already in the model:
// api/src/services/leads.service.ts
import { createService } from '@frontierjs/junction'
export default createService({})<!-- web/src/resources/Lead.mesa -->
<script module>
import { createResource } from '@frontierjs/sierra/resource'
export const leads = createResource('leads')
</script>That empty service answers find, get, create, update, patch and remove, refuses bad input, grades every caller and filters the list by the row policy. A file in a realm holds only what the model cannot say.
Two more nouns describe what an app becomes rather than what it is: a Release is how it ships, and a Suite is how it is verified.
See it: The walkthrough, one model becoming a database, an API and a UI.
Declare first, then write code
A Declaration is something the app states and the framework enforces: a model, a gate, a transition, a service's list of methods. A Hook is code that runs. Prefer the first, because a declaration is read by every part of the app at once, and code is read only where it runs.
When an app needs more, there are four ways in, tried in this order:
- Declaration: change the data's own rules in the schema.
- Hook: step into one call's pipeline, before or after the work.
- Plugin: attach a capability to the whole app, such as jobs or integrations.
- Provider: swap the implementation behind a seam, such as where mail is sent.
Each step is wider than the one before it. Reaching for a hook where a declaration would do means the rule lives in one service and nowhere else.
See it: The pitch, Extend, with a sample of each.
Access lives on the model
Who may do what is declared in the schema and enforced where the data is written and read. A route, a job, a script and an agent all reach the data through the same check, so none of them can forget it.
Every caller is graded to a level on a ladder from 0 to 9, and @@gate names the level each operation needs, in the order read, create, update, delete:
| 0 | STRANGER | 5 | ADMINISTRATOR |
| 1 | VISITOR | 6 | OWNER |
| 2 | READER | 7 | SYSADMIN |
| 3 | CREATOR | 8 | SYSTEM, reached only by asSystem() |
| 4 | USER | 9 | LOCKED, which nothing passes |
Reading Lead top to bottom:
@@gate(2.4.4.5): a READER may read, a USER may create and update, an ADMINISTRATOR may delete. A stranger gets nothing.@@allow(read, ownerId == auth().id): a row policy. It is compiled into the query, so a USER's list holds only their own leads.@encryptedonphone: stored encrypted and left out of every ordinary read.@@transitions: the only movesstatuscan make. Contacting a lead twice is refused, and one move can carry a gate of its own.
The browser receives the same rules, so a screen can hide a button the user cannot press. That is a courtesy and nothing more: the server enforces the rule whatever the screen shows. A schema that declares no access rule at all is an open, plain ORM; once it declares one, a model with no gate is reachable only by the system. asSystem() is the one way past a gate, and it is audited.
See it: One field, from the model through each boundary.
The chain has a direction
A call travels down as data and a query, and comes back up as a result or an error. Each realm meets the next at a Boundary, and each boundary is a named checkpoint, not a wall: the caller is graded, input is checked, and the result is wrapped in one envelope.
Every translation along the way has exactly one owner. One place turns an error into an HTTP status. One place reads ?$limit=20 off a URL and hands the service a directive, and nothing past that point sees the $. When something comes out wrong, there is one place to look.
See it: The seams, one POST and every handoff it crosses.
Change flows outward
Every fact has one origin, the row. When a row is written, the write is announced once as an Event on a Channel, and every screen bound to that channel updates. A write that went through no service, from a job or a script, is still announced, because the announcement comes from the data and not from the caller.
So the UI binds; it does not own. A screen holds a reference to the data, never a second copy that has to be kept in step, and live updates are how every app behaves rather than a feature one adds.
See it: The ripple, one line changed and what moves.
Surfaces sit beside the schema
An app's folder is db/ and, beside it, one folder per surface: the places the app is reached from.
api/ | The services, over HTTP and WebSocket |
web/ | The application people sign in to |
site/ | A public site, built to static pages |
widgets/ | Pieces embedded in somebody else's page |
extension/ | A browser extension |
desktop/ · mobile/ | Native apps |
cli/ | A command line and terminal UI |
Every interface is written in Mesa, and a surface is where its compiled output goes, so a component reads the same in all of them. shared/ is a root but not a surface: pure code two surfaces both import, which imports neither.
Three axioms
Everything above is one of three rules, applied again:
- One origin. A fact is stated once, and everything else is derived from it. The schema, change.
- One name. A thing has one name in every realm, so
Lead,db.lead,/api/leadsandleadsare found from each other. Three realms. - One owner. Each rule and each translation lives in one place. Access, the chain.