Repository navigation
Composition Root & Configuration
Home · Architecture · Backend core
In short
-
backend/src/tz_ps_conductor/dependencies.pyis the composition root: it builds everything a process shares, once per process. - Only a root may ask it for a dependency. Everything deeper takes what it needs as arguments.
- One process owns a storage root, through the root lock.
- A process reads one JSON config document, once. Each top-level key belongs to one package, and nothing below the root reads config.
backend/src/tz_ps_conductor/dependencies.py builds everything a process shares.
- Nothing is held as a ready-made module-level instance.
- The module keeps empty slots behind one re-entrant lock and fills them on first use.
-
build_x()reads config and assembles the object. -
get_x()hands it out.- Built once per process:
get_runner,get_persistence,get_object_store,get_network_file_formatsand the config itself. - Built on each call: the staging spaces, the export space and the three executors, which are light objects.
- The executors first call
get_runner(), because only that starts the durable runtime.
- Built once per process:
-
stop_x()exists for whatever starts something process-wide:stop_runner,stop_persistence,stop_telemetry,stop_root_lock. -
clear_dependencies()resets everything and exists for tests.
The rule for callers is "pull at a root, push below it".
- Only a root may call a
get_x():dependencies.pyitself, a__main__, a FastAPI dependency, the HTTP lifespan, or a public entry point such asProject.getandNetwork.solve. - Everything deeper takes its collaborators as arguments.
- A caller with its own warehouse uses
Project.build_factory(warehouse, staging_space).
-
Persistence, fromtz_ps_datawarehouse.build_persistence: theWarehouse(networks and projects) and the run, import, export, workflow-run and heartbeat stores, with onestop.get_warehouse()and the store getters read their part of it. -
The warehouse kind.
storage.warehouse_kinddefaults toGIT. Only the root falls back toNON_VERSIONED, and only when the document names no kind, sets no warehouse settings, and git is not installed. -
The object store: a
LocalObjectStore. This is the one place an object store adapter is named. -
The solver registry. Each discovered solver is wrapped in
LocalProcessSolver, so the instance in the API process only answers whether it is provisioned and which options it offers. The solve runs in a child process, whichtz_ps_conductor/solve_process.pyprepares. -
The runner.
start_durable_runnerintz_ps_conductor/durability.pybuilds theRunnerwith aDbosExecutor, starts the durable runtime with the import, export, workflow and measures steps, runs the start-up sweeps, and queues the measures backfill. - Capabilities: what this server can do, read from the warehouse it opened. See Backend core.
One process owns a storage root.
-
start_root_lock()takes an operating-system lock under the root'sstatefolder. - A held root raises
StorageRootInUseError. -
serve, the HTTP lifespan,seedandbackfill-measurestake the lock. A notebook that uses the Python API does not. - Storage describes the lock itself.
tz-ps-conductor serve (backend/libs/tz_ps_app/src/tz_ps_app/__main__.py) does three things, in this order:
- It lays
--rootand--portover the default config file. - It takes the root lock, before it binds the port.
- It builds the app.
The rest happens in the FastAPI lifespan in tz_ps_http/app.py, which the tz-ps-http command runs as well. The command's standard-output lines and exit codes are a contract with the desktop app, which The HTTP API and the contracts owns.
The diagram shows the order in which serve and the lifespan start the shared dependencies, and the order in which they stop.
sequenceDiagram
participant CLI as tz-ps-conductor serve
participant Root as dependencies.py
participant Life as HTTP lifespan
participant Store as Persistence
participant Run as Runner and durable runtime
CLI->>Root: lay flags over the config document
CLI->>Root: start_root_lock
CLI->>Life: build the app and start uvicorn
Life->>Root: start_telemetry
Life->>Root: start_root_lock again, a no-op
Life->>Root: get_warehouse
Root->>Root: configure logging and discover frameworks
Root->>Store: build_persistence
Life->>Root: get_import_store
Life->>Root: write the demo project at a first start
Life->>Root: get_runner
Root->>Run: discover solvers and start the durable runtime
Run->>Run: recover workflows, run sweeps, queue the measures backfill
Life-->>CLI: listening
Note over Life,Run: shutdown
Life->>Run: stop_runner
Life->>Store: stop_persistence
Life->>Root: stop_telemetry
Life->>Root: stop_root_lock
What the order guarantees:
- Telemetry starts first, so a bad telemetry config stops the start before storage opens.
- The runner stops first, because it holds the warehouse and the run store.
- A failed demo-project write is logged and never stops the server.
In a notebook there is no lifespan. Importing tz_ps_conductor installs framework discovery on Framework, so the first read of the framework registry configures logging from the config and discovers the frameworks.
A process reads one JSON document, once.
-
TZ_PS_CONDUCTOR_CONFIGholds either the JSON itself or a path to a file. - Unset,
~/tz-ps-conductor/config.jsonis read when it exists. - Otherwise every package uses its defaults.
Each top-level key belongs to one package.
- The package subclasses
Config(tz_ps_models) and names itskey. - The root reads it with
get_config(MyConfig). A validation failure becomesInvalidConfigError. - A key no package claims is ignored.
- The retired key
warehouseis refused by name, because ignoring it would quietly move storage to the default root.
| Key | Class | Package | What it sets |
|---|---|---|---|
storage |
StorageConfig |
tz_ps_datawarehouse |
The root path, the warehouse kind and its settings, the inline series length, DuckDB's memory limit |
durable |
DurableConfig |
tz_ps_durable_runner |
Worker and import concurrency, retry and backoff, the solver log cap and polls, heartbeat and takeover times |
compute |
ComputeConfig |
tz_ps_conductor |
The memory limits of the solve process |
logging |
LoggingConfig |
tz_ps_conductor |
The console level, and the log file's path and level |
telemetry |
TelemetryConfig |
tz_ps_conductor |
Whether to export, and the OTLP endpoint |
seed |
SeedConfig |
tz_ps_conductor |
Whether a first start writes the demo project |
updates |
UpdatesConfig |
tz_ps_conductor |
Whether to look for a newer release |
http_server |
HttpServerConfig |
tz_ps_http |
Host, port, allowed origins, the import size limit, the live evaluation limits |
No environment variable overrides a key, with two exceptions, each applied by a validator on its own config class:
-
TZ_PS_CONDUCTOR_SEEDoverseed.demo_data. -
TZ_PS_CONDUCTOR_CHECK_RELEASESoverupdates.check_releases.
Nothing below the root reads config. The root hands values down inside objects:
-
DuckdbLimitsto the warehouse. -
SolveLimitsinsideSolverDependencies. - A
LogCapto the run store.
The solve process is the exception in mechanism only: it reads the same document through the environment variable it inherits.
Using the app
Architecture
- Overview
- Python API
- Domain model
- Backend core
- Composition root and config
- Expression language internals
- Storage
- Execution
- Imports and exports
- Workflow engine
- HTTP API and contracts
- Frontend and desktop
- Build, CI and release
Contributing