Your own configuration

Bind your application's own YAML sections to Kotlin data classes or Java records — from the same application.yaml, overlays, system properties and environment variables StoatFlow reads — with secrets from files, every problem reported at once, and no extra framework.

An application rarely needs StoatFlow's settings alone: a database pool, an HTTP client, an LLM provider each want a URL, a timeout, a credential. StoatFlow's configuration layer, io.stoatflow:stoatflow-config, binds those sections too — from the same application.yaml, the same overlays, -D system properties and environment variables — so the runtime needs no Spring, Micronaut or Quarkus beside it.

A section of your own

Write the section beside StoatFlow's in application.yaml:

stoatflow:
  application-id: payments-enricher
  bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:-localhost:9092}

payments-db:
  url: jdbc:postgresql://db:5432/payments
  user: payments
  password: ${secret:payments-db-password}   # a file in the mounted secrets directory
  max-pool-size: 10
  connect-timeout: 5s

Declare a class for it, bind it, and pass the same configuration to the runtime:

import io.stoatflow.config.Configuration
import io.stoatflow.config.Secret
import java.time.Duration

data class PaymentsDb(
    val url: String,
    val user: String,
    val password: Secret,
    val maxPoolSize: Int = 10,
    val connectTimeout: Duration = Duration.ofSeconds(5),
)

fun main() {
    val configuration = Configuration.load()          // StoatFlow's standard sources
    val db = configuration.bind<PaymentsDb>("payments-db")

    StoatFlowRuntime
        .fromConfig(configuration, topologyBuilder = { builder -> buildTopology(builder, db) })
        .start()
}
  • Keys are kebab-case (max-pool-size for maxPoolSize); camelCase and snake_case spellings match as well. @ConfigName("…") names a key that does not derive from the field.
  • Defaults: a Kotlin constructor default, or for a Java record @ConfigDefault("…") (written as it would be in YAML), Optional<T>, or a @Nullable type. A field with neither is required.
  • Validation: a data class's init { require(…) } or a record's compact constructor runs as part of the bind; its message becomes the error.
  • Types: String, Char, Boolean, Int/Long/Short/Byte (range-checked), Double/Float, BigDecimal, BigInteger, enums (by name; case, - and _ ignored), Duration (500ms, 10s, 5m, 1h, 2d or ISO-8601 PT30S), URI, Path, UUID, Secret, List/Set (a YAML list or a comma-separated value), Map<String, T>, nested classes and nullable types. Anything else through a converter (below).

StoatFlowRuntime.fromConfig(topologyBuilder) without a configuration still works: it loads the standard sources itself. Load the configuration yourself when you bind sections of your own, so StoatFlow and your code read one set of sources and /config shows both.

Where a value comes from

Highest precedence first:

  1. Environment variables: the key's YAML path with every . and - as _, upper-cased — payments-db.max-pool-size is PAYMENTS_DB_MAX_POOL_SIZE. StoatFlow resolves the name against your class, so nothing needs escaping.
  2. -D system properties: the YAML path as written — -Dpayments-db.max-pool-size=20.
  3. STOATFLOW_CONFIG_FILES overlays (YAML only, later files win).
  4. The bundled application.yml, then application.yaml.
  5. The class's defaults.

The files merge per bind, against your class: an overlay's maxPoolSize replaces a base file's max-pool-size, while a map's keys match only as written (io.acme.foo and io.acme.Foo stay two entries). A later file's empty value (url: with nothing after it) changes nothing; an explicit ~ or null clears an earlier value only where the field can be null — a nullable or Optional field, a nullable map value — and elsewhere is as if it were absent. A key written twice in one YAML mapping fails the load, naming both lines.

In values, ${VAR} reads a system property, then an environment variable; ${VAR:-default} falls back to the default; ${env:NAME} and ${sys:name} read one source each; ${secret:name} reads a secret file. A placeholder that cannot be resolved fails only where a bound value holds it.

Lists and maps from variables

FieldVariableEffect
hosts: List<String>PAYMENTS_DB_HOSTS=db-1,db-2the whole list (\, is a literal comma)
hosts: List<String>PAYMENTS_DB_HOSTS_1=db-2element 1 of the YAML's list; the next free index appends
endpoints: List<Endpoint>APP_ENDPOINTS_0_TIMEOUT=10sone field of element 0
tags: Set<String>APP_TAGS=a,bthe whole set (a set has no index)

A Map field takes entries from variables only when it says how the rest of the name becomes the key:

data class LlmProvider(val baseUrl: URI, val apiKey: Secret, val timeout: Duration = Duration.ofSeconds(30))
data class LlmConfig(
    val defaultProvider: String,
    @ConfigMapKeys(MapKeyStyle.KEBAB) val providers: Map<String, LlmProvider>,
)

LLM_PROVIDERS_PRIMARY_TIMEOUT=60s sets llm.providers.primary.timeout, and LLM_PROVIDERS_PRIMARY_EU_TIMEOUT the key primary-eu — the rest of the name is matched against LlmProvider's fields. MapKeyStyle.DOTTED reads one _ as ., KEBAB as -, SNAKE as _; in every style __ is a literal _ and ___ a literal -. A map without @ConfigMapKeys takes entries from YAML, placeholders and -D properties only, so a section named kafka never turns KAFKA_HOME into an entry.

Which section owns a variable

StoatFlow decides once, at start, which section a variable belongs to: the longest section name that prefixes it, among StoatFlow's sections and the top-level sections of your YAML — LLM_CACHE_TTL belongs to llm-cache, not llm. A section that only variables or -D properties supply has no YAML to be found in: declare it, and it owns its variables from the start:

val configuration = Configuration.builder().section("llm-cache").load()

