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.
What can be synced
Section titled “What can be synced”| 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.
Declare and sync
Section titled “Declare and sync”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}var set = Definitions.DefinitionSet.define("orders") .withRoles(List.of(Definitions.Role.of("admin") .withPermissions(List.of(Definitions.Permission.of("sales", "order", "manage"))))) .withEventTypes(List.of(Definitions.EventType.of("orders:sales:order:placed", "Order placed"))) .withConnections(List.of(Definitions.Connection.of("billing", "Billing webhooks"))) .withSubscriptions(List.of(Definitions.Subscription.of( "order-billing", "Placed orders to billing", "/webhooks/orders", List.of(Definitions.SubscriptionEventType.of("orders:sales:order:placed"))) .withConnectionCode("billing"))) .withScheduledJobs(List.of(Definitions.ScheduledJob.of( "orders:nightly-reconcile", "Nightly reconcile", List.of("0 0 2 * * *")))) .withDocs(List.of(Definitions.Doc.of("getting-started", "# Getting started\n")));
// A path target ("/webhooks/orders") resolves against this base at sync time.var client = FlowCatalystClient.builder() .baseUrl(platformUrl).clientCredentials(clientId, clientSecret) .subscriptionTargetBaseUrl("https://billing.example.com") .build();client.definitions().sync(set, SyncOptions.removingUnlisted());Annotations work too: @AsEventType, @AsConnection, @AsSubscription, @AsDispatchPool and
@AsRole on classes you register explicitly with DefinitionScanner.scan("orders", List.of(...))
(there is no classpath scanning).
import { FlowCatalystClient, sync } from "@flowcatalyst/sdk";
const definitions = sync .defineApplication("orders") .withRoles([{ name: "admin", displayName: "Orders admin", permissions: ["orders:sales:order:manage"] }]) .withEventTypes([{ code: "orders:sales:order:placed", name: "Order placed" }]) .withDispatchPools([{ code: "orders-default", name: "Orders", concurrency: 8, rateLimit: 600 }]) .withConnections([{ code: "billing", name: "Billing webhooks" }]) .withSubscriptions([ { code: "order-billing", name: "Placed orders to billing", target: "/webhooks/orders", connectionCode: "billing", dispatchPoolCode: "orders-default", mode: "BLOCK_ON_ERROR", eventTypes: [{ eventTypeCode: "orders:sales:order:placed" }], }, ]) .build();
const result = await client .definitions({ subscriptionTargetBaseUrl: "https://billing.example.com" }) .sync(definitions, { removeUnlisted: true });if (result.isErr()) throw new Error(result.error.message); // error.partial has what did syncDefinitions are attributes on classes in the scanned paths (flowcatalyst.definitions.paths,
default app/FlowCatalyst):
use FlowCatalyst\Attributes\{AsConnection, AsDispatchPool, AsEventType, AsPermission, AsRole, AsSubscription};use FlowCatalyst\Enums\DispatchMode;
#[AsPermission(context: 'sales', aggregate: 'order', action: 'manage', description: 'Manage orders')]final class ManageOrders {}
#[AsRole(name: 'admin', displayName: 'Orders admin', permissions: [ManageOrders::class])]final class AdminRole {}
#[AsEventType(subdomain: 'sales', aggregate: 'order', event: 'placed', name: 'Order placed')]final class OrderPlaced {}
#[AsDispatchPool(code: 'orders-default', name: 'Orders', rateLimit: 600, concurrency: 8)]final class OrdersPool {}
#[AsConnection(code: 'billing', name: 'Billing webhooks')]final class BillingConnection {}
#[AsSubscription( code: 'order-billing', name: 'Placed orders to billing', target: '/webhooks/orders', // resolved against APP_URL at sync time connectionCode: 'billing', queue: 'default', // required by the attribute; not sent dispatchPoolCode: 'orders-default', eventTypes: ['orders:sales:order:placed'], mode: DispatchMode::BLOCK_ON_ERROR,)]final class OrderBillingSubscription {}php artisan flowcatalyst:scan # discover and cache the attributed classesphp artisan flowcatalyst:sync --dry-run # show what would be sentphp artisan flowcatalyst:sync --remove-unlistedThe application prefix comes from FLOWCATALYST_APP_CODE. --roles, --event-types,
--subscriptions and the like sync one category; with spatie/laravel-permission installed the
sync also seeds the local permission tables (--no-spatie to skip). For programmatic sets use
SyncDefinitionSet::forApplication('orders') with DefinitionSynchronizer.
let set = DefinitionSet::for_application("orders") .add_role(RoleDefinition::make("orders:admin") .with_permissions(vec!["orders:sales:order:manage".into()])) .add_event_type(EventTypeDefinition::make("orders:sales:order:placed", "Order placed")) .add_connection(ConnectionDefinition::make("billing", "Billing webhooks")) .add_subscription( SubscriptionDefinition::make("order-billing", "Placed orders to billing", "/webhooks/orders") .with_connection_code("billing") .add_event_type(SubscriptionBinding::make("orders:sales:order:placed")), ) .add_doc(DocDefinition::make("getting-started", "# Getting started\n"));
DefinitionSynchronizer::new(client) .with_subscription_target_base_url("https://billing.example.com") .sync(&set, &SyncOptions::default()) .await .into_result()?;The Rust synchronizer checks each category locally first (duplicates, code shapes, permissions outside the application, five-field crons) and fails before sending.
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 |
Subscription mode
Section titled “Subscription mode”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.
Remove what you no longer declare
Section titled “Remove what you no longer declare”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
acmeremoves onlyacme’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.
Scope to a client
Section titled “Scope to a client”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.
Codes, not ids
Section titled “Codes, not ids”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
connectionCodemeans a connection owned by this application. SetsharedConnection: true(WithSharedConnectionCodein Go) to name a shared, application-less connection instead. There is no fallback between the two. - A
dispatchPoolCodethe 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).
Read the result
Section titled “Read the result”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.SkippedRoleslists role names that are not roles. - Java:
syncthrowsDefinitionSyncExceptioncarrying what did sync (e.result()). - TypeScript: an
Errwhosepartialis 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.
When to run it
Section titled “When to run it”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.
Related
Section titled “Related”- Subscriptions and connections and applications.
- Permissions and roles.
- SDK sync reference: the endpoints and their payloads.
- Copy definitions between environments: the console’s export and import, for definitions that are not in code.
- Decision: application-owned connections and code-first sync.