Skip to content

Configuration ​

You manage app configuration through an .env file. zero lets you inject and override values as needed.

Your configs must live in the app-folder/configs directory.

bash
❯ tree -a
.
├── build.zig
├── build.zig.zon
├── configs
│   └── .dev.env
│   └── .prod.env
│   └── .env
├── src
│   ├── main.zig
│   └── root.zig
└── static
    └── favicon.ico

4 directories, 6 files

Defaults ​

These defaults get you started.

bash
APP_NAME=zero
HTTP_PORT=8080
LOG_LEVEL=info

Overrides ​

zero overrides environment-specific config based on the APP_ENV value.

bash
APP_ENV=dev

In the example above, if .dev.env exists in configs, zero overrides the defaults and starts for that environment.

Configuration Per Service ​

This list covers the config zero supports. zero wires each service automatically and keeps it available for the app's lifetime.

App ​

bash
APP_NAME=zero
APP_VERSION=1.0.0
APP_ENV=dev
LOG_LEVEL=info

HTTP_PORT=8080
METRICS_PORT=2121               # separate listener for /metrics (not the app port)

LOG_FORMAT=text                 # text | json — emit one JSON object per log line
ZERO_LOG_TIMEZONE=local        # local | utc | IANA name (e.g. America/New_York)
REQUIRED_CONFIG_KEYS=          # comma-separated; app exits at startup if any are unset/empty
METRICS_CARDINALITY_LIMIT=     # 4096 label sets per metric by default; 0 = no cap

TIP

Metrics are exposed on a separate listener (METRICS_PORT, default 2121), not on the app's HTTP_PORT. See Observability.

HTTP Server ​

These protections apply to inbound requests. zero reads them from configs/.env and applies them before your handlers run. See Resilience for details.

bash
HTTP_PORT=8080

ZERO_REQUEST_TIMEOUT_MS=30000     # per-request timeout (ms); stalled clients can't pin a worker
INBOUND_MAX_CONCURRENT=0          # bulkhead; 0 = unlimited. Excess returns 503
ZERO_KEEPALIVE_TIMEOUT_MS=60000   # idle keep-alive connection close (ms)
ZERO_HTTP_WORKERS=2               # I/O event-loop workers
ZERO_HTTP_THREAD_POOL_COUNT=32    # handler thread pool size
ZERO_HTTP_MAX_BODY_SIZE=8388608   # reject bodies above this with 413 (8 MiB)
ZERO_HTTP_LARGE_BUFFER_SIZE=1048576   # pooled HTTP body-buffer size (bytes)
ZERO_HTTP_LARGE_BUFFER_COUNT=16       # pooled HTTP body-buffer count (≈ resident pool)

HEALTH_SNAPSHOT_REFRESH_MS=5000   # background health check interval; 0 = probe inline
SHUTDOWN_DRAIN_TIMEOUT_MS=10000   # wait for in-flight requests after a signal
HEALTH_CHECK_SERVICE_PATH=/.well-known/health   # path used to ping downstream services

Database ​

bash
DB_HOST=localhost
DB_USER=user
DB_PASSWORD=password
DB_NAME=demo
DB_PORT=5432
DB_DIALECT=postgres
DB_SSL_MODE=disable
SQL_CIRCUIT_BREAKER_ENABLE=false  # trip open after 5 consecutive failures (error.CircuitOpen)
bash
DB_DIALECT=sqlite
SQLITE_PATH=./data/app.db
SQLITE_CREATE=true
SQLITE_WRITE=true
SQLITE_THREADING=multi-thread
SQLITE_POOL_SIZE=4            # pooled connections (default 4, max 64); WAL for writes
bash
DUCKDB_PATH=./data/app.db         # enabled when set; empty path = :memory: (in-process OLAP)
SQL_CIRCUIT_BREAKER_ENABLE=false  # trip open after 5 consecutive failures (error.CircuitOpen)
bash
CLICKHOUSE_URL=http://localhost:8123   # required; enables ClickHouse as ctx.SQL
CLICKHOUSE_DB=default                 # optional default database
CLICKHOUSE_USER=                      # optional; sent as X-ClickHouse-User
CLICKHOUSE_PASSWORD=                  # optional; sent as X-ClickHouse-Key
SQL_CIRCUIT_BREAKER_ENABLE=false  # trip open after 5 consecutive failures (error.CircuitOpen)
bash
DB_DIALECT=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=zero
DB_PASSWORD=zero
DB_NAME=demo
MYSQL_POOL_SIZE=10            # connection pool size (default 10)
MYSQL_SSL_MODE=disabled       # disabled | preferred | required
MYSQL_SSL_CA=                # CA path; required when MYSQL_SSL_MODE=required
bash
DB_DIALECT=supabase
SUPABASE_DB_PROJECT=abcdefghijklmno     # -> db.<ref>.supabase.co (set this or HOST)
SUPABASE_DB_HOST=db.abcdefghijklmno.supabase.co
SUPABASE_DB_PORT=5432
SUPABASE_DB_USER=postgres
SUPABASE_DB_PASSWORD=
SUPABASE_DB_NAME=postgres
SUPABASE_DB_SSL_MODE=require

