Day 1

Start here

Engineers new to the repo: this page is the front door. After it, read Architecture. Field names live in the data dictionary.

Repo paths below are relative to the git clone root. Playbooks in skills/ win over inventing a procedure.

Five minutes

1. Product

Signed-in entry is /today.html. Journey pages: Today, Active Trader, Investor, Portfolio, Insights. Retired: /index-react.html.

2. Runtime

Cloudflare Pages serves the UI. Five Worker scripts run API, crons, and broker mirroring. D1 + KV hold the book and live quotes.

3. Who sees prices

Pro / VIP / Admin only. Code tier free is a signed-in Member who never paid — no live prices, no scores.

4. Merge ≠ deploy

Pages follows main. Workers deploy per script. Confirm deployedSha on /timed/health, not a green Actions run.

1. Stack

LayerWhat it is
Pages frontendPrebuilt HTML/JS from react-app/ → react-app-dist/. Auto-deploys on 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 — sidecar in 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.

2. Read in the repo (~15–20 min)

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

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

3. Product surfaces

Authenticated HTML sits behind Cloudflare Access (Google OAuth). Public landing is /splash.html.

PagePathRole
Today/today.htmlDaily ingest — Market Pulse, Brief, bubble map. Product entry.
Active Trader/active-trader.htmlKanban lanes + narrative brief
Investor/investor.htmlLong-term cards + search/filter
Portfolio/portfolio.htmlThree books: Short Term, Long Term, Day Trader
Insights/insights.htmlModel analysis + CIO watchlist
Learn/learn.htmlEducational walkthrough
Splash/splash.htmlPublic landing
Index (retired)/index-react.htmlRedirect stub to Today. Do not compile or ship as a page.

4. Repo map

PathRole
worker/Source + wrangler.toml for timed-trading-ingest. Routes, scoring, trade logic, DOs.
worker-feed/Config for tt-feed. Price-feed cron after cutover.
worker-engine/Config for tt-engine. Same bundle (main = "../worker/index.js"). */5 scoring + lifecycle.
worker-research/Config for tt-research. Hourly research + 22:00 UTC batch.
worker-bridge/Separate codebase for tt-broker-bridge. No CF Access end-user auth.
react-app/Source HTML + JSX, shared rail, _worker.js (Pages proxy).
react-app-dist/Built output Pages serves. Commit after npm run build:frontend.
scripts/Build, deploy, replay, analysis helpers.
skills/Reusable playbooks.
tasks/todo.md, lessons.md, session plans.
docs/Longer architecture docs + runbooks.
CONTEXT.md / AGENTS.mdSession onboarding — load every session.

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

5. Which worker runs what

Canonical detail: skills/worker-topology.md.

Worker scriptConfig dirOwns
timed-trading-ingestworker/All /timed/* HTTP, Durable Objects, leftover crons
tt-feedworker-feed/Price-feed cron + stream keep-alive
tt-engineworker-engine/*/5 scoring + trade lifecycle
tt-researchworker-research/Hourly research + nightly batch
tt-broker-bridgeworker-bridge/Broker connect / order / positions / reconcile

Cutover flags (do not dual-run)

DomainMonolith (stop)Dedicated (start)
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

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

Role workers declare their own bindings. A binding added only to worker/wrangler.toml is missing on feed/engine/research. Durable Objects stay owned by the monolith; role workers reference them with script_name = "timed-trading-ingest".

6. Pages vs Worker

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

7. Local run

Full notes: AGENTS.md → Cursor Cloud specific instructions.

npm install     # no lockfile; use install, not ci

# git-ignored worker/.dev.vars
TIMED_API_KEY=local-dev-key
CF_ACCESS_AUD=local-dev-aud

# Terminal A — API
cd worker && ../node_modules/.bin/wrangler dev --port 8787

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

Without those secrets, wrangler dev returns 503 runtime_misconfigured. Optional live keys: TWELVEDATA_API_KEY, OPENAI_API_KEY. Port 8788 is allow-listed in worker CORS.

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

Cloudflare Access cannot complete on a typical cloud VM. Exercise authenticated logic via curl + API key. Only public surfaces such as /splash render in a browser there.

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
curl "http://localhost:8787/cdn-cgi/handler/scheduled"   # crons do not auto-fire

Local D1 starts empty; schema is created lazily. POST /timed/ingest-capture is a robust ingest smoke. Tests: npm test (vitest). There is no lint step. npm run build:frontend always dirties react-app-dist/ cache-bust stamps — revert if the build was only to verify.

8. Auth and entitlements

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

LabelMeaningLive prices + scores
ProPaying subscriberYes
VIPInvite / manual grant (no monthly fee)Yes (entitled like Pro)
AdminOperatorYes
MemberSigned in, never paid — code tier freeNo
AnonNot signed inNo

9. Price pipeline

Full rules: .cursor/rules/price-data-pipeline.mdc. Field catalog: data dictionary. 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). Never poll t for freshness. Writers must not regress stamps.
  5. PriceStream DO must own every symbol in timed:prices or KV lag can clobber cron stamps on orphans.
  6. Never write AH fields during RTH. Preserve day-change and EXT when the session is closed.
  7. Footer must include “Market data powered by Twelve Data”.

10. When something looks wrong

Prices stuck on yesterday

Check per-row q_ts / p_ts and /timed/health valueStaleCount. Blob t can refresh while p is a zombie.

UI field blank, no error

Pages and workers deploy independently. A new _-prefixed ticker field in the UI with an undeployed worker stamp looks empty. See tests/ui-worker-field-contract.test.js.

Green CI, old prod

Read deployedSha and Cloudflare version dates. A merge is not a deploy. Stamp ENGINE_GIT_SHA on hand deploys.

401 / 403 / 404 / 503

skills/debug-http-codes.md. Local 503 is usually missing .dev.vars.

11. Common tasks

NeedSkill
Deploy / confirm prod movedskills/deploy.md
Which cron / workerskills/worker-topology.md
Stale / wrong ticker scoreskills/rescore-ticker.md
Snapshot / universeskills/all-snapshot.md
D1 / KV inspectskills/d1-debugging.md, skills/kv-inspection.md
HTTP codesskills/debug-http-codes.md
New route / WS / LLM HTMLskills/security-auth-patterns.md
Broker / partner isolationskills/broker-bridge.md, skills/partner-onboarding.md
Frontend blank / buildskills/frontend-build.md
Discord / billingskills/discord-alerts.md, skills/billing-and-sales-tax.md

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

12. House rules

13. First-week checklist

Day 1 — Orient

Day 2 — Local loop

Day 3 — Data plane

Day 4 — Auth

Day 5 — Deploy awareness

Days 6–7 — One vertical slice

14. Ask, do not invent

  • Which cutover flags are live in prod — read dashboard vars or health; do not assume from this page
  • Partner broker credentials and BRIDGE_* secrets — never commit
  • Any infra not in worker*/wrangler.toml or a skill