Unclassified

IntegrateWise Continuity Bridge — One Full Prompt to Replit

Status: SUPERSEDED BUILD HANDOFF. This prompt must not be used as a current
implementation source. Its product name, Descope authority, UI layers and
storage assumptions are historical. Start from
ARCHITECTURE_LOCK.md and
CONSOLIDATED_PRODUCT_PLATFORM_CONTRACT_v1.2.md.

Canonical Reference: CANONICAL_PLATFORM_ARCHITECTURE.md
This document is downstream of the canonical architecture. Refer to the canonical source for current truth.

Original handoff claim (superseded): This was once treated as a build
handoff. It no longer overrides the frozen architecture.


1. The One-Liner (What We Are Building)

The OODA Engine for Business Continuity.

A multi-tenant continuity bridge that preserves organizational context, memory, governance, and execution across all tools, humans, and AI agents — through one stable continuity contract. Consumers (humans, ChatGPT, Claude, Cursor) connect once. The Bridge connects to everything else.

Doctrine: Truth you own. AI you rent. Approval in between.

Core Loop (OODA): Every tool, every user, every AI agent runs the same four-phase decision cycle:

  1. Observe — Read from the Spine (unified context)
  2. Orient — Assemble Entity360 + Memory + Knowledge
  3. Decide — Propose action, score confidence, govern
  4. Act — Execute approved action, writeback to Spine, compound memory

The product is not a platform. It is a Continuity Bridge. The category is The Operational Continuity Platform.


2. What Exists (The Live Repo)

You are continuing from the integratewise-live/ codebase. It contains:

  • 19 of 26 services as Cloudflare Workers (with wrangler.toml)
  • Vite + React frontend (apps/web) with shadcn/ui
  • MCP connector (services/mcp-connector/) with test endpoint
  • Massive connector catalog (packages/connectors/ — 50+ providers)
  • Normalizer (services/normalizer/) with NA0-NA5 pipeline skeleton
  • Governance (services/govern/) with confidence gate
  • Think (services/think/) — cognitive brain engine
  • Supabase deeply entangled as current relational store
  • Marketing page bloat (50+ pages in frontend that belong on Webflow)

You do NOT start from zero. You complete, cleanup, and deploy what exists.


3. The Cleanup (Do This First)

Run these commands immediately. Do not build new features until this is done.

# 1. Delete marketing page bloat (moves to Webflow, not in app)
rm -rf apps/web/src/components/landing/
rm -rf apps/web/src/components/landing/v2/
rm -rf apps/web/src/components/landing/v3/
rm -rf apps/web/src/components/marketing-site/
rm -rf apps/web/src/components/site/
rm -rf apps/web/src/components/marketing/
rm -rf apps/web/src/components/landing/ui/

# 2. Delete migration artifacts
rm -rf apps/web/src/shims/
rm -rf apps/web/test-results/
rm -f apps/web/SHIM_MODULES_CREATED.md

# 3. Delete legacy Node.js servers (Worker is canonical)
rm -rf services/knowledge/server/

# 4. Delete empty/minimal packages
rm -rf packages/hub/
rm -rf packages/website/

# 5. Delete old architecture docs (superseded by this prompt)
rm -f ARCHITECTURE_OVERVIEW.md ARCHITECTURE_OVERVIEW_CORRECTED.md \
  BUSINESS_OPS_SCHEMA_PLAN.md CONNECTOR_CS_SUPPORT_REPORT.md \
  CONNECTOR_IMPLEMENTATION_REPORT.md IMPLEMENTATION_SUMMARY.md \
  REPOSITORY_MAP.md REPOSITORY_TREE.txt CLAUDE.md AGENTS.md \
  WORK_COMPLETE_SUMMARY.md bitbucket-pipelines.yml \
  bitbucket-pipelines-production.yml

# 6. Delete Clerk traces (auth migration incomplete)
rm -f sql-migrations/flow-a/029_clerk_auth_schema.sql

# 7. Remove .env from git (SECURITY P0)
git rm --cached .env 2>/dev/null || true
echo ".env" >> .gitignore
echo ".env.*" >> .gitignore

# 8. Remove build artifacts from git
find . -name "tsconfig.tsbuildinfo" -exec git rm --cached {} \;
echo "*.tsbuildinfo" >> .gitignore

