[System Data Routing Spec]

Comprehensive data routing, transaction sequence diagrams, time-series metrics pipelines, and global storage mapping.

This page

Hoox operates as a highly orchestrated distributed event loop. Because execution logic is split into isolated compute nodes, data flows recursively through multiple V8 transitions, asynchronous queues, time-series datasets, and database ledgers.

This document provides complete, low-level technical specifications and Mermaid sequence diagrams for our primary data routing pipelines: Webhook Trade execution, AI Risk management, PDF browser rendering, Observability tracking, and Pine strategy bar-close → trade-worker.


1. Webhook to Trade Execution Flow (High-Speed Path)

This is the primary transaction pipeline. When a trade signal is received, the system validates the payload, locks the trace ID, executes the order at the edge closest to the exchange, records the fill, and alerts the user.

Diagram

Rendering…


2. Autonomous AI Risk Monitoring Flow (Cron Cycle)

Running on a configurable Cron schedule (1–1440 minutes; default every 15 minutes), the risk management loop queries SQLite records, audits active exposures, calculates trailing stop deviations, and manages emergency halts.

Diagram

Rendering…


3. PDF Portfolio Report Rendering Flow

Runs twice daily to automate HTML dashboard rendering, compile PDFs via Puppeteer on the edge, offload to R2 storage, and dispatch download corridors.

Diagram

Rendering…


4. Exchange ↔ D1 position reconciliation

After fills, D1 position rows are updated asynchronously (waitUntil). Agent housekeeping (and a manual operator call) re-syncs the ledger from live exchange APIs:

Diagram

Rendering…

Exchange is the source of truth; D1 is a cache for risk + dashboard.


5. Observability & Time-Series Analytics Flow

To maintain complete cross-worker telemetry without blocking critical order threads, Hoox routes analytics data points asynchronously to a dedicated metrics warehouse.

Diagram

Rendering…


6. Pine strategy bar-close → trade-worker

When a deployed Pine Script™ strategy is scheduled for bar-close evaluation, pyne-worker runs on cron, loads newer OHLCV bars from R2, evaluates the script, and forwards actionable strategy events to trade-worker over the TRADE_SERVICE binding with mesh internal auth and an idempotency key.

Diagram

Rendering…

HopAuth / headerNotes
Public /run, /scripts, cron job APIsX-API-Key (API_KEY secret)Tooling isolate — not mesh INTERNAL_KEY
pyne → trade-worker /webhookX-Internal-Auth-Key (INTERNAL_KEY_BINDING or trade-execute key)Required for live forward; optional DEFAULT_EXCHANGE on payload
Duplicate protectionIdempotency key on forwardtrade-worker / DO path rejects replays

💾 7. Global Data Persistence Mapping

Storage PlatformNamespace / Database NameData Payload DetailsAssociated Compute Workers
D1 Databasetrade-data-db (SQLite)Executed fills, open position matrices, Drizzle tracking logs.d1-worker, trade-worker, agent-worker
CONFIG_KVCONFIG_KV (Key-Value)16-key global runtime manifest, emergency Kill Switch.All Workers + Next.js Dashboard
SESSIONS_KVSESSIONS_KV (Key-Value)Session access states and API authorization cookies.hoox Gateway
R2 Storagetrade-reports (S3 Bucket)Compiled PDF portfolio reports.report-worker
R2 Storagehoox-system-logs (S3 Bucket)Verbose JSON exchange API payloads (REST & WebSocket logs).trade-worker
Vectorizemy-rag-index (Vector DB)Semantic chat and history vector embeddings.telegram-worker

🔗 Next Steps