Day 2

Architecture & partner onboarding

How a browser click becomes a quote, a score, and optionally a broker order. Front door for day 1 is Start here.

Repo sources of truth — do not duplicate wholesale: AGENTS.md, CONTEXT.md, skills/worker-topology.md, skills/deploy.md, skills/security-auth-patterns.md, skills/partner-onboarding.md, skills/user-state-matrix.md, .cursor/rules/price-data-pipeline.mdc.

1. System diagram

Timed Trading system architecture

2. Request path

Browser  →  CF Access (authenticated HTML)
         →  Cloudflare Pages (react-app-dist + _worker.js)
         →  proxy /timed/*  →  timed-trading-ingest
                                 ├─ Durable Objects (PriceStream, PriceHub, …)
                                 ├─ D1 timed-trading-ledger
                                 ├─ KV timed:prices / timed:latest / …
                                 └─ /timed/broker/* stamps owner from session
                                      → tt-broker-bridge
                                      → IBKR / Webull / Robinhood / E*TRADE

Role workers (same worker/ bundle, role-gated):
  tt-feed      price cron + stream keep-alive  →  KV + TwelveData WS
  tt-engine    */5 scoring + trade lifecycle   →  D1 + KV
  tt-research  hourly arms + 22:00 UTC batch   →  D1

External: TwelveData · Alpaca · Discord · Stripe · SendGrid · OpenAI

The browser never talks to the bridge. Pages and workers deploy independently.

3. Components

PieceScript / pathNotes
Main APItimed-trading-ingest ← worker/Only place that owns DO classes and migrations
Feedtt-feed ← worker-feed/After cutover: price feed + keep-alive
Enginett-engine ← worker-engine/*/5 scoring + trade lanes
Researchtt-research ← worker-research/Hourly arms + 22:00 UTC batch
Bridgett-broker-bridge ← worker-bridge/Sidecar; no end-user CF Access auth
FrontendPages ← react-app-dist/Independent of worker deploys
QuotesTwelveData (+ Alpaca fallback/exec)Prefer native change fields
Alerts / billingDiscord, Stripe, CF AccessSee discord-alerts + billing skills

Which *_EXTERNAL / *_ENABLED pairs are live is a dashboard fact. Probe health / Cloudflare vars — do not assume from this page.

4. What to deploy

ChangeDeploy
worker/** (shared logic)Monolith both envs and tt-engine + tt-research
worker/feed/**tt-feed as well
worker-bridge/**Bridge worker only
react-app/**npm run build:frontend, commit dist, push main (Pages)

CI: deploy-worker.yml, deploy-feed.yml, deploy-engine.yml, deploy-research.yml.

A merge is not a deploy. Verify Cloudflare version dates or /timed/health deployedSha. Stamp ENGINE_GIT_SHA on hand deploys. Detail: skills/deploy.md.

5. Auth and trust boundaries

WhoLive prices + scores
Pro / VIP / AdminYes
Member (free) / anonNo — redacted

Server: canAccessLivePrices() / redactTickerMapForTier(). UI: window._ttIsPro.

BoundaryRule
Mutating admin routesrequireKeyOrAdmin (+ destructive confirm when irreversible)
Licensed market dataServer-side tier redact; cache keys include tier bucket
CF Access JWTFail closed (verifyAccessJWT); no “degrade gracefully”
API keyPrefer X-API-Key; ?key= deprecated
WebSocketsTicket flow: /timed/ws-ticket then ?ticket=
Broker bridgeBrowser never hits the bridge; /timed/broker/* stamps owner from session email
LLM HTMLSanitize (DOMPurify); treat model output as untrusted

6. Price invariants

Do not re-implement. Read the pipeline rule and the data dictionary.

  1. TwelveData primary; parse native quote change fields (parseTdQuote).
  2. Client daily change only via getDailyChange(t).
  3. Every timed:prices writer stamps q_ts + p_ts and never regresses them.
  4. Freshness / health use value stamps, not blob t.
  5. PriceStream DO ownership of every symbol in timed:prices.
  6. No AH writes during RTH; preserve closed-session day/EXT.
  7. Licensing footer: “Market data powered by Twelve Data”.

7. Skills

SituationSkill
Deploy / verify liveskills/deploy.md
Which worker / cronskills/worker-topology.md
Rescore / snapshotskills/rescore-ticker.md, skills/all-snapshot.md
D1 / KVskills/d1-debugging.md, skills/kv-inspection.md
HTTP / new route / WSskills/debug-http-codes.md, skills/security-auth-patterns.md
Broker automation / trading partnerskills/broker-bridge.md, skills/partner-onboarding.md
Frontend / smokeskills/frontend-build.md, skills/mc-holistic-smoke-test.md

8. Partner checklist

For an engineering partner joining the codebase. For a broker-mirror product partner, use skills/partner-onboarding.md instead.

Access and tooling

Ramp

First production-adjacent change

Security before self-serve prod writes