Cache ​

The cache is a named KV store (default name cache, Redis-backed). The supported backends mirror the KV Store: redis (default), nats_kv, sqlite and memory.

bash
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_USER=redis
REDIS_PASSWORD=password
REDIS_DB=0
# optional TLS
REDIS_TLS_ENABLED=false
REDIS_TLS_CA_CERT=
REDIS_TLS_KEY=
REDIS_TLS_CERT=

CACHE_CIRCUIT_BREAKER_ENABLE=false  # trip open after 5 consecutive failures (error.CircuitOpen)

KV Store ​

KV stores are registered in code via App.addKVStore(name, backend, opts). Each backend reads its connection settings from the same env groups used elsewhere:

  • redis → REDIS_* (see Cache)
  • nats_kv → NATS_* (see PubSub)
  • sqlite → SQLITE_* (see Database)
  • memory → no configuration

By default zero registers a store named cache (Redis-backed) that the caching middleware consumes.

bash
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_USER=redis
REDIS_PASSWORD=password
REDIS_DB=0
bash
SQLITE_PATH=./data/kv.db
SQLITE_CREATE=true
SQLITE_WRITE=true

File Store ​

File stores are registered in code via App.addFileStore(name, backend, opts). The local, s3, gcs, and supabase backends are implemented; ftp and sftp are declared but not yet implemented.

bash
FILE_STORE_ROOT=./data/files   # root directory for the local backend
bash
S3_BUCKET=my-bucket            # required
S3_REGION=us-east-1            # default us-east-1
S3_ACCESS_KEY=AKIA...          # required
S3_SECRET_KEY=...              # required
S3_ENDPOINT=                   # optional; defaults to https://s3.<region>.amazonaws.com
bash
FILE_STORE_BACKEND=gcs
GCS_BUCKET=my-bucket              # required
GCS_ENDPOINT=https://storage.googleapis.com
GCS_PROJECT=                     # optional
GCS_CLIENT_ID=                   # optional; OAuth2 client-credentials grant
GCS_CLIENT_SECRET=               # optional
GCS_SCOPE=https://www.googleapis.com/auth/devstorage.full_control
# GCS_ACCESS_TOKEN=               # optional; bypasses the token fetch (sidecar)
bash
FILE_STORE_BACKEND=supabase
SUPABASE_STORAGE_BUCKET=my-bucket
SUPABASE_STORAGE_ACCESS_KEY=       # S3 Access Key from Supabase Storage, NOT a JWT
SUPABASE_STORAGE_SECRET_KEY=
SUPABASE_STORAGE_REGION=us-east-1  # required for the SigV4 scope
SUPABASE_STORAGE_PROJECT=abcdefghijklmno   # -> https://<ref>.supabase.co/storage/v1/s3
bash
TBD
bash
TBD

NoSQL ​

A type-erased document / wide-column store, exposed as ctx.NoSQL. zero auto-selects the backend from whichever *_CONTACT_POINTS env you set:

  • CASSANDRA_CONTACT_POINTS → Cassandra (CQL native protocol v4). See Cassandra (experimental).
  • COUCHBASE_CONTACT_POINTS → Couchbase (N1QL over HTTP). See Couchbase.
  • MONGODB_CONTACT_POINTS → MongoDB (OP_MSG wire protocol). See MongoDB (experimental).
  • ARANGO_HOST → ArangoDB (AQL over HTTP). See ArangoDB.

