How saeidshahriari/etrm-data-platform works
Purpose and entry points
ETRM Data Platform is a secured batch lakehouse for European electricity prices and synthetic energy trades. It lands raw market data, produces medallion Parquet datasets, calculates risk/P&L, flags suspicious trades, and exposes results through a dashboard and MCP agent. Primary operational entry points are Makefile, Airflow DAG dags/etrm_pipeline_dag.py, local runner main.py, Streamlit dashboard/app.py, and MCP server agent/etrm_mcp_server.py.
Orchestration and runtime boundary
Apache Airflow coordinates the manually triggered etrm_medallion_pipeline, including security checkpoints and local-mode Spark execution. DAG task code must defer heavy imports to task execution, separating scheduler parsing from data-processing dependencies.
• dags/etrm_pipeline_dag.py
• Dockerfile
• docker-compose.yml
Runtime is Python 3.12, Java 17, Airflow 3/Celery, and PySpark 4. Spark transformations run local-mode inside an Airflow worker; standalone Spark services remain deployment infrastructure rather than the primary execution backend.
Secure ingestion and source boundary
Market prices originate from the external SMARD API; trades are generated synthetically and stored in PostgreSQL. Secure ingestion scans and validates records before landing raw Bronze data. Invalid rows are quarantined; batches exceeding the failure threshold are rejected, preventing poisoned data from advancing.
• src/ingestion/secure_ingest.py
• src/ingestion/fetch_market_data.py
• src/ingestion/generate_trades.py
Secrets/configuration are Vault-backed, with HashiCorp Vault KV v2 used in development mode.
• src/config.py
• src/ingestion/vault_client.py
• config/config.yaml
Data-security and quality gate
The live-data boundary combines custom injection/malware-style scanning with schema, domain-range, and statistical poisoning checks. It protects downstream Spark, analytics, and AI surfaces from SQL/script/path/prompt injection and anomalous-but-in-range values.
• src/security/scanner.py
• src/quality/schemas.py
• src/quality/gates.py
This is distinct from repository and infrastructure security scanning in GitHub Actions and on-demand DAST.
• .github/workflows/security.yml
• security/run_dast.sh
Medallion processing and stores
Bronze preserves raw API payloads; Silver creates cleaned, typed market-price and trade datasets; Gold produces business-ready P&L, counterparty exposure, and portfolio summaries. Parquet is the lake format on a shared local mount. PostgreSQL 16 serves application trade storage and separate Airflow metadata storage.
• src/processing/bronze_to_silver.py
• src/processing/silver_to_gold.py
• docker-compose.yml
ML surveillance stage
The pipeline derives trade features, trains an unsupervised Isolation Forest, records experiments through MLflow, and writes scored/flagged trade outputs for analyst consumption. Features connect trade behavior to market context, including price deviation, volume, notional, contract duration, and concentration.
• src/ml/features.py
• src/ml/train_anomaly_model.py
• src/ml/score_trades.py
Consumption interfaces
The Streamlit dashboard reads current lakehouse/risk and surveillance outputs for live operational views. The MCP agent uses DuckDB to query Parquet in place. Agent queries are deliberately constrained to read-only SELECT/WITH statements and whitelisted tables, making the agent a controlled analytics boundary rather than a write interface.
• dashboard/app.py
• agent/etrm_mcp_server.py
Main entry points: secure_ingest.py Secure ingestion · silver_to_gold.py Gold Parquet · scanner.py Security & quality gate · bronze_to_silver.py Silver Parquet
Components 19
Orchestration
- Makefile
Makefile - Local runner
main.py - Medallion pipeline DAG · Manually triggered pipeline with security checkpoints and worker-run Spark tasks.
dags/etrm_pipeline_dag.py - Airflow worker · Heavy processing imports occur only during task execution.
Dockerfile
Secure ingestion
- Vault KV v2 · Development secrets and configuration source.
src/ingestion/vault_client.py - SMARD API
src/ingestion/fetch_market_data.py - Synthetic trade generator
src/ingestion/generate_trades.py - Trade PostgreSQL
docker-compose.yml - Secure ingestion · Rejects batches over the invalid-row threshold before Bronze landing.
src/ingestion/secure_ingest.py - Security & quality gate · Scans injection and malware patterns plus schema, range, and poisoning anomalies.
src/security/scanner.py - Quarantine
src/ingestion/secure_ingest.py
Lakehouse & analytics
- Bronze Parquet · Preserves raw market payloads.
src/processing/bronze_to_silver.py - Silver Parquet · Typed market-price and trade datasets.
src/processing/bronze_to_silver.py - Gold Parquet · P&L, counterparty exposure, and portfolio summaries.
src/processing/silver_to_gold.py
ML surveillance
- Trade features · Combines trade behavior with market context.
src/ml/features.py - Isolation Forest training · Records unsupervised anomaly experiments in MLflow.
src/ml/train_anomaly_model.py - Trade scoring · Writes scored and flagged trade outputs.
src/ml/score_trades.py
Consumption
- Operations dashboard
dashboard/app.py - MCP analytics agent · Uses DuckDB over whitelisted Parquet tables and SELECT/WITH queries only.
agent/etrm_mcp_server.py
Connections 20
- Makefile → Medallion pipeline DAG: operates
- Local runner → Medallion pipeline DAG: runs locally
- Medallion pipeline DAG → Airflow worker: dispatches tasks
- Vault KV v2 → Secure ingestion: supplies secrets
- SMARD API → Secure ingestion: market prices
- Synthetic trade generator → Trade PostgreSQL: stores trades
- Trade PostgreSQL → Secure ingestion: trade records
- Airflow worker → Secure ingestion: executes
- Secure ingestion → Security & quality gate: scans and validates
- Security & quality gate → Bronze Parquet: accepted records
- Security & quality gate → Quarantine: invalid records
- Bronze Parquet → Silver Parquet: clean and type
- Silver Parquet → Gold Parquet: derive business metrics
- Silver Parquet → Trade features: trades and prices
- Trade features → Isolation Forest training: feature set
- Isolation Forest training → Trade scoring: trained model
- Trade features → Trade scoring: scoring features
- Trade scoring → Gold Parquet: flagged trade outputs
- Gold Parquet → Operations dashboard: risk and surveillance views
- Gold Parquet → MCP analytics agent: Parquet analytics