{"slug":"documentation/BOOTABLE_APP_PLAN","title":"IntegrateWise Web App — Bootable State Plan","section":"documentation","sectionLabel":"Documentation","status":"unclassified","type":"document","path":"documentation/BOOTABLE_APP_PLAN.mdx","bytes":6473,"description":null,"updated":null,"source":"integratewise/Integratewise-docs-wiki","content":"\n## Current Architecture (What Actually Exists)\n\n### Codebase Location\n\n- **Source:** `/Users/nirmal/Github/integratewise-live/integratewise-complete/apps/web/`\n- **Build copy:** `/tmp/iw-build/` (bypasses macOS `com.apple.provenance` permission block)\n- **Package manager:** pnpm@9 (monorepo with 41 workspace projects)\n- **Framework:** Next.js 16.0.10 (Turbopack)\n- **DB:** Supabase (project: `hrrbciljsqxnmuwwnrnt`)\n- **Secrets:** Doppler (prod) / `.env.local` (dev)\n\n### Two Parallel UI Systems (Root Cause of Issues)\n\n| System            | Location                                     | Layout                                 | Auth                                                                 | Data                                  |\n| ----------------- | -------------------------------------------- | -------------------------------------- | -------------------------------------------------------------------- | ------------------------------------- |\n| **V1 \"Original\"** | `src/app/(app)/`                             | `UnifiedShell` + RBAC + Domain Shells  | `middleware.ts` → Supabase session check → redirect to `/auth/login` | Requires `profiles`, `tenants` tables |\n| **V2 \"Kimi's\"**   | `src/app/dashboard/`, `src/app/tasks/`, etc. | `DashboardLayout` (standalone sidebar) | None (blocked by V1 middleware)                                      | All hardcoded mock data               |\n\n**V1** has 400+ pages inside `(app)/`, including admin panel with 40+ sub-pages. Uses:\n\n- `UnifiedShell` → `useRBAC` hook → Supabase `profiles` table lookup → Domain shell injection\n- `TenantProvider` → fetches `/api/tenant/context`\n- `middleware.ts` → catches ALL non-public routes, requires Supabase auth session\n- Auth login at `/auth/login` using `auth-client.ts` → Cloudflare Auth Worker at `auth.integratewise.ai`\n\n**V2** (Kimi's commit `bffe6a2`) added 16 standalone pages using a simple `DashboardLayout`. These pages:\n\n- Work independently without any DB connection\n- Render static mock data\n- Use a simpler sidebar component\n- Have a new login page at `/login-new` wired to direct Supabase auth\n\n### The Conflict\n\nThe `middleware.ts` from V1 intercepts ALL routes and redirects unauthenticated users to `/auth/login`. Even after disabling it, **Turbopack caches the compiled middleware** and continues redirecting. The `.next` cache must be fully cleared + server restarted for middleware changes to take effect.\n\n### What's NOT Set Up\n\n- **No SQL schema** in Supabase — `profiles`, `tenants`, `roles`, `health_check` tables don't exist\n- **No `/api/tenant/context`** route returning tenant data\n- **No `exec_sql` RPC** stored procedure in Supabase\n- **Auth worker** at `auth.integratewise.ai` is not deployed (V1's auth-client.ts points there)\n- **27 Cloudflare Workers** referenced in docs — none deployed\n\n---\n\n## Plan: 3 Tasks to Bootable State\n\n### Task 1: Fix Middleware + Clear Cache (5 min)\n\n**Goal:** Allow all standalone pages to load without auth redirect\n\n**Steps:**\n\n1. Replace `middleware.ts` with a minimal version that ONLY protects `/(app)/` routes\n2. Delete `.next/` cache completely\n3. Restart dev server\n4. Verify: `/dashboard`, `/test`, `/onboarding`, `/login-new` all load\n\n**Why:** The Turbopack cache holds the compiled old middleware. Even renaming the file doesn't work without cache clear. The simplest fix is a clean middleware that only gates `(app)` routes.\n\n### Task 2: Create Supabase Schema (10 min)\n\n**Goal:** Create the minimum tables so V1 auth + RBAC works\n\n**Steps:**\n\n1. Create SQL migration with:\n   - `profiles` table (id, full_name, avatar_url, role, tenant_id, created_at)\n   - `tenants` table (id, name, industry, plan, created_at)\n   - `health_check` table (id, checked_at)\n   - Basic RLS policies\n2. Run migration against Supabase (via dashboard SQL editor or CLI)\n3. Create a test user in Supabase Auth dashboard\n4. Verify: `/test` page shows \"Database Connected\"\n\n### Task 3: Wire Login → Dashboard Flow (10 min)\n\n**Goal:** Complete auth flow: login → session → dashboard with real data\n\n**Steps:**\n\n1. Ensure `/login-new` calls `signInWithSupabaseEmail` (already done)\n2. On success, redirect to `/dashboard`\n3. Verify the Supabase session cookie is set\n4. Dashboard loads (with static data for now — that's fine)\n\n---\n\n## Files Modified So Far (This Session)\n\n| File                                                                                | Change                                                         | Status                     |\n| ----------------------------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------- |\n| `apps/web/.env.local`                                                               | Created with Supabase credentials                              | ✅ Done                    |\n| `apps/web/src/app/login-new/page.tsx`                                               | Wired to `signInWithSupabaseEmail` + error handling            | ✅ Done                    |\n| `apps/web/src/components/shell/UnifiedShell.tsx`                                    | Fixed lowercase imports + moved Search import                  | ✅ Done                    |\n| `apps/web/src/app/page.tsx`                                                         | Redirect to `/login-new` instead of `/today`                   | ✅ Done                    |\n| `apps/web/src/app/(app)/{accounts,integrations,knowledge,pipeline,settings,tasks}/` | Removed to fix parallel route conflicts                        | ✅ Done (in /tmp/iw-build) |\n| `apps/web/src/middleware.ts`                                                        | Renamed to `.disabled` (but Turbopack cache didn't pick it up) | ⚠️ Needs proper fix        |\n\n## Key Insight: macOS Provenance Block\n\nThe source directory has `com.apple.provenance` extended attributes (macOS Sequoia security) that prevent:\n\n- `mkdir` inside the directory (pnpm install fails)\n- `cp` of `.env.local`\n\n**Workaround:** Copy to `/tmp/iw-build/`, install there, run from there. All code changes need to be made in BOTH locations (source for git, /tmp for running).\n\n## Doppler Note\n\nProduction uses Doppler for secrets. The `.env.local` approach is for local dev only. Both paths are supported by `provider.ts` which reads `process.env.NEXT_PUBLIC_SUPABASE_URL` regardless of source.\n"}