# 9. Consolidate duplicate packages
# packages/tenancy/ → merge into services/tenants/ or packages/types/
# packages/webhooks/ → merge into services/webhook-ingress/
# packages/connector-contracts/ + packages/connector-utils/ → merge into packages/connectors/
# packages/db/ (supabase.ts) → migrate to packages/lib/db-gate.ts, then delete

# 10. Commit
git add -A
git commit -m "chore: canonical cleanup — delete marketing bloat, migration artifacts, Clerk traces, .env, build artifacts. Consolidate duplicate packages."

4. The Architecture (4 Layers, 26 Services)

4.1 Conceptual Layers (Trust Boundaries)

Consumers  ↔  Continuity Bridge  ↔  Continuity Kernel  ↔  Provider Fabric
LayerWhat It IsWhat Consumers See
ConsumersHumans, AI assistants (ChatGPT, Claude, Cursor), apps, toolsOne MCP connection, one JWT, one web workbench
Continuity BridgePublic interface: identity, auth, discovery, projections, capabilities, governance entry, eventsIdentity, Discovery, Projections, Capabilities, Events
Continuity KernelInternal context substrate: Spine, Memory, Knowledge, Context, Governance, WorkflowNothing. Consumers never import internal topology.
Provider FabricReplaceable external execution: SaaS, databases, APIs, queues, agentsNothing. Entirely behind the Kernel.

4.2 The 26 Services (Physical Topology)

All 26 are Cloudflare Workers with wrangler.toml. All wired into gateway as service bindings.

Tier 0 — Ingress & Routing

ServiceWorker NamePurposeBinding Name
gatewayintegratewise-gatewaySingle entry; JWT validation; tenant routing; rate-limitN/A (entry)
webhook-ingressiw-webhook-ingressReceives external webhooks (Salesforce, HubSpot, Stripe, GitHub)WEBHOOK_INGRESS

Tier 1 — Tenant & Sync

ServiceWorker NamePurposeBinding Name
tenantsiw-tenantsMulti-tenant context, RBAC, plan limitsTENANTS
connector-synciw-connector-syncOrchestrates connector syncCONNECTOR_SYNC
normalizeriw-normalizer8-stage NA0–NA5 pipelineNORMALIZER

Tier 2 — Projection & Rendering

ServiceWorker NamePurposeBinding Name
pipelineiw-pipelineONLY writer to the SpinePIPELINE
twin-orchestratoriw-twin-orchestratorOODA Engine — persistent per-user DOTWIN_ORCHESTRATOR
l2iw-l2Department × industry overlay projectionsL2
intelligenceiw-intelligenceAnalytics, insights, signal generationINTELLIGENCE
knowledgeiw-knowledgeKnowledge base, docs, semantic searchKNOWLEDGE
governiw-governGovernance rules engine, approval gatesGOVERN
storeiw-storePersistence for projectionsSTORE
actiw-actAction execution / write-back to providersACT

Tier 3 — Capability Runtime & Orchestration

ServiceWorker NamePurposeBinding Name
hermesiw-hermesMessage queue + execution engine (DO)HERMES
triageiw-triageConfidence routing + active-memory decayTRIAGE
workflowiw-workflowDurable orchestration (pause, retry, saga)WORKFLOW
iw-agent-runtimeiw-agent-runtimeMCP-compliant AI agent executionIW_AGENT_RUNTIME
mcp-connectoriw-mcp-connectorMCP bridge: external agents → scoped SpineMCP_CONNECTOR

Tier 4 — Supporting

ServiceWorker NamePurposeBinding Name
agent-registryiw-agent-registryCatalog of available agentsAGENT_REGISTRY
billingiw-billingUsage tracking + plan enforcementBILLING
adminiw-adminPlatform admin, tenant mgmtADMIN
loaderiw-loaderCold-start pre-loader, Nango webhook handlerLOADER
folder-watcheriw-folder-watcherDO filesystem watcherFOLDER_WATCHER
continuityiw-continuityMemory consolidation + decayCONTINUITY
telemetryiw-telemetryTraces, metrics, observabilityTELEMETRY
thinkiw-thinkLLM reasoning orchestrationTHINK
connectoriw-connectorOAuth callback handler (Nango)CONNECTOR
spine-v2iw-spine-v2Spine normalization & graphSPINE_V2