A section named so that StoatFlow's own sections cover its variables (runtime-extras, stoatflow-orders, logging), or after a JVM system-property namespace (user, file, http, java, os), is refused when you bind it.

Secrets

${secret:name} reads the file name from the secrets directory — STOATFLOW_SECRETS_DIR, default /run/secrets, where Docker puts its secrets and where a Kubernetes Secret volume lands with one file per key:

# Pod spec
automountServiceAccountToken: false     # see below: its mount would land inside /run/secrets
volumes:
  - name: secrets
    secret:
      secretName: payments-secrets      # keys: payments-db-password, licence
containers:
  - name: app
    volumeMounts:
      - { name: secrets, mountPath: /run/secrets, readOnly: true }

On Debian- and Ubuntu-based images /var/run is a link to /run, so Kubernetes' service-account token, mounted at /var/run/secrets/kubernetes.io/serviceaccount, would land inside the read-only Secret volume and the container would not start. StoatFlow does not call the Kubernetes API: switch the token off, as above, or mount the Secret elsewhere and point STOATFLOW_SECRETS_DIR at it (Kubernetes).

  • The file is read as UTF-8 with one trailing newline removed (what kubectl create secret --from-file and most editors leave), and nothing else trimmed. A name is a file name only: /, \ and .. are refused.
  • A missing file is an error at start naming its path, never its value — only when a bound value uses it. Secrets are read once; a rotated secret takes effect at the next restart.
  • Declare the field Secret (reveal(), Java getValue()): its value never appears in the class's toString(), in /config, in logs or in error messages. A secret bound into a plain String field logs a warning, because a toString() of the class would print it.

Your own secret store plugs in the same way: register a resolver for a prefix, and its values are treated as secrets.

val configuration = Configuration.builder()
    .addPlaceholderResolver("vault") { key -> vault.read(key) }   // ${vault:kv/llm#primary}
    .load()

When something is wrong

A bind reports every problem of the section at once, each with its key and where the value came from:

Invalid configuration (2 problems):
  - payments-db.max-pool-size: 'ten' is not an Int (env PAYMENTS_DB_MAX_POOL_SIZE)
  - payments-db.url: missing (application.yaml:6)

A key nothing reads logs a warning with the closest field (payments-db.max-pool-sise … did you mean payments-db.max-pool-size?), and so does a variable under your section's prefix that names nothing. configuration.bind("payments-db", PaymentsDb::class.java, BindOptions(strict = true)) makes an unread key an error; BindOptions(environment = false) or (systemProperties = false) turns a section's variables or properties off; BindOptions(defaults = mapOf("payments-db" to mapOf("url" to "jdbc:…"))) gives the bind values to use where no source sets a key — its lowest source, which has() never sees.

Plugins, /config and the read API

  • A plugin binds its own section from the runtime's configuration: context.configuration().bind<PaymentsDb>("payments-db") (Plugins). A resolver or converter the plugin needs is registered by the application on the builder it passes to fromConfig.
  • /config shows every section bound through the runtime's configuration beside StoatFlow's, with Secret fields, resolver-produced secrets and every key whose name contains password, pwd, secret, credential, token, auth, api-key, private-key or access-key (in any spelling — privateKeyPem and private-key-pem alike, oauth-issuer too) masked, and a URL's user:password@ stripped (REST API). Under such a name the whole value is masked, a list or a map included, and so is a section named that way (credentials:): name a section identity-provider rather than auth if its settings should stay visible.
  • configuration.has("payments-db.url") asks the merged files; boundSections() returns each bound section's tree with Secret fields and resolver-produced secrets masked — not by key name, and URLs keep their credentials, which only /config masks and strips, so do not log it as you would /config; topLevelSections() lists the YAML's sections. has() and topLevelSections() see neither variables nor system properties.

Extending it

NeedUse
A value type the binder does not knowaddConverter(HostAndPort::class) { text -> HostAndPort.parse(text) }
Values from Vault, SSM or a tableaddSource(source, SourcePrecedence.ABOVE_FILES) with a ConfigSource (variables and -D still win)
A secret storeaddPlaceholderResolver("vault") { key -> … }
Another YAML fileaddFile(path) or addResource("/application-local.yaml")
A tool whose file is its whole configurationConfiguration.builder().withoutStandardSources().addFile(path)

There is no classpath scanning and no dependency injection: binding a section and registering an extension are calls you make.

Tests

Inject the environment and system properties instead of forking a JVM:

val configuration = Configuration.builder()                        // the test classpath's application.yaml
    .withEnvironment(mapOf("PAYMENTS_DB_MAX_POOL_SIZE" to "20"))
    .withSystemProperties(emptyMap())
    .load()
configuration.bind<PaymentsDb>("payments-db").maxPoolSize shouldBe 20

StoatFlowTestDriver.fromConfig(configuration, topologyBuilder = { builder, config -> … }) runs a topology test on the same configuration (Testing); stoatflow.application-id defaults to stoatflow-test there when the configuration sets none.

Native image

StoatFlow's own configuration classes are registered for a native image. Your own classes — data classes and records — need a reflection entry in src/main/resources/META-INF/native-image/<group>/<artifact>/reachability-metadata.json (Native image):

{
  "reflection": [
    {
      "type": "com.example.PaymentsDb",
      "allDeclaredConstructors": true,
      "allDeclaredMethods": true,
      "allDeclaredFields": true,
      "allPublicConstructors": true,
      "allPublicMethods": true,
      "allPublicFields": true
    }
  ]
}

Without it the bind fails at start, naming the class.

Limits

  • Kotlin data classes and Java records only — no JavaBeans, no sealed hierarchies.
  • Values are read once, at start; there is no reloading.
  • Resolution is per bound class: two classes can read one path differently.
  • A processor gets its configuration from the topology code that constructs it; there is no appConfigs() lookup.