# deskiziarecords/smart-exe architecture

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

- Interactive diagram: https://gitdiagram.com/deskiziarecords/smart-exe
- Repository: https://github.com/deskiziarecords/smart-exe

## Overview

1. **Overall shape**
   This repo is a Python-first trading system with three clear zones: a **live decision/execution loop**, an **offline learning and analysis pipeline**, and a **small UI/server layer** for monitoring. The main runtime appears to be centered around `main.py`, with `start_hyperion.py`, `main_server.py`, and `controller.py` acting as alternate launch/orchestration paths.

2. **Market data boundary**
   Live market input is handled by the data-ingestion side of the system, represented by `oanda_stream.py` and `tick_aggregator.py` in the tree, plus the README’s `data_feed.py` concept. This layer is responsible for taking OANDA market data and turning raw ticks into structured price windows that downstream engines can evaluate.

3. **Pattern encoding subsystem**
   `encoder.py`, `pattern_encoder_fast.py`, and `core/jax_pattern_engine.py` form the feature/pattern interpretation layer. Their role is to convert candle or tick sequences into symbolic or vectorized representations that can be compared, scored, or passed into memory/model components. The presence of a “fast” encoder and a JAX-based engine suggests performance-sensitive pattern processing.

4. **Memory and similarity search**
   `memory.py` and `memory/jax_faiss_memory.py` implement the repository’s pattern memory. This is not just storage; it is a retrieval layer that likely compares current market structure against prior sessions and associates patterns with outcomes. FAISS is the key architectural boundary here: it separates the live engine from fast nearest-neighbor retrieval over stored embeddings or signatures.

5. **Risk gating and trade approval**
   `risk_engine.py` and `lambda7.py` are the decision gates between “interesting market state” and “order allowed.” The README describes entropy filtering, memory agreement, and macro causal validation. Architecturally, this means the system is designed to **reject by default** and only pass a trade when multiple independent checks align.

6. **Execution layer**
   `trader.py` is the order-placement boundary, likely responsible for translating an approved signal into OANDA orders and handling execution details like sizing and trade submission. `market_engine.py` appears to sit near this boundary as a market/state manager, probably coordinating conditions needed for execution or live tracking.

7. **Control and orchestration**
   `controller.py` and `main.py` are the main application coordinators. `controller.py` is especially important for multi-asset or session-based orchestration, while `main.py` is the single-symbol/live-brain entry point described in the README. `start_hyperion.py` likely wraps startup behavior for the full system.

8. **Logging and feedback loop**
   `logger.py` captures blocked trades and other decision outputs, with `logs/blocked_trades.jsonl` as the persistent audit trail described in the README. This logging boundary is important because rejected trades are treated as training data, not just diagnostics.

9. **Offline dataset and learning pipeline**
   `dataset_builder.py` turns live-session logs into training data. That creates the feedback loop from rejected/accepted decisions back into future model improvement. The repo also contains `model.py`, which the README frames as a GRU-ready neural component, suggesting the system is designed to evolve from rule-heavy gating toward learned prediction.

10. **Training and experimental ML**
   The `geometric_training/train_per_asset.py` path and the `training GRU` directory indicate a separate offline experimentation area for per-asset or model training workflows. This is distinct from live execution: training consumes historical logs/exports, while the live loop consumes market data and emits trades or blocks.

11. **UI and operator surface**
   The `ui/` directory is a separate React/Vite frontend. It is likely a monitoring or visualization layer rather than the trading core itself. `main_server.py` likely exposes the backend API that bridges live system state, logs, and model outputs to the frontend.

12. **Artifacts and exported state**
   Files like `vector_export.json` and `report.json` indicate offline export artifacts, likely used for inspection, memory serialization, or training/report generation. These sit outside the live path and help move data between the execution subsystem and analysis/training tools.

13. **Technology boundaries that matter**
   The repo is primarily Python, with a frontend in TypeScript/React/Vite. FAISS is used for similarity search, and the README explicitly mentions OANDA as the external trading/data provider. JAX and PyTorch appear in the tree/README as acceleration and modeling technologies, but they are secondary to the core architecture: ingest, encode, retrieve memory, gate risk, execute, log, retrain.

