flexpool 0.2.0

The flexpool command line: check portfolios, scenarios and alarm journals, make secrets and tokens, probe a daemon.
# ⚡ 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.

[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)

> **Status: pre-release.** Everything below runs end to end on simulated and replayed market
> days. Orders are paper orders: no exchange is connected, and devices are only ever read.

## Try it

With Docker:

```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, with Rust 1.100 and [`just`](https://just.systems): `just run` starts the
daemon, `just ci` runs every check, `just install` puts the `flexpool` command on your path.

## 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 |
| **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

See [CONTRIBUTING.md](CONTRIBUTING.md), [AGENTS.md](AGENTS.md) for AI coding agents,
[SECURITY.md](SECURITY.md) and the [threat model](THREAT_MODEL.md).

Licensed under either [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE), at your option.