Newcomer guide

Newcomer Repo & Workers Guide

Audience: engineers new to the Timed Trading repo (day 1 / first week). Start here, then follow the reading path below.

Companion: engineering partner onboarding (architecture diagram, price invariants, security boundaries, partner checklist).

1. What you are looking at

Timed Trading is a Cloudflare Workers + Pages product:

LayerWhat it is
Pages frontendPrebuilt HTML/JS from react-app/ → react-app-dist/, auto-deploys on git push to main
API monolithtimed-trading-ingest — all /timed/* routes + Durable Objects
Role cron workerstt-feed, tt-engine, tt-research — same codebase, role-gated crons
Broker bridgett-broker-bridge — separate sidecar (worker-bridge/) for IBKR / Webull / Robinhood (+ E*TRADE scaffold)
DataD1 (timed-trading-ledger) + KV (timed:prices, timed:latest, …)
Market dataTwelveData primary; Alpaca for execution / fallback

Product entry for signed-in users is /today.html (not the retired /index-react.html).

2. Read in this order (~15–20 min)

Paths below are in the git repo root (e.g. /workspace/… on the agent VM, or the local clone):

  1. AGENTS.md — onboarding contract, house rules, Cursor Cloud local tips
  2. CONTEXT.md — stack, deploy, journey pages, condensed critical lessons
  3. skills/README.md — index of how-to playbooks
  4. skills/worker-topology.md — which worker runs which cron
  5. skills/deploy.md — what to deploy when; merge ≠ deploy

Do not try to memorize CONTEXT.md lessons on day 1. Skim the Stack / Deploy / Product entry sections; grep lessons when something looks familiar.

3. Repo map

PathRole
worker/Main Worker source + wrangler.toml for timed-trading-ingest. Routes, scoring, trade logic, DOs (PriceStream, PriceHub, …).
worker-feed/Wrangler config for tt-feed. Bundles feed entry + shared worker/ modules. Owns price-feed cron after cutover.
worker-engine/Wrangler config for tt-engine. Same monolith bundle (main = "../worker/index.js"). Owns */5 scoring + trade lifecycle.
worker-research/Wrangler config for tt-research. Same monolith bundle. Owns hourly research + 22:00 UTC nightly batch.
worker-bridge/Separate codebase for tt-broker-bridge. Broker adapters, sizing, reconciler, mirror kernel. No CF Access end-user auth.
react-app/Source HTML + JSX pages, shared rail, tokens, _worker.js (Pages proxy).
react-app-dist/Built output Pages serves. Commit after npm run build:frontend.
scripts/Build, deploy helpers, replay, analysis.
skills/Reusable playbooks (prefer these over inventing procedures).
tasks/Live plans (todo.md), lessons (lessons.md), session plans.
docs/Longer architectural docs + runbooks.
CONTEXT.md / AGENTS.mdSession onboarding — load every session.

Mental model: four Cloudflare Worker scripts share one trading codebase; the bridge is a fifth script with its own tree. Pages is independent of Worker deploys.

4. Which worker runs what

Canonical detail: skills/worker-topology.md.

Worker scriptConfig dirOwns
timed-trading-ingestworker/All /timed/* HTTP, Durable Objects, any cron not externalized
tt-feedworker-feed/Price-feed cron + stream keep-alive (worker/feed/*)
tt-engineworker-engine/*/5 scoring + trade lifecycle lanes
tt-researchworker-research/Hourly research arms + nightly mega-batch
tt-broker-bridgeworker-bridge/Broker connect / order / positions / reconcile (sidecar)

Cutover flags (do not dual-run)

DomainMonolith (stop doing X)Dedicated (start doing X)
FeedPRICE_FEED_EXTERNAL=trueFEED_ENABLED=true on tt-feed
EngineENGINE_EXTERNAL=trueENGINE_ENABLED=true on tt-engine
ResearchRESEARCH_SLOTS_EXTERNAL=trueRESEARCH_ENABLED=true on tt-research

Order: flip monolith *_EXTERNAL first, then enable the dedicated worker. Overlap corrupts state. Flags are dashboard vars (keep_vars = true); never wrangler secret put a name that already exists as a var.

Binding parity

Role workers declare their own bindings. A binding added only to worker/wrangler.toml is not on tt-engine/feed/research. DOs stay owned by the monolith — role workers reference them with script_name = "timed-trading-ingest". Silent if (env.SOME_BINDING) fallbacks have caused multi-day freshness outages; prefer surfacing misses in health/tombstones.

5. Pages vs Worker (critical)

ConcernPagesWorker(s)
ServesHTML/JS/CSS from react-app-dist//timed/* JSON APIs, crons, DOs
Deploy triggerPush/merge to main (git-connected Pages)Wrangler / CI workflows per script
Localwrangler pages dev react-app-dist --port 8788wrangler dev in worker/ on 8787
Proxyreact-app/_worker.js hardcodes WORKER_ORIGIN to production—

6. How to run locally

Full notes live in AGENTS.md → Cursor Cloud specific instructions. Condensed:

Prerequisites