4.3 The 17-Layer Physical Stack (0–16)

#LayerServicesStorage
0Tenant Lifecycletenants, loader, adminD1 tenants, tenant_spine_config
1Customer Ecosystemconnector, connector-sync, agent-registryNango vault, connectors table
2Surface Layerapps/web, apps/mcp-serverCloudflare Pages, R2 assets
3Gateway LayergatewayN/A — pure routing
4Identity & Organizationtenants (RBAC)D1 rbac_roles, rbac_permissions
5Continuity Bridgeconnector-sync, normalizer, mcp-connector, webhook-ingressD1 sync_jobs, normalizer_state, KV Discovery cache
6Adaptive SpinepipelineD1 entities, relationships, spine_audit_log
7Context Assemblyintelligence, knowledgeVectorize, AI Search, KV context cache
8Shared Memorycontinuity, triageD1 memory (active/staging/archived), KV decay
9Capability Engineiw-agent-runtime, thinkOpenRouter API, KV model config
10Governance LayergovernD1 governance_audit_log, action_proposals
11Capability Runtimehermes, workflow, act, mcp-connectorDurable Objects, Queues (ACT_QUEUE, PIPELINE_QUEUE)
12Projection Registryl2, storeD1 projections, projection_registry
13Registry Layeragent-registry, intelligenceD1 capability_registry, endpoint_registry, KV cache
14Continuity Enginecontinuity, twin-orchestratorD1 continuity_graph, KV session handoffs
15Data & Infrastructuretelemetry, folder-watcherD1 audit_logs, R2 telemetry, Workers Analytics
16Endpoint Registrygateway (serves), intelligence (updates)KV + D1 endpoint_registry

Cross-cutting: Security (WAF, TLS, CF Secrets, Zero Trust), Observability, Reliability (idempotency, retries, DLQ, backpressure), Compliance (audit & lineage, retention, encryption, tenant isolation).


5. The OODA Engine (Core Mental Model)

Every tool, every user, every AI agent runs this loop:

OBSERVE ──► ORIENT ──► DECIDE ──► ACT ──► (memory compounds) ──► OBSERVE...

Phase 1: OBSERVE

  • What: Ingest signals from webhooks, sync polls, user actions, file changes
  • Who: webhook-ingress, connector-sync, folder-watcher
  • Output: Raw payload → PIPELINE_QUEUE

Phase 2: ORIENT

  • What: Assemble Entity360 + Memory + Knowledge into context
  • Who: normalizer (NA0–NA5), intelligence (Context Assembly), knowledge (RAG)
  • Output: Normalized entity + enriched context

Phase 3: DECIDE

  • What: Twin reasons, proposes action, governance scores confidence
  • Who: twin-orchestrator (OODA engine), govern (confidence gate)
  • Rules:
    • ≥ 0.85 → Auto-approve → ACT_QUEUE
    • 0.70 – 0.85 → My Desk review → human approves/rejects
    • < 0.70 → Discard → spine_audit_log (discard reason)

Phase 4: ACT

  • What: Execute approved action, writeback to Spine, update memory
  • Who: act (execution), integration-router (provider adapter), continuity (memory promotion)
  • Output: Outcome written to Spine → compounding memory for next loop

The Twin runs this loop continuously (hourly cron) for every user. The workbench runs it on every interaction. Every connected tool runs it on every event. The difference is speed: tool = milliseconds, Twin = minutes, user = seconds.


6. The Two Planes (North / South)

Consumers → [Gateway] → Spine → [Integration Router] → Provider Tools
             (North)                   (South)

North Plane (Ingress): gateway + mcp-connector (inbound MCP). All consumers enter here. JWT validation. Tenant routing. Discovery. Rate-limit.

South Plane (Egress): act + Integration Router. Only service that touches external APIs. Adapter selection: Nango (OAuth-mature), MCP (AI-native), Native (direct REST). Entity360 context injected on outbound.

Rule: Neither plane talks to the other except through the Spine.


7. MCP Pool (Bidirectional, First-Class)

7.1 Inbound MCP Pool (North Plane)

