# ak495867/kraken architecture

> Architecture diagram of the GitHub repository ak495867/kraken, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ak495867/kraken
- Repository: https://github.com/ak495867/kraken

## Overview

#### Purpose and Entry Points
Kraken is a local-first, deterministic market-research engine for point-in-time analysis, empirical forecast calibration, regime/dynamics diagnostics, and governed vendor-data workflows. Its user-facing entry point is the Python CLI/package at `src/kraken/__main__.py` and `src/kraken/cli.py`. Native computations are exposed to Python through `cpp/bindings.cpp`.

#### Native Deterministic Analytics Core
The C++17 core owns numerical consistency and market-time validity gates before analytics execute. It computes stable statistics, features, empirical forecast bands, calibration distances, regime labels, and dynamics diagnostics.
- Core contracts and value types: `cpp/include/kraken_core/core.hpp`, `cpp/include/kraken_core/types.hpp`
- Input/cutoff/availability validation: `cpp/validation.cpp`, `cpp/include/kraken_core/validation.hpp`
- Analytics stages: `cpp/features.cpp`, `cpp/sonar.cpp`, `cpp/calibration.cpp`
- Regime and liquidity/volatility structure: `cpp/regime.cpp`, `cpp/dynamics.cpp`

Primary boundary: Python supplies typed, validated workflow inputs; pybind11 calls deterministic native routines; native results return to Python for reports, audit artifacts, and orchestration.

#### Point-in-Time Research and Walk-Forward Workflows
Python composes local CSV/JSON data into chronological research runs. It enforces availability timestamps, partitions history into train/embargo/validation/evaluation segments, and keeps post-cutoff outcomes separate from fit history.
- Research orchestration: `src/kraken/research.py`, `src/kraken/analysis.py`
- Forecast calibration workflow: `src/kraken/calibration.py`
- Historical equity/options workflow: `src/kraken/backtest.py`
- Domain inputs and event handling: `src/kraken/corporate_actions.py`, `src/kraken/distributions.py`, `src/kraken/earnings.py`

The flow is local input → parsing/normalization → point-in-time validation → native features/analytics → chronological calibration or backtest report.

#### Data, Vendor Governance, and Provenance
Kraken deliberately has no remote market-data connector or bundled licensed dataset. Vendor exports are accepted through versioned local mapping contracts, then fingerprinted and governed by manifest/attestation checks.
- File and schema handling: `src/kraken/io.py`, `src/kraken/normalizers.py`
- Vendor plugin discovery and acceptance: `src/kraken/vendor.py`, `src/kraken/acceptance.py`
- Hashes, run lineage, and report artifacts: `src/kraken/provenance.py`, `src/kraken/audit.py`
- Plugin assets/contracts: `vendor_plugins/canonical/1.0.0/plugin.json`, `vendor_plugins/snapshot_v1/1.0.0/plugin.json`

Important trust boundary: manifests, calendars, authorization attestations, and every referenced local file must agree by SHA-256; invalid or incomplete contracts fail closed.

#### Configuration and Result Packaging
Strict versioned research configuration is parsed at both Python/runtime and native layers, supporting reproducible output for identical inputs and compiler policy.
- Python runtime configuration: `src/kraken/config_runtime.py`
- Native configuration API/parser: `cpp/config.cpp`, `cpp/include/kraken_core/config.hpp`
- Versioned configurations: `configs/research_config.v1.kcfg`, `configs/production_risk_limits.json`
- Bundle/report assembly: `src/kraken/bundles.py`, `src/kraken/diagnostics.py`

#### Operational Runtime Boundary
A separate container-oriented runtime can ingest HTTPS JSON observations, persist immutable records in SQLite WAL, emit JSONL alerts and Prometheus-compatible metrics, and run paper-first execution controls. It is operationally distinct from the research pipelines and refuses live brokerage without a provider-specific implementation and approvals.
- Runtime orchestration: `src/kraken/production.py`, `tools/run_production.py`
- Risk, execution, and operations endpoints: `src/kraken/risk.py`, `src/kraken/execution.py`, `src/kraken/operations.py`
- Deployment container/runbook: `deploy/Dockerfile`, `deploy/README.md`

