Core (modules, instances, context, config)
Status: M1. Java names are given where the shape matters; the rules are language-neutral.
1. Modules and the application lifecycle
Section titled “1. Modules and the application lifecycle”A module has an id (lowercase, [a-z][a-z0-9-]*, unique in the application) and four
hooks:
| Hook | May do | May not do |
|---|---|---|
register(AppBuilder) |
declare settings, provide services, contribute migrations, claim configuration components (amended 2026-10-14, config-and-code; registering drivers is gone) | build services, read config values, start threads |
boot(App) |
read config, look up services, add health checks, start background work | provide new services |
started(App) |
work that needs every module booted: compile a route table, start accepting traffic | provide new services |
shutdown(App) |
stop background work it started | — |
App.builder.module(a).module(b)...start:
- Calls every module’s
register, in the order listed. - Loads and validates config (section 4). Any problem fails here.
- Builds every provided service eagerly. A provider is a function from a lookup to a value; when it asks for another service, that one is built first. The resulting build order is recorded.
- Calls every module’s
boot, in the order listed. - Calls every module’s
started, in the order listed, after everyboothas completed. Use it for work that depends on what other modules did inboot, so that module order does not matter for it. If anybootfailed, nostartedruns. - Returns the running
App.
Failures, all thrown from start as StartupException, collected where possible so one start
reports every problem, each naming its module and key:
- two modules with one id; two providers for one type;
- a lookup of a type nobody provides (names the module whose provider asked);
- a cycle between providers (names the cycle);
- any config error (section 4);
- an instance factory failure (section 2; before 2026-10-14 also an unknown driver name);
- a removed key or an unknown key under a claimed component (config and code, section 5);
- an exception from a provider, a
boothook or astartedhook.
If start fails after building some services, it closes those it built, in reverse order,
before throwing.
Test overrides (MA item 2, 2026-10-10). AppBuilder.override(Class<T> type, T instance)
replaces the service a module provides for type: the module’s provider is never run, and every
lookup of type (other providers’, App.get, App.find) returns instance. Rules:
- Test mode only. Test mode is declared by
APP_ENVbeing exactlytestin the environment the builder reads (environment(Map), else the process environment; blank or absent meanslocal). With any override outside test mode,startandlaunchthrowStartupException(one problem per overridden type, key = the type name, message naming the actual environment) before any module’sregisterruns, so nothing is built and an override cannot reach a deployed application.APP_ENV=testalso enablesconfig/secrets.local.yaml(section 4), as before. Ruling taken: no separate “test mode” switch on the builder, because production code could call it; the environment name is a deployment fact. - The type must be provided by some module; otherwise start-up fails (“overridden, but no module
provides this type”). Conservative ruling: overriding an implementation class instead of the
interface modules look up would otherwise do nothing, silently. Optional collaborators nobody
provides are added with a test module’s
provide, not withoverride. - The framework’s seeded types (
Config,InstantSource,Ids,MonotonicClock;Driversuntil 2026-10-14) cannot be overridden (start-up fails); the builder has methods for the clocks and environment. overrideitself throwsIllegalArgumentExceptionat once for a second override of one type or an instance that is not of the type. It may be called in any order with the other builder methods; the test-mode check happens when the application starts.- The application does not close an override at shutdown (the test owns it). Each override is logged at WARN at start-up, naming the type and the module whose provider it replaced.
- Commands (
launch) see the overrides too.
Services the core module provides (MA item 3, 2026-10-10): Metrics and Background
(background-and-metrics contract). Health joined the seeded framework types (Config, Drivers,
InstantSource, Ids, MonotonicClock), which no module may provide or override; so did
EnvironmentVariables (MA item 5: reads one variable of the builder’s environment by exact name,
with no way to list them; the env secret driver uses it). App.close
stops background loops before any module’s shutdown hook.
Lookup is get(Class<T>): a typed read from a map built in step 3, throwing when nobody
provides the type. find(Class<T>) is the same read returning Optional<T> (no throw), for
optional collaborators. No reflection. Only one
provider per type; named variants are reached through their capability’s registry (section 2).
Note 2026-10-14 (config and code, sections 3.1 and 11): the app.* settings
below were briefly moved to code (HealthPolicy, MetricsOptions, AppBuilder.shutdownDrain) and
are configuration again, as written here; the core claims the app component, so a misspelt key
under it fails start-up.
Shutdown (App.close, idempotent, also run from a JVM shutdown hook the builder may
install): module shutdown hooks in reverse module order (for every module whose boot ran, which
includes any whose started ran or failed), then every built service that is
AutoCloseable in reverse build order. Each step’s failure is logged and does not stop the
rest. Setting app.shutdown.drain (duration, default 10s) is the time each hook may take
before it is logged as overrun and the next one runs.
Health: App.health holds named checks added at boot. check runs them all, each with
a timeout (app.health.timeout, default 2s), and returns a result per check: Up, Down(reason)
or TimedOut.
Criticality (MA item 7, 2026-10-10). Every check is CRITICAL or INFORMATIONAL
(Criticality). add(name, check) adds a critical check; add(name, check, criticality) chooses.
A critical check that is not Up makes the application not ready; an informational one is run and
reported the same way but never decides readiness. The report (HealthReport) carries the names of
the informational checks: isUp is true when every check is up, isReady when every critical
check is up, criticality(name) says which a check ran with.
- Configuration wins over what a module asked for, by check name:
app.health.criticalandapp.health.informational(string lists, default empty). A name in both fails start-up (problem onapp.health.informational). A name that matches no check after everystartedhook ran is a WARN, not a failure: some checks are added conditionally (theoutboxcheck exists only when the table does), so one configuration must work for deployments with and without them. - Defaults: every check the framework adds is critical except
flowcatalystandoutbox(flowcatalyst contract section 1 and 3), which are informational because the platform is not on the request path. A platform outage therefore no longer takes every replica out of rotation;app.health.critical: [flowcatalyst]restores the old behaviour. - The HTTP side (http contract section 8) answers
/health/readyfromisReady.
2. Named instances and drivers
Section titled “2. Named instances and drivers”Amended 2026-10-14 (config and code, section 2.1): driver names are gone from configuration. Drivers,
DriverFactory and AppBuilder.drivers are removed; a capability whose instances come from
configuration (database, Redis) builds each with one InstanceFactory (Instances.build(capability, section, lookup, factory)), and capabilities with a driver choice (locks, secret stores) are wired
in code. The text below holds for instance sections otherwise; read driver as removed.
A capability with drivers (locks now; cache, storage, mail later) works the same way:
locks: default: main instances: main: { driver: database } shared: { driver: redis, connection: default, prefix: "fw:lock:" } local: { driver: memory }- Modules register drivers by name for a capability:
drivers.register(LockStore.class, "redis", factory). A second registration of one name for one capability fails start-up. - At start-up every configured instance is built from its section. An instance naming an unregistered driver fails start-up, listing the registered names.
- The factory receives the instance name, its
InstanceConfigsection and the service lookup. It reads its keys through typed getters. After the factory returns, any key in the section it did not read (other thandriver) fails start-up as unknown: a typo cannot pass silently. - A capability with only one driver in practice may declare a default driver name; its instances
may then omit
driver(database instances default topostgresql, Redis instances toredis). Capabilities with a real choice (locks, cache) have no default driver. - The factory also receives the instances of the same capability already built, so wrapper drivers can refer to them.
defaultnames the instance returned by the capability’sdefaultInstance. If there is exactly one instance,defaultmay be omitted. If there are several and it is omitted, or it names a missing instance, start-up fails.- The capability registry (
Locks) is itself a provided service:get(name)returns the instance or throwsIllegalArgumentExceptionnaming the known instances. - A capability with no configured instances is valid; its registry is empty and
getthrows. - Wrapper drivers (failover, prefixed, metered) are out of scope for M1, but the factory’s access to the registry of already-built instances must allow them later.
3. Context
Section titled “3. Context”Context is a value passed explicitly to use cases and handlers. It is never stored in a static
or a thread-local by the framework.
| Field | Type | Required |
|---|---|---|
| client | ClientId |
always (design rule 8) |
| principal | PrincipalId |
no |
| principal kind | PrincipalKind: USER, SERVICE or FIELD_WORKER |
no; only with a principal (added 2026-10-14; FIELD_WORKER 2026-11-03, below) |
| application | ApplicationCode |
no |
| correlation id | CorrelationId |
always; generated when absent |
| causation id | text | no (added in M2a: the event or message that caused this work) |
| execution id | text | no (added in M2a: the job or run this work belongs to) |
| permissions | set of text | no; empty when absent (added in M4c: what the principal may do, from the sessions-and-login contract section 7.3) |
Id types are records wrapping a validated non-blank string. ClientId matches
[A-Za-z0-9._-]{1,100}: it never contains :, so it can be embedded in composite keys (locks,
cache) without two clients producing the same key. ApplicationCode matches [a-z][a-z0-9-]*. M1 provides the types; building a Context from a request is M3.
Amended by M4c (2026-10-13): permissions is a set of permission strings. hasPermission(required)
is true when some held permission matches the required one: both have the same number of
:-separated segments and each held segment is * or equal to the required segment (the
platform’s rule, shared/auth/auth.go). A blank required permission never matches. Constructors
without permissions keep working (empty set). The real resolver that fills it is the
sessions-and-login contract.
Amended 2026-10-14 (the receiver principal, ruling 2026-10-12, re-confirmed 2026-10-14):
Context carries the principal kind, PrincipalKind with exactly two values, USER (a person)
and SERVICE (a service account), the platform’s type claim. Rules:
- The kind is present only together with a principal. A kind without a principal is refused when
the context is built (
IllegalArgumentException). A principal without a kind is allowed: the kind is then unknown (absent), which is what every constructor that predates the kind gives. Those constructors keep working unchanged. withPrincipal(id, kind)sets both.withPrincipal(id)sets the principal and clears the kind, so a kind can never describe a different principal than the one it came with.- The framework’s own producers always set it: the request resolver of the sessions-and-login
contract from the token’s or session’s
type(SERVICEis a service account, anything else a user, as built in M4c), and the FlowCatalyst receiversSERVICE(flowcatalyst contract section 4b). - The kind is not written to the outbox: neither the event payload nor the audit item has a field
for it on the platform. It is for
authorizeand for logs. - Causation and execution ids keep their meaning: causation is the message that caused this work (for a receiver, the delivered dispatch job or scheduled-job instance), execution the job or run this work belongs to.
Amended 2026-11-03 (field workers, sessions-and-login contract section 15): PrincipalKind gains
a third value, FIELD_WORKER, a person who signed in to the platform’s field plane (worker code and
PIN on an enrolled device, principal id fwu_...). It is set only by the request resolver from a
field access token. A field worker has no platform authority and belongs to exactly one client.
Code that switches on the kind must handle it: the Go linter’s exhaustive check flags a missing
case, and the Java enum switch must not use a default that treats it as USER. The kind is still not
written to the outbox.
Amended 2026-11-06 (impersonated field requests, sessions-and-login contract section 15.5): Context
gains an optional actor (id, type field_worker or principal, name): who is signed in as
the principal. Rules: the principal stays the subject (the worker) and the actor is the
operator; an actor is present only on a request whose field token carries act, and only the
request resolver sets it. withPrincipal clears it (an actor acts as one principal); forClient and
the other copies keep it. It is added to the log attributes. Go fw.Context.Actor /
WithActor(fw.Actor), Java Context.findActor / withActor(Actor).
Amended 2026-11-07 (early-adopter fixes A3, A4):
Contextgains an optional subject name: the principal’s display name. The request resolver sets it from the token’s (or session’s)nameclaim when there is one: always for a field worker, for a user or service when the token carries it. It describes the principal, never the actor (the actor keeps its ownname). Like the kind, it needs a principal (refused without one) andwithPrincipalclears it;forClient,withActorand the other copies keep it. It is not written to the outbox, nor added to the log attributes (it is a person’s name). Gocx.SubjectName/WithSubjectName(name), JavasubjectName/findSubjectName/withSubjectName(String).Context.ofService(client, principal)(Gofw.ServiceContextFor(client, principalID)): a context for the client with that principal of kindSERVICEand a generated correlation id, for work with no platform principal of its own, such as an inbound provider webhook the application verified.ClientId.PLATFORM(_platform; Gofw.PlatformClient, whichauth.PlatformClientandflowcatalyst.PlatformClientIDnow name) is the core’s name for “no particular client”, the value the receivers and the client selector already used (Receivers.PLATFORM_CLIENTandClientSelector.PLATFORMare now this constant). The outbox does not write it as a dispatch job’sclientCode(write-path contract section 7a), nor, since 2026-11-18, as an event’s or an audit row’s (section 7).
Amended 2026-11-15 (the principal’s tier, admin contract section 3a): Context gains an optional
tier: the principal’s tier claim as its token said it (ANCHOR, PARTNER or CLIENT). The request
resolver sets it from the token (or the session) when the claim is present and not blank, for a bearer token and
for a session alike; a field worker has none. It is for gates about who the principal is, not what it may do,
and grants nothing. isPlatformOperator() is true exactly when the tier is ANCHOR: a PARTNER, a CLIENT,
any other spelling (lower-case anchor) and no tier are not. Like the kind and the subject name it needs a
principal (refused without one) and withPrincipal clears it; forClient and the other copies keep it. It is
not written to the outbox and not added to the log attributes. Go cx.Tier() / IsPlatformOperator() /
WithTier(tier), Java tier() / findTier() / isPlatformOperator() / withTier(String) and
Context.TIER_ANCHOR; the canonical constructor gains a trailing tier component, the constructor without it
is kept.
3a. Work for one client after another (amendment 2026-10-18, friction F3 and F15)
Section titled “3a. Work for one client after another (amendment 2026-10-18, friction F3 and F15)”A scheduled-job firing and a background loop have no client of their own (the receiver’s context is
the platform’s, _platform; a loop has none), but the work they do is per client and goes through use
cases, which are scoped to one client. Two pieces make that the ordinary path rather than a
workaround:
Context.forClient(ClientId)copies the context for another client and keeps everything else: principal, principal kind, application, correlation, causation and execution ids and permissions. It does not check that the principal may act for that client; that is the use case’sauthorize, as for any caller (a service principal that is allowed to run the use case for one client is allowed for each).PerClient.each(base, clients, task)runstaskwithbase.forClient(client)for each client, in order, each client once. An exception in one client is logged and recorded asFailedfor that client and the others still run; the result is a map ofDone(value)orFailed(cause)per client started. It stops starting clients when the thread is interrupted (shutdown); clients not started are absent. It does no locking, retrying or parallelism: the caller’s lock gate or overlap lock serialises runs, and a client’s work is as long as it is.
Where the clients come from is the application’s. The usual source is one deliberate query that is
not scoped to a client and returns client codes only (the tickets example: “clients that have an overdue
ticket”), after which every read and write is scoped to the client in hand. The platform does not fire
a job once per client (ruled 2026-10-18). Build ClientId from the client’s code, never the platform’s id
(guide: “What goes in a ClientId”).
Go (2026-10-18): Context.ForClient(ClientID) and fw.EachClient(ctx, log, base, clients, task).
task returns (R, error); the result is a slice of ClientResult[R]{Client, Value, Err} in run order
(Go maps are unordered); a task that panics is recorded as Failed with a *PanicError (Java catches
Exception only); “interrupted” is ctx being done, checked before each client, and a task cut short by
it is recorded Failed like Java’s InterruptedException. A nil logger logs nothing. ForClient panics
on the zero client or the zero Context, EachClient on the zero base Context.
4. Config
Section titled “4. Config”Amended 2026-10-14 (config and code): configuration holds the settings of services and connections and secrets; things an application can have many of (lock stores, secret stores, HTTP clients, rate limiters, loops) are defined in code. Keys of those that moved fail start-up with the place they moved to, and a module may claim a component so that unknown keys under it fail (sections 5 and 8 there).
Declarations
Section titled “Declarations”Every setting is declared once, in code, by the module that reads it, during register:
| Part | Values |
|---|---|
| key | dotted lowercase, [a-z][a-z0-9_-]*(\.[a-z][a-z0-9_-]*)* |
| type | string, integer, long, boolean, duration, URI, enum, string list |
| kind | value or secret |
| default | a value, or none |
| required | yes or no; a required setting with no value after all sources fails start-up |
| description | text, for tooling |
A key declared twice fails start-up. Instance sections (section 2) are the one exception to “declared in code”: their keys are read by the driver factory and checked for unknown keys after it runs.
Sources, lowest to highest
Section titled “Sources, lowest to highest”- The declaration’s default.
config/application.yaml, thenconfig/application-{env}.yaml. Missing files are fine.- Environment variables.
- External stores: none in M1 (AWS and the platform are M5).
env is the environment variable APP_ENV, default local. The config directory is
config/ under the working directory unless the builder is given another path.
Environment variable names: the key uppercased with . and - replaced by _, so
database.instances.main.url is DATABASE_INSTANCES_MAIN_URL. Only names derived from
declared keys and from instance sections present in the files are looked up; the environment
is never scanned. Instances cannot be created from environment variables alone.
Values: durations accept 500ms, 30s, 5m, 2h, 1d and ISO-8601 (PT30S). Booleans
accept true/false only. A value that does not parse fails start-up with the key, the source
it came from and the expected type. The raw text of a secret is never included in an error.
Secrets
Section titled “Secrets”Secretis its own type.toStringreturnsSecret[****]; it is not serialisable; the raw value is read withreveal.- A secret declaration never has a real default.
- When
envislocalortest,config/secrets.local.yamlis read as a source between the files and the environment. In any other environment that file is ignored. The project template lists it in.gitignore.
Reading
Section titled “Reading”After start-up, Config returns typed values for declared settings (config.get(setting)) and
sections for instance configuration. Values do not change while running in M1.
Names and where a setting can live (ruling 2026-10-09)
Section titled “Names and where a setting can live (ruling 2026-10-09)”Keys are one global namespace; the framework adds no module prefix (a duplicate key fails start-up naming both modules). A module id need not appear in its keys.
Every key has a component (its first segment) and a path (the rest, any number of dotted
parts): mail.host is component mail, path host; mail.smtp.host is component mail, path
smtp.host. The name is the same everywhere a setting can live; only the address around it
differs:
| Store | Address of mail.smtp.host in application amazing-app |
|---|---|
| default, files, environment | mail.smtp.host (env MAIL_SMTP_HOST) |
| FlowCatalyst platform (M5) | client (tenant-scoped settings only) / amazing-app:mail / smtp.host |
- The application code comes from
flowcatalyst.applicationand is never written in a key. On the platform it is the scope of the setting (access is checked on application and client, plan section 6 offramework-plumbing.md);{application}:{component}has the same shape as an event type’s prefix. - A setting stored on the platform needs at least two segments. A one-segment key is allowed for local sources only; declaring it with a platform store fails start-up.
- The framework’s own components cannot be stored on the platform:
app,http,database,redis,locks,flowcatalyst. They are deployment settings (env or files). Declaring a platform-stored setting under one of them fails start-up. - Scope: a service-scoped setting has one value for the application; a tenant-scoped setting has one value per client. Local sources have no client dimension, so a tenant-scoped setting read locally needs an explicit client to resolve against.
- A declaration may name an explicit platform component and path when the default mapping does not suit. The local name is unchanged.
- Two different keys can map to one environment variable (
mail.host-name,mail.host.name); start-up fails naming both (built 2026-10-09: the loader compares every declared key with every other, and the instance-section keys found in the files, those with aninstancessegment, with the declared keys and with each other; the message names both keys and the declaring module, or the file for an instance key). The platform driver in M5 must do the same.
Errors
Section titled “Errors”StartupException lists every config problem found, each with key and source: unparseable
value, missing required setting, unknown key in an instance section, unknown driver, duplicate
declaration, two keys that read the same environment variable.
5. Commands (added with M4a)
Section titled “5. Commands (added with M4a)”A module may claim a command name in register with app.command(Command); Command is a name
and run(App, List<String> args, PrintStream out) returning an exit code. AppBuilder.launch(args)
looks at the first argument: a claimed name runs the command after start-up step 3 (services built,
no boot) and closes the application, returning Launch.Ran(exitCode); anything else starts
normally and returns Launch.Started(app). Two modules claiming one name fail start-up. start
is unchanged for callers that do not use commands.
Amended 2026-10-14 (OpenAPI contract section 9; built with MO the same day): a module may also
claim a declaration-phase command (app.command(DeclarationCommand): a name and
run(Declarations, List<String> args, PrintStream out)). launch runs it after step 1 (register)
only: no configuration is loaded or validated, no service is built, no boot runs, so it works
without a database or the environment. Declarations is a read-only view of the registered
contributions and declared settings. Command names are one namespace across both kinds. The first
user is framework-http’s openapi command.
As built (MO): DeclarationCommand (name, run(Declarations, List<String>, PrintStream)),
claimed with the AppBuilder.command(DeclarationCommand) overload. Declarations has
moduleIds, settings (the Declarations) and contributions(Class). A register-phase problem
(two modules with one id, a register hook that threw) still fails with StartupException before the
command runs; a command that throws exits 1. For tools and tests, AppBuilder.declarations runs
the register phase only and returns the same view (the builder is used up).
Amended 2026-10-18 (first-application feedback): a command, declaration-phase or not, that throws any
Throwable, Error included, exits 1 (Launch.Ran(1)) with the application closed. An Error out of a
provider (step 3) or a boot/started hook closes every service already built and propagates; before this,
only Exceptions were handled, and a leftover non-daemon thread (an HTTP client’s Vert.x event loop) kept the
JVM alive after main died.