All four share the same get / put / delete / query verbs; you pass a full statement (CQL, N1QL, AQL, or a MongoDB command document).

bash
CASSANDRA_CONTACT_POINTS=127.0.0.1:9042   # required; enables the Cassandra backend
CASSANDRA_KEYSPACE=my_keyspace            # required when enabled
CASSANDRA_USER=                           # optional
CASSANDRA_PASSWORD=                       # optional
bash
COUCHBASE_CONTACT_POINTS=127.0.0.1:8091   # required; enables the Couchbase backend
COUCHBASE_BUCKET=my_bucket                # required when enabled
COUCHBASE_USER=                           # optional
COUCHBASE_PASSWORD=                       # optional
bash
MONGODB_CONTACT_POINTS=127.0.0.1:27017    # required; enables the MongoDB backend
MONGODB_DB=my_db                          # required when enabled
MONGODB_USER=                             # optional (SCRAM-SHA-256)
MONGODB_PASSWORD=                         # optional
MONGODB_TLS=false                         # optional; true to enable TLS
MONGODB_TLS_VERIFY=false                  # optional; verify server cert
MONGODB_AUTH_SOURCE=admin                 # optional; defaults to admin
bash
ARANGO_HOST=http://localhost:8529   # required; enables the ArangoDB backend
ARANGO_DB=_system                  # required when enabled
ARANGO_USER=                       # optional
ARANGO_PASSWORD=                   # optional

Time Series ​

A type-erased time-series store, auto-wired when INFLUXDB_URL (or OPENTSDB_URL) is set.

The influxdb and opentsdb backends are implemented; the handle is exposed as ctx.Timeseries.

INFLUXDB_URL, INFLUXDB_BUCKET, and INFLUXDB_TOKEN are all required once the datasource is enabled (v3 uses a flat database plus token model. There is no INFLUXDB_ORG).

bash
INFLUXDB_URL=http://localhost:8181        # required; enables the time-series datasource
INFLUXDB_BUCKET=my-bucket                 # required when enabled
INFLUXDB_TOKEN=my-super-secret-token      # required; sent as Authorization: Bearer
bash
OPENTSDB_URL=http://localhost:4242        # required; enables the OpenTSDB backend
OPENTSDB_TOKEN=                           # optional; sent as Authorization: Bearer

A type-erased search store, auto-wired when SOLR_URL (or MEILI_HOST) is set.

The solr and meilisearch backends are implemented; the handle is exposed as ctx.Search.

SOLR_DEFAULT_COLLECTION is required once the datasource is enabled;

SOLR_BASIC_AUTH is optional (user:password for HTTP Basic).

bash
SOLR_URL=http://localhost:8983/solr       # required; enables the search datasource
SOLR_DEFAULT_COLLECTION=my_collection     # required when enabled
SOLR_BASIC_AUTH=                          # optional; "user:password" for HTTP Basic
bash
MEILI_HOST=http://localhost:7700     # required; enables the Meilisearch backend
MEILI_INDEX=movies                  # required when enabled
MEILI_API_KEY=                     # optional; sent as Authorization: Bearer

Graph ​

A type-erased graph store, auto-wired when DGRAPH_URL is set. The dgraph backend is implemented; the handle is exposed as ctx.Graph. See Graph.

bash
DGRAPH_URL=http://localhost:8080     # required; enables the Dgraph backend
DGRAPH_API_KEY=                     # optional; sent as X-Dgraph-AccessToken

Message Queue / PubSub ​

PUBSUB_BACKEND selects the transport. When unset, pub/sub is disabled.

bash
PUBSUB_BACKEND=KAFKA
PUBSUB_BROKER=localhost:9092
CONSUMER_ID=zero-consumer
KAFKA_BATCH_SIZE=100
KAFKA_BATCH_BYTES=1048576
KAFKA_BATCH_TIMEOUT=1000
KAFKA_SECURITY_PROTOCOL=PLAINTEXT
KAFKA_SASL_MECHANISM=        # e.g. PLAIN / SCRAM-SHA-256
KAFKA_SASL_USERNAME=
KAFKA_SASL_PASSWORD=
KAFKA_TLS_CA_CERT_FILE=
KAFKA_TLS_CERT_FILE=
KAFKA_TLS_KEY_FILE=
KAFKA_TLS_INSECURE_SKIP_VERIFY=false