14. **Diagramming summary**
   For an architecture diagram, the cleanest flow is: **OANDA data → tick aggregation/encoding → memory + causal/risk evaluation → trade decision → trader/execution**, with a side loop from **logger → dataset_builder → model/training → improved parameters/memory artifacts**. The UI/server layer should be drawn as an observability/control plane around the live system, not inside the trading decision path.

Main entry points: [`memory.py`](https://github.com/deskiziarecords/smart-exe/blob/main/memory.py) (Pattern memory), [`core/jax_pattern_engine.py`](https://github.com/deskiziarecords/smart-exe/blob/main/core/jax_pattern_engine.py) (JAX engine), [`risk_engine.py`](https://github.com/deskiziarecords/smart-exe/blob/main/risk_engine.py) (Risk engine), [`controller.py`](https://github.com/deskiziarecords/smart-exe/blob/main/controller.py) (Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_live["Live trading"]
  node_oanda["OANDA stream<br/>market feed<br/>[oanda_stream.py]"]
  node_ticks["Tick aggregator<br/>market buffer<br/>[tick_aggregator.py]"]
  node_market["Market engine<br/>state engine<br/>[market_engine.py]"]
  node_encoder["Pattern encoder<br/>feature encoder<br/>[encoder.py]"]
  node_fast_encoder["Fast encoder<br/>accelerated encoder"]
  node_jax_engine["JAX engine<br/>pattern engine"]
  node_risk{{"Risk engine<br/>trade gate<br/>[risk_engine.py]"}}
  node_lambda7{{"Lambda7 gate<br/>approval gate<br/>[lambda7.py]"}}
  node_trader["Trader<br/>execution<br/>[trader.py]"]
end

subgraph group_offline["Offline learning"]
  node_dataset["Dataset builder<br/>data prep<br/>[dataset_builder.py]"]
  node_model["Model<br/>[model.py]"]
  node_train["Per-asset training<br/>training job<br/>[train_per_asset.py]"]
  node_report["Reports<br/>artifacts<br/>[report.json]"]
  node_vector_export["Vector export<br/>artifact<br/>[vector_export.json]"]
end

subgraph group_ops["Control plane"]
  node_main(("Main loop<br/>entrypoint<br/>[main.py]"))
  node_start_hyperion(("Startup wrapper<br/>launcher<br/>[start_hyperion.py]"))
  node_controller["Controller<br/>orchestrator<br/>[controller.py]"]
  node_server["Main server<br/>api/server<br/>[main_server.py]"]
  node_logger["Decision log<br/>audit/logger<br/>[logger.py]"]
  node_ui["Operator UI<br/>frontend<br/>[App.tsx]"]
end

subgraph group_memory["Memory layer"]
  node_memory[("Pattern memory<br/>retrieval store<br/>[memory.py]")]
  node_faiss[("FAISS memory<br/>nearest-neighbor")]
end

node_main -->|"orchestrates"| node_controller
node_start_hyperion -->|"boots"| node_controller
node_controller -->|"subscribes"| node_oanda
node_oanda -->|"feeds"| node_ticks
node_ticks -->|"encodes"| node_encoder
node_ticks -->|"encodes"| node_fast_encoder
node_encoder -->|"scores"| node_jax_engine
node_fast_encoder -->|"scores"| node_jax_engine
node_jax_engine -->|"queries"| node_memory
node_memory -->|"retrieves"| node_faiss
node_jax_engine -->|"candidates"| node_risk
node_memory -->|"agreement"| node_risk
node_risk -->|"validates"| node_lambda7
node_lambda7 -->|"approves"| node_trader
node_market -->|"context"| node_trader
node_trader -->|"records"| node_logger
node_risk -->|"blocks"| node_logger
node_logger -->|"exports"| node_dataset
node_dataset -->|"trains"| node_model
node_model -->|"used by"| node_train
node_train -->|"emits"| node_report
node_memory -->|"exports"| node_vector_export
node_server -->|"serves"| node_ui
node_main -->|"exposes"| node_server
node_controller -->|"updates"| node_server

click node_main "https://github.com/deskiziarecords/smart-exe/blob/main/main.py"
click node_start_hyperion "https://github.com/deskiziarecords/smart-exe/blob/main/start_hyperion.py"
click node_controller "https://github.com/deskiziarecords/smart-exe/blob/main/controller.py"
click node_server "https://github.com/deskiziarecords/smart-exe/blob/main/main_server.py"
click node_logger "https://github.com/deskiziarecords/smart-exe/blob/main/logger.py"
click node_ui "https://github.com/deskiziarecords/smart-exe/blob/main/ui/src/App.tsx"
click node_oanda "https://github.com/deskiziarecords/smart-exe/blob/main/oanda_stream.py"
click node_ticks "https://github.com/deskiziarecords/smart-exe/blob/main/tick_aggregator.py"
click node_market "https://github.com/deskiziarecords/smart-exe/blob/main/market_engine.py"
click node_encoder "https://github.com/deskiziarecords/smart-exe/blob/main/encoder.py"
click node_fast_encoder "https://github.com/deskiziarecords/smart-exe/blob/main/pattern_encoder_fast.py"
click node_jax_engine "https://github.com/deskiziarecords/smart-exe/blob/main/core/jax_pattern_engine.py"
click node_memory "https://github.com/deskiziarecords/smart-exe/blob/main/memory.py"
click node_faiss "https://github.com/deskiziarecords/smart-exe/blob/main/memory/jax_faiss_memory.py"
click node_risk "https://github.com/deskiziarecords/smart-exe/blob/main/risk_engine.py"
click node_lambda7 "https://github.com/deskiziarecords/smart-exe/blob/main/lambda7.py"
click node_trader "https://github.com/deskiziarecords/smart-exe/blob/main/trader.py"
click node_dataset "https://github.com/deskiziarecords/smart-exe/blob/main/dataset_builder.py"
click node_model "https://github.com/deskiziarecords/smart-exe/blob/main/model.py"
click node_train "https://github.com/deskiziarecords/smart-exe/blob/main/geometric_training/train_per_asset.py"
click node_report "https://github.com/deskiziarecords/smart-exe/blob/main/report.json"
click node_vector_export "https://github.com/deskiziarecords/smart-exe/blob/main/vector_export.json"

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_oanda,node_ticks,node_market,node_encoder,node_fast_encoder,node_jax_engine,node_risk,node_lambda7,node_trader toneBlue
class node_dataset,node_model,node_train,node_report,node_vector_export toneAmber
class node_main,node_start_hyperion,node_controller,node_server,node_logger,node_ui toneMint
class node_memory,node_faiss toneRose
```

## Components

### Live trading

Real-time market intake, pattern evaluation, risk gating, and execution.

- [OANDA stream](https://github.com/deskiziarecords/smart-exe/blob/main/oanda_stream.py): market feed · External live market data source and stream adapter. · `oanda_stream.py`
- [Tick aggregator](https://github.com/deskiziarecords/smart-exe/blob/main/tick_aggregator.py): market buffer · Converts raw ticks into structured price windows. · `tick_aggregator.py`
- [Market engine](https://github.com/deskiziarecords/smart-exe/blob/main/market_engine.py): state engine · Maintains live market state and execution-adjacent coordination. · `market_engine.py`
- [Pattern encoder](https://github.com/deskiziarecords/smart-exe/blob/main/encoder.py): feature encoder · Transforms candles or ticks into symbolic or vector representations. · `encoder.py`
- [Fast encoder](https://github.com/deskiziarecords/smart-exe/blob/main/pattern_encoder_fast.py): accelerated encoder · Performance-oriented pattern encoder implementation. · `pattern_encoder_fast.py`
- [JAX engine](https://github.com/deskiziarecords/smart-exe/blob/main/core/jax_pattern_engine.py): pattern engine · JAX-based pattern processing and scoring core. · `core/jax_pattern_engine.py`
- [Risk engine](https://github.com/deskiziarecords/smart-exe/blob/main/risk_engine.py): trade gate · Filters candidates using entropy, agreement, and validation checks. · `risk_engine.py`
- [Lambda7 gate](https://github.com/deskiziarecords/smart-exe/blob/main/lambda7.py): approval gate · Additional causal or macro validation for trade approval. · `lambda7.py`
- [Trader](https://github.com/deskiziarecords/smart-exe/blob/main/trader.py): execution · Translates approved signals into orders and execution actions. · `trader.py`

### Offline learning

Dataset generation, model training, and export artifacts.

- [Dataset builder](https://github.com/deskiziarecords/smart-exe/blob/main/dataset_builder.py): data prep · Turns logs and session history into training data. · `dataset_builder.py`
- [Model](https://github.com/deskiziarecords/smart-exe/blob/main/model.py): ml model · Learned predictive component used by the offline and future live pipeline. · `model.py`
- [Per-asset training](https://github.com/deskiziarecords/smart-exe/blob/main/geometric_training/train_per_asset.py): training job · Offline per-asset training workflow and experiments. · `geometric_training/train_per_asset.py`
- [Reports](https://github.com/deskiziarecords/smart-exe/blob/main/report.json): artifacts · Exported analysis outputs and serialized reports. · `report.json`
- [Vector export](https://github.com/deskiziarecords/smart-exe/blob/main/vector_export.json): artifact · Exported embeddings or memory state for inspection or reuse. · `vector_export.json`

### Control plane

Launchers, orchestration, logging, and operator-facing server/UI.

- [Main loop](https://github.com/deskiziarecords/smart-exe/blob/main/main.py): entrypoint · Primary live trading entry for a single-symbol or focused runtime. · `main.py`
- [Startup wrapper](https://github.com/deskiziarecords/smart-exe/blob/main/start_hyperion.py): launcher · Alternate bootstrap path for the broader system. · `start_hyperion.py`
- [Controller](https://github.com/deskiziarecords/smart-exe/blob/main/controller.py): orchestrator · Coordinates sessions, assets, and overall runtime flow. · `controller.py`
- [Main server](https://github.com/deskiziarecords/smart-exe/blob/main/main_server.py): api/server · Backend surface for monitoring and control. · `main_server.py`
- [Decision log](https://github.com/deskiziarecords/smart-exe/blob/main/logger.py): audit/logger · Persists blocked trades and decision outcomes. · `logger.py`
- [Operator UI](https://github.com/deskiziarecords/smart-exe/blob/main/ui/src/App.tsx): frontend · React/Vite dashboard for observability and interaction. · `ui/src/App.tsx`

### Memory layer

Similarity search and pattern memory used by the live engine.

- [Pattern memory](https://github.com/deskiziarecords/smart-exe/blob/main/memory.py): retrieval store · Live memory of prior patterns and outcomes. · `memory.py`
- [FAISS memory](https://github.com/deskiziarecords/smart-exe/blob/main/memory/jax_faiss_memory.py): nearest-neighbor · Vector similarity retrieval backing the memory boundary. · `memory/jax_faiss_memory.py`

## Connections

- Main loop → Controller: orchestrates · Main runtime delegates session and asset coordination.
- Startup wrapper → Controller: boots · Startup wrapper initializes the coordinated system.
- Controller → OANDA stream: subscribes · Controller ties live runtime to market data input.
- OANDA stream → Tick aggregator: feeds · Raw market stream is normalized into tick windows.
- Tick aggregator → Pattern encoder: encodes · Aggregated price action is transformed into patterns.
- Tick aggregator → Fast encoder: encodes · High-throughput path for pattern encoding.
- Pattern encoder → JAX engine: scores · Encoded structures are evaluated by the pattern engine.
- Fast encoder → JAX engine: scores · Accelerated patterns flow into the same scoring core.
- JAX engine → Pattern memory: queries · Pattern engine consults prior analogues and outcomes.
- Pattern memory → FAISS memory: retrieves · Similarity search is backed by vector lookup.
- JAX engine → Risk engine: candidates · Pattern results become trade candidates for gating.
- Pattern memory → Risk engine: agreement · Memory consensus informs whether a setup is trusted.
- Risk engine → Lambda7 gate: validates · Secondary causal or macro gate is applied.
- Lambda7 gate → Trader: approves · Only approved signals can reach execution.
- Market engine → Trader: context · Market state supports order timing and live handling.
- Trader → Decision log: records · Execution outcomes and blocked decisions are logged.
- Risk engine → Decision log: blocks · Rejected trades are persisted for audit and learning.
- Decision log → Dataset builder: exports · Decision history becomes offline training material.
- Dataset builder → Model: trains · Prepared data feeds the predictive model.
- Model → Per-asset training: used by · Model training experiments consume the learned component.
- Per-asset training → Reports: emits · Training produces reports and analysis outputs.
- Pattern memory → Vector export: exports · Pattern memory state can be serialized for offline use.
- Main server → Operator UI: serves · Backend exposes state and logs to the operator UI.
- Main loop → Main server: exposes · Live runtime can publish status through the server layer.
- Controller → Main server: updates · Orchestrator feeds control and monitoring data upward.
