# โก flexpool
**An open-source virtual power plant for aggregators.** flexpool pools batteries, homes and
depots, plans them against day-ahead prices, offers their flexibility to grid operators and
proves what was delivered. Every number is exact, every decision has a reason, and every step
can be replayed.
[](https://crates.io/crates/flexpool)
[](#-license)
[](rust-toolchain.toml)
๐ [Documentation](https://hupe1980.github.io/flexpool/) ยท
๐ [Getting started](https://hupe1980.github.io/flexpool/getting-started/) ยท
๐ [API](https://hupe1980.github.io/flexpool/api/) ยท
๐ [Changelog](CHANGELOG.md)
> ๐งช **Experimental.** Pre-1.0: APIs can change between releases. Everything runs end to end on
> simulated and replayed market days; orders are paper orders, no exchange is connected, and
> devices are only ever read. Test with your counterparties before production use.
<a href="site/static/img/desk-plan.en.webp"><picture>
<source media="(prefers-color-scheme: dark)" srcset="site/static/img/desk-plan-dark.en.webp">
<img width="720" src="site/static/img/desk-plan.en.webp" alt="The flexpool desk's Plan view: for Pool Nord the revenue on paper against perfect foresight, the expected revenue with its range, one sentence on when the batteries charge and discharge, and charts of price, power and state of charge over the day.">
</picture></a>
## ๐ Quick start
```sh
git clone https://github.com/hupe1980/flexpool && cd flexpool
docker compose up -d --wait
open http://localhost:8080 # ๐ฅ๏ธ the operator desk
```
The demo replays a market day on a test clock, with 400 assets in two pools. Some of the API:
```sh
curl -s localhost:8080/api/v1/portfolio # pools, assets, MW and MWh
curl -s 'localhost:8080/api/v1/plan/day-ahead?risk=cautious' # schedule, water values, orders per pool
curl -s localhost:8080/api/v1/book/day-ahead/delivery # the Fahrplan against measured delivery
curl -s -X POST localhost:8080/api/v1/sandbox/clock/advance \
-H 'content-type: application/json' -d '{"to":"next-gate"}' # โฉ jump to the next market gate
```
๐ฆ **From source** (Rust 1.100, [`just`](https://just.systems)): `just run` starts the daemon,
`just ci` runs every check.
๐งฐ **The command line** checks portfolios, scenarios and alarm journals offline:
```sh
cargo install flexpool
flexpool portfolio check portfolio/demo
```
## ๐ฅ๏ธ The desk
Calm by default, loud on exception. Every value shows its age, every order has a reason, and
nothing reaches a market until a person releases it. In German and English, light and dark.
| | |
|---|---|
| <a href="site/static/img/desk-buch.en.webp"><img width="420" src="site/static/img/desk-buch.en.webp" alt="The Book view during delivery: 68 released orders with their digest, positions per pool, and a battery trip in Pool Nord with buy proposals for the next hour."></a> | <a href="site/static/img/desk-zeitstrahl.en.webp"><img width="420" src="site/static/img/desk-zeitstrahl.en.webp" alt="The Timeline view: the day's prices inside the forecast's 50 % and 80 % bands, the gates as markers, and a table scoring three forecast models."></a> |
| ๐ **Book and delivery:** the release with its digest, positions after the auction, the Fahrplan against measured power | ๐ **Timeline:** prices, the forecast fan and every model scored over 14 days |
| <a href="site/static/img/desk-flex.en.webp"><img width="420" src="site/static/img/desk-flex.en.webp" alt="The Flexibility view: a grid operator's request, the offered 0.28 MW against the requested band, the offer sent and ordered, and the settlement disputed at ISP 72."></a> | <a href="site/static/img/desk-lage.en.webp"><img width="420" src="site/static/img/desk-lage.en.webp" alt="The Overview: the open alarm, the connection, the sandbox scenario, the next gate and the portfolio's feed-in and stored energy."></a> |
| ๐ค **Flexibility:** a grid operator's request answered, sent by a person, the settlement recomputed | ๐งญ **Overview:** what matters now, readable in five seconds |
## โจ What it does
| | | |
|---|---|---|
| ๐ | **Portfolio as code** | Owners, pools, technical units and assets in `portfolio.toml` and `assets.csv`, checked down to every MaLo check digit |
| ๐ก | **Telemetry** | Simulated in the sandbox, or read from SunSpec and IEC 60870-5-104 devices, read-only, with a quality on every value |
| ๐จ | **Alarms** | One alarm per cause (ISA-18.2), acknowledged on a hash-chained journal, handed over between shifts, paged as signed CloudEvents |
| ๐ฎ | **Forecast** | Day-ahead price quantiles, scored against published prices, with a place for your own model |
| ๐งฎ | **Plan** | Scenarios and a storage optimiser with a risk knob: a schedule, water values and protective orders per battery pool |
| ๐ | **Book** | Pre-trade checks, a release a person makes, a kill switch, positions and the Fahrplan nomination for mako |
| โก | **Delivery** | The Fahrplan against measured power, the running quarter projected, and what to trade back |
| ๐ฌ | **Explanations** | *Warum?* on every order from its facts; *Nachrechnen* recomputes any release from its journal record |
| ๐ค | **Flexibility market** | UFTP 3.1 requests become offers built from the units behind a congestion point; every settlement is recomputed before it is accepted |
| ๐ | **Interfaces** | REST with OpenAPI 3.1, CloudEvents with published schemas, Standard Webhooks, read-only MCP tools, W3C Trace Context |
| ๐ | **Data protection** | Personal data declared on every event; `erasure@1` acted on and confirmed truthfully |
## ๐๏ธ Workspace
| Component | Purpose |
|---|---|
| [flexpool-core](crates/flexpool-core) | Exact units, the Berlin quarter-hour calendar, the single float-to-decimal boundary |
| [flexpool-portfolio](crates/flexpool-portfolio) | Parse, check, query and summarise the portfolio |
| [flexpool-telemetry](crates/flexpool-telemetry) | Measurement quality, the live store, quarter-hour means, the sandbox simulator |
| [flexpool-alarms](crates/flexpool-alarms) | The alarm engine, the hash-chained journal, handover and KPIs |
| [flexpool-forecast](crates/flexpool-forecast) | Probabilistic day-ahead forecasts and their scoring |
| [flexpool-plan](crates/flexpool-plan) | Scenarios, the storage optimiser with CVaR, water values, orders |
| [flexpool-rules](crates/flexpool-rules) | Dated market and alarm rules, each citing its source ([`rules/`](rules)) |
| [flexpool-sim](crates/flexpool-sim) | Bitemporal market data, scenarios, the test clock and replay |
| [flexpool-adapters](crates/flexpool-adapters) | Read-only SunSpec Modbus TCP and IEC 60870-5-104 sessions |
| [flexpool-files](crates/flexpool-files) | Bounded, contained reads of the files an operator keeps |
| [flexpool-service](crates/flexpool-service) | The HTTP shell: configuration, authentication, limits, problem documents, trace context |
| [flexpoold](services/flexpoold) | The daemon: API, MCP, events, the flexibility market |
| [flexpool](crates/flexpool) | The offline command line; it never links the daemon |
| [desk](desk) | The operator desk (React, TypeScript), served by flexpoold |
| [xtask](xtask) | The repository guards `just ci` runs |
๐ฏ The domain crates read no clock, do no I/O and spawn no task. Money and energy are exact
decimals, and business time is the Europe/Berlin quarter hour.
## ๐ Part of the Open Utility Stack
flexpool fills the aggregator role in the
[Open Utility Stack](https://hupe1980.github.io/open-utility-stack/). It follows the stack's
conventions for events, contracts and autonomy, so its counterparts, like
[fms](https://github.com/hupe1980/fms) on the grid operator's side, can be replaced by any
system that follows them too. [`platform.toml`](platform.toml) declares what it emits and
consumes.
## ๐ค Contributing and security
- ๐ ๏ธ [CONTRIBUTING.md](CONTRIBUTING.md): build, test and the repository guards
- ๐ค [AGENTS.md](AGENTS.md): the rules for AI coding agents
- ๐ก๏ธ [SECURITY.md](SECURITY.md) and the [threat model](THREAT_MODEL.md)
## ๐ License
Licensed under either [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE), at your option.