cd /workspace   # or clone root
npm install     # no lockfile; use install not ci

Create git-ignored worker/.dev.vars:

TIMED_API_KEY=local-dev-key
CF_ACCESS_AUD=local-dev-aud

Optional for live quotes / LLM: TWELVEDATA_API_KEY, OPENAI_API_KEY.

Without those secrets, wrangler dev returns 503 runtime_misconfigured.

Boot

# Terminal A — API (Miniflare KV/D1/DO; small seed universe)
cd worker && ../node_modules/.bin/wrangler dev --port 8787

# Terminal B — frontend (after build)
cd /workspace
npm run build:frontend
./node_modules/.bin/wrangler pages dev react-app-dist --port 8788

Port 8788 is allow-listed in worker CORS_ALLOW_ORIGIN.

Auth locally

CallerEffect
?key=local-dev-key or X-API-Key: local-dev-keyAdmin-tier, unredacted prices + scores
No keyMember/anon view (_redacted:true)

Cloudflare Access (Google OAuth) cannot complete on a typical cloud VM — only public surfaces like /splash render in a browser. Exercise authenticated logic via curl + API key.

Useful local probes

curl -s "http://localhost:8787/timed/health"
curl -s "http://localhost:8787/timed/all?slim=1" -H "X-API-Key: local-dev-key" | head -c 200

# Crons do not auto-fire in wrangler dev:
curl "http://localhost:8787/cdn-cgi/handler/scheduled"

Local D1 starts empty; schema is created lazily by d1Ensure*Schema(). POST /timed/ingest-capture is a robust way to exercise ingest without a full scoring universe.

Tests (the only gate)

npm test          # vitest
# CI also: node --check on worker entrypoints + esbuild bundle check

There is no lint step. npm run build:frontend always dirties react-app-dist/ cache-bust stamps — revert if built only to verify.

7. Auth, tiers, and entitlements (day-1 version)

Canonical matrices: skills/user-state-matrix.md, skills/security-auth-patterns.md.

LabelMeaning
ProPaying subscriber
VIPInvite / manual grant — entitled like Pro (no monthly fee)
AdminOperator
MemberSigned in, never paid — code tier free
AnonNot signed in

Live prices + proprietary scores go to Pro / VIP / Admin only:

8. Price pipeline (invariants to internalize)

Full rules: workspace .cursor/rules/price-data-pipeline.mdc + CONTEXT lessons. Do not invent alternate change math.

  1. TwelveData first (DATA_PROVIDER=twelvedata); Alpaca is execution / fallback.
  2. getDailyChange(t) in react-app/shared-price-utils.js is the only client daily-change path.
  3. KV timed:prices short keys: p, pc, dc, dp, … Extended: ahp, ahdc, ahdp.
  4. Value timestamps are mandatory: q_ts (quote receipt) and p_ts (last price move). Freshness gates key off these — never poll t. Writers must stamp and never regress stamps.
  5. PriceStream DO (TwelveData WS) must own symbols in timed:prices; orphan symbols can get clobbered by KV eventual consistency between cron and DO.
  6. Outside RTH, preserve day-change and EXT fields appropriately; never write AH fields during RTH.
  7. Footer must include "Market data powered by Twelve Data" (licensing).

If prices look "stuck on yesterday," check value stamps and /timed/health (valueStaleCount), not just t.

9. Where to look for common tasks

NeedSkill (repo path)
Deploy / confirm prod movedskills/deploy.md
Which cron / workerskills/worker-topology.md
Stale / wrong ticker scoreskills/rescore-ticker.md
Snapshot / universe / stale scoresskills/all-snapshot.md
D1 queryskills/d1-debugging.md
KV inspectskills/kv-inspection.md
HTTP 401/403/404/503skills/debug-http-codes.md
New route / WS / LLM HTMLskills/security-auth-patterns.md
Broker / IBKR / Webullskills/broker-bridge.md
Partner broker isolationskills/partner-onboarding.md
Frontend blank / buildskills/frontend-build.md
UI design systemskills/verda-ui-migration.md
Discord alertsskills/discord-alerts.md
Billing / VIP / taxskills/billing-and-sales-tax.md

Full index: skills/README.md. If more than ~3 tool calls inventing a procedure, write a skill before leaving.

10. House rules (do not skip)

From AGENTS.md / CONTEXT:

11. First-week checklist

Day 1 — Orient

Day 2 — Local loop

Day 3 — Data plane

Day 4 — Auth & gating

Day 5 — Deploy awareness

Days 6–7 — One vertical slice

12. Architecture visual

Timed Trading system architecture

Mermaid + partner-facing detail: engineering partner onboarding.

13. Unknowns / do not invent

Mark these as “ask the operator” rather than guessing:

  • Exact production Cloudflare account / Pages project dashboard URLs (not required for local work)
  • Which cutover flags are currently live in prod (read dashboard vars or /timed/health / role health endpoints — do not assume)
  • Partner-specific broker credentials and BRIDGE_* secrets (never commit; see partner-onboarding skill)
  • Any infra not present under worker*/wrangler.toml or documented in skills