# ADR-0003: Declarative YAML configuration, validate-then-swap

URL: https://scalws.com/docs/adr/0003-configuration-model/
Source: `docs/adr/0003-configuration-model.md` in the ScalWS repository

* Status: Accepted (2026-10-05)

## Context
Requirement: declarative, validated before activation, atomically reloadable,
roll-backable; a failed config never replaces the last-known-good. The original example is
YAML. `serde_yaml` is deprecated upstream.

## Decision
* YAML parsed with `serde-saphyr` into strongly typed structs with `deny_unknown_fields`.
* Three phases: **parse** (syntax/types) → **validate** (pure semantic checks in
  `scalws-config`: names, duplicates, ranges, unsupported features) → **prepare** (I/O:
  certificates, document roots, upstream addresses; builds the immutable `ActiveState`).
* Activation is `ArcSwap::store` of the prepared snapshot. Requests in flight keep the old
  snapshot alive.
* Listener topology changes require a restart and are rejected on reload.
* Model hierarchy: `tenants[] → applications[] → domains[] + runtime + routes[]`.
* Runtime types not implemented in this build (`php`, `node`, `python`, `container`) are
  part of the schema but fail validation with an explicit "not available until M2" error.
  Update (1.0.0, 2026-11-12): all four runtimes are implemented and the error no longer exists.

## Consequences
* `scalwsctl check` and reload share one code path, so "check passes" means "reload succeeds"
  barring environmental changes between the two.
* Persisted LKG snapshots and rollback land with the admin API (M9).