Endpoint: mcp.integratewise.ai/v1/mcp (SSE/stdio)
Role: AI assistants (ChatGPT, Claude, Cursor, Perplexity) connect to us to read scoped Spine/Memory.
Primary ingress: This is the primary front door. Traditional SaaS webhooks are secondary.

Server implementation:

// services/mcp-connector/src/index.ts (inbound MCP server)


const app = new Hono();

// SSE endpoint for MCP transport
app.post("/sessions", async (c) => {
  const jwt = await verifyGatewayJWT(c.req.header("Authorization"));
  const tenantId = jwt.tenant_id; // FROM JWT CLAIM, never client payload
  const scope = await getMCPToolCatalog(tenantId); // from Discovery
  return c.json({ sessionId, tools: scope, readOnly: true });
});

app.post("/invoke", async (c) => {
  const { sessionId, tool, params } = await c.req.json();
  const sessionTenant = await resolveTenantFromSession(sessionId); // KV lookup
  const jwtTenant = c.get("jwt").tenant_id;

  // P0: Cross-tenant session reuse = 403 (fail-loud, not 404)
  if (jwtTenant !== sessionTenant) {
    return c.json({ error: "Cross-tenant access denied" }, 403);
  }

  // Read-only default. Write requires governance approval.
  const result = await executeCapability(tenantId, tool, params);
  await auditLog({ via: "mcp", tenantId, tool, outcome: result });
  return c.json(result);
});

// P0: Every endpoint requires Bearer JWT
// P0: x-tenant-id extracted from JWT, never from client payload
// P0: Tool catalog filtered by Discovery (tenant sees only their capabilities)
// P0: Every invocation logged to spine_audit_log

Consumer Config (the ONLY MCP entry users need):

{
  "mcpServers": {
    "integratewise": {
      "type": "sse",
      "url": "https://mcp.integratewise.ai/v1/mcp",
      "headers": {
        "Authorization": "Bearer ${input:integratewise_jwt}"
      },
      "description": "IntegrateWise Continuity Bridge — OODA Engine for Business Continuity"
    }
  },
  "inputs": [
    {
      "id": "integratewise_jwt",
      "type": "promptString",
      "description": "IntegrateWise Gateway JWT — from Settings → API Keys",
      "password": true
    }
  ]
}

Key rule: One entry. Not 21. Not 5. One. The Bridge routes to 20+ providers internally.

7.2 Outbound MCP Pool (South Plane)

Inside Integration Router. We connect to provider MCP servers (Salesforce MCP, Slack MCP, GitHub MCP). Entity360 context injected before outbound call.


8. Frontend: One Full UI (Not Marketing Pages)

8.1 Tech Stack

  • Vite (not Next.js, not Replit)
  • React 18 + TypeScript
  • shadcn/ui (installed, used in components/ui/)
  • Tailwind CSS
  • Deploy target: Cloudflare Pages (wrangler.toml in apps/web/)
  • API client: @integratewise/sdk (packages/sdk/) — capability-first, NEVER direct Supabase calls

8.2 What to Build (8 Lenses, Not 12)

The workbench has 8 projections (lenses). Not 12 departments. The 12 department directories in components/domains/ map to these 8:

Canonical LensMaps From (existing dirs)Workbench Route
Salesdomains/sales/, domains/salesops//workbench/sales
CSdomains/account-success//workbench/cs
Financedomains/finance//workbench/finance
Executivedomains/revops/, domains/bizops//workbench/executive
Architecturedomains/product-engineering//workbench/architecture
Operationsdomains/business-ops/, domains/procurement//workbench/operations
Personaldomains/personal//workbench/personal
Developerdomains/it-admin//workbench/developer

Delete or merge: marketing/, student-teacher/, service/ (map to CS or Operations).

8.3 Core Components to Build/Wire

ComponentPurposeData Source
Entity360Complete view of any entity (account, deal, contact)Gateway SDK → spine.entity.get
TwinRailInline proposal panel (right side)Gateway SDK → twin.propose
ProposalCardApprove/Modify/DismissGateway SDK → governance.decide
SignalFeedReal-time notificationsWebSocket or polling → signal.list
MyDeskApproval queue (0.70–0.85 proposals)Gateway SDK → proposal.list + proposal.approve
CommandPaletteQuick actions, searchGateway SDK → discovery + capability.invoke
DomainSidebarRole-based navigationGateway SDK → discovery.projections

