Configuration Sources#
Tinyauth supports three configuration sources β YAML files, environment variables, and CLI flags β through a pluggable loader chain powered by the paerser library. All sources populate the same Config struct, and later loaders in the chain override earlier ones.
Loader Chain and Priority#
At startup, three loaders are registered in order :
FileLoader β FlagLoader β EnvLoader
Each loader implements the ResourceLoader interface from paerser/cli. The chain executes sequentially; the first loader that returns done = true short-circuits further loading. Because EnvLoader runs last, environment variables have the highest priority, overriding both flags and file values.
FileLoader#
FileLoader resolves the config file path from either:
- The
--traefik.configfileCLI flag (parsed at load time), or - The
TINYAUTH_CONFIGFILEenvironment variable as a fallback.
If neither is set it is a no-op. When a path is found, it calls file.Decode() from paerser/file to unmarshal the file (YAML, TOML, or JSON are all supported by the underlying decoder) into the Config struct .
Note: The flag key is named
traefik.configfileinternally β a legacy of paerser's Traefik origins β but the env var is the idiomaticTINYAUTH_CONFIGFILE.
EnvLoader#
EnvLoader scans all environment variables for the prefix TINYAUTH_ and calls env.Decode() from paerser/env. Field names follow the TINYAUTH_<SECTION>_<KEY> convention, e.g. TINYAUTH_SERVER_PORT or TINYAUTH_DATABASE_DRIVER . Nested structs use additional underscore-separated segments, and map keys are bracketed: TINYAUTH_AUTH_USERATTRIBUTES_[NAME]_EMAIL .
FlagLoader#
FlagLoader parses CLI arguments via flag.Decode() from paerser/flag. Flags use dot-separated names mirroring the struct hierarchy (e.g. --server.port=3000). If no args are present, it short-circuits immediately .
Paerser Processing Pipeline#
All three loaders share the same internal pipeline from paerser:
- Source β flat map β flags, env vars, or file contents are normalized to
key=valuepairs. - Flat map β node tree β keys are split into a hierarchical
Nodestructure. - Node tree + struct reflection β typed struct β
paerser/parserwalks the target struct and fills fields with typed values.
Config Struct and Defaults#
The Config struct covers all configuration domains: Server, Database, Auth, OAuth, OIDC, Apps, LDAP, Tailscale, UI, Log, Analytics, Resources, and Experimental. Defaults are set by NewDefaultConfiguration(env) before any loaders run; loaders overlay values on top. When running in Docker, path defaults (e.g. for the database) are adjusted automatically.
tinyauth config Command#
The registered configCmd exposes the resolved configuration at runtime, which is useful for debugging which values were ultimately loaded from which source.
Full Configuration Reference#
The auto-generated configuration reference in the docs repository lists every supported env var, flag, and its default value. It is generated from the Config struct and is the canonical source for available options.
Key Files#
| File | Role |
|---|---|
cmd/tinyauth/tinyauth.go | Wires loaders into the CLI command |
internal/utils/loaders/loader_file.go | YAML/TOML/JSON file loader |
internal/utils/loaders/loader_env.go | Environment variable loader |
internal/utils/loaders/loader_flag.go | CLI flag loader |
internal/model/config.go | Config struct + NewDefaultConfiguration |
internal/model/constants.go | DefaultNamePrefix ("TINYAUTH_") |
docs: generated_configuration.mdx | Full reference for all options |
github.com/tinyauthapp/paerser | Shared parsing/loading library |