# shine0078/nt8bridgecleandiscovery architecture

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

- Interactive diagram: https://gitdiagram.com/shine0078/nt8bridgecleandiscovery
- Repository: https://github.com/shine0078/nt8bridgecleandiscovery

## Overview

#### Purpose and entry points
NT8BridgeClean is a safety-first, clean-room research and validation repository for a NinjaTrader 8 Keltner-breakout strategy. It combines deterministic offline research, native NT8 compatibility/Playback validation, and fail-closed release authorization; it explicitly rejects live trading today. Primary entry points are the Python CLI at `nt8_research/__main__.py` / `nt8_research/cli.py`, the release evaluator `Scripts/evaluate_release.py`, and manually operated NT8 strategy sources under `Strategies/`.

#### Offline research engine
The deterministic Python engine models completed-bar signals, next-open entries, costs, sizing, protection, session flattening, and risk breakers. It runs scenario matrices and produces reproducible metrics/artifacts rather than placing orders.
- `nt8_research/engine.py`
- `nt8_research/scenarios.py`
- `nt8_research/models.py`

Market-data ingestion, indicators, and performance calculations form the engine boundary: raw data is intentionally outside the tracked tree, while generated research outputs are committed for audit.
- `nt8_research/data.py`
- `nt8_research/indicators.py`
- `nt8_research/metrics.py`
- `Results/research_results.json`

#### Candidate locking and release policy
Candidate plans preregister strategy identity, parameters, validation windows, and permitted evidence. Release evaluation consumes only candidate-bound, hash-validated artifacts and fails closed on missing, stale, superseded, or inconsistent evidence. It is the sole authority for `APPROVED`/live authorization.
- `Validation/resilient_candidate_plan.json`
- `nt8_research/release.py`
- `Scripts/evaluate_release.py`
- `NativeValidation/evidence_contract.json`

The active candidate is distinct from the permanently burned predecessor lock:
- `Validation/candidate_lock.json`
- `Results/release_evaluation.json`

#### NinjaScript strategy layer
Three NinjaScript versions represent baseline, successor, and active resilient candidates. The resilient strategy is the operational focus: it defaults to Sim101/Playback101, blocks real-time accounts unless explicitly authorized, logs incidents/order states, persists loss locks, and protects against connection/position anomalies.
- `Strategies/RobustKeltnerBreakout.cs`
- `Strategies/RobustKeltnerBreakoutResilient.cs`
- `Strategies/RobustKeltnerBreakoutSuccessor.cs`
- `Strategies/ConnectionStateGate.cs`

This layer runs inside NinjaTrader 8.1.7.2, not the Python runtime. Source installation and native compilation are controlled compatibility boundaries.

#### Native NT8 automation and safety boundary
Python scripts automate evidence-oriented NT8 workflows: discover UI state, install exact candidate sources, configure Playback/Sim101, capture output, and compile. Native mutations are acknowledgment-gated, candidate-scoped, and restricted to simulated/Playback validation; discovery tooling is read-only.
- `nt8_research/native_automation.py`
- `nt8_research/native_artifacts.py`
- `Scripts/install_resilient_candidate.py`
- `Scripts/run_nt8_shadow_compile.ps1`

NT8 is an external Windows desktop runtime; its Control Center/UI automation and installed Custom project are treated as untrusted operational boundaries. Environment evidence is sanitized:
- `Scripts/collect_nt8_environment.py`
- `Results/nt8_environment_evidence.json`

#### Playback resilience validation
Operational validation exercises connection loss, partial fills, orphan-position reconciliation, and restart-persistent loss locks in NT8 Playback. Raw captures are preserved first; evidence builders derive reproducible summaries, including rejected or not-exercised outcomes rather than converting them to passes.
- `Scripts/build_operational_evidence.py`
- `NativeValidation/evidence/playback/resilient_orphan_position_reconciliation/`
- `NativeValidation/evidence/playback/resilient_restart_restores_loss_lock/`
- `Results/resilient_orphan_position_reconciliation_evidence.json`

#### Evidence custody and packaging
Evidence is SHA-256-bound across source, native compile captures, logs, exports, and derived results. Import packages and commission templates support controlled NT8 installation; broker-control evidence is deliberately private and must come from independent redacted exports.
- `NativeValidation/package_manifest.json`
- `NativeValidation/evidence/resilient_native_compile/compile_capture.json`
- `Scripts/build_nt8_import_package.ps1`
- `Scripts/build_broker_evidence.py`

#### Execution and CI
The project runs on Python with dependencies declared in `pyproject.toml` and `requirements.txt`; NinjaTrader-specific validation requires Windows and NT8. CI enforces repository-side safety/regression checks but cannot substitute for native, manually supervised validation.
- `pyproject.toml`
- `.github/workflows/ci.yml`
- `docs/CI_VALIDATION.md`

Main entry points: [`nt8_research/release.py`](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/release.py) (Release evaluator), [`nt8_research/engine.py`](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/engine.py) (Backtest engine), [`Scripts/build_operational_evidence.py`](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Scripts/build_operational_evidence.py) (Operational evidence builder), [`Scripts/install_resilient_candidate.py`](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Scripts/install_resilient_candidate.py) (Install and compile workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_research["Offline research"]
  node_cli["Research CLI<br/>Python entry point<br/>[cli.py]"]
  node_engine["Backtest engine<br/>Python engine<br/>[engine.py]"]
  node_scenarios["Scenario matrix<br/>Python scenarios<br/>[scenarios.py]"]
  node_market_boundary["Market data and analytics<br/>ingestion/indicators/metrics<br/>[data.py]"]
  node_research_results["Research results<br/>committed artifact"]
end

subgraph group_release["Release authorization"]
  node_candidate_plan["Candidate plan<br/>preregistration"]
  node_candidate_lock["Candidate lock<br/>immutable lock"]
  node_release_evaluator["Release evaluator<br/>Python policy engine<br/>[release.py]"]
  node_release_result["Release evaluation<br/>authorization artifact"]
end

subgraph group_native["Native NT8 validation"]
  node_nt8_runtime{{"NinjaTrader 8 runtime<br/>external Windows desktop"}}
  node_resilient_strategy["Resilient strategy<br/>NinjaScript candidate"]
  node_strategy_lineage["Strategy lineage<br/>NinjaScript variants"]
  node_native_automation["Native automation<br/>Python automation"]
  node_playback_validation["Playback resilience tests<br/>manual native validation"]
end

subgraph group_evidence["Evidence custody"]
  node_evidence_contract["Evidence contract<br/>validation policy"]
  node_operational_evidence["Operational evidence builder<br/>evidence derivation"]
  node_native_compile_capture["Native compile capture<br/>hash-bound evidence"]
  node_package_manifest["Package manifest<br/>installation custody"]
end

subgraph group_delivery["Automation and CI"]
  node_install_workflow["Install and compile workflow<br/>controlled scripts"]
  node_ci["Repository CI<br/>GitHub Actions<br/>[ci.yml]"]
end

node_cli -->|"runs"| node_engine
node_engine -->|"evaluates"| node_scenarios
node_engine -->|"uses"| node_market_boundary
node_engine -->|"writes"| node_research_results
node_candidate_plan -->|"locks"| node_candidate_lock
node_candidate_plan -->|"bounds"| node_release_evaluator
node_candidate_lock -->|"validates"| node_release_evaluator
node_evidence_contract -->|"governs accepted evidence"| node_release_evaluator
node_release_evaluator -->|"emits"| node_release_result
node_strategy_lineage -.->|"candidate lineage"| node_resilient_strategy
node_resilient_strategy -->|"runs in"| node_nt8_runtime
node_native_automation -->|"automates UI"| node_nt8_runtime
node_install_workflow -->|"installs exact source"| node_resilient_strategy
node_install_workflow -->|"compiles in"| node_nt8_runtime
node_nt8_runtime -->|"produces raw captures"| node_playback_validation
node_playback_validation -->|"supplies captures"| node_operational_evidence
node_operational_evidence -->|"derives conforming evidence"| node_evidence_contract
node_nt8_runtime -->|"records compilation"| node_native_compile_capture
node_package_manifest -->|"controls package contents"| node_install_workflow
node_research_results -->|"candidate evidence"| node_release_evaluator
node_native_compile_capture -->|"candidate evidence"| node_release_evaluator
node_operational_evidence -->|"candidate evidence"| node_release_evaluator
node_ci -.->|"checks repository safety"| node_release_evaluator

click node_cli "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/cli.py"
click node_engine "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/engine.py"
click node_scenarios "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/scenarios.py"
click node_market_boundary "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/data.py"
click node_research_results "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Results/research_results.json"
click node_candidate_plan "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Validation/resilient_candidate_plan.json"
click node_candidate_lock "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Validation/candidate_lock.json"
click node_release_evaluator "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/release.py"
click node_release_result "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Results/release_evaluation.json"
click node_resilient_strategy "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Strategies/RobustKeltnerBreakoutResilient.cs"
click node_strategy_lineage "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Strategies/RobustKeltnerBreakout.cs"
click node_native_automation "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/native_automation.py"
click node_playback_validation "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/evidence/playback/resilient_orphan_position_reconciliation/capture_manifest.json"
click node_evidence_contract "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/evidence_contract.json"
click node_operational_evidence "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Scripts/build_operational_evidence.py"
click node_native_compile_capture "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/evidence/resilient_native_compile/compile_capture.json"
click node_package_manifest "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/package_manifest.json"
click node_install_workflow "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Scripts/install_resilient_candidate.py"
click node_ci "https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/.github/workflows/ci.yml"

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_engine,node_scenarios,node_market_boundary,node_research_results toneBlue
class node_candidate_plan,node_candidate_lock,node_release_evaluator,node_release_result toneAmber
class node_nt8_runtime,node_resilient_strategy,node_strategy_lineage,node_native_automation,node_playback_validation toneMint
class node_evidence_contract,node_operational_evidence,node_native_compile_capture,node_package_manifest toneRose
class node_install_workflow,node_ci toneIndigo
```

## Components

### Offline research

Deterministic Python analysis with committed audit outputs.

- [Research CLI](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/cli.py): Python entry point · `nt8_research/cli.py`
- [Backtest engine](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/engine.py): Python engine · Models completed-bar trading, protection, sessions, and breakers. · `nt8_research/engine.py`
- [Scenario matrix](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/scenarios.py): Python scenarios · `nt8_research/scenarios.py`
- [Market data and analytics](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/data.py): ingestion/indicators/metrics · Raw market data remains outside the tracked repository. · `nt8_research/data.py`
- [Research results](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Results/research_results.json): committed artifact · `Results/research_results.json`

### Release authorization

Candidate-bound, fail-closed release decision.

- [Candidate plan](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Validation/resilient_candidate_plan.json): preregistration · Defines identity, windows, parameters, and permitted evidence. · `Validation/resilient_candidate_plan.json`
- [Candidate lock](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Validation/candidate_lock.json): immutable lock · Active lock is distinct from the burned predecessor. · `Validation/candidate_lock.json`
- [Release evaluator](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/release.py): Python policy engine · Sole authority for APPROVED and live authorization. · `nt8_research/release.py`
- [Release evaluation](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Results/release_evaluation.json): authorization artifact · `Results/release_evaluation.json`

### Native NT8 validation

Windows/NT8 compatibility and Playback safety boundary.

- **NinjaTrader 8 runtime**: external Windows desktop · Untrusted Control Center/UI and installed Custom-project boundary.
- [Resilient strategy](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Strategies/RobustKeltnerBreakoutResilient.cs): NinjaScript candidate · Defaults to Sim101/Playback101 and guards account, connection, position, and loss-lock state. · `Strategies/RobustKeltnerBreakoutResilient.cs`
- [Strategy lineage](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Strategies/RobustKeltnerBreakout.cs): NinjaScript variants · Baseline and successor sources provide candidate lineage. · `Strategies/RobustKeltnerBreakout.cs`
- [Native automation](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/nt8_research/native_automation.py): Python automation · Candidate-scoped, acknowledgment-gated simulated/Playback workflows. · `nt8_research/native_automation.py`
- [Playback resilience tests](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/evidence/playback/resilient_orphan_position_reconciliation/capture_manifest.json): manual native validation · Exercises connection loss, fills, reconciliation, and persisted loss locks. · `NativeValidation/evidence/playback/resilient_orphan_position_reconciliation/capture_manifest.json`

### Evidence custody

Hash-bound validation captures and derived evidence.

- [Evidence contract](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/evidence_contract.json): validation policy · `NativeValidation/evidence_contract.json`
- [Operational evidence builder](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Scripts/build_operational_evidence.py): evidence derivation · Preserves rejected and not-exercised outcomes. · `Scripts/build_operational_evidence.py`
- [Native compile capture](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/evidence/resilient_native_compile/compile_capture.json): hash-bound evidence · `NativeValidation/evidence/resilient_native_compile/compile_capture.json`
- [Package manifest](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/NativeValidation/package_manifest.json): installation custody · `NativeValidation/package_manifest.json`

### Automation and CI

Controlled installation, packaging, and repository checks.

- [Install and compile workflow](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/Scripts/install_resilient_candidate.py): controlled scripts · Installs exact sources and runs shadow compilation. · `Scripts/install_resilient_candidate.py`
- [Repository CI](https://github.com/shine0078/nt8bridgecleandiscovery/blob/main/.github/workflows/ci.yml): GitHub Actions · Safety and regression checks; not a substitute for native validation. · `.github/workflows/ci.yml`

## Connections

- Research CLI → Backtest engine: runs
- Backtest engine → Scenario matrix: evaluates
- Backtest engine → Market data and analytics: uses
- Backtest engine → Research results: writes
- Candidate plan → Candidate lock: locks
- Candidate plan → Release evaluator: bounds
- Candidate lock → Release evaluator: validates
- Evidence contract → Release evaluator: governs accepted evidence
- Release evaluator → Release evaluation: emits
- Strategy lineage → Resilient strategy: candidate lineage
- Resilient strategy → NinjaTrader 8 runtime: runs in
- Native automation → NinjaTrader 8 runtime: automates UI
- Install and compile workflow → Resilient strategy: installs exact source
- Install and compile workflow → NinjaTrader 8 runtime: compiles in
- NinjaTrader 8 runtime → Playback resilience tests: produces raw captures
- Playback resilience tests → Operational evidence builder: supplies captures
- Operational evidence builder → Evidence contract: derives conforming evidence
- NinjaTrader 8 runtime → Native compile capture: records compilation
- Package manifest → Install and compile workflow: controls package contents
- Research results → Release evaluator: candidate evidence
- Native compile capture → Release evaluator: candidate evidence
- Operational evidence builder → Release evaluator: candidate evidence
- Repository CI → Release evaluator: checks repository safety
