Use feature flags from code
Applications declare their feature flags in code, sync the definitions to FlowCatalyst, and evaluate flags locally in memory from a cached snapshot. Feature flags explains the evaluation rules, precedence and governance model; this guide shows the code across the SDKs.
If you are building on the FlowCatalyst application framework in Go or Java, see Framework feature flags and Platform flags driver for module wiring and the headless admin section.
1. Declare and sync definitions
Section titled “1. Declare and sync definitions”Declare each flag with a stable key (^[a-z][a-z0-9._-]{0,99}$), type (BOOL or ENUM),
default value, lifecycle and governance. Syncing is idempotent: it creates new flags, updates
metadata, marks removed flags as orphaned (inCode = false), and preserves live kill switches,
rules and client overrides.
set := sync.ForApplication("orders"). AddFeatureFlag(sync.MakeBoolFlag("checkout.express", false). WithDescription("Enable one-click express checkout"). WithLifecycle("RELEASE"). WithGovernance("CLIENT_MANAGED"). WithExposeToClient(true)). AddFeatureFlag(sync.MakeEnumFlag("routing.engine", []string{"standard", "fast"}, "standard"). WithDescription("Route calculation engine"). WithLifecycle("EXPERIMENT"). WithGovernance("OPERATORS_ONLY"))
res := sync.NewSynchronizer(fcClient).Sync(ctx, set, sync.DefaultOptions())var express = BoolFlag.of("checkout.express", false) .description("Enable one-click express checkout") .lifecycle(FlagLifecycle.RELEASE) .governance(FlagGovernance.CLIENT_MANAGED) .exposeToClient(true);
var engine = EnumFlag.of("routing.engine", List.of("standard", "fast"), "standard") .description("Route calculation engine") .lifecycle(FlagLifecycle.EXPERIMENT) .governance(FlagGovernance.OPERATORS_ONLY);
// Contributed via FlagsModule and synced automatically by FlowCatalystModule DefinitionSync.import { FlowCatalystClient, flags } from '@flowcatalyst/sdk';
const express = flags.boolFlag('checkout.express', false, { description: 'Enable one-click express checkout', lifecycle: 'RELEASE', governance: 'CLIENT_MANAGED', exposeToClient: true,});
const engine = flags.enumFlag('routing.engine', ['standard', 'fast'] as const, 'standard', { description: 'Route calculation engine', lifecycle: 'EXPERIMENT', governance: 'OPERATORS_ONLY',});
const evaluator = new flags.FeatureFlagsClient(client, 'orders', [express, engine]);await evaluator.syncDefinitions();use FlowCatalyst\Facades\FlowCatalyst;use FlowCatalyst\Flags\FlagDefinition;
$defs = [ FlagDefinition::bool( key: 'checkout.express', defaultValue: false, description: 'Enable one-click express checkout', lifecycle: 'RELEASE', governance: 'CLIENT_MANAGED', exposeToClient: true, ), FlagDefinition::enum( key: 'routing.engine', allowedValues: ['standard', 'fast'], defaultValue: 'standard', description: 'Route calculation engine', lifecycle: 'EXPERIMENT', governance: 'OPERATORS_ONLY', ),];
FlowCatalyst::featureFlags('orders', $defs)->syncDefinitions();2. Evaluate in memory
Section titled “2. Evaluate in memory”Always pass an explicit evaluation context carrying the tenant (client) and any targeting
attributes (principal, tier, roles, custom attrs). Evaluation is pure and runs strictly
against the cached snapshot.
// Fetch conditional snapshot (uses If-None-Match / 304 Not Modified)snap, changed, err := sdkflags.New(fcClient).FetchSnapshot(ctx, "orders", lastRevision)
// For framework services, evaluate through *flags.Flags with PlatformFlags:evalCtx := flags.FromContext(cx).WithAttr("site", "west")if appFlags.EvalBool(evalCtx, ExpressCheckout).Value { // ...}engine := flags.EvalEnum(appFlags, evalCtx, RoutingEngine).ValueEvalContext evalCtx = EvalContext.from(ctx).withAttr("site", "west");
if (appFlags.bool(evalCtx, EXPRESS_CHECKOUT)) { // ...}String engine = appFlags.enumValue(evalCtx, ROUTING_ENGINE);await evaluator.refresh(); // conditional GET with ETag / 304
const evalCtx: flags.EvalContext = { client: 'acme', principal: 'prn_0HZXEQ5Y8JY5Z', tier: 'CLIENT', roles: ['orders:manager'], attrs: { site: 'west' },};
if (evaluator.bool(evalCtx, express)) { // ...}const chosen = evaluator.enumValue(evalCtx, engine); // typed as 'standard' | 'fast'use FlowCatalyst\Flags\EvalContext;
$ff = FlowCatalyst::featureFlags('orders', $defs);$ff->refresh(); // conditional GET with ETag / 304, cached in Laravel Cache
$evalCtx = new EvalContext( client: 'acme', principal: 'prn_0HZXEQ5Y8JY5Z', tier: 'CLIENT', roles: ['orders:manager'], attrs: ['site' => 'west'],);
if ($ff->bool($evalCtx, 'checkout.express')) { // ...}$chosen = $ff->enum($evalCtx, 'routing.engine');3. Laravel Pennant integration (PHP)
Section titled “3. Laravel Pennant integration (PHP)”In Laravel applications using laravel/pennant, register FlowCatalystPennantDriver so standard
Feature::for($scope)->active('checkout.express') and Feature::for($scope)->value('routing.engine')
calls evaluate directly against the FlowCatalyst snapshot:
use FlowCatalyst\Flags\EvalContext;use FlowCatalyst\Flags\FlowCatalystPennantDriver;use Illuminate\Support\Facades\App;use Laravel\Pennant\Feature;
Feature::extend('flowcatalyst', function ($app) use ($defs) { $client = $app->make(\FlowCatalyst\Client\FlowCatalystClient::class) ->featureFlags('orders', $defs);
return new FlowCatalystPennantDriver( client: $client, scopeResolver: fn (mixed $scope): EvalContext => new EvalContext( client: $scope?->tenantCode ?? '_platform', principal: $scope?->principalId, roles: $scope?->roles ?? [], ), );});4. Expose selected flags to browsers or mobile apps
Section titled “4. Expose selected flags to browsers or mobile apps”Only flags declared with exposeToClient = true are included in client-exposed evaluation. Never
send raw rules or other tenants’ overrides to a browser or mobile client.
exposed := appFlags.EvaluateClientExposed(evalCtx)// Returns flags.ExposedFlags{Revision: snap.Revision, Flags: map[string]any{...}}ExposedFlags exposed = appFlags.evaluateClientExposed(evalCtx);// exposed.revision(), exposed.flags()const exposed = evaluator.evaluateClientExposed(evalCtx);// { revision: number, flags: Record<string, boolean | string> }$exposed = $ff->evaluateClientExposed($evalCtx);// ['revision' => int, 'flags' => array<string, bool|string>]5. Delegated client overrides (X-On-Behalf-Of)
Section titled “5. Delegated client overrides (X-On-Behalf-Of)”Applications that provide a self-service settings screen for client administrators can set or clear
a CLIENT_MANAGED override through the platform’s delegated client-override endpoint while
passing X-On-Behalf-Of: <principalId> so the platform records the acting user in the audit log.
The platform refuses changes to OPERATORS_ONLY flags (403 FLAG_OPERATORS_ONLY) and locked
client overrides (403 FLAG_LOCKED).
See each SDK’s dedicated page for complete API signatures: