# engineio/math-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/engineio/math-sdk
- Repository: https://github.com/engineio/math-sdk

## Overview

Stake Engine Math SDK defines slot-game rules, simulates outcomes, optimizes win distributions, and emits backend/configuration files, lookup tables, and simulation results. The principal workflow is game-specific configuration and logic driving board generation, event and win-state updates, then simulation output; a separate optimization branch evaluates target distributions, while analytics and verification inspect generated artifacts. The tree and excerpts establish several internal calls, but not the full game-run dispatch or Python-to-Rust optimizer handoff, so those links are omitted.

Main entry points: [`src/state/state.py`](https://github.com/engineio/math-sdk/blob/main/src/state/state.py) (Game State), [`src/calculations/board.py`](https://github.com/engineio/math-sdk/blob/main/src/calculations/board.py) (Board Generation), [`src/executables/executables.py`](https://github.com/engineio/math-sdk/blob/main/src/executables/executables.py) (Game Executables), [`src/events/events.py`](https://github.com/engineio/math-sdk/blob/main/src/events/events.py) (Book Events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game Definitions"]
  node_game_rules["Game Rules"]
  node_game_runs["Game Entry<br/>[run.py]"]
end

subgraph group_runtime["Simulation Runtime"]
  node_config["Game Configuration<br/>[config.py]"]
  node_board["Board Generation<br/>[board.py]"]
  node_statistics["Random Outcomes<br/>[statistics.py]"]
  node_symbol["Symbol Storage<br/>[symbol.py]"]
  node_executables["Game Executables<br/>[executables.py]"]
  node_tumble["Tumble Logic<br/>[tumble.py]"]
  node_ways["Ways Calculation<br/>[ways.py]"]
  node_cluster["Cluster Calculation<br/>[cluster.py]"]
  node_line_calc["Line Calculation<br/>[lines.py]"]
  node_scatter["Scatter Calculation<br/>[scatter.py]"]
  node_state["Game State<br/>[state.py]"]
  node_win_manager["Win Tracking<br/>[win_manager.py]"]
  node_events["Book Events<br/>[events.py]"]
  node_books["Book Storage<br/>[books.py]"]
  node_simulations["Simulation Runs<br/>[run_sims.py]"]
end

subgraph group_optimization["Optimization"]
  node_opt_config["Optimization Inputs"]
  node_optimizer["Rust Optimizer<br/>[main.rs]"]
  node_optimizer_exes["Optimization Exes<br/>[exes.rs]"]
end

subgraph group_outputs["Outputs And Analysis"]
  node_write_data["Artifact Writer<br/>[write_data.py]"]
  node_output_files["Output Paths"]
  node_paths["Path Settings<br/>[paths.py]"]
  node_distribution_analysis["Distribution Analysis"]
  node_analytics["Game Analytics"]
  node_pay_splits["Pay Split Analysis<br/>[get_pay_splits.py]"]
  node_symbol_hits["Symbol Hit Analysis<br/>[get_symbol_hits.py]"]
  node_verification["RGS Verification"]
end

node_author(("Game Author"))

node_author -.->|"defines rules"| node_game_rules
node_board -->|"uses state"| node_state
node_board -->|"samples outcomes"| node_statistics
node_board -->|"emits reveal"| node_events
node_executables -->|"uses logic"| node_tumble
node_executables -->|"emits events"| node_events
node_executables -->|"checks conditions"| node_state
node_state -->|"tracks wins"| node_win_manager
node_state -->|"creates storage"| node_symbol
node_state -->|"configures paths"| node_output_files
node_state -->|"records books"| node_books
node_events -->|"adds events"| node_books
node_simulations -->|"writes results"| node_write_data
node_output_files -->|"uses root paths"| node_paths
node_optimizer -->|"uses definitions"| node_optimizer_exes
node_game_rules -.->|"sets optimization"| node_opt_config
node_analytics -->|"loads splits"| node_pay_splits
node_analytics -->|"loads hit counts"| node_symbol_hits
node_verification -->|"checks distribution"| node_distribution_analysis

click node_game_rules "https://github.com/engineio/math-sdk/blob/main/games/template/game_calculations.py"
click node_game_runs "https://github.com/engineio/math-sdk/blob/main/games/template/run.py"
click node_config "https://github.com/engineio/math-sdk/blob/main/src/config/config.py"
click node_board "https://github.com/engineio/math-sdk/blob/main/src/calculations/board.py"
click node_statistics "https://github.com/engineio/math-sdk/blob/main/src/calculations/statistics.py"
click node_symbol "https://github.com/engineio/math-sdk/blob/main/src/calculations/symbol.py"
click node_executables "https://github.com/engineio/math-sdk/blob/main/src/executables/executables.py"
click node_tumble "https://github.com/engineio/math-sdk/blob/main/src/calculations/tumble.py"
click node_ways "https://github.com/engineio/math-sdk/blob/main/src/calculations/ways.py"
click node_cluster "https://github.com/engineio/math-sdk/blob/main/src/calculations/cluster.py"
click node_line_calc "https://github.com/engineio/math-sdk/blob/main/src/calculations/lines.py"
click node_scatter "https://github.com/engineio/math-sdk/blob/main/src/calculations/scatter.py"
click node_state "https://github.com/engineio/math-sdk/blob/main/src/state/state.py"
click node_win_manager "https://github.com/engineio/math-sdk/blob/main/src/wins/win_manager.py"
click node_events "https://github.com/engineio/math-sdk/blob/main/src/events/events.py"
click node_books "https://github.com/engineio/math-sdk/blob/main/src/state/books.py"
click node_simulations "https://github.com/engineio/math-sdk/blob/main/src/state/run_sims.py"
click node_opt_config "https://github.com/engineio/math-sdk/blob/main/optimization_program/optimization_config.py"
click node_optimizer "https://github.com/engineio/math-sdk/blob/main/optimization_program/src/main.rs"
click node_optimizer_exes "https://github.com/engineio/math-sdk/blob/main/optimization_program/src/exes.rs"
click node_write_data "https://github.com/engineio/math-sdk/blob/main/src/write_data/write_data.py"
click node_output_files "https://github.com/engineio/math-sdk/blob/main/src/config/output_filenames.py"
click node_paths "https://github.com/engineio/math-sdk/blob/main/src/config/paths.py"
click node_distribution_analysis "https://github.com/engineio/math-sdk/blob/main/utils/analysis/distribution_functions.py"
click node_analytics "https://github.com/engineio/math-sdk/blob/main/utils/game_analytics/retrieve_game_information.py"
click node_pay_splits "https://github.com/engineio/math-sdk/blob/main/utils/game_analytics/get_pay_splits.py"
click node_symbol_hits "https://github.com/engineio/math-sdk/blob/main/utils/game_analytics/get_symbol_hits.py"
click node_verification "https://github.com/engineio/math-sdk/blob/main/utils/rgs_verification.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_game_rules,node_game_runs toneBlue
class node_config,node_board,node_statistics,node_symbol,node_executables,node_tumble,node_ways,node_cluster,node_line_calc,node_scatter,node_state,node_win_manager,node_events,node_books,node_simulations toneAmber
class node_opt_config,node_optimizer,node_optimizer_exes toneMint
class node_write_data,node_output_files,node_paths,node_distribution_analysis,node_analytics,node_pay_splits,node_symbol_hits,node_verification toneRose
class node_author toneIndigo
```

## Components

### Game Definitions

- [Game Rules](https://github.com/engineio/math-sdk/blob/main/games/template/game_calculations.py): `games/template/game_calculations.py`
- [Game Entry](https://github.com/engineio/math-sdk/blob/main/games/template/run.py): `games/template/run.py`

### Simulation Runtime

- [Game Configuration](https://github.com/engineio/math-sdk/blob/main/src/config/config.py): `src/config/config.py`
- [Board Generation](https://github.com/engineio/math-sdk/blob/main/src/calculations/board.py): `src/calculations/board.py`
- [Random Outcomes](https://github.com/engineio/math-sdk/blob/main/src/calculations/statistics.py): `src/calculations/statistics.py`
- [Symbol Storage](https://github.com/engineio/math-sdk/blob/main/src/calculations/symbol.py): `src/calculations/symbol.py`
- [Game Executables](https://github.com/engineio/math-sdk/blob/main/src/executables/executables.py): `src/executables/executables.py`
- [Tumble Logic](https://github.com/engineio/math-sdk/blob/main/src/calculations/tumble.py): `src/calculations/tumble.py`
- [Ways Calculation](https://github.com/engineio/math-sdk/blob/main/src/calculations/ways.py): `src/calculations/ways.py`
- [Cluster Calculation](https://github.com/engineio/math-sdk/blob/main/src/calculations/cluster.py): `src/calculations/cluster.py`
- [Line Calculation](https://github.com/engineio/math-sdk/blob/main/src/calculations/lines.py): `src/calculations/lines.py`
- [Scatter Calculation](https://github.com/engineio/math-sdk/blob/main/src/calculations/scatter.py): `src/calculations/scatter.py`
- [Game State](https://github.com/engineio/math-sdk/blob/main/src/state/state.py): `src/state/state.py`
- [Win Tracking](https://github.com/engineio/math-sdk/blob/main/src/wins/win_manager.py): `src/wins/win_manager.py`
- [Book Events](https://github.com/engineio/math-sdk/blob/main/src/events/events.py): `src/events/events.py`
- [Book Storage](https://github.com/engineio/math-sdk/blob/main/src/state/books.py): `src/state/books.py`
- [Simulation Runs](https://github.com/engineio/math-sdk/blob/main/src/state/run_sims.py): `src/state/run_sims.py`

### Optimization

- [Optimization Inputs](https://github.com/engineio/math-sdk/blob/main/optimization_program/optimization_config.py): `optimization_program/optimization_config.py`
- [Rust Optimizer](https://github.com/engineio/math-sdk/blob/main/optimization_program/src/main.rs): `optimization_program/src/main.rs`
- [Optimization Exes](https://github.com/engineio/math-sdk/blob/main/optimization_program/src/exes.rs): `optimization_program/src/exes.rs`

### Outputs And Analysis

- [Artifact Writer](https://github.com/engineio/math-sdk/blob/main/src/write_data/write_data.py): `src/write_data/write_data.py`
- [Output Paths](https://github.com/engineio/math-sdk/blob/main/src/config/output_filenames.py): `src/config/output_filenames.py`
- [Path Settings](https://github.com/engineio/math-sdk/blob/main/src/config/paths.py): `src/config/paths.py`
- [Distribution Analysis](https://github.com/engineio/math-sdk/blob/main/utils/analysis/distribution_functions.py): `utils/analysis/distribution_functions.py`
- [Game Analytics](https://github.com/engineio/math-sdk/blob/main/utils/game_analytics/retrieve_game_information.py): `utils/game_analytics/retrieve_game_information.py`
- [Pay Split Analysis](https://github.com/engineio/math-sdk/blob/main/utils/game_analytics/get_pay_splits.py): `utils/game_analytics/get_pay_splits.py`
- [Symbol Hit Analysis](https://github.com/engineio/math-sdk/blob/main/utils/game_analytics/get_symbol_hits.py): `utils/game_analytics/get_symbol_hits.py`
- [RGS Verification](https://github.com/engineio/math-sdk/blob/main/utils/rgs_verification.py): `utils/rgs_verification.py`

### Other components

- **Game Author**

## Connections

- Game Author → Game Rules: defines rules
- Board Generation → Game State: uses state (evidence: `src/calculations/board.py`)
- Board Generation → Random Outcomes: samples outcomes (evidence: `src/calculations/board.py`)
- Board Generation → Book Events: emits reveal (evidence: `src/calculations/board.py`)
- Game Executables → Tumble Logic: uses logic (evidence: `src/executables/executables.py`)
- Game Executables → Book Events: emits events (evidence: `src/executables/executables.py`)
- Game Executables → Game State: checks conditions (evidence: `src/executables/executables.py`)
- Game State → Win Tracking: tracks wins (evidence: `src/state/state.py`)
- Game State → Symbol Storage: creates storage (evidence: `src/state/state.py`)
- Game State → Output Paths: configures paths (evidence: `src/state/state.py`)
- Game State → Book Storage: records books (evidence: `src/state/state.py`)
- Book Events → Book Storage: adds events (evidence: `src/events/events.py`)
- Simulation Runs → Artifact Writer: writes results (evidence: `src/state/run_sims.py`)
- Output Paths → Path Settings: uses root paths (evidence: `src/config/output_filenames.py`)
- Rust Optimizer → Optimization Exes: uses definitions (evidence: `optimization_program/src/main.rs`)
- Game Rules → Optimization Inputs: sets optimization
- Game Analytics → Pay Split Analysis: loads splits (evidence: `utils/game_analytics/retrieve_game_information.py`)
- Game Analytics → Symbol Hit Analysis: loads hit counts (evidence: `utils/game_analytics/retrieve_game_information.py`)
- RGS Verification → Distribution Analysis: checks distribution (evidence: `utils/rgs_verification.py`)