Kafka TLS

KAFKA_SECURITY_PROTOCOL still defaults to PLAINTEXT. TLS is only used when you set it to SSL or SASL_SSL. From 0.5.4, KAFKA_TLS_INSECURE_SKIP_VERIFY defaults to false. That value goes to librdkafka as enable.ssl.certificate.verification, so certificate verification is off unless you set the key to true. Set it explicitly if you relied on the old default.

bash
PUBSUB_BACKEND=NATS
PUBSUB_BROKER=nats://localhost:4222
NATS_STREAM=zero
NATS_SUBJECTS=>
NATS_MAX_WAIT=5000
NATS_MAX_PULL_WAIT=5000
NATS_CONSUMER=zero-consumer
NATS_CREDS_FILE=          # optional, for authenticated NATS
bash
PUBSUB_BACKEND=MQTT
PUBSUB_BROKER=tcp://127.0.0.1:1883
MQTT_PROTOCOL=tcp
MQTT_HOST=127.0.0.1   # prefer ip address
MQTT_PORT=1883
MQTT_USER=
MQTT_PASSWORD=
MQTT_CLIENT_ID_SUFFIX=zero-subscriber
MQTT_QOS=0
MQTT_KEEP_ALIVE=true
MQTT_RETRIEVE_RETAINED=false
bash
PUBSUB_BACKEND=SQS
SQS_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/123456789012/zero-queue
AWS_REGION=us-east-1
AWS_ACCESS_KEY=
AWS_SECRET_KEY=
bash
PUBSUB_BACKEND=GCP          # or GOOGLE
GCP_PROJECT=my-gcp-project
GCP_SUBSCRIPTION=zero-sub
GCP_ENDPOINT=https://pubsub.googleapis.com
GCP_CLIENT_ID=
GCP_CLIENT_SECRET=
GCP_SCOPE=https://www.googleapis.com/auth/pubsub
# GCP_ACCESS_TOKEN=          # optional; bypasses the token fetch (sidecar)

:::

Auth ​

zero supports basic and api_key authentication on the registered routes.

You can register more than one key by separating values with commas.

bash
AUTH_MODE=Basic
AUTH_KEYS="bmFtZTpwYXNzd29yZA==,bmFtZTE6cGFzc3dvcmQx"
bash
AUTH_MODE=APIKey
AUTH_API_KEYS="caf208fb-e407-497a-8f03-d636fb689b2e,b12eb288-e7b5-4919-8082-09586e4b6dd7"
bash
AUTH_MODE=OAuth
AUTH_JWKS_URL=http://localhost:8080/.well-known/jwks.json
AUTH_REFRESH_INTERVAL=10
OAUTH_AUDIENCE=my-api          # optional; when set, JWT aud claim must match
OAUTH_ISSUER=https://idp.example.com  # optional; when set, JWT iss claim must match

RBAC ​

Role-based access control rules are loaded by app.rbacFromEnv() (call it in main), which reads the RBAC_CONFIG env var. There is no code-based app.rbac(...) API and no RBAC_ROLE_* env-var form. RBAC_CONFIG is the sole supported schema.

Routes with a rule are protected; routes without one stay public.

The caller's role is taken from the JWT role claim, so RBAC pairs with AUTH_MODE=OAuth.

RBAC_CONFIG is a single endpoint-rule object or an array of them:

json
{ "permissions": ["ROLE", ...], "endpoint": "/path", "methods": ["GET", ...], "exempt": false }
bash
RBAC_CONFIG=[{"permissions":["ADMIN"],"endpoint":"/api/admin/*","methods":["GET","POST"],"exempt":true},{"permissions":["USER"],"endpoint":"/api/resource","methods":["GET"]}]

exempt: true bypasses RBAC for the listed methods only; other methods on that endpoint stay protected (require a matching role rule).

HTTP Service ​

Access external services under a custom service name. Change only the config when the service URL changes.

bash
SERVICE_URL="http://localhost:8080" #custom key (read in your own main and passed to addHttpService)

Per-service behavior is resolved from SERVICE_<NAME>_* env keys, where <NAME> is the service name passed to addHttpService, uppercased, with non-alphanumeric characters mapped to _ (e.g. service payments-api → SERVICE_PAYMENTS_API_*).

Explicit options passed in code override the env defaults.

