Skip to content

Declare definitions in code

An application owns things on the platform: the event types it publishes, the roles and permissions its users get, the connections and subscriptions that deliver to it, its dispatch pools, scheduled jobs, process diagrams, documentation pages and API description. Declare them in your code and sync them as a deploy step: the platform makes its rows match what you declared. The code is then the source of truth, reviewed like any other change, and the same definitions work in every environment.

Category Endpoint (/api/applications/{appCode}/...) Notes
Roles roles/sync Short names become app:name. Permissions are four segments, app:context:aggregate:action, inside the application. Permissions reach the platform only through the roles that grant them. See permissions in code.
Event types event-types/sync Codes are four segments starting with the application code.
Dispatch pools dispatch-pools/sync Concurrency and rate limit (per minute).
Connections connections/sync Application-owned; the platform assigns the application’s service account, so the definition carries no credentials.
Subscriptions subscriptions/sync Name the connection by code, the pool by code.
Processes processes/sync Diagrams (Mermaid by default) for documentation.
Scheduled jobs scheduled-jobs/sync Six-field, seconds-first crons; see run work on a schedule.
Principals principals/sync Users by email with role names.
OpenAPI openapi/sync The application’s API document, shown in the console.
Docs docs/sync Markdown pages for administrators; always a full replace.
Push push/sync Push topic rules and ticket keys; see topics and tickets.

The SDKs call them in dependency order: roles, event types, dispatch pools, connections, subscriptions, processes, scheduled jobs, principals, OpenAPI, docs. That way a subscription can name a connection, pool and event type created earlier in the same run. Each category is its own call: a failure in one does not undo the others, but subscriptions are not sent when their connections failed (their codes could not resolve).

The credentials fcdev init and the console provision for an application (the platform:application-service role) may sync every category for their own application and no other.

set := sync.ForApplication("orders").
AddRole(sync.MakeRole("admin").WithDisplayName("Orders admin").
WithPermissions("orders:sales:order:view", "orders:sales:order:manage")).
AddEventType(sync.MakeEventType("orders:sales:order:placed", "Order placed")).
AddDispatchPool(sync.MakeDispatchPool("orders-default", "Orders").WithConcurrency(8).WithRateLimit(600)).
AddConnection(sync.MakeConnection("billing", "Billing webhooks")).
AddSubscription(sync.MakeSubscription("order-billing", "Placed orders to billing",
"https://billing.example.com/webhooks/orders").
WithConnectionCode("billing").
WithDispatchPool("orders-default").
WithMode("BLOCK_ON_ERROR").
Bind("orders:sales:order:placed", "")).
AddScheduledJob(sync.MakeScheduledJob("orders:nightly-reconcile", "Nightly reconcile", "0 0 2 * * *").
WithTargetURL("https://orders.example.com/jobs")).
AddProcess(sync.MakeProcess("orders:sales:place-order", "Place order").WithBody("graph LR; Cart-->Placed")).
AddDoc(sync.MakeDoc("getting-started", "# Getting started\n"))
res := sync.NewSynchronizer(c).Sync(ctx, set, sync.DefaultOptions())
if res.HasErrors() {
log.Fatal(res.Errors()) // map of category -> error
}

Not every SDK’s set builder covers every category yet:

Category Go Java TypeScript PHP Rust
Roles, event types, pools, connections, subscriptions, principals, processes, scheduled jobs yes yes yes yes yes
Docs yes yes not in the set builder not in the set builder yes
OpenAPI yes yes yes yes (--openapi-file) yes
Push rules and keys no yes yes yes yes
Path targets resolved against a base URL no (absolute URLs) yes yes yes (APP_URL) yes

A subscription’s mode (IMMEDIATE, NEXT_ON_ERROR or BLOCK_ON_ERROR) is applied by the sync on create and on update. Your code is the source of truth, so a mode changed in the console is overwritten by the next sync that carries a mode. A definition that leaves the mode out keeps the stored mode, and a new subscription takes the default. A value that is not one of the three is refused with the validation code INVALID_MODE. See Ordering.

By default a sync creates and updates; it removes nothing. Pass remove-unlisted (sync.WithRemoveUnlisted(), SyncOptions.removingUnlisted(), { removeUnlisted: true }, --remove-unlisted, SyncOptions { remove_unlisted: true, .. }) to make the platform remove rows of that application and scope that your set no longer lists. The guards:

  • Only rows that came from code or the API are touched. Anything created in the console is never changed or removed by a sync.
  • It applies per category and per scope: a set for client acme removes only acme’s rows, and a global set only the global ones.
  • A connection still used by a subscription is not removed: that connection sync is refused as a whole (CONNECTION_REFERENCED).
  • Docs are always a full replace, with or without the option.
  • A category the set leaves empty is not sent, so it is not cleared. To empty a category on purpose, remove its rows in the console or via the API.

Run remove-unlisted from one place per application (your deploy pipeline), never from two sets that each hold half the definitions: the second sync would remove what the first just created.

Connections and subscriptions can be global (every client) or belong to one client. Scope a whole set with ForClient("acme") (Go), .forClient("acme") (Java, TypeScript), or one row with its own client. Use the client’s identifier, not its id: identifiers are the same in every environment. Java and TypeScript also accept a per-client target base URL (forClient("acme", "https://acme.example.com")), for tenants with their own host.

A multi-tenant codebase usually builds one global set plus one set per client. Sync them with syncGrouped (Java, TypeScript): it merges sets that share an application and makes exactly one call per (application, client) scope, global first, so two sets for the same scope cannot undo each other under remove-unlisted. Scheduled jobs carry their own client per job.

Everything that refers to something else does it by code: a subscription’s connectionCode and dispatchPoolCode, a role’s permissions, a principal’s roles. Ids are generated per environment, so an id written into code works in one environment only.

  • A bare connectionCode means a connection owned by this application. Set sharedConnection: true (WithSharedConnectionCode in Go) to name a shared, application-less connection instead. There is no fallback between the two.
  • A dispatchPoolCode the platform cannot resolve is silently left unset, and the subscription uses the default pool. Sync the pool in the same set (pools are synced before subscriptions).

Every SDK returns a per-category result (created, updated, deleted, unchanged) and an error per category that failed. Treat any error as a failed deploy step:

  • Go: res.HasErrors(), res.Errors(); res.Principals.SkippedRoles lists role names that are not roles.
  • Java: sync throws DefinitionSyncException carrying what did sync (e.result()).
  • TypeScript: an Err whose partial is the full result.
  • PHP: the command prints a table and exits non-zero on failure.
  • Rust: SyncResult::into_result() turns any failed category into an error.

A principal’s passwordHash is used only when the sync creates the user; for existing users it is reported as ignored.

Run the sync as a step of every deploy, after the new code is out and before traffic depends on new definitions (an event type must exist before subscribers can bind to it). It is idempotent: an unchanged set changes nothing. In development, run it whenever you change a definition.