mando-lib

Core library crate for the Mando workspace. Provides data models, repository abstractions, service layer, external adapters, and shared utilities used by mando-bess and py-mando.

Module Overview

mando-lib/src/
├── lib.rs
├── datapoint.rs        # Data point models & identification
├── service.rs          # MandoService trait & implementations
├── repo.rs             # Repository trait abstractions
├── repo_duckdb.rs      # DuckDB backend
├── repo_postgres.rs    # PostgreSQL backend
├── repo_sqlite.rs      # SQLite backend
├── repo_passthrough.rs # Caching/proxy layer
├── arrow.rs            # Apache Arrow FFI helpers
├── validation/         # JSON schema validation
├── workflow/           # Flow execution engine
├── adapter/
│   ├── alpiq/          # EntraIdClient, EBS, MDR, OPL
│   ├── volue/          # EMS, ATP auth providers
│   └── fingrid/        # Market data
├── audit/              # Audit trail (Postgres/Mock/DuckDB)
├── setting/            # Configuration management
├── python/             # PyO3 exports (feature-gated)
├── codegen/            # Client code gen (feature-gated)
├── bess/               # BESS-specific logic (AFRR)
├── model/              # DataRange, DynamicTime, market models
├── util/               # DataFrame ops, resolution conversion
└── tracing/            # OpenTelemetry setup

Key Types

DataPointId

Hierarchical identifier for time series data:

pub struct DataPointId {
    id: String,
    id_fragments: Vec<String>,
}
// "Asset/FI/Battery/SoC" → ["Asset", "FI", "Battery", "SoC"]

DataPointType

pub enum DataPointType {
    TimeSeriesDouble,
    TimeSeriesDoubleMatrix,
    StaticData,
}

MandoService (trait)

Central async trait for all data operations:

#[async_trait]
pub trait MandoService {
    async fn retrieve_catalog(...) -> Result<Vec<RepoDataPointId>, RepoError>;
    async fn retrieve(...) -> Result<HashMap<DataPointId, (Config, DataFrame, ...)>, RepoError>;
    async fn insert(...) -> Result<HashMap<DataPointId, u64>, RepoError>;
    async fn retrieve_at(...) -> ...;
    async fn retrieve_history(...) -> ...;
    async fn send(...) -> ...;
}

Repository (trait)

Generic database abstraction with specialized sub-traits:

  • Repository — base trait
  • DataPointRepository — data point CRUD
  • CacheRepository — caching operations

MandoServiceConfig

pub struct MandoServiceConfig {
    pub data_point_configs: Vec<MandoDataPointConfig>,
    pub data_point_types: HashMap<DataPointId, MandoDataPointType>,
}

DataPointFilterQueryMode

pub enum DataPointFilterQueryMode {
    ORIGINAL,   // Raw data
    OVERRIDE,   // Override layer
    MERGED,     // Override + original combined
}

Repository Implementations

ImplModuleDatabaseUse Case
RepositoryPostgresrepo_postgres.rsPostgreSQLProduction primary store
RepositoryDuckDbrepo_duckdb.rsDuckDBAnalytics/OLAP workloads
RepositorySqliterepo_sqlite.rsSQLiteLocal dev / lightweight
RepositoryPassthroughrepo_passthrough.rsAnyOptional caching layer

Factory functions: create_mando_service_duck_db(), create_mando_service_sqlite(), etc.

External Adapters

Alpiq

  • EntraIdClient — Azure AD / Entra ID authentication
  • EBS — Energy Balance System
  • MDR — Market Data Repository
  • OPL — Operations Planning

Volue

  • EMS — Energy Management System
  • ATP — Authentication/token providers

Fingrid

  • External Finnish market data integration

Feature Flags

FeatureWhat it enables
appAxum web framework + OpenTelemetry (used by mando-bess)
codegenCode generation tools with CSV support
pythonPyO3 classes/functions (#[pyclass], #[pyfunction])
workflowFlow/workflow execution engine

Error Handling

Uses mando-lib-macro’s #[derive(ErrorCode)] alongside thiserror:

#[derive(Error, ErrorCode)]
pub enum DataPointError {
    #[error("path fragment '{0}' must contain...")]
    InvalidPathFragmentFormat(usize, String),
}

Errors propagate via Result<T, RepoError> and Result<T, DataPointError>.