Circuit Breaker ​

A circuit breaker can guard each downstream so a flapping dependency fails fast. It is configured with SERVICE_<NAME>_CB_*.

When unset, the breaker defaults to failure_threshold = 5 and cooldown_ms = 30000 (and half_open_trials = 1).

bash
SERVICE_PAYMENTS_API_CB_FAILURE_THRESHOLD=5     # consecutive failures before opening
SERVICE_PAYMENTS_API_CB_COOLDOWN_MS=30000       # ms to wait before half-open trial

Rate Limiter ​

Each outbound service can carry its own client-side rate limiter, configured with SERVICE_<NAME>_RATE_LIMIT*.

When SERVICE_<NAME>_RATE_LIMIT is unset, no per-service limiter is applied (this is independent of the global request limiter).

bash
SERVICE_PAYMENTS_API_RATE_LIMIT=100             # max outbound requests per window
SERVICE_PAYMENTS_API_RATE_LIMIT_WINDOW_MS=60000 # window length in ms (default 60000)

Timeouts & Retries ​

bash
SERVICE_PAYMENTS_API_TIMEOUT_MS=30000           # per-request timeout (ms)
SERVICE_PAYMENTS_API_MAX_RETRIES=3              # retry attempts on transient failure
SERVICE_PAYMENTS_API_RETRY_BASE_MS=100          # base backoff (ms) for exponential retry

Outbound Auth ​

bash
SERVICE_PAYMENTS_API_AUTH_MODE=apiKey
SERVICE_PAYMENTS_API_API_KEY=secret
bash
SERVICE_PAYMENTS_API_AUTH_MODE=basic
SERVICE_PAYMENTS_API_BASIC_USER=user
SERVICE_PAYMENTS_API_BASIC_PASS=pass
bash
SERVICE_PAYMENTS_API_AUTH_MODE=oauth
SERVICE_PAYMENTS_API_OAUTH_TOKEN_URL=http://idp/token
SERVICE_PAYMENTS_API_OAUTH_CLIENT_ID=client
SERVICE_PAYMENTS_API_OAUTH_CLIENT_SECRET=secret
SERVICE_PAYMENTS_API_OAUTH_SCOPE=            # optional
SERVICE_PAYMENTS_API_OAUTH_AUDIENCE=         # optional

Rate Limiter ​

The rate limiter is a middleware enabled globally via RATE_LIMIT_ENABLE and is on by default (set RATE_LIMIT_ENABLE=false to disable it, e.g. for load tests). The key used to bucket requests is selected with RATE_LIMIT_KEY. /.well-known/* is exempt so health checks are never throttled. See Rate Limiter.

bash
RATE_LIMIT_ENABLE=true     # enabled by default; set false to disable
RATE_LIMIT_KEY=ip          # ip | header | custom
RATE_LIMIT_MAX=100         # max requests per window (0 → default 100)
RATE_LIMIT_WINDOW=60       # window length in seconds (0 → default 60)
RATE_LIMIT_TRUSTED_PROXIES=  # IPs/CIDRs allowed to set X-Forwarded-For; empty = ignore it

The limiter can also run in a distributed mode backed by Redis, so the counter is shared across all your replicas. Set RATE_LIMIT_STORE=redis and configure Redis: if Redis is unreachable it fails open (requests are allowed).

bash
RATE_LIMIT_STORE=redis      # memory (default) | redis
# plus REDIS_HOST / REDIS_PORT / REDIS_USER / REDIS_PASSWORD / REDIS_DB

Key modes:

  • ip: bucket by client address.
  • header: bucket by the X-Forwarded-For header (custom header name set in code).
  • custom: application-defined key computed in code.

Remote Log ​

When REMOTE_LOG_URL is set, zero registers an outbound HTTP client for it and a cron job that periodically fetches the current log level from that endpoint and hot-reloads the in-process LOG_LEVEL, no restart required.

The remote endpoint must return JSON containing a level field, where level is one of debug, info, warn, error, fatal or none.

A zero service serves this at GET /remote.log.service?id=<uuid> (the level field is what gets read)

The feature is opt-in and never exposes an endpoint on this service.

bash
REMOTE_LOG_URL=                        # e.g. http://log-level-service/remote.log.service
REMOTE_LOG_REFRESH_INTERVAL=30         # seconds between fetches (default 30)