Skip to content

Architecture

James Dunkerley edited this page Dec 3, 2026 · 29 revisions

Home

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.

The pages

Page Read it when you want to know
Backend core
  • Which package does what.
  • Which package may import which.
  • How a plug-in is found.
The domain model
  • What a network is made of in memory.
  • How a value is held.
  • What a framework declares.
The Python API
  • What Project, Network and ComponentHandle each do.
  • How a notebook builds and edits a network.
The composition root and configuration
  • Where a dependency is built, and who may ask for it.
  • The order a server starts and stops in.
  • What the config document sets.
The expression language
  • How one grammar gives two parsers.
  • Who checks, compiles and evaluates an expression.
Storage
  • How a network version is kept on disk or in PostgreSQL.
  • What a handover is.
  • Why no number becomes a Python object on a write.
Execution
  • What happens between pressing Run and reading results.
  • How a run survives a restart.
Network file imports and exports
  • How a file format is announced.
  • How an import and an export run.
The workflow engine
  • How a workflow is built, stored and run.
  • Which steps are recorded and which run again.
The HTTP API and the contracts
  • How a route is shaped.
  • How an error becomes a problem document.
  • How the OpenAPI contract, the SDK and the expression grammar stay in step.
The frontend and the desktop app
  • How the React app is laid out.
  • How the Electron shell runs the backend.
Build, CI and release
  • How to set up a checkout.
  • What CI runs.
  • How a wheel, an image and an installer are made.
Adding a framework
  • What a framework is made of.
  • The steps to add one.
Testing philosophy
  • Which kind of test a change needs.
  • The rules the suites hold.
Testing review
  • What the suites cover today, with numbers.
  • Where they are thin.

Who uses it, and through what

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
Loading
  • The browser app is the React app in frontend/. The published wheel carries its built files, and tz-ps-conductor serve serves 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 same serve command as a child process, waits for the line that says it is listening, and shows the same React app.
  • A notebook imports tz_ps_conductor and calls Project and Network directly. 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.

The parts of the repository

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

The ideas that hold it together

Most of these are rules that a test or a lint enforces. Ideas 8 and 10 are conventions.

  1. 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.
  2. Packages are layered, and the layers are checked.
    • tz_ps_models is the bottom; each package may import only the rows below it.
    • [tool.importlinter] in backend/pyproject.toml is the architecture, and a test fails when a new package is missing from it.
    • See Backend core.
  3. One composition root.
    • backend/src/tz_ps_conductor/dependencies.py reads 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.
  4. 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.
  5. 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.
  6. 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.
  7. The API is contract first.
    • contracts/openapi/core-api.yaml is 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 type slug the client matches on.
    • See The HTTP API and the contracts.
  8. The app asks what the server can do.
    • The frontend reads GET /api/capabilities and 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.
  9. One vocabulary for names.
    • A function's leading verb says what it does and what happens when the thing is absent (get_ raises, find_ answers None).
    • A test reads the table in backend/CLAUDE.md and fails on a verb that is not in it.
    • See the Naming section of backend/CLAUDE.md.
  10. 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 backend in one picture

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
Loading

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.

The life of a network

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
Loading
  1. 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.)
  2. Edit. Each save sends the changed components with the version_id the editor last read. The warehouse refuses the write when another save got there first, and the app shows a conflict. (HTTP API, optimistic concurrency.)
  3. 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.)
  4. Run. POST …/runs records 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.)
  5. 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.)
  6. 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.
  7. 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.

Where it runs

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
  • An installer.
  • It carries its own Python runtime with every released backend package.
  • It includes PyPSA, and not the optional Calliope packages.
~/tz-ps-conductor:
  • projects/ and .git/ hold the warehouse.
  • state/ holds runs and checkpoints.
  • objects/ holds handovers.
The wheel
  • uv tool install of the one tz-ps-conductor wheel.
  • It holds the same packages and the built frontend/.
The same folder as the desktop app.
A container
  • The image, built with DATABASE=git or DATABASE=postgresql.
  • With git: a mounted storage root.
  • With postgresql: one database holds the warehouse, the run records and the workflow checkpoints.
  • With postgresql, a mounted root still holds the object store, scratch space and logs.
A checkout
  • make dev at the root.
  • The backend is on port 8080.
  • frontend/ is on port 3000 and proxies the API.
.context/ in the checkout.

Build, CI and release has the commands for each.

Where the rules are written

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.md at 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.md holds the words.
  • Docstrings hold each contract, on the Protocol or the method it governs.

Clone this wiki locally