Repository navigation
Architecture
In short.
- Conductor keeps power system networks and solves them with an energy modelling framework.
- A versioned warehouse, which is the default, also keeps every version of each.
- It is one Python process that serves a JSON API and a React app
- It keeps its data in a warehouse
- git
- plain files
- PostgreSQL
- It runs each solve in a child process under a durable workflow.
- Frameworks, solvers, file formats and kinds of warehouse are plug-ins found by entry point, so the core names none of them.
This page is the map; each section links to the page that explains the part.
The words used in this guide are those of GLOSSARY.md:
- a modeller builds a network of components in a project, a framework defines the component types
- a solver solves the network for that framework, and each run writes its results as a new version of the network.
| Page | Read it when you want to know |
|---|---|
| Backend core |
|
| The domain model |
|
| The Python API |
|
| The composition root and configuration |
|
| The expression language |
|
| Storage |
|
| Execution |
|
| Network file imports and exports |
|
| The workflow engine |
|
| The HTTP API and the contracts |
|
| The frontend and the desktop app |
|
| Build, CI and release |
|
| Adding a framework |
|
| Testing philosophy |
|
| Testing review |
|
There are three ways in, and all three reach the same Python API. Two go through the server, which owns the storage root; a notebook calls the API directly.
flowchart TD
modeller(["Modeller"])
subgraph served["Through the server"]
direction LR
browser["Browser<br/>the React app"]
desktop["Desktop app<br/>starts serve as a child"]
serve["tz-ps-conductor serve<br/>API and app on one port"]
browser --> serve
desktop --> serve
end
subgraph direct["Direct"]
notebook["Notebook or script<br/>import tz_ps_conductor"]
end
api["tz_ps_conductor<br/>Project and Network: the one Python API"]
data[("Storage root or database")]
modeller --> served
modeller --> direct
serve -- "holds the root lock" --> api
notebook -- "takes no lock" --> api
api --> data
-
The browser app is the React app in
frontend/. The published wheel carries its built files, andtz-ps-conductor serveserves them beside the API from one port (http://127.0.0.1:8080/by default). -
The desktop app (
desktop/) is an Electron shell. It starts the sameservecommand as a child process, waits for the line that says it is listening, and shows the same React app. -
A notebook imports
tz_ps_conductorand callsProjectandNetworkdirectly. It opens the same storage but takes no lock on it.
What happens after a run is submitted (the durable runtime, the solve process and the object store) is on Execution and Storage.
There is no authentication. The server binds to 127.0.0.1 unless the config says otherwise.
| Folder | Holds | Stack |
|---|---|---|
backend/ |
The Python service: the application package tz_ps_conductor under src/ and 21 workspace libraries under libs/. |
Python 3.13 to 3.14, uv, hatchling, FastAPI, pydantic, DuckDB, DBOS |
contracts/ |
What the backend and the frontends agree on: the OpenAPI document and the expression grammar with its shared tables and cases. | OpenAPI YAML, ANTLR 4 |
frontend-sdk/ |
The API client generated from the OpenAPI document, and the TypeScript expression parser generated from the grammar. | Orval, antlr-ng |
frontend/ |
The React app. | React 19, Vite, TanStack Router, Query and Form |
desktop/ |
The Electron shell and its packaging. | Electron, electron-builder |
deploy/, Dockerfile
|
The image: one config file for each database, and the entry point. | Docker |
docs/ |
specs/, the dated design documents committed with the work they describe, and examples/, the notebooks. |
Markdown, Jupyter |
.github/ |
The CI workflows. | GitHub Actions |
Most of these are rules that a test or a lint enforces. Ideas 8 and 10 are conventions.
-
The core names no framework.
- A framework is three packages (a description, its file formats and its solver) that announce themselves under entry-point groups.
- The conductor, the runner and the HTTP layer are forbidden by import-linter to import any of them, so Conductor runs with whichever are installed.
- See Adding a framework.
-
Packages are layered, and the layers are checked.
-
tz_ps_modelsis the bottom; each package may import only the rows below it. -
[tool.importlinter]inbackend/pyproject.tomlis the architecture, and a test fails when a new package is missing from it. - See Backend core.
-
-
One composition root.
-
backend/src/tz_ps_conductor/dependencies.pyreads the config and builds everything shared. - Code below it takes what it needs as arguments and reads no config.
- See The composition root and configuration.
-
-
Every save is a version.
- On the default warehouse a version is a git commit.
- A run writes its results as a new version whose parent is the inputs it solved.
- A warehouse that keeps one version only says so through a capability.
- See Storage.
-
Work that must finish is a durable workflow.
- A solve, an import, an export and a workflow run are each checkpointed step by step.
- A restart continues them or fails them cleanly.
- See Execution.
-
A solve runs in its own process, on a copy.
- The numbers go to the solver and come back through a handover: a JSON document and the series as parquet in the object store.
- On the way back, the run values (measures and constraint results) are a second parquet object.
- A year of hourly results is about 110 million numbers, so on that path none may become a Python object.
- Memory tests hold each path to a cost for each value.
- See Execution and Storage.
-
The API is contract first.
-
contracts/openapi/core-api.yamlis written by hand, and a test compares it with the routes in both directions. - The TypeScript client is generated from it.
- An error is a problem document whose
typeslug the client matches on. - See The HTTP API and the contracts.
-
-
The app asks what the server can do.
- The frontend reads
GET /api/capabilitiesand the framework description routes. - It does not infer a feature from the shape of another response.
- Most of the UI is built from the framework description, but some places still assume PyPSA.
- See Adding a framework, which lists them.
- The frontend reads
-
One vocabulary for names.
- A function's leading verb says what it does and what happens when the thing is absent (
get_raises,find_answersNone). - A test reads the table in
backend/CLAUDE.mdand fails on a verb that is not in it. - See the Naming section of
backend/CLAUDE.md.
- A function's leading verb says what it does and what happens when the thing is absent (
-
A test must be shown to fail.
- A new test is run against the one change to production code that should break it.
- Nothing records that this was done.
- See Testing philosophy.
The core names no framework. It finds each framework's three packages by entry point, and both sides import only the foundations.
flowchart LR
subgraph core["The core: names no framework"]
direction TB
app["tz_ps_app · tz_ps_http"]
wf["tz_ps_workflow"]
conductor["tz_ps_conductor"]
exec["tz_ps_runner<br/>tz_ps_durable_runner"]
store["tz_ps_datawarehouse<br/>tz_ps_local_objectstore"]
app --> wf --> conductor --> exec --> store
end
subgraph plug["A framework x: pypsa, calliope"]
direction TB
solver["tz_ps_solver_x<br/>solves"]
files["tz_ps_files_x<br/>reads and writes files"]
desc["tz_ps_x<br/>describes components"]
solver --> files --> desc
end
subgraph base["Foundations"]
direction TB
ports["tz_ps_ports<br/>the contracts"]
models["tz_ps_expressions<br/>tz_ps_models"]
ports --> models
end
core -. "entry points,<br/>no import" .-> plug
core --> base
plug --> base
The picture leaves some packages out. The table has every one, in the order of the import-linter layers: a package may import the rows below it, and packages on one row may not import each other.
| Layer | Packages | Job |
|---|---|---|
| 1 | tz_ps_app |
The tz-ps-conductor command; serves the built frontend |
| 2 | tz_ps_http |
FastAPI routes and problem documents |
| 3 |
tz_ps_workflow · tz_ps_demo_data
|
Workflows and the demo project |
| 4 | tz_ps_conductor |
Project and Network; the composition root |
| 5 |
tz_ps_runner · tz_ps_durable_runner · tz_ps_solver_pypsa · tz_ps_solver_calliope
|
Runs, durable jobs, and each framework's solver |
| 6 |
tz_ps_files_pypsa · tz_ps_files_calliope
|
Each framework's file formats |
| 7 |
tz_ps_pypsa · tz_ps_calliope · tz_ps_datawarehouse · tz_ps_local_objectstore · tz_ps_reader_support · tz_ps_solver_support
|
Framework descriptions, storage, and shared helpers |
| 8 | tz_ps_duckdb_filesystem |
DuckDB's bridge to stored objects |
| 9 | tz_ps_ports |
The plug-in and execution contracts |
| 10 | tz_ps_expressions |
The expression language |
| 11 | tz_ps_models |
The domain model |
tz_ps_testing, which holds the shared test fixtures, sits above all of these and never ships.
One path through the whole system. A cylinder is the warehouse, and the double border is the child process. The steps below the picture say more, with the page that explains each.
flowchart LR
create(["1 · Create"]) --> edit["2 · Edit"] --> store[("3 · Store")] --> run["4 · Run"] --> solve[["5 · Solve"]] --> publish[("6 · Publish")] --> read["7 · Read"]
read -. "change something and run again" .-> edit
- Create. The modeller makes a project and a network, and picks a framework. The app reads the framework's component types and attributes from the API, so the forms and the grid are built from the framework description. (The domain model.)
-
Edit. Each save sends the changed components with the
version_idthe editor last read. The warehouse refuses the write when another save got there first, and the app shows a conflict. (HTTP API, optimistic concurrency.) - Store. The warehouse splits the version into a JSON document and its series. Short series stay in the document, and long ones go to parquet, or to array rows in PostgreSQL. (Storage.)
-
Run.
POST …/runsrecords a run and a job and hands the job to the durable runtime. The runtime writes an input handover, starts a child process for the network's framework, and streams the solver's log back. (Execution.) - Solve. In the child, the framework's solver package reads the handover, builds the framework's own model, solves it, and writes an output handover. (Adding a framework, the solver port.)
- Publish. The runtime writes the output as a new version of the network, authored by the run, and records the outcome. The inputs it solved are that version's parent.
- Read. The app reads results, measures and custom statistics from that version. A custom statistic or a custom constraint is an expression in one language that the backend and the editor both parse from one grammar.
There are four ways to run Conductor. The first two are for a modeller's own machine, and both keep their data in the same folder.
| Shape | What is installed | Where the data is |
|---|---|---|
| The desktop app |
|
~/tz-ps-conductor:
|
| The wheel |
|
The same folder as the desktop app. |
| A container |
|
|
| A checkout |
|
.context/ in the checkout. |
Build, CI and release has the commands for each.
This wiki explains how the system fits together. The rules a change must follow live in the repository, next to the code they govern, and they win where this wiki disagrees.
-
CLAUDE.mdat the root, and one in each subproject and in some packages, holds the rules and traps that no code, test or config states. -
docs/specs/holds the design document of each feature, dated, as it was decided. -
GLOSSARY.mdholds the words. - Docstrings hold each contract, on the Protocol or the method it governs.
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