{"slug":"business/FRONTEND_LAYER_MAP","title":"IntegrateWise — Frontend Layer Map","section":"business","sectionLabel":"Business","status":"unclassified","type":"document","path":"business/FRONTEND_LAYER_MAP.mdx","bytes":22396,"description":null,"updated":null,"source":"integratewise/Integratewise-docs-wiki","content":"\n> **Version:** 2.0 | **Date:** June 9, 2026 | **Status:** FINAL\n> **Repo:** integratewise-live/apps/web/\n> **Design:** Forest + Paper tokens (--iw-forest, --iw-paper, --iw-gold)\n> **Data Layer:** CF Gateway (`gateway.dev.integratewise.ai`) — zero Supabase frontend dependency\n> **Auth:** OAuth 2.0 via `auth.integratewise.ai` (RS256 JWT, 1hr access, 30d refresh)\n> **Provider:** `VITE_SPINE_PROVIDER=gateway-proxy` (live), `local-mock` (dev), `spine-db` (legacy)\n\n---\n\n## Frontend Infrastructure (CF Gateway Wiring — Complete June 9, 2026)\n\nAll data flows through CF Workers. Zero direct Supabase from the browser.\n\n### Core Modules\n\n| Module              | Path                                 | Purpose                                                    |\n| ------------------- | ------------------------------------ | ---------------------------------------------------------- |\n| AuthManager         | `src/lib/auth-manager.ts`            | OAuth 2.0 token lifecycle (PKCE, refresh, coalescing)      |\n| GatewayHttpClient   | `src/lib/gateway-client.ts`          | HTTP client (retry, 401/429/5xx, offline queue)            |\n| SpineGatewayAdapter | `src/utils/spine/gateway-adapter.ts` | Drop-in `spineClient` replacement via Gateway              |\n| SSE Client          | `src/lib/sse-client.ts`              | Real-time signals (exponential backoff + polling fallback) |\n| Query Client        | `src/lib/query-client.ts`            | TanStack Query singleton (30s stale, 5m GC)                |\n| Onboarding Machine  | `src/lib/onboarding.ts`              | 4-step state machine (localStorage persistence)            |\n| Onboarding API      | `src/lib/onboarding-api.ts`          | Step 1–4 API calls + retry + resume                        |\n\n### React Hooks\n\n| Hook                              | Path                             | Purpose                                |\n| --------------------------------- | -------------------------------- | -------------------------------------- |\n| `useAuth()`                       | `src/hooks/use-auth.ts`          | user, isAuthenticated, signIn, signOut |\n| `useHydration()`                  | `src/hooks/use-hydration.ts`     | Morning-context + delta invalidation   |\n| `useSyncProgress(provider)`       | `src/hooks/use-sync-progress.ts` | Creamy Layer polling (2s)              |\n| `usePublicFlags/Pricing/Status()` | `src/hooks/use-public-data.ts`   | No-auth landing page data              |\n| `useSSE()`                        | `src/hooks/use-sse.ts`           | Real-time signal subscription          |\n| `useGatewayQuery()`               | `src/hooks/use-gateway-query.ts` | TanStack + Gateway convenience         |\n\n### Contexts\n\n| Context         | Path                               | Purpose                                   |\n| --------------- | ---------------------------------- | ----------------------------------------- |\n| AuthProvider    | `src/contexts/auth-context.tsx`    | Auth state for all components             |\n| NetworkProvider | `src/contexts/network-context.tsx` | Offline detection + write failure surface |\n\n### Build Enforcement\n\n| Mechanism   | Path                                        | Purpose                                         |\n| ----------- | ------------------------------------------- | ----------------------------------------------- |\n| Vite Plugin | `vite-plugins/no-supabase-gateway-proxy.ts` | Fails build if Supabase in gateway-proxy bundle |\n| CI Script   | `scripts/check-no-supabase.ts`              | Post-build scan of dist/assets/\\*.js            |\n\n### Auth Flow\n\n```\nUser → auth.integratewise.ai/oauth/authorize (PKCE + state)\n     → OAuth consent\n     → /auth/callback?code=...&state=...\n     → AuthManager.handleCallback() → token pair\n     → Access token in memory, refresh in localStorage (iw_rt_{userId})\n     → Proactive refresh at exp - 5min\n     → On 401: single coalesced refresh → replay queued requests\n```\n\n### Data Flow (Authenticated)\n\n```\nComponent → spineClient.from(\"table\").select().eq() → SpineGatewayAdapter\n         → QueryBuilder collects filters → .then() resolves\n         → GatewayHttpClient.get(path, params)\n         → Authorization: Bearer {token}, x-tenant-id: {tenant}\n         → CF Gateway validates → D1/KV → response\n         → { data, error } (Supabase-compatible shape)\n```\n\n---\n\n## L0 — ONBOARDING\n\n**Purpose:** Entry → Setup → First value in <2 minutes\n**Route prefix:** `/onboarding`\n**Code:** `apps/web/src/components/activation/onboarding/`\n\n| Screen     | Component          | Route                | Data Source                   | Time |\n| ---------- | ------------------ | -------------------- | ----------------------------- | ---- |\n| Login      | CF Access          | `/` (intercepted)    | CF Zero Trust (Google/GitHub) | 0s   |\n| Welcome    | WelcomeStep.tsx    | `/onboarding` step 1 | None (static)                 | ~15s |\n| Profile    | ProfileStep.tsx    | `/onboarding` step 2 | None (user input)             | ~30s |\n| Goals      | GoalsStep.tsx      | `/onboarding` step 3 | None → Spine Selector runs    | ~25s |\n| Connectors | ConnectorsStep.tsx | `/onboarding` step 4 | GET /api/v1/connector/list    | ~45s |\n| Loading    | AILoader.tsx       | (transition)         | Creamy sync running           | ~10s |\n\n**After L0:** User lands in L1. Never returns unless adding a new tool.\n\n**Backend calls:**\n\n- `POST /api/v1/onboarding/initialize` → creates tenant_spine_config\n- `POST /api/v1/onboarding/connect` → creates Nango session\n- `GET /api/v1/connector/list` → catalog (domain-ranked)\n\n---\n\n## L1 — USER WORKBENCH\n\n**Purpose:** Where you WORK. Personal + one domain. Daily use.\n**Route prefix:** `/personal/*` and `/work/*`\n**Code:** `apps/web/src/components/l1/`\n**Shell:** `workspace-shell-new.tsx` (Personal/Work toggle)\n**Config:** `workspace-config.ts` (drives sidebar per domain)\n\n### Personal View (`/personal/*`)\n\n| View          | Component                 | Route                   | Data Source                             |\n| ------------- | ------------------------- | ----------------------- | --------------------------------------- |\n| Dashboard     | dashboard.tsx             | /personal/dashboard     | GET /api/v1/projections/morning-context |\n| Today         | hub-today-view.tsx        | /personal/hub-today     | GET /api/v1/workspace/space/today       |\n| Tasks         | (shared)                  | /personal/tasks         | GET /api/v1/workspace/view/tasks        |\n| Calendar      | (shared)                  | /personal/calendar      | GET /api/v1/workspace/view/calendar     |\n| Notes         | (shared)                  | /personal/notes         | GET /api/v1/workspace/view/notes        |\n| Projects      | founder-projects-view.tsx | /personal/projects      | GET /api/v1/workspace/view/projects     |\n| Knowledge Hub | knowledge-hub-view.tsx    | /personal/knowledge-hub | GET /api/v1/knowledge/memories          |\n| Bookmarks     | bookmarks-view.tsx        | /personal/bookmarks     | GET /api/v1/workspace/view/bookmarks    |\n| What's New    | whats-new-view.tsx        | /personal/whats-new     | GET /api/v1/workspace/view/whats-new    |\n| AI Chat       | (link to L3)              | /personal/ai-chat       | Opens Twin handoff                      |\n\n### Work View (`/work/*`) — ONE domain per user\n\n**Resolved by:** `tenant_users.department` → `workspace-config.ts`\n\n#### Customer Success (43 views)\n\n| View                 | Route                      | Data Source                                               |\n| -------------------- | -------------------------- | --------------------------------------------------------- |\n| Dashboard            | /work/dashboard            | GET /api/v1/workspace/dashboard?domain=CUSTOMER_SUCCESS   |\n| Accounts             | /work/accounts             | GET /api/v1/pipeline/entities?type=account                |\n| Today                | /work/cs-today             | GET /api/v1/projections/morning-context                   |\n| Tasks                | /work/tasks                | GET /api/v1/workspace/view/tasks                          |\n| Meetings             | /work/meetings             | GET /api/v1/workspace/view/meetings                       |\n| Renewals             | /work/renewals             | GET /api/v1/pipeline/entities?type=renewal                |\n| Risk Matrix          | /work/risk-matrix          | GET /api/v1/intelligence/signals?type=risk                |\n| At-Risk              | /work/at-risk              | GET /api/v1/intelligence/signals?severity=critical        |\n| Health Scores        | /work/account-health       | GET /api/v1/pipeline/entities?type=account                |\n| API Portfolio        | /work/api-portfolio        | GET /api/v1/pipeline/entities?type=api_portfolio          |\n| Platform Health      | /work/platform-health      | GET /api/v1/pipeline/entities?type=platform_health_metric |\n| Success Plans        | /work/success-plans        | GET /api/v1/pipeline/entities?type=success_plan           |\n| Engagement Log       | /work/engagement-log       | GET /api/v1/pipeline/entities?type=engagement             |\n| Initiatives          | /work/initiatives          | GET /api/v1/pipeline/entities?type=initiative             |\n| Strategic Objectives | /work/strategic-objectives | GET /api/v1/pipeline/entities?type=strategic_objective    |\n| Risk Register        | /work/risk-register        | GET /api/v1/pipeline/entities?type=risk_register          |\n| Value Streams        | /work/value-streams        | GET /api/v1/pipeline/entities?type=value_stream           |\n| Capabilities         | /work/capabilities         | GET /api/v1/pipeline/entities?type=capability             |\n| People & Team        | /work/people-team          | GET /api/v1/pipeline/entities?type=people_team            |\n| Stakeholder Outcomes | /work/stakeholder-outcomes | GET /api/v1/pipeline/entities?type=stakeholder_outcome    |\n| Insights             | /work/insights             | GET /api/v1/intelligence/signals                          |\n| Documents            | /work/documents            | GET /api/v1/knowledge/documents                           |\n| Contacts             | /work/contacts             | GET /api/v1/pipeline/entities?type=contact                |\n| Kanban               | /work/kanban               | GET /api/v1/workspace/view/kanban                         |\n\n#### BizOps / Founder (29 views)\n\n| View              | Route               | Data Source                                      |\n| ----------------- | ------------------- | ------------------------------------------------ |\n| Dashboard         | /work/dashboard     | GET /api/v1/workspace/dashboard?domain=BIZOPS    |\n| Founder Ops       | /work/founder-ops   | GET /api/v1/workspace/bi/founder                 |\n| CEO View          | /work/ceo           | GET /api/v1/workspace/bi/executive               |\n| COO View          | /work/coo           | GET /api/v1/workspace/bi/department/operations   |\n| CIO/CTO View      | /work/cio-cto       | GET /api/v1/workspace/bi/department/engineering  |\n| Strategic Hub     | /work/strategic-hub | GET /api/v1/workspace/bi/department/strategy     |\n| Operations Center | /work/operations    | GET /api/v1/workspace/bi/department/ops          |\n| BI View           | /work/bi            | GET /api/v1/workspace/bi/executive               |\n| Knowledge Mgmt    | /work/knowledge     | GET /api/v1/knowledge/documents                  |\n| HR View           | /work/hr            | GET /api/v1/workspace/bi/department/hr           |\n| Legal View        | /work/legal         | GET /api/v1/workspace/bi/department/legal        |\n| Partnerships      | /work/partnerships  | GET /api/v1/workspace/bi/department/partnerships |\n| Sales Hub         | /work/sales         | GET /api/v1/workspace/bi/department/sales        |\n| Marketing         | /work/marketing     | GET /api/v1/workspace/bi/department/marketing    |\n| Clients           | /work/clients       | GET /api/v1/pipeline/entities?type=account       |\n| Tasks             | /work/tasks         | GET /api/v1/workspace/view/tasks                 |\n| Workflows         | /work/workflows     | GET /api/v1/pipeline/entities?type=workflow      |\n| Analytics         | /work/analytics     | GET /api/v1/workspace/bi/signals                 |\n| Today             | /work/bizops-today  | GET /api/v1/projections/morning-context          |\n\n#### Sales (routes)\n\n| View            | Route                 | Data Source                                       |\n| --------------- | --------------------- | ------------------------------------------------- |\n| Dashboard       | /work/dashboard       | GET /api/v1/workspace/dashboard?domain=SALES      |\n| Pipeline        | /work/pipeline        | GET /api/v1/pipeline/entities?type=opportunity    |\n| Pipeline Kanban | /work/pipeline-kanban | GET /api/v1/workspace/view/pipeline-kanban        |\n| Deals           | /work/deals           | GET /api/v1/pipeline/entities?type=opportunity    |\n| Contacts        | /work/contacts        | GET /api/v1/pipeline/entities?type=contact        |\n| Activities      | /work/activities      | GET /api/v1/pipeline/entities?type=activity       |\n| Forecasting     | /work/forecasting     | GET /api/v1/pipeline/entities?type=forecast       |\n| Quotes          | /work/quotes          | GET /api/v1/pipeline/entities?type=quote          |\n| Sequences       | /work/sequences       | GET /api/v1/pipeline/entities?type=email_sequence |\n| Analytics       | /work/sales-analytics | GET /api/v1/workspace/bi/department/sales         |\n\n#### Other Domains (same pattern)\n\nAll domains follow: `GET /api/v1/pipeline/entities?type={entity_type}` for entity views, `GET /api/v1/workspace/dashboard?domain={DOMAIN}` for dashboards.\n\n### Shared Routes (all users)\n\n| View       | Route          | Data Source                             |\n| ---------- | -------------- | --------------------------------------- |\n| Entity 360 | /entity360/:id | GET /api/v1/projections/entity360/:id   |\n| Connectors | /connectors    | GET /api/v1/connector/list              |\n| Bridge     | /bridge        | GET /api/v1/projections/morning-context |\n| Settings   | /settings      | GET /api/v1/auth/me                     |\n\n---\n\n## L2 — OVERLAY (Awareness Drawer)\n\n**Purpose:** Twin's passive presence. Interrupts only when warranted.\n**Code:** `apps/web/src/components/l2/cognitive/`\n**Trigger:** `cognitive-triggers.tsx` (evaluates awareness profile)\n\n| Component              | Purpose                      | Data Source                               |\n| ---------------------- | ---------------------------- | ----------------------------------------- |\n| l2-drawer-animated.tsx | Drawer shell (bottom-to-top) | N/A (layout)                              |\n| cognitive-triggers.tsx | Evaluates signals vs profile | GET /api/v1/intelligence/signals          |\n| SpinePanel             | Entity operational context   | GET /api/v1/projections/entity360/:id     |\n| ContextPanel           | Entity relationship context  | Same as above                             |\n| live-signals-strip.tsx | Signal indicator bar         | GET /api/v1/intelligence/signals          |\n| ai-insight-popup.tsx   | Critical popup               | POST from Twin via continuity-tool-server |\n| [Open Twin ↗] button   | Handoff to L3                | twin-owui-handoff.ts                      |\n\n**Awareness Profile (drives what appears):**\n\n```json\n{\n  \"signal_entitlements\": [\"health_drop\", \"renewal_approaching\"],\n  \"panel_entitlements\": [\"spine\", \"context\"],\n  \"threshold\": 0.75,\n  \"department\": \"customer_success\",\n  \"role\": \"manager\"\n}\n```\n\n---\n\n## L3 — OWUI (Twin Full Surface)\n\n**Purpose:** Where you THINK. Full reasoning. Voice. Agent execution.re\n**URL:** `twin.integratewise.ai` (Hostinger)\n**Code:** `integratewise-ops/vps-operations-stack/openwebui/`\n**Embed:** `apps/web/src/components/l1/twin/twin-workbench.tsx` (iframe)\n\n| Component              | Purpose                         | Technology                             |\n| ---------------------- | ------------------------------- | -------------------------------------- |\n| Open WebUI             | Chat surface, model switching   | ghcr.io/open-webui/open-webui:ollama   |\n| Agent Zero             | Reasoning, tool use, delegation | frdel/agent-zero:latest                |\n| x.ai Audio Proxy       | Voice (TTS + STT)               | Custom proxy → x.ai API                |\n| Continuity Tool Server | Spine reads/writes              | Custom → pipeline.dev.integratewise.ai |\n| Agent Zero Tool Server | A0 integration                  | Custom bridge                          |\n| iw-l1-handoff-inlet.py | Reads L1→L3 context             | OWUI filter                            |\n\n**MCP Connection:**\n\n- URL: `https://mcp.integratewise.ai/invoke`\n- Auth: `Bearer iw-mcp-spine-key-2026`\n- Tools: 18 (memory._, spine._, book._, kb._)\n\n**Voice:**\n\n- TTS: x.ai via xai-audio-proxy (voice: \"eve\")\n- STT: x.ai via xai-audio-proxy (Whisper)\n- Model: Grok-4.3 (default, swappable)\n\n---\n\n## L4 — MEMORY (Knowledge Projection)\n\n**Purpose:** Where you KNOW. The library. Governed knowledge.\n**Surface:** Coda (external tool, projection)\n**Sync:** `packages/coda-pack/sync-org-memory.ts`\n**Data:** D1 org_memory → MCP → Coda tables\n\n| Structure            | Content                                                                                                        | Source                                       |\n| -------------------- | -------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |\n| Departments (14)     | Strategy, Product, Marketing, Sales, CS, Ops, Finance, HR, Data, Legal, Security, Partnerships, Innovation, AI | org_memory.related_departments               |\n| Functional Quadrants | Think / Decide / Work / Learn                                                                                  | org_memory.category → mapped                 |\n| Node Fields          | ID, Title, Category, Function, Department, Content, Confidence, State, Date, Entity Refs                       | org_memory columns                           |\n| Graph Relations      | depends_on, influences, leads_to                                                                               | org_memory.entity_refs (resolved from Spine) |\n\n**No archive.** Everything active or superseded (with lineage).\n\n---\n\n## API Contract Summary\n\nAll frontend calls go through `gateway.dev.integratewise.ai`:\n\n### Auth Endpoints (auth.integratewise.ai)\n\n| Pattern                | Purpose                       | Used By                                      |\n| ---------------------- | ----------------------------- | -------------------------------------------- |\n| `GET /oauth/authorize` | Initiate OAuth (PKCE + state) | AuthManager.signIn()                         |\n| `POST /oauth/token`    | Exchange code / refresh       | AuthManager.handleCallback(), refreshToken() |\n| `POST /oauth/revoke`   | Revoke refresh token          | AuthManager.signOut()                        |\n\n### Public Endpoints (no auth required)\n\n| Pattern                      | Purpose       | Used By            |\n| ---------------------------- | ------------- | ------------------ |\n| `GET /api/v1/public/flags`   | Feature flags | usePublicFlags()   |\n| `GET /api/v1/public/pricing` | Pricing data  | usePublicPricing() |\n| `GET /api/v1/public/status`  | System status | usePublicStatus()  |\n\n### Authenticated Endpoints\n\n| Pattern                                      | Purpose            | Used By                     |\n| -------------------------------------------- | ------------------ | --------------------------- |\n| `GET /api/v1/projections/morning-context`    | Morning briefing   | useHydration(), L1 /desk    |\n| `GET /api/v1/projections/entity360/:id`      | Full entity view   | L1 Entity 360, L2 panels    |\n| `GET /api/v1/projections/governance/board`   | Tasks + proposals  | L1 governance views         |\n| `GET /api/v1/projections/inbox`              | Unified queue      | L1 /inbox                   |\n| `GET /api/v1/pipeline/entities?type=X`       | Entity queries     | L1 all domain views         |\n| `GET /api/v1/pipeline/status?connector=X`    | Creamy Layer sync  | useSyncProgress()           |\n| `GET /api/v1/pipeline/delta-status`          | Delta check        | useHydration() background   |\n| `GET /api/v1/intelligence/signals`           | Active signals     | L2 triggers, L1 today views |\n| `GET /api/v1/connector/list`                 | Connector catalog  | L0 + L1 /connectors         |\n| `GET /api/v1/connectors/:provider/authorize` | OAuth redirect URL | Onboarding Step 3           |\n| `GET /api/v1/connectors/:provider/callback`  | OAuth callback     | Onboarding Step 3           |\n| `GET /api/v1/knowledge/memories`             | Org memory browse  | L1 knowledge views          |\n| `POST /api/v1/workspace/initialize`          | Create workspace   | Onboarding Step 1           |\n| `POST /api/v1/workspace/configure-domain`    | Domain config      | Onboarding Step 2           |\n| `POST /api/v1/workspace/configure-rbac`      | RBAC config        | Onboarding Step 2           |\n| `POST /api/v1/workspace/activate`            | Finalize setup     | Onboarding Step 4           |\n| `GET /api/v1/workspace/dashboard?domain=X`   | Domain dashboard   | L1 work dashboards          |\n| `GET /api/v1/workspace/bi/department/:dept`  | Department data    | L1 BizOps views             |\n| `GET /api/v1/auth/me`                        | Session validation | All layers                  |\n\n### Real-Time Endpoints\n\n| Pattern                         | Purpose             | Used By                              |\n| ------------------------------- | ------------------- | ------------------------------------ |\n| `GET /stream/signals`           | SSE signal delivery | sseClient / useSSE()                 |\n| `GET /stream/pipeline-progress` | SSE sync progress   | useSyncProgress() (optional upgrade) |\n\n---\n\n_One app. Five layers. Personal + Work. Same Spine. Same gateway. Same memory._\n_Auth: OAuth 2.0 (RS256). Data: CF Gateway → D1/KV. Real-time: SSE. Zero Supabase frontend._\n"}