This replaces the stale pre-R524 monolithic system-architecture.html. R524 split src/index.ts from a ~41K-line monolith into a 12-module structure while keeping the entrypoint single-file. tsc baseline is 0 errors as of R526. The platform runs entirely on Cloudflare — no AWS/GCP — with NetSuite as the system of record reached via TBA OAuth1 + a custom RESTlet.
| file | LOC (approx) | responsibility |
|---|---|---|
src/index.ts | ~33,000 | fetch/scheduled/queue/email entrypoints, HTTP routes, sync engine (syncTable, syncLineTable, handleSyncTier), workflow tool impls |
src/chat_tools/impls.ts | ~6,700 | all executeChatTool branches — 175+ tools |
src/chat_tools/prompt.ts | ~230 | CHAT_TOOLS_FOR_PROMPT catalog + filterToolsForRole + GFS_OPERATIONAL_CONTEXT |
src/chat_tools/index.ts | barrel | module re-exports |
src/sync_table_map.ts | ~790 | SYNC_TIERS, SyncTableSpec, SYNC_TABLE_MAP — canonical mirror config |
src/lib/auto_context.ts | ~715 | customer/vendor/item auto-context generators, entity extraction |
src/lib/ns.ts | ~100 | NS RESTlet OAuth1 + ns_suiteql |
src/lib/recall.ts | ~140 | prior-context recall |
src/lib/guardrail.ts | ~50 | guardrail logging |
src/lib/escape.ts | ~10 | SQL escape helpers |
src/lib/role_context.ts | ~20 | role types |
src/lib/workflow_runner.ts | ~400 (substrate) | executeWorkflowContract — the runner for 22 workflow contracts (R549) |
src/lib/events.ts | ~280 (substrate) | event ledger + CDC subscriptions (R553/R560) |
src/lib/customer_health.ts | ~360 (substrate) | 6 leading-indicator signals + composite (R557/R558/R561) |
src/lib/sql_helpers.ts | ~120 | shared SQL helpers (date normalize, existence guards) |
src/lib/index.ts | barrel | module re-exports |
src/email.ts | ~600 | inbound email pipeline (5 mailboxes) |
src/document_converter.ts | ~500 | PDF/DOCX/XLSX → Markdown |
src/annual_roll_workflow.ts | ~400 | Pillar 4 annual price roll — CF Workflow class with step.do + step.sleep + step.waitForEvent |
src/durable_objects.ts | ~200 | CostCapDO + PushMutexDO |
tsc baseline: 0 errors (R526) · was 125 pre-R525. Import cycle: closed in R524 — chat_tools/impls.ts only imports type Env from ../index; all value imports go through ../lib + ../sync_table_map.
| binding | kind | purpose |
|---|---|---|
DB | D1 | canonical data store · 162 tables |
STORAGE | R2 bucket | PDFs, attachments, backups |
CACHE | KV namespace | query cache, locks, kill switches |
VECTORIZE | Vectorize | 4 indexes: ns_knowledge, decision_corpus, bid_corpus, entity_notes |
AI | Workers AI | Llama 3.3 inference + embeddings |
NS_PUSH_QUEUE | CF Queue | NetSuite write queue |
NS_PUSH_DLQ | CF Queue | dead-letter queue (3rd retry) |
COST_CAP_DO | Durable Object | daily AI spend cap enforcement |
PUSH_MUTEX_DO | Durable Object | single-drainer mutex for ns_pending_pushes |
ANNUAL_ROLL_WORKFLOW | CF Workflow | pillar 4 annual price roll · July 1 SY cutover |
EMAIL | Email Routing | 5 inbound mailboxes |
BROWSER | Browser Rendering | PDF render for spec sheets + quotes |
| external | protocol | purpose |
|---|---|---|
| NetSuite | TBA OAuth1 | system of record · customscript_gfs_platform_query RESTlet for writes; SuiteQL for reads |
| Dropbox | HTTPS | source documents (specs, price quotes, bid PDFs) · manual + scheduled pull |
| CF Email Routing | SMTP | 5 inbound mailboxes: pricerequest@ · spec@ · bid@ · ar@ · ops@ (per src/email.ts) |
| Council v2 LLMs | HTTPS API | Claude (Anthropic) + Kimi (Moonshot) + Workers AI Llama 3.3 · 3-model parallel + anonymized peer review |
?preview=true|confirm=true — preview shows dependency cone; confirm requires X-Edit-Token.NS_PUSH_QUEUE./pricing/<slug>, /vendor/<slug>, /item/<code>, /bid/<id>.proposed_actions for admin approval before NS push (ADR-031).