Agent Context — Alpiq BESS (Mando)
Dense reference for AI agents to quickly gather project context. Load this file first when working on any Mando crate.
Identity
- Project: Battery Energy Storage System optimization platform
- Org: Alpiq, Sales & Origination / Flexible Assets
- Repo:
sales-and-origination/flexible-assets/bess/poc/mando (GitLab)
- Source path:
/Users/andras/coding/alpiq_cicd/sales-and-origination/flexible-assets/bess/poc/mando
- Language: Rust 1.88.0 (edition 2021) + Python 3.12 via PyO3
- Version: 1.4.11
- Main branch:
develop
Workspace Crates
| Crate | Type | Purpose |
|---|
mando-lib | lib | Core: data models, repos (PG/DuckDB/SQLite), service trait, adapters (Alpiq/Volue/Fingrid), flows, validation |
mando-lib-macro | proc-macro | #[derive(ErrorCode)] — maps error enum variants to static string codes |
mando-bess | bin | REST API (Axum 0.8.7, port 8080): routes, flow execution, scheduling, auth (JWT/Entra ID) |
py-mando | cdylib | PyO3 extension: algo params, DataFrame ops, algo runner HTTP server, adapters for Python |
mando-scrt | bin | Rust-based Python runtime: virtual module injection, Arrow FFI streaming, memory-safe algo hosting (PyO3 auto-initialize) |
mando-cli | bin | YAML-driven workflow orchestrator: recipes, docker compose, interactive prompts, state replay (standalone repo) |
Key Abstractions
MandoService (async trait)
├── retrieve / retrieve_at / retrieve_history — read data points
├── insert — write data points
├── retrieve_catalog — list available data points
└── send — push data externally
Repository (trait) → DataPointRepository, CacheRepository
├── RepositoryPostgres (production)
├── RepositoryDuckDb (analytics/OLAP)
├── RepositorySqlite (local dev)
└── RepositoryPassthrough (caching layer)
DataPointId = hierarchical path: "Asset/FI/Battery/SoC" → ["Asset","FI","Battery","SoC"]
DataPointType = TimeSeriesDouble | TimeSeriesDoubleMatrix | StaticData
DataPointFilterQueryMode = ORIGINAL | OVERRIDE | MERGED
Feature Flags (mando-lib)
| Flag | Enables |
|---|
app | Axum + OpenTelemetry (used by mando-bess) |
codegen | Code generation with CSV |
python | PyO3 classes/functions |
workflow | Flow execution engine |
Flow Engine
Versioned workflows for BESS trading strategies:
- Trading (v1) — market trading
- Manual Schedule (v1, v2) — operator schedules
- Auction (v3) — auction bidding
- Intraday / IDC Trading — intraday ops
- Data Update — data pipelines
- AFRR — frequency restoration reserve
External Integrations
| System | Adapter | Purpose |
|---|
| Azure Entra ID | EntraIdClient | Authentication |
| Alpiq EBS | adapter/alpiq/ | Energy Balance System |
| Alpiq MDR | adapter/alpiq/ | Market Data Repository |
| Alpiq OPL | adapter/alpiq/ | Operations Planning |
| Volue EMS | adapter/volue/ | Energy Management System |
| Volue ATP | adapter/volue/ | Token provider |
| Fingrid | adapter/fingrid/ | Finnish market data |
Tech Stack Summary
| Layer | Technology |
|---|
| Web | Axum 0.8.7, Tower middleware |
| Data | Polars 0.49.1, Arrow 56.2.0 |
| DB | PostgreSQL (deadpool), DuckDB 1.4.2, SQLite (rusqlite) |
| Auth | JWT (RS256), Entra ID, Volue EMS/ATP |
| Python | PyO3 0.25.1, pyo3-polars 0.22.0, Maturin 1.9.2 |
| Observability | OpenTelemetry 0.30.0 (OTLP/gRPC), tracing |
| API docs | utoipa + Scalar UI |
| GraphQL | cynic 3.12.0 + graphql-ws-client |
| Serialization | serde, serde_json, serde_yaml, Apache Avro |
| Error handling | thiserror + custom #[derive(ErrorCode)] |
mando-bess Routes
| Endpoint | Method | Purpose |
|---|
/query_data | — | Read data points |
/save_data | — | Write data points |
/flow/{id} | — | Manage flows |
/flow_executions | — | List executions |
/flow_executions/{asset_id} | — | Asset executions |
/audit_logs | — | Audit trail |
/settings | — | Configuration CRUD |
/versions | — | Component versions |
Build Commands
cargo build # Build workspace
cargo test # Run tests
cd mando-bess && cargo run # Run service (port 8080)
cd py-mando && maturin develop # Build Python extension
CI/CD
- Platform: GitLab CI
- Stages: Security (Snyk) → Container → Setup → Build/Test → Publish → Release → Pages
- Branching:
feature/*, bugfix/*, develop → Dev ECR; release/* → Prod ECR
- Runtime image:
debian:13.1-slim with libssl3, samba-libs, bundled libduckdb.so
File Layout
mando/
├── mando-lib/src/ # 13 subdirs: adapter/, audit/, bess/, model/, util/, workflow/, ...
├── mando-bess/src/ # flow/ (9 subdirs), route/ (7 modules), database/, model/
├── mando-lib-macro/src/ # Single lib.rs
├── py-mando/src/ # 12 modules: algo, polars, adapter, data_point, ...
├── assets/ # Test data
├── lib/libduckdb/ # Bundled DuckDB 1.4.2
├── scripts/ # Benchmarks, load tests, seed data
└── test/ # Integration tests