Start here
Engineers new to the repo: this page is the front door. After it, read Architecture. Field names live in the data dictionary.
Five minutes
Signed-in entry is /today.html. Journey pages: Today, Active Trader, Investor, Portfolio, Insights. Retired: /index-react.html.
Cloudflare Pages serves the UI. Five Worker scripts run API, crons, and broker mirroring. D1 + KV hold the book and live quotes.
Pro / VIP / Admin only. Code tier free is a signed-in Member who never paid — no live prices, no scores.
Pages follows main. Workers deploy per script. Confirm deployedSha on /timed/health, not a green Actions run.
1. Stack
| Layer | What it is |
|---|---|
| Pages frontend | Prebuilt HTML/JS from react-app/ → react-app-dist/. Auto-deploys on push to main. |
| API monolith | timed-trading-ingest — all /timed/* routes + Durable Objects. |
| Role cron workers | tt-feed, tt-engine, tt-research — same codebase, role-gated crons. |
| Broker bridge | tt-broker-bridge — sidecar in worker-bridge/ for IBKR / Webull / Robinhood (E*TRADE scaffold). |
| Data | D1 timed-trading-ledger + KV (timed:prices, timed:latest, …). |
| Market data | TwelveData primary; Alpaca for execution / fallback. |
2. Read in the repo (~15–20 min)
AGENTS.md— onboarding contract, house rules, local Cloud tipsCONTEXT.md— stack, deploy, journey pages, condensed lessonsskills/README.md— how-to indexskills/worker-topology.md— which worker runs which cronskills/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.
| Page | Path | Role |
|---|---|---|
| Today | /today.html | Daily ingest — Market Pulse, Brief, bubble map. Product entry. |
| Active Trader | /active-trader.html | Kanban lanes + narrative brief |
| Investor | /investor.html | Long-term cards + search/filter |
| Portfolio | /portfolio.html | Three books: Short Term, Long Term, Day Trader |
| Insights | /insights.html | Model analysis + CIO watchlist |
| Learn | /learn.html | Educational walkthrough |
| Splash | /splash.html | Public landing |
| Index (retired) | /index-react.html | Redirect stub to Today. Do not compile or ship as a page. |
4. Repo map
| Path | Role |
|---|---|
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.md | Session 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 script | Config dir | Owns |
|---|---|---|
timed-trading-ingest | worker/ | All /timed/* HTTP, Durable Objects, leftover crons |
tt-feed | worker-feed/ | Price-feed cron + stream keep-alive |
tt-engine | worker-engine/ | */5 scoring + trade lifecycle |
tt-research | worker-research/ | Hourly research + nightly batch |
tt-broker-bridge | worker-bridge/ | Broker connect / order / positions / reconcile |
Cutover flags (do not dual-run)
| Domain | Monolith (stop) | Dedicated (start) |
|---|---|---|
| Feed | PRICE_FEED_EXTERNAL=true | FEED_ENABLED=true on tt-feed |
| Engine | ENGINE_EXTERNAL=true | ENGINE_ENABLED=true on tt-engine |
| Research | RESEARCH_SLOTS_EXTERNAL=true | RESEARCH_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
| Concern | Pages | Worker(s) |
|---|---|---|
| Serves | HTML/JS/CSS from react-app-dist/ | /timed/* JSON, crons, DOs |
| Deploy trigger | Push/merge to main | Wrangler / CI per script |
| Local | wrangler pages dev react-app-dist --port 8788 | wrangler dev in worker/ on 8787 |
| Proxy | react-app/_worker.js hardcodes WORKER_ORIGIN to production | — |
npm run deploy:workerdoes not update UI pages.- A
worker/change without redeploying tt-engine / tt-research leaves cron lanes on old code. - Green GitHub Actions is not proof prod moved. Check
deployedSha. - To hit a local worker from Pages, temporarily point built
react-app-dist/_worker.jsathttp://localhost:8787. Revert; do not commit.
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.
| Caller | Effect |
|---|---|
X-API-Key: local-dev-key (or deprecated ?key=) | Admin-tier, unredacted prices + scores |
| No key | Member/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.
| Label | Meaning | Live prices + scores |
|---|---|---|
| Pro | Paying subscriber | Yes |
| VIP | Invite / manual grant (no monthly fee) | Yes (entitled like Pro) |
| Admin | Operator | Yes |
| Member | Signed in, never paid — code tier free | No |
| Anon | Not signed in | No |
- Server:
canAccessLivePrices()+redactTickerMapForTier()inworker/api.js - UI:
window._ttIsPro - Prefer structured 200s with
_redacted/tier_requiredon poll endpoints, not noisy 4xx - CF Access gates authenticated HTML. Stripe drives Pro. VIP/admin grants use
subscription_status='manual' - Operator API key: prefer
X-API-Key;?key=is deprecated
9. Price pipeline
Full rules: .cursor/rules/price-data-pipeline.mdc. Field catalog: data dictionary. Do not invent alternate change math.
- TwelveData first (
DATA_PROVIDER=twelvedata); Alpaca is execution / fallback. getDailyChange(t)inreact-app/shared-price-utils.jsis the only client daily-change path.- KV
timed:pricesshort keys:p,pc,dc,dp. Extended:ahp,ahdc,ahdp. - Value timestamps are mandatory:
q_ts(quote receipt) andp_ts(last price move). Never polltfor freshness. Writers must not regress stamps. - PriceStream DO must own every symbol in
timed:pricesor KV lag can clobber cron stamps on orphans. - Never write AH fields during RTH. Preserve day-change and EXT when the session is closed.
- Footer must include “Market data powered by Twelve Data”.
10. When something looks wrong
Check per-row q_ts / p_ts and /timed/health valueStaleCount. Blob t can refresh while p is a zombie.
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.
Read deployedSha and Cloudflare version dates. A merge is not a deploy. Stamp ENGINE_GIT_SHA on hand deploys.
skills/debug-http-codes.md. Local 503 is usually missing .dev.vars.
11. Common tasks
| Need | Skill |
|---|---|
| Deploy / confirm prod moved | skills/deploy.md |
| Which cron / worker | skills/worker-topology.md |
| Stale / wrong ticker score | skills/rescore-ticker.md |
| Snapshot / universe | skills/all-snapshot.md |
| D1 / KV inspect | skills/d1-debugging.md, skills/kv-inspection.md |
| HTTP codes | skills/debug-http-codes.md |
| New route / WS / LLM HTML | skills/security-auth-patterns.md |
| Broker / partner isolation | skills/broker-bridge.md, skills/partner-onboarding.md |
| Frontend blank / build | skills/frontend-build.md |
| Discord / billing | skills/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
- No emojis in code, commits, or PRs unless asked.
- User-facing product copy: avoid “you / your”.
- Never inline daily change math — use
getDailyChange. - Gate live prices + scores to Pro/VIP/Admin.
- Plan non-trivial work in
tasks/todo.md. - Stop after two failed attempts at the same approach — re-plan.
- Verify before done. After operator corrections, update
tasks/lessons.mdand a one-liner in CONTEXT. - One logical change per commit/PR. Before pushing an existing branch:
bash scripts/check-branch-merge-state.sh.
13. First-week checklist
Day 1 — Orient
- Read AGENTS.md + CONTEXT Stack/Deploy/Product + skills README
- Name the five Worker scripts and what Pages serves
npm install,npm testgreen (or know why not)
Day 2 — Local loop
worker/.dev.varswith placeholder secrets- Boot wrangler on 8787; hit
/timed/healthand keyed/timed/all?slim=1 - Build frontend; note the Pages→production proxy
- Trigger a scheduled handler once
Day 3 — Data plane
- Inspect
timed:prices; findq_ts/p_ts - Trace one ticker: TwelveData → PriceStream/cron → KV → UI
getDailyChange - Read
skills/all-snapshot.md(slim index vs full payload OOM)
Day 4 — Auth
- Walk Member vs Pro vs VIP vs Admin
- Call an endpoint without key (redacted) vs with key (full)
- Read security-auth-patterns (route guards, WS tickets, no unguarded mutators)
Day 5 — Deploy awareness
- Read deploy.md; list which scripts a
worker/**change touches - Know how to verify
deployedSha
Days 6–7 — One vertical slice
- Pick a small skill-backed task and ship behind PR / check-branch-merge-state
- Grep
tasks/lessons.mdfor the area touched before claiming done
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.tomlor a skill