Protect your first record
Write a minimal FRL rule and follow a record action.
A Frontbacked theme is the reusable website package you ship: pages, styles, scripts, assets, optional skins, and optional rules for the data and actions the site supports.
Frontbacked Rule Language (FRL) gives that theme a protected data layer without making every theme become a server project. It answers four questions for every post type:
- What fields are allowed?
- How should incoming data be cleaned or computed?
- Who can create, get, list, edit, or delete this data?
- Should this action create related writes or async work?
FRL lives in the theme's single rules file: backend/index.frl.
What FRL Unlocks
FRL is more than a validation file. It is the place where a theme describes its data powers:
| Feature | What it lets your theme do |
|---|---|
version 2; | Declare the current FRL grammar. Put it before any other statement. |
post blocks | Define records such as articles, products, comments, plans, tickets, reviews, portfolios, or lessons. |
user block | Shape and validate custom signed-in user data. |
schema | Reject unknown fields and validate nested objects, arrays, enums, files, prices, defaults, and immutable fields. |
before hooks | Trim, normalize, compute slugs, set derived status, and prepare trusted fields before validation. |
allow rules | Decide who can create, get, list, edit, delete, read, or write each post type. |
after hooks | Run follow-up work after validation and permissions pass. |
| Related writes | Create, edit, delete, or increment related posts after a successful action. |
allow list(...) policies | Control who can list a post type and set default/max list limits. |
endpoint.* blocks | Add custom guarded JSON endpoints for workflows that are not plain CRUD. |
http.* helpers | Contact approved outside services from FRL with host review and loop protection. |
must(...) and mustNot(...) | Stop a hook or endpoint when a required assertion fails. |
dedupe | Make repeat endpoint requests return the same outcome instead of duplicating work. |
$secret | Reference admin-filled private values without building custom settings forms. |
as aliases | Give admin UIs friendlier labels for post types, fields, endpoints, secret keys, and private settings without renaming the stored data. |
One Current Syntax
FRL uses version 2, including when the version declaration is omitted. Keep version 2; at the top of your rules to make the language version explicit. Version 1 rules must be migrated before use.
| Older syntax | Write this instead |
|---|---|
await http.post(...) | http.post(...); calls are awaited automatically. |
promise(...) and on resolved | An endpoint.* callback with dedupe and post.* writes. |
profile or auth blocks | user with $user.current.data and $user.pending.data. Account access is controlled by site settings. |
process or create process in a post | before create, before edit, or another write hook. |
| Structural trigger blocks | post.* helpers inside after hooks. |
An endpoint's nested process block | Statements directly inside the endpoint. |
idempotency | dedupe. |
str.id(length) | random.id(length). |
not value | !value; use mustNot(...) for assertions. |
validateExists | exists. |
servertime | serverTime. |
A fields { ... } wrapper inside schema | Field declarations directly inside schema { ... }. Nested object fields still use fields: { ... }. |
An after hook waits for its calls to finish. For queued notification delivery, use notification.send(...).
A Minimal Rule File
Rule input (JSON)
Use a complete version 2 rule file. Select a post with “postType” and “action”, or an “endpoint” by name. Saved data, jobs, payments and email need the local server. Dedupe replay protection also needs a site.
Check complete rules or run schemas, permissions, hooks and calculations against the input above. Add excerpts to a complete rule before running.
This defines a leads post type. When a frontend page calls Frontbacked.createPost({ type: "leads", post }), Frontbacked applies the rule and either stores a clean, valid post or returns a useful error.
Rule Flow
For create, edit, and delete actions, Frontbacked evaluates a post rule in this order:
- Prepare rule values such as
$post,$actor,$action,$admin,$secret,$page,$currency, and$this. - Fill server-generated fields, then schema defaults for missing or
nullfields during create. - Run every matching
beforehook in source order.before writeruns for create, edit, and delete, and comma groups such asbefore create, editshare setup across selected actions. - Validate the
schema. - Evaluate every matching
allowrule. All of them must pass. - Run matching
afterhooks for write actions when present. - Materialize any related writes queued by
post.*helpers.
get and list do not run before or after hooks. get checks single-post permissions, while list checks whether the visitor may request the list and what size the list may be. Use FQL where or filter to choose which rows appear in a list. Because allow read: also applies to list requests, allow read: and allow list: cannot use post-scoped values such as $post, $row, or $rowMeta, even through helper functions. If an action has no matching allow rule, Frontbacked denies it.
For webhook callbacks and delayed external work, use endpoint.* with dedupe and post.* helpers. That keeps callback handling in the same clear endpoint model as every other custom route.
Continue with Define record and account rules.