8.4 Hooks to Implement

// hooks/useDiscovery.ts
// Called once on app load. Cached 5 minutes.
// Returns: identity, tenant, workspace, projections, capabilities, features, limits

// hooks/useEntity360.ts
// Fetches complete entity view across all connected tools

// hooks/useTwinProposal.ts
// Submits to Twin, receives proposal with confidence

// hooks/useCapability.ts
// Generic capability invoker (NEVER direct Supabase)

9. The Swappable Layers (7× Agnostic Moat)

Every infrastructure layer is swappable. The Integration Manager owns the adapter selection.

DimensionDefaultSwappable ToAdapter File
FrontendVite + React (Pages)Next.js, Electron, React Native, iOSpackages/lib/ui-adapter.ts
AuthGateway JWT + API KeysClerk, Stack, Descope, Auth0packages/lib/auth-adapter.ts
Relational StoreSupabase PostgreSQL (current)Neon, RDS, PlanetScale, HyperDrivepackages/lib/db-gate.ts
CacheCloudflare KVRedis, Upstash, DynamoDBpackages/lib/cache-adapter.ts
QueueCloudflare QueuesSQS, RabbitMQ, Kafkapackages/lib/queue-adapter.ts
AI / ModelOpenRouter (gpt-5-mini)Claude, Grok, Gemini, Ollamapackages/lib/openrouter.ts
DeploymentCloudflare WorkersVercel, Lambda, Fly.io, K8spackages/lib/deploy-adapter.ts

Current state: packages/lib/ already has db-gate.ts, openrouter.ts, cache.ts. Build the adapter interfaces to formalize swappability.


10. Database Schema (D1 + PostgreSQL via HyperDrive)

10.1 D1 (Operational + Cache)

  • spine_entities — Canonical entities (see §14 of FINAL_E2E_SYSTEM.md)
  • governance_audit_log — Immutable approval decisions
  • memory — Active/staging/archived tiers
  • tenant_spine_config — Per-tenant config
  • endpoint_registry — Living API contract
  • rbac_roles, rbac_permissions — Access control

Rule: Every query has WHERE tenant_id = ?. Cross-tenant = 403 (fail-loud).

10.2 PostgreSQL (Relational Graph — via HyperDrive or Supabase)

  • The Spine relational graph (complex relationships, historical analytics) runs on PostgreSQL.
  • Accessed through packages/lib/db-gate.ts (adapter pattern).
  • Current: Supabase. Future: HyperDrive, Neon, RDS.
  • Migration path: D1 for hot paths (<10ms), PostgreSQL for analytical queries and complex joins.

11. Security Posture (P0 Blockers — Close Before Live)

#VulnerabilityFixOwner Service
1Cross-tenant data leakWHERE tenant_id = ? on every query. 403 fail-loud.ALL services
2Tenant-id spoofingExtract tenant_id from JWT claim only. Strip client-provided x-tenant-id.gateway
3Tenant middleware no-opEnforce service bindings carry tenant_id implicitly.gateway
4HITL DO global singletonidFromName(tenant_id + user_id), not "global"govern
5Invitation cross-tenant scanAdd WHERE tenant_id = ? to invitation lookuptenants
6Hardcoded secretsMove to Cloudflare Secrets. Rotate any leaked.admin
7.env committedgit rm --cached, add .gitignore, scan historyadmin
8SQL injectionUse Drizzle ORM or parameterized queries. No raw string concat.continuity, knowledge
9MCP-JWT bypassRequire Authorization: Bearer <jwt> on /tools, /invoke, /mcp, /sessionsmcp-connector
10Auth root thrashingFreeze on API Keys + JWT. Remove Clerk/Stack/Descope imports.gateway

Audit rule: Audit write failure stops the operation. No silent drops.


12. GTM Motion (Sign Up → Live in < 5 Minutes)

12.1 Distribution

  • Primary: MCP app in ChatGPT Store, Claude connectors, Perplexity apps
  • Secondary: Web landing (Webflow, not in app) → app.integratewise.ai
  • Tertiary: Direct API signup for enterprise

12.2 Signup Flow

  1. User clicks "Add IntegrateWise" in ChatGPT
  2. MCP connects to mcp.integratewise.ai/v1/mcp
  3. User authenticates (Google/GitHub/email) → Gateway issues JWT
  4. Schema AI (gpt-5-mini) hydrates tenant: entity types, relationships, RBAC
  5. D1 partition created, tenant_spine_config row, memory tables
  6. User sees Discovery response: "Connect Salesforce" (one-click Nango)
  7. Target: signup → workspace < 5 min; first tool < 10 min; normalizer p99 < 2s

12.3 Customer-Zero Kill Shot

  • Two apps: Salesforce + Slack, read-only, approval-required, 90-day retention
  • Win: VP CS answers "what's our risk?" without opening Salesforce or Slack
  • Land-and-expand: 3rd app = "enable" toggle, not a project

13. Build Order (What to Do in Sequence)

Week 1: Cleanup + Foundation

  • Run all cleanup commands (§3)
  • Close P0 #1–10 (security)
  • Wrap all Supabase queries behind db-gate.ts
  • Delete packages/supabase/ (after migration)
  • Verify pnpm -r build passes
  • Verify pnpm -r typecheck passes

Week 2: Core Services

  • Build twin-orchestrator DO (OODA engine)
  • Build hermes (message queue wrapper around Queues)
  • Build triage (confidence routing)
  • Wire twin-orchestrator → govern → act → Spine
  • Implement useDiscovery, useEntity360, useTwinProposal hooks

Week 3: MCP + Frontend

  • Harden MCP-JWT on all inbound endpoints
  • Build TwinRail, ProposalCard, SignalFeed components
  • Delete all marketing pages from frontend
  • Consolidate 12 departments → 8 lenses
  • Deploy frontend to Cloudflare Pages

Week 4: Integration + Polish

  • Build Integration Manager (adapter selection layer)
  • Test end-to-end: Salesforce → Normalizer → Spine → Twin → Govern → Act → Writeback
  • Performance: p99 < 2s for normalizer, < 10ms for Entity360 cache hit
  • Deploy all services via wrangler deploy
  • CI/CD: GitHub Actions → typecheck → test → deploy

14. Reference Documents (In Repo)

DocumentPurposeLocation
FINAL_E2E_SYSTEM.mdCanonical architecture specification/docs/FINAL_E2E_SYSTEM.md
L1_REALITY_CHECK.mdAudit of actual codebase vs. canon/docs/L1_REALITY_CHECK.md
REALITY_AUDIT.mdDetailed repo structure analysis/docs/REALITY_AUDIT.md
OODA_ENGINE.mdOODA loop formalizationTo be created from this prompt

15. The One Command to Deploy

# After cleanup and build:
pnpm -r build
pnpm deploy:gateway
pnpm deploy:mcp-server
pnpm deploy:workbench
pnpm deploy:workers  # all 26

# Verify:
curl https://mcp.integratewise.ai/v1/health
curl https://api.integratewise.ai/api/v1/discovery -H "Authorization: Bearer $JWT"

16. What NOT to Build

Do NOT BuildWhyWhere It Goes Instead
Marketing pages (landing, pricing, blog)Bloats app, slows deployWebflow (integratewise.ai)
Marketplace UIWe list in THEIR marketplaces (ChatGPT, Claude)Not our app
Partner portalNot needed for CZFuture, not now
Per-app OAuth flowsNango handles thisservices/connector/
Frontend → direct DB callsViolates architectureAlways through Gateway SDK
Clerk / Stack AuthAuth root thrashingGateway JWT (internal) + Descope (canonical external identity + outbound authorization authority); Nango dormant compatibility
Next.js migrationAlready on ViteVite is canonical
12 department lensesCanon locks 8Merge 12 → 8

17. Closing Statement

Build the OODA Engine.

Observe everything. Orient into context. Decide with confidence. Act with governance. Compound memory every cycle. Deploy to Cloudflare. One MCP connection. One JWT. One Bridge.

The last auth for endless continuity.


Version: 1.0.0-CANONICAL
Date: 2026-07-02
Status: LOCKED — all §14 conflicts resolved
Handoff target: Replit agent for live deployment