Architecture Overview

NSE is hexagonal (ports-and-adapters) and event-driven. Broker platforms,

models and network adapters are isolated behind port contracts

(IMT5Port, IGatewayPort), so the domain never knows which broker — or

whether a broker — is attached.

        ┌────────────────────────  ports (contracts)  ───────────────────────┐
        │                                                                    │
 Market │  ┌──────────┐   ┌──────────┐   ┌─────────┐   ┌────────┐            │
 data ──┼─►│ features │──►│  model   │──►│ signals │──►│  risk  │            │
 (MT5 / │  │ 50D/70D  │   │ ScalpNet │   │ policy  │   │ engine │            │
 paper) │  └──────────┘   └──────────┘   └─────────┘   └───┬────┘            │
        │                                                  ▼                 │
        │                                          ┌──────────────┐          │
        │                                          │  execution   │          │
        │                                          │ OrderManager │          │
        │                                          └──────┬───────┘          │
        ▼                                                 ▼                  │
 ┌──────────────┐   ┌──────────────┐   ┌──────────────────────────────┐       │
 │  adapters    │   │  accounting  │   │  application (LiveEngine)    │       │
 │ mt5/paper/db │   │ SQLite WAL   │   │  async event loop, web       │       │
 └──────────────┘   └──────────────┘   └──────────────────────────────┘       │
        └────────────────────────────────────────────────────────────────────┘

Layers

LayerLocationResponsibilityHard boundary
Domainsrc/nexus_scalp/domain/Immutable Pydantic contracts (TickData, TradeProposal, Position, AccountInfo)frozen models; .model_copy(update=…)
Portssrc/nexus_scalp/ports/IMT5Port, IGatewayPort protocol interfacessignature change ⇒ all adapters update
Adapterssrc/nexus_scalp/adapters/MT5 Win32 IPC, ZMQ remote gateway, paper simulator, SQLite WAL AuditRepositoryno sync DB on the hot path
Featuressrc/nexus_scalp/features/50D base → 70D canonical assembly, schema registry + hash, regimeschema is SSoT; ordering is contract
Modelssrc/nexus_scalp/models/ScalpNet dual-path (2D snapshot / 3D TCN+attention), 4-logit headinput dim must equal schema dim
Training / Labelingsrc/nexus_scalp/training/, labeling/purged walk-forward, triple-barrier labels (Polars)embargo/purge required; no lookahead
Signals / Strategiessrc/nexus_scalp/signals/, strategies/policy, ~30-rule SMC matrix, factorynever holds adapter or risk handle
Risksrc/nexus_scalp/risk/dynamic volume, margin clamps, tier capsauthoritative for boundaries
Executionsrc/nexus_scalp/execution/OrderManager: 60-scenario router, 11 position statesauthoritative for dispatch; HARD_MAX_LOTS=10
Accountingsrc/nexus_scalp/accounting/ledger, PnL, market calendar, retentionhistorical rows immutable
Applicationsrc/nexus_scalp/application/LiveEngine async loop: tick → features → … → webnever block the event loop
Intelligence closed loopexperience/, intelligence/, mslie/, research/, shadow/, news/, model_lifecycle/, governance/autopsy, behavior detection, candidate training, shadow, promotion gateszero order authority; promotion operator-gated
Model Factorysrc/nexus_scalp/model_generation/artifact-first datasets/experiments/models with manifestsinference needs no DB
Observability / Opsobservability/, hygiene/, incidents/, forensics/, settings/structured logs, hygiene (AUDIT_ONLY default), incidents, deploy gateincidents never mutate trading/risk/models
Web/APIsrc/nexus_scalp/web/, Web/FastAPI REST + SSE + WebSocket, buildless SPA Control Centerbackground tasks registered in app.state
Releasesrc/nexus_scalp/release/installer/CLI surface, update/rollback, verifyupdate blocked while LIVE

The closed intelligence loop

Live trade → accounting → experience → autopsy → research → candidate

training → shadow comparison → (operator-gated) promotion. Everything is

rebuildable from immutable ledgers.

Where to look next