External/runtime dependencies materially include CPython 3.10–3.12, CMake/C++17, pybind11/scikit-build-core packaging, local SQLite, HTTPS ingestion clients, and Prometheus scrape consumers.

#### Build and Release Integrity
CMake builds the native extension; Python packaging produces source distributions and platform wheels. Release verification checks versioning, archive contents, native/plugin inclusion, generated-artifact exclusion, and checksums.
- Build definitions: `CMakeLists.txt`, `pyproject.toml`
- Release verification: `tools/check_release.py`, `tools/wheel_smoke.py`
- CI/release matrix: `.github/workflows/native-quality.yml`

Main entry points: [`src/kraken/research.py`](https://github.com/ak495867/kraken/blob/main/src/kraken/research.py) (Research orchestration), [`src/kraken/calibration.py`](https://github.com/ak495867/kraken/blob/main/src/kraken/calibration.py) (Calibration and backtest), [`cpp/bindings.cpp`](https://github.com/ak495867/kraken/blob/main/cpp/bindings.cpp) (pybind11 bindings), [`src/kraken/acceptance.py`](https://github.com/ak495867/kraken/blob/main/src/kraken/acceptance.py) (Acceptance and attestation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_research["Research workflows"]
  node_cli["Python CLI/package<br/>entrypoint<br/>[__main__.py]"]
  node_research["Research orchestration<br/>workflow<br/>[research.py]"]
  node_walkforward["Calibration and backtest<br/>workflow<br/>[calibration.py]"]
  node_domain_events["Corporate and event inputs<br/>domain inputs"]
  node_reports["Bundles and diagnostics<br/>reporting<br/>[bundles.py]"]
  node_runtime_config["Runtime configuration<br/>[config_runtime.py]"]
end

subgraph group_native["Native analytics"]
  node_native_bindings{{"pybind11 bindings<br/>Python/native boundary<br/>[bindings.cpp]"}}
  node_native_validation["Market-time validation<br/>native gate<br/>[validation.cpp]"]
  node_native_analytics["Features and calibration<br/>native analytics<br/>[features.cpp]"]
  node_native_regimes["Regime and dynamics<br/>native analytics<br/>[regime.cpp]"]
end

subgraph group_governance["Data governance"]
  node_local_inputs["Local CSV/JSON exports<br/>local data"]
  node_io_normalization["Parsing and normalization<br/>data processing<br/>[io.py]"]
  node_vendor_contracts["Vendor plugin contracts<br/>versioned contracts<br/>[plugin.json]"]
  node_acceptance{{"Acceptance and attestation<br/>trust gate<br/>[acceptance.py]"}}
  node_provenance["Lineage and audit artifacts<br/>provenance<br/>[provenance.py]"]
end

subgraph group_operations["Operational runtime"]
  node_production["Production orchestrator<br/>operational service<br/>[production.py]"]
  node_https_ingest["HTTPS observations<br/>external input"]
  node_sqlite[("SQLite WAL records<br/>immutable store")]
  node_risk_execution["Risk and paper execution<br/>execution controls<br/>[execution.py]"]
  node_ops_outputs["Alerts and metrics<br/>operational outputs<br/>[operations.py]"]
end

subgraph group_delivery["Build and release"]
  node_build["CMake and Python packaging<br/>build system<br/>[CMakeLists.txt]"]
  node_release_checks{{"Release verification<br/>release gate<br/>[check_release.py]"}}
end

node_cli -->|"starts"| node_research
node_research -->|"composes"| node_walkforward
node_local_inputs -->|"read locally"| node_io_normalization
node_vendor_contracts -->|"defines mapping"| node_acceptance
node_io_normalization -->|"normalized exports"| node_acceptance
node_acceptance -->|"accepted inputs"| node_research
node_domain_events -->|"event context"| node_research
node_runtime_config -->|"governs run"| node_research
node_research -->|"typed workflow inputs"| node_native_bindings
node_native_bindings -->|"calls"| node_native_validation
node_native_validation -->|"valid inputs"| node_native_analytics
node_native_analytics -->|"diagnostic features"| node_native_regimes
node_native_regimes -->|"deterministic results"| node_walkforward
node_walkforward -->|"reports"| node_reports
node_reports -->|"audit artifacts"| node_provenance
node_https_ingest -->|"JSON observations"| node_production
node_production -->|"immutable records"| node_sqlite
node_sqlite -->|"observations"| node_risk_execution
node_risk_execution -->|"alerts and metrics"| node_ops_outputs
node_build -->|"compiles extension"| node_native_bindings
node_build -->|"packages"| node_release_checks

click node_cli "https://github.com/ak495867/kraken/blob/main/src/kraken/__main__.py"
click node_research "https://github.com/ak495867/kraken/blob/main/src/kraken/research.py"
click node_walkforward "https://github.com/ak495867/kraken/blob/main/src/kraken/calibration.py"
click node_domain_events "https://github.com/ak495867/kraken/blob/main/src/kraken/corporate_actions.py"
click node_reports "https://github.com/ak495867/kraken/blob/main/src/kraken/bundles.py"
click node_native_bindings "https://github.com/ak495867/kraken/blob/main/cpp/bindings.cpp"
click node_native_validation "https://github.com/ak495867/kraken/blob/main/cpp/validation.cpp"
click node_native_analytics "https://github.com/ak495867/kraken/blob/main/cpp/features.cpp"
click node_native_regimes "https://github.com/ak495867/kraken/blob/main/cpp/regime.cpp"
click node_io_normalization "https://github.com/ak495867/kraken/blob/main/src/kraken/io.py"
click node_vendor_contracts "https://github.com/ak495867/kraken/blob/main/vendor_plugins/canonical/1.0.0/plugin.json"
click node_acceptance "https://github.com/ak495867/kraken/blob/main/src/kraken/acceptance.py"
click node_provenance "https://github.com/ak495867/kraken/blob/main/src/kraken/provenance.py"
click node_runtime_config "https://github.com/ak495867/kraken/blob/main/src/kraken/config_runtime.py"
click node_production "https://github.com/ak495867/kraken/blob/main/src/kraken/production.py"
click node_risk_execution "https://github.com/ak495867/kraken/blob/main/src/kraken/execution.py"
click node_ops_outputs "https://github.com/ak495867/kraken/blob/main/src/kraken/operations.py"
click node_build "https://github.com/ak495867/kraken/blob/main/CMakeLists.txt"
click node_release_checks "https://github.com/ak495867/kraken/blob/main/tools/check_release.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_research,node_walkforward,node_domain_events,node_reports,node_runtime_config toneBlue
class node_native_bindings,node_native_validation,node_native_analytics,node_native_regimes toneAmber
class node_local_inputs,node_io_normalization,node_vendor_contracts,node_acceptance,node_provenance toneMint
class node_production,node_https_ingest,node_sqlite,node_risk_execution,node_ops_outputs toneRose
class node_build,node_release_checks toneIndigo
```

## Components

### Research workflows

Local point-in-time analysis and reporting.

- [Python CLI/package](https://github.com/ak495867/kraken/blob/main/src/kraken/__main__.py): entrypoint · `src/kraken/__main__.py`
- [Research orchestration](https://github.com/ak495867/kraken/blob/main/src/kraken/research.py): workflow · `src/kraken/research.py`
- [Calibration and backtest](https://github.com/ak495867/kraken/blob/main/src/kraken/calibration.py): workflow · Chronological train, embargo, validation, and evaluation workflows. · `src/kraken/calibration.py`
- [Corporate and event inputs](https://github.com/ak495867/kraken/blob/main/src/kraken/corporate_actions.py): domain inputs · `src/kraken/corporate_actions.py`
- [Bundles and diagnostics](https://github.com/ak495867/kraken/blob/main/src/kraken/bundles.py): reporting · `src/kraken/bundles.py`
- [Runtime configuration](https://github.com/ak495867/kraken/blob/main/src/kraken/config_runtime.py): configuration · Strict versioned research configuration. · `src/kraken/config_runtime.py`

### Native analytics

Deterministic C++17 computation boundary.

- [pybind11 bindings](https://github.com/ak495867/kraken/blob/main/cpp/bindings.cpp): Python/native boundary · `cpp/bindings.cpp`
- [Market-time validation](https://github.com/ak495867/kraken/blob/main/cpp/validation.cpp): native gate · Rejects invalid inputs, cutoffs, and availability states before analytics. · `cpp/validation.cpp`
- [Features and calibration](https://github.com/ak495867/kraken/blob/main/cpp/features.cpp): native analytics · Stable statistics, forecast bands, and calibration distances. · `cpp/features.cpp`
- [Regime and dynamics](https://github.com/ak495867/kraken/blob/main/cpp/regime.cpp): native analytics · Liquidity/volatility structure and dynamics diagnostics. · `cpp/regime.cpp`

### Data governance

Versioned local vendor inputs and provenance.

- **Local CSV/JSON exports**: local data · No bundled licensed dataset or remote market-data connector.
- [Parsing and normalization](https://github.com/ak495867/kraken/blob/main/src/kraken/io.py): data processing · `src/kraken/io.py`
- [Vendor plugin contracts](https://github.com/ak495867/kraken/blob/main/vendor_plugins/canonical/1.0.0/plugin.json): versioned contracts · Local mappings define accepted vendor exports. · `vendor_plugins/canonical/1.0.0/plugin.json`
- [Acceptance and attestation](https://github.com/ak495867/kraken/blob/main/src/kraken/acceptance.py): trust gate · Manifest, calendar, authorization, and file hashes fail closed. · `src/kraken/acceptance.py`
- [Lineage and audit artifacts](https://github.com/ak495867/kraken/blob/main/src/kraken/provenance.py): provenance · `src/kraken/provenance.py`

### Operational runtime

Separate container-oriented paper-first runtime.

- [Production orchestrator](https://github.com/ak495867/kraken/blob/main/src/kraken/production.py): operational service · `src/kraken/production.py`
- **HTTPS observations**: external input
- **SQLite WAL records**: immutable store
- [Risk and paper execution](https://github.com/ak495867/kraken/blob/main/src/kraken/execution.py): execution controls · Refuses live brokerage without provider implementation and approvals. · `src/kraken/execution.py`
- [Alerts and metrics](https://github.com/ak495867/kraken/blob/main/src/kraken/operations.py): operational outputs · JSONL alerts and Prometheus-compatible metrics. · `src/kraken/operations.py`

### Build and release

Native extension packaging and release verification.

- [CMake and Python packaging](https://github.com/ak495867/kraken/blob/main/CMakeLists.txt): build system · Builds the C++ extension and source/platform distributions. · `CMakeLists.txt`
- [Release verification](https://github.com/ak495867/kraken/blob/main/tools/check_release.py): release gate · Checks archives, inclusion, exclusions, and checksums. · `tools/check_release.py`

## Connections

- Python CLI/package → Research orchestration: starts
- Research orchestration → Calibration and backtest: composes
- Local CSV/JSON exports → Parsing and normalization: read locally
- Vendor plugin contracts → Acceptance and attestation: defines mapping
- Parsing and normalization → Acceptance and attestation: normalized exports
- Acceptance and attestation → Research orchestration: accepted inputs
- Corporate and event inputs → Research orchestration: event context
- Runtime configuration → Research orchestration: governs run
- Research orchestration → pybind11 bindings: typed workflow inputs
- pybind11 bindings → Market-time validation: calls
- Market-time validation → Features and calibration: valid inputs
- Features and calibration → Regime and dynamics: diagnostic features
- Regime and dynamics → Calibration and backtest: deterministic results
- Calibration and backtest → Bundles and diagnostics: reports
- Bundles and diagnostics → Lineage and audit artifacts: audit artifacts
- HTTPS observations → Production orchestrator: JSON observations
- Production orchestrator → SQLite WAL records: immutable records
- SQLite WAL records → Risk and paper execution: observations
- Risk and paper execution → Alerts and metrics: alerts and metrics
- CMake and Python packaging → pybind11 bindings: compiles extension
- CMake and Python packaging → Release verification: packages
