Permissions and definitions
Your repository is the source of truth for the roles, permissions, event types and other
definitions your application owns. You declare them as PHP classes with attributes, and
flowcatalyst:sync pushes them to the platform. The same flow is described for every language in
Sync definitions and Permissions in code;
the model is in Permissions and roles.
Sync uses the service account, not the login client:
FLOWCATALYST_CLIENT_ID=svc_...FLOWCATALYST_CLIENT_SECRET=...FLOWCATALYST_APP_CODE=blogThe service account needs roles-write on the application. Definition classes are discovered under
the directories in flowcatalyst.definitions.paths (default app/FlowCatalyst).
Permissions and roles
Section titled “Permissions and roles”The platform has no standalone “create permission” endpoint: permissions reach it through the roles that grant them. Declare a permission once and link it from many roles by class.
use FlowCatalyst\Attributes\AsPermission;
// "application" defaults to FLOWCATALYST_APP_CODE, giving "<app>:posts:post:view"#[AsPermission(context: 'posts', aggregate: 'post', action: 'view', description: 'View posts')]class ViewPosts {}use App\FlowCatalyst\Permissions\{EditPosts, ViewPosts};use FlowCatalyst\Attributes\AsRole;
#[AsRole(name: 'editor', displayName: 'Editor', permissions: [ViewPosts::class, EditPosts::class])]class EditorRole {}#[AsRole] takes name, displayName, description, permissions, clientManaged (clients may
assign the role to their own users) and application. A role’s permissions list may contain
#[AsPermission] class names, PermissionInput objects or plain
application:context:aggregate:action strings. Role names are stored on the platform as
<app>:<name>.
A permission that no role references never reaches the platform, but it is still seeded locally.
Other definitions
Section titled “Other definitions”All of these accept an application: argument to override the default application.
| Attribute | Declares | Main arguments |
|---|---|---|
#[AsEventType] |
An event type | subdomain, aggregate, event, name, description, clientScoped |
#[AsConnection] |
A connection | code, name, description, externalId, client |
#[AsSubscription] |
A subscription | code, name, target, connectionCode, queue, dispatchPoolCode, eventTypes, mode, maxRetries, timeoutSeconds, maxAgeSeconds, delaySeconds, dataOnly, sharedConnection, client |
#[AsDispatchPool] |
A dispatch pool | code, name, rateLimit (100), concurrency (10) |
#[AsProcess] |
A process document | subdomain, processName, name, body, diagramType (mermaid), tags |
#[AsScheduledJob] |
A scheduled job | code, name, crons, timezone, payload, concurrent, tracksCompletion, timeoutSeconds, deliveryMaxAttempts, targetUrl, clientId |
On a subscription, a mode you declare is applied by the sync on create and on update, so it overwrites a mode changed in the console; leave it out to keep the stored mode. An unknown value is refused with INVALID_MODE.
Event types
Section titled “Event types”The code is application:subdomain:aggregate:event; the application prefix is added at sync.
use FlowCatalyst\Attributes\AsEventType;
#[AsEventType(subdomain: 'comments', aggregate: 'comment', event: 'created', name: 'Comment Created', clientScoped: true)]final class CommentCreated extends BaseDomainEvent { /* ... */ }Add the directory holding such classes (for example app_path('UseCases')) to
flowcatalyst.definitions.paths.
Connections and subscriptions
Section titled “Connections and subscriptions”A connection is application-owned: the platform assigns the application’s own service account, so
the definition carries no credentials. Connections sync before subscriptions in the same run, so a
subscription’s connectionCode resolves immediately.
use FlowCatalyst\Attributes\{AsConnection, AsSubscription};
#[AsConnection(code: 'orders-webhook', name: 'Orders Webhook')]class OrdersWebhookConnection {}
#[AsSubscription( code: 'order-notifications', name: 'Order Notifications', target: '/webhooks/orders', connectionCode: 'orders-webhook', queue: 'orders', dispatchPoolCode: 'default', eventTypes: ['myapp:orders:order:placed'], maxRetries: 5, timeoutSeconds: 30,)]class OrderNotificationSubscription {}target is a path or an absolute URL. A path is joined onto
flowcatalyst.subscriptions.target_base_url (or APP_URL) when you run the sync, so the same class
works in every environment. connectionCode names a connection owned by this application; set
sharedConnection: true to reference an application-less connection. There is no fallback between
the two, so the wrong choice is a CONNECTION_NOT_FOUND 404, never a silent switch of credentials.
mode takes FlowCatalyst\Enums\DispatchMode (IMMEDIATE, NEXT_ON_ERROR, BLOCK_ON_ERROR).
See Subscriptions and connections.
Scheduled jobs
Section titled “Scheduled jobs”Crons are six-field, seconds first. The code is sent as declared. A class that implements
FlowCatalyst\ScheduledJobs\HandlesScheduledJob (or merely has a public
handle(array $envelope, callable $log) method) is wired automatically: the SDK registers a signed
route, resolves your class from the container when the platform fires, and records the return value
as the completion result.
use FlowCatalyst\Attributes\AsScheduledJob;use FlowCatalyst\ScheduledJobs\HandlesScheduledJob;
#[AsScheduledJob( code: 'orders:nightly-report', name: 'Nightly report', crons: ['0 0 2 * * *'], timezone: 'UTC', tracksCompletion: true, timeoutSeconds: 600,)]final class NightlyReportJob implements HandlesScheduledJob{ public function handle(array $envelope, callable $log): mixed { $log('info', 'starting'); return ['rows' => 120]; }}Disable the auto-registered route with FLOWCATALYST_SCHEDULED_JOBS_ROUTE=false if you want to
mount ScheduledJobRunner::processWithResponse() yourself; guard it with the fc-signature
middleware and keep it out of body-mutating middleware groups. Concurrency is the receiver’s
responsibility. See Scheduled jobs.
Scan and sync
Section titled “Scan and sync”php artisan flowcatalyst:scan # find attributed classes and cache themphp artisan flowcatalyst:sync --dry-run # previewphp artisan flowcatalyst:sync # push| Option | Effect |
|---|---|
--app=<code> |
Application code to sync (default FLOWCATALYST_APP_CODE). |
--roles, --event-types, --subscriptions, --connections, --dispatch-pools, --principals, --processes, --scheduled-jobs, --push |
Sync only that category. |
--openapi, --openapi-file=<path> |
Publish only the attached OpenAPI document, or attach one before sync. |
--remove-unlisted |
Full replace per application and category: remove API-sourced definitions that are not in your cache. Definitions created in the console are left alone. |
--no-spatie |
Skip seeding the local Spatie tables. |
--dry-run |
Show what would be synced. |
If spatie/laravel-permission is installed, sync also seeds the local Spatie tables so local
authorisation matches what was pushed (FLOWCATALYST_SEED_SPATIE). In CI:
php artisan flowcatalyst:scanphp artisan flowcatalyst:sync --remove-unlistedSeveral applications in one codebase
Section titled “Several applications in one codebase”Each definition’s application is resolved in this order: application: on the attribute, then the
longest-prefix match in definitions.application_map, then --app / FLOWCATALYST_APP_CODE. Sync
groups definitions by application and posts each group to its own endpoint.
'definitions' => [ 'application_map' => [ 'App\\Orders\\' => 'orders', 'Vendor\\Logistics\\' => 'logistics', ],],An application is contacted only if at least one definition resolves to it. Moving the last
definition of a category out of an application therefore leaves the old rows in place rather than
pruning them; remove them by hand or sync that application explicitly with --app.
Programmatic sync
Section titled “Programmatic sync”For dynamic definitions, multi-tenant applications or custom error handling, build sets in code and
call DefinitionSynchronizer:
use FlowCatalyst\Sync\{DefinitionSynchronizer, EventTypeDefinition, RoleDefinition, SyncDefinitionSet, SyncOptions};
$synchronizer = app(DefinitionSynchronizer::class);
$set = SyncDefinitionSet::forApplication('my-app') ->withRoles([ new RoleDefinition(name: 'admin', displayName: 'Administrator', permissions: ['my-app:settings:setting:manage']), ]) ->withEventTypes([ EventTypeDefinition::make('User Created', 'my-app', 'users', 'user', 'created'), ]);
$result = $synchronizer->sync($set, SyncOptions::withRemoveUnlisted());
if ($result->hasErrors()) { foreach ($result->getErrors() as $type => $error) { logger()->error("Failed to sync {$type}: {$error}"); }}$totals = $result->getTotals();syncAll([...$sets]) syncs several applications and returns results keyed by application code.
SyncOptions has factories such as rolesOnly(), eventTypesOnly(), scheduledJobsOnly() and
pushOnly(), or construct it with removeUnlisted: and per-category flags.
For a multi-tenant application that serves many clients, build one set per client with
SyncDefinitionSet::forApplication('app')->forClient('acme', targetBaseUrl: 'https://acme.example.com')
instead of using client: on attributes. Attributes are compiled into the codebase; the tenant
list is runtime data. The optional definitions.set_providers config lists classes implementing
ProvidesSyncDefinitionSets so flowcatalyst:sync picks such sets up too.
Custom permission resolvers
Section titled “Custom permission resolvers”When a request carries a FlowCatalyst bearer token, the fc-token guard validates it offline
(JWKS, no network call) and asks a PermissionResolver for the principal’s permission codes:
namespace FlowCatalyst\Auth\Contracts;
interface PermissionResolver{ /** @return string[] Effective permission codes ("app:context:aggregate:action"). */ public function resolve(array $roles, ?string $token = null): array;}The service provider binds a default with bindIf, in this order of precedence:
- A
PermissionResolveryou bind yourself. CataloguePermissionResolver, when anRbacCatalogueis bound (offline, from a catalogue in code).- By config
FLOWCATALYST_OIDC_PERMISSION_RESOLVER:token(default) reads the token’sscopeclaim;api_mecallsGET /api/meand caches the answer by token.
An offline catalogue:
use FlowCatalyst\Auth\Rbac\{RbacBuilder, RbacCatalogue};
$this->app->instance(RbacCatalogue::class, RbacBuilder::make() ->role('billing-admin')->grants(['billing:invoice:invoice:create', 'billing:invoice:invoice:read']) ->role('support')->grants(['billing:ticket:*:*']) ->build());A resolver backed by local Spatie tables:
final class SpatiePermissionResolver implements PermissionResolver{ public function resolve(array $roles, ?string $token = null): array { if ($roles === []) return []; sort($roles); return Cache::remember('fc.perms.' . md5(implode(',', $roles)), 60, fn () => \Spatie\Permission\Models\Role::query() ->where('guard_name', 'web')->whereIn('name', $roles) ->with('permissions:id,name')->get() ->flatMap(fn ($r) => $r->permissions->pluck('name')) ->unique()->values()->all()); }}
// AppServiceProvider::register()$this->app->bind(PermissionResolver::class, fn () => new SpatiePermissionResolver());Four things to get right:
- The token’s
rolesclaim must match your stored role names (check whether they arrive bare orapp:-prefixed). - Stored permission names must be the canonical lowercase
application:context:aggregate:action. - Wildcards work: a stored
orders:order:*:*satisfies a check fororders:order:order:view. - A resolver only fills permissions. Scope (
hasClientAccess(),hasApplicationAccess()) still comes from the token’sclientsandapplicationsclaims.
Decide whether a lookup error fails the request or fails closed by returning []; the api_me
resolver fails closed.
Errors
Section titled “Errors”Sync errors are collected per category in SyncResult (hasErrors(), getErrors()); the artisan
command prints them and exits non-zero. A definition that resolves to no application and has no
default is reported and skipped without blocking the others. API failures raise the exceptions
described in Control plane.