Context
Chatto is growing beyond a single web/API process. Some capabilities should be
able to run as independent processes in production while still being easy for
single-process self-hosters to run from chatto run.
Examples include:
- a Prometheus exporter that reads existing NATS resources and does not need
ChattoCore - a future Bleve search service that replays
EVT, maintains its own index, and answers search requests over NATS - future media workers for CPU-heavy video transcoding, image processing, and derivative generation
These processes need common configuration loading, logging, NATS connection
setup, graceful shutdown, and access to shared Chatto infrastructure. At the
same time, they must not casually call ChattoCore.Run, because the main core
boot path legitimately performs boot-time mutations and repair work.
Decision
Introduce runtime units as the convention for optional Chatto processes.
A standalone-capable runtime unit:
- can run standalone as
chatto <unit> - can run embedded in
chatto runwhen its provider or unit config section hasenabled = true; this selects process composition rather than whether a separate consumer-facing feature is exposed - receives shared config, NATS, JetStream, logger, and version through a small runtime environment
- decides explicitly which existing resources or domain services it opens
- does not start embedded NATS when running standalone
A main-app auxiliary unit is the documented exception. It owns an
optional listener, worker, or lifecycle under chatto run, but it can use the
main app's in-process operation layer. It does not need a standalone command.
This exception is suitable only when a separate process would need a new
private service contract with the main app and would not improve isolation.
Standalone units connect to an existing NATS server as clients. For default
single-process embedded-NATS installs, operators either enable the embedded TCP
listener or set the unit's enabled = true flag so chatto run starts it in
process using the already-established NATS connection.
Runtime units use a shared explicit registration catalogue for composition and
diagnostics. chatto run starts enabled registrations under one coordinated
lifecycle, while a standalone unit command starts the same implementation
regardless of its embedded enabled setting. Feature-consumer configuration
stays separate when a replaceable provider is involved. For example,
search.enabled exposes message search through the main app, while
search_provider.enabled decides whether chatto run embeds Chatto's bundled
provider.
chatto run supervises enabled optional units independently. A unit that
returns unexpectedly is restarted with exponential backoff capped at 30
seconds, while the main app remains available. Standalone commands instead
return the unit failure to their process supervisor. Units must therefore make
startup and repeated execution safe; durable workers resume through their
application-owned consumer rather than process-local state.
Runtime units are classified by behavior:
- Observer: reads existing resources and exposes diagnostics, such as the Prometheus exporter. No durable writes.
- Projection service: consumes
EVT, maintains a unit-owned index or read model, and exposes a NATS service, such as future search. Usually no durable writes. - Worker: performs background work and may append durable facts through the
owning service or
evtstream.Publisher, such as future media processing. - Main app: the ConnectRPC/web/realtime-delivery process that owns
ChattoCoreboot and HTTP compatibility facades. - Main-app auxiliary: an optional, separately supervised capability that uses the main app's operation layer and cannot run standalone. A route on the existing public HTTP server is part of the main app, not an auxiliary runtime unit.
Durable domain facts still go through EVT, and any unit that writes them must
use the same multi-replica-safe OCC and service-boundary rules as the main
process.
Consequences
Standalone workers and embedded single-process deployments can share one unit implementation instead of maintaining separate boot paths.
A main-app auxiliary still gets explicit configuration, registration, supervision, and lifecycle ownership. It does not claim independent deployment or require a private network API only to satisfy the runtime-unit convention.
An embedded optional capability can recover from missing executables, projection failures, deleted durable consumers, and other unit-local failures without forcing the main app to restart. Persistent failures remain visible in logs at the bounded restart cadence instead of silently leaving the capability stopped.
The main chatto run process remains the only path that starts embedded NATS
and runs the full ChattoCore boot sequence. Side units stay explicit about
whether they are read-only projections, request/reply services, or durable
writers.
Future units should reuse the runtime-unit harness before adding new command
setup, signal handling, NATS connection logic, or ad hoc embedded-mode flags.
Workers that need singleton behavior must still coordinate through NATS
primitives such as MEMORY_CACHE leases; embedding a unit in chatto run is an
operator convenience, not a correctness boundary.
Replaceable provider units communicate with the main app through the same versioned NATS contract in embedded and standalone topologies. See ADR-053.