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
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
| Piece | Script / path | Notes |
|---|---|---|
| Main API | timed-trading-ingest ← worker/ | Only place that owns DO classes and migrations |
| Feed | tt-feed ← worker-feed/ | After cutover: price feed + keep-alive |
| Engine | tt-engine ← worker-engine/ | */5 scoring + trade lanes |
| Research | tt-research ← worker-research/ | Hourly arms + 22:00 UTC batch |
| Bridge | tt-broker-bridge ← worker-bridge/ | Sidecar; no end-user CF Access auth |
| Frontend | Pages ← react-app-dist/ | Independent of worker deploys |
| Quotes | TwelveData (+ Alpaca fallback/exec) | Prefer native change fields |
| Alerts / billing | Discord, Stripe, CF Access | See 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
| Change | Deploy |
|---|---|
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
| Who | Live prices + scores |
|---|---|
| Pro / VIP / Admin | Yes |
Member (free) / anon | No — redacted |
Server: canAccessLivePrices() / redactTickerMapForTier(). UI: window._ttIsPro.
| Boundary | Rule |
|---|---|
| Mutating admin routes | requireKeyOrAdmin (+ destructive confirm when irreversible) |
| Licensed market data | Server-side tier redact; cache keys include tier bucket |
| CF Access JWT | Fail closed (verifyAccessJWT); no “degrade gracefully” |
| API key | Prefer X-API-Key; ?key= deprecated |
| WebSockets | Ticket flow: /timed/ws-ticket then ?ticket= |
| Broker bridge | Browser never hits the bridge; /timed/broker/* stamps owner from session email |
| LLM HTML | Sanitize (DOMPurify); treat model output as untrusted |
- Discord — outbound from the main worker;
skills/discord-alerts.md - Stripe — Checkout + webhooks on the main worker;
skills/billing-and-sales-tax.md - CF Access — User Pages policy regex must list every authenticated page
- Broker tenant isolation for a trading partner is a different model:
skills/partner-onboarding.md
6. Price invariants
Do not re-implement. Read the pipeline rule and the data dictionary.
- TwelveData primary; parse native quote change fields (
parseTdQuote). - Client daily change only via
getDailyChange(t). - Every
timed:priceswriter stampsq_ts+p_tsand never regresses them. - Freshness / health use value stamps, not blob
t. - PriceStream DO ownership of every symbol in
timed:prices. - No AH writes during RTH; preserve closed-session day/EXT.
- Licensing footer: “Market data powered by Twelve Data”.
7. Skills
| Situation | Skill |
|---|---|
| Deploy / verify live | skills/deploy.md |
| Which worker / cron | skills/worker-topology.md |
| Rescore / snapshot | skills/rescore-ticker.md, skills/all-snapshot.md |
| D1 / KV | skills/d1-debugging.md, skills/kv-inspection.md |
| HTTP / new route / WS | skills/debug-http-codes.md, skills/security-auth-patterns.md |
| Broker automation / trading partner | skills/broker-bridge.md, skills/partner-onboarding.md |
| Frontend / smoke | skills/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
- Repo access; Cloudflare visibility as needed — operator grants; do not invent IAM
- Node 22 +
npm install; wrangler via./node_modules/.bin/wrangler - Local API work uses the API-key path when CF Access cannot complete in the browser
- Secrets never committed:
worker/.dev.vars, bridge, Stripe, TwelveData, Discord
Ramp
- Completed Start here Day 1–5
- Can name the five Worker scripts and what Pages serves
- Can explain Pages vs Worker deploy independence
- Can explain Member vs Pro vs VIP vs Admin for price/score gating
- Looks up a skill before inventing a procedure
First production-adjacent change
- Touches the correct deploy surface(s)
- Runs
bash scripts/check-branch-merge-state.shbefore pushing an existing branch - Verifies live behavior (health / route string / UI), not only green CI
- Updates lessons/CONTEXT if the operator corrects an assumption
Security before self-serve prod writes
- No unguarded mutating
/timed/*routes - No browser→bridge shortcuts; no
ownerfrom client input - No licensed data leaked to Member/anon caches
- No emoji in commits/PRs; no “you/your” in user-facing product copy