{"slug":"operations/REPO_CLEANUP_AUDIT","title":"IntegrateWise Repo Cleanup Audit","section":"operations","sectionLabel":"Operations","status":"unclassified","type":"document","path":"operations/REPO_CLEANUP_AUDIT.mdx","bytes":15987,"description":null,"updated":null,"source":"integratewise/Integratewise-docs-wiki","content":"\n> **Tier C — Historical.** This document is a point-in-time snapshot preserved for reference. For current architecture, see [CANONICAL_PLATFORM_ARCHITECTURE.md](../architecture/CANONICAL_PLATFORM_ARCHITECTURE.md).\n\n> Generated: 2026-06-30 | Auditor: Claude (Cowork)\n> Architecture baseline: v3.8.0, DECISIONS 22–27\n\n---\n\n## Summary\n\n| Category                             | Count                          | Severity |\n| ------------------------------------ | ------------------------------ | -------- |\n| Root markdown clutter                | 59 orphan `.md` files          | Medium   |\n| Supabase remnants in source          | 316 files (`.ts`/`.tsx`/`.js`) | High     |\n| Legacy pre-consolidation services    | 6 workers                      | Medium   |\n| Dead/mystery root dirs               | 5 dirs                         | High     |\n| `apps/web` framework mismatch        | Next.js ≠ CLAUDE.md says Vite  | High     |\n| `apps/web.old` (stale backup)        | 24 MB                          | Medium   |\n| Editor/AI tool caches in repo        | ~65 MB                         | Low      |\n| `packages/supabase` (entire package) | Should not exist               | High     |\n| `packages/db/src/supabase.ts`        | Legacy DB client               | High     |\n| `packages/lib/src/neon.ts`           | Legacy Neon/DB client          | High     |\n| Dist folders committed to git        | 12 packages                    | Low–Med  |\n| Neon/legacy DB references in source  | ~10 files                      | High     |\n| `supabase/` dir at repo root         | Full Supabase config           | High     |\n| `migrations/supabase-export/`        | Should be archived             | Medium   |\n| `twilight-limit-8567/` mystery dir   | CF template, not IW code       | High     |\n\n---\n\n## 1. Root-Level Markdown Clutter (59 files)\n\n**The problem:** 59 `.md` files live at repo root. Most are AI-generated session artifacts, delivery summaries, phase completion notes, and architecture drafts that have since been superseded or committed to `docs/`.\n\n**Keep:** `README.md`, `CLAUDE.md`, `CONTRIBUTING.md`, `CHANGELOG.md`, `AGENTS.md`\n\n**Move to `docs/`:** Anything still relevant (architecture references, deployment guides)\n\n**Delete:** All `*_COMPLETE.md`, `*_SUMMARY.md`, `PHASE_*.md`, `DELIVERY_*.md`, `DEPLOYMENT_*.md`, `MERGE_SUMMARY_*.md`, `SESSION_SUMMARY_*.md`, `VERCEL_DEPLOYMENT_STATUS.md` and similar ephemeral artifacts.\n\nFiles to delete (54 files — all except the 5 above):\n\n```\nAI_AGENT_PROVIDER_ARCHITECTURE.md  AI_HOME_SPEC.md  ARCHITECTURE.md\nARCHITECTURE_DIAGRAMS.md  ARCHITECTURE_INDEX.md  ARCHITECTURE_REFERENCE.md\nARCHITECTURE_SCORES_v1.0.md  ARCHITECTURE_VISUALIZATION_COMPLETE.md\nAUTH_CONNECTOR_INTEGRATION.md  BACKEND_CONSOLIDATION_v1.0.md\nCAPABILITY_RESOLVER_PATTERN.md  CLEANUP_SUMMARY.md\nCOMPLETE_PROVIDER_AGNOSTIC_GUIDE.md  CONTINUITY_BRIDGE_COMPLETE.md\nCORE_ENGINE_EXCAVATION.md  CUSTOMER_ZERO_LAUNCH.md  DELIVERY_COMPLETE.md\nDEPLOYMENT_ANALYSIS_FULL.md  DEPLOYMENT_FIX.md  DEPLOYMENT_READY.md\nDEPLOYMENT_SUMMARY.md  DIAGRAM_VERIFICATION.md  ECOSYSTEM.md\nENDPOINTS_SUMMARY.md  FEATURE_BUCKET_LIST.md  FINAL_DELIVERY_SUMMARY.md\nGO_LIVE_DEPLOYMENT_GUIDE.md  HANDOFF_ACCEPTANCE.md  IMPLEMENTATION_COMPLETE.md\nINTEGRATED_VISION.md  INTEGRATEWISE_RECOVERY_PLAN.md  INTEGRATION_REMOVAL_PLAN.md\nL1_CHAT_SHELL_IMPLEMENTATION.md  MCP_ADK_SPINE_CACHE_ARCHITECTURE.md\nMERGE_SUMMARY_FROM_MAIN.md  ONE_CONNECTOR_ARCHITECTURE.md\nPHASE_1_COMPLETE.md  PHASE_1_EXECUTION.md  PHASE_2A_COMPLETE.md\nPLATFORM_ACTIVATION_FRAMEWORK.md  PLATFORM_ADAPTER_LAYER.md  PLATFORM_DELIVERY.md\nPRODUCT_MAPPING_RECOVERY.md  PRODUCT_PHILOSOPHY.md  PROJECTION_OS_ARCHITECTURE.md\nPROJECT_STATUS_AND_DEPLOYMENT.md  PROVIDER_AGNOSTIC_ARCHITECTURE.md\nRECOVERY_PLAN_EXECUTIVE_SUMMARY.md  REPOSITORY_SUMMARY.md\nSESSION_SUMMARY_2026_06_25_26.md  SPINE_CONNECTION_POOL_ARCHITECTURE.md\nSPINE_SCHEMA_SYNTHESIS.md  SYSTEM_ARCHITECTURE.md  THREE_PILLARS_ARCHITECTURE.md\nUNIVERSAL_CONNECTION_POOL_ARCHITECTURE.md  VERCEL_DEPLOYMENT_STATUS.md\n```\n\n**Also delete:** `REPOSITORY_TREE.txt` (generated artifact), `integratewise-docs.patch`, `spine-pipeline-backend.patch`\n\n---\n\n## 2. `apps/web` Framework Mismatch ⚠️ HIGH PRIORITY\n\n**The problem:** CLAUDE.md declares `apps/web` as a \"Vite + React 18 SPA\" and references `src/AppShell.tsx`, `src/lib/auth-manager.ts`. In reality, `apps/web` is a **Next.js 16 App Router app** with `@clerk/nextjs`, `@supabase/ssr`, `@supabase/supabase-js`, and a `next.config.mjs`. Neither `src/AppShell.tsx` nor `src/lib/auth-manager.ts` exist.\n\n**The actual Vite SPA** is `apps/web.old` — which still has `index.html`, `vite.config`, and the original Vite structure.\n\n**Actions needed:**\n\n- Decide which is the canonical frontend and update CLAUDE.md to match reality\n- `apps/web` uses Clerk auth (not CF Gateway credential auth as documented) — reconcile\n- `apps/web` uses `@supabase/ssr` and `@supabase/supabase-js` directly — violates DECISION 22\n- Remove Supabase client calls from `apps/web/app/auth/callback/route.ts`, `apps/web/supabase/` dir, and ~30 other web files\n- `apps/web.old` (24 MB) — archive or delete once canonical app is confirmed\n\n---\n\n## 3. Supabase Remnants (316 source files)\n\n**The problem:** DECISION 22 banned Supabase from the product plane. 316 `.ts`/`.tsx`/`.js` files still import or reference it.\n\n**Highest-priority removals:**\n\n| File                                    | Issue                                |\n| --------------------------------------- | ------------------------------------ |\n| `packages/supabase/`                    | Entire package — should be deleted   |\n| `packages/db/src/supabase.ts`           | Supabase DB client — replace with D1 |\n| `packages/db/src/index.ts`              | Exports Supabase client              |\n| `packages/rbac/src/engine.ts`           | RBAC uses Supabase                   |\n| `packages/types/src/schema-accessor.ts` | Supabase schema access               |\n| `packages/types/src/schema-updater.ts`  | Supabase schema writes               |\n| `packages/lib/src/audit.ts`             | Audit writes to Supabase             |\n| `packages/lib/src/circuit-breaker.ts`   | Circuit breaker references Supabase  |\n| `packages/connector-utils/src/index.ts` | Connector utils use Supabase         |\n| `apps/web/app/auth/callback/route.ts`   | Supabase auth callback               |\n| `apps/web/supabase/`                    | Supabase migrations inside web app   |\n\n**Also flag:** `migrations/supabase-export/` — keep for historical reference but add a clear README that these are retired migrations, not active schema.\n\n---\n\n## 4. Legacy Services (pre-consolidation workers, DECISION 16)\n\nPer DECISION 16, these are \"reference only\" but are still active Workers with `wrangler.toml`:\n\n| Service               | Files          | Status                                           |\n| --------------------- | -------------- | ------------------------------------------------ |\n| `services/loader`     | 33 `.ts` files | Pre-consolidation — absorbed into `pipeline`     |\n| `services/normalizer` | 11 `.ts` files | Pre-consolidation — absorbed into `pipeline`     |\n| `services/think`      | 22 `.ts` files | Pre-consolidation — absorbed into `intelligence` |\n| `services/act`        | 2 `.ts` files  | Pre-consolidation — absorbed into `intelligence` |\n| `services/govern`     | 10 `.ts` files | Pre-consolidation — absorbed into `intelligence` |\n| `services/store`      | 3 `.ts` files  | Pre-consolidation — absorbed into `pipeline`     |\n\n**Recommendation:** Move these into `infra/retirement/` or a `services/_legacy/` subdirectory to make clear they are not deployed. Remove from Cloudflare if deployed there. Do NOT delete yet — they are reference material for the consolidation migration.\n\n**Also flag (ambiguous status):**\n\n- `services/hermes` — not in CLAUDE.md service list; purpose unclear\n- `services/huggingface-inference` — 1 file; likely an experiment\n- `services/core-engine` — not in CLAUDE.md active list; 5 files\n- `services/schema-ai` — not in CLAUDE.md active list; 3 files\n- `services/projection-engine` — 4 files; listed in architecture but not active workers list\n- `services/projection-registry` — 1 file; same\n- `services/capability-resolver` — 1 file; same\n- `services/agent-registry` — 1 file; same\n- `services/telemetry` — 1 file; same\n\n---\n\n## 5. Dead / Mystery Root Directories\n\n| Dir                    | Size                       | What it is                                                                                                                                                                                            | Action                                           |\n| ---------------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |\n| `twilight-limit-8567/` | Large (has `node_modules`) | A **Cloudflare Workflows template demo** — not IW code at all. Has its own `package.json`, `wrangler.jsonc`, React Vite frontend. Appears to be a CF starter template that was checked in by mistake. | **Delete**                                       |\n| `file-mis/`            | Tiny                       | Contains one `mockup.html`. Already in `.gitignore`.                                                                                                                                                  | **Delete**                                       |\n| `vitest-stubs/`        | Tiny                       | One `cloudflare-workers.ts` stub.                                                                                                                                                                     | Move to `packages/` or `tests/` or delete        |\n| `mcp/figma/`           | Small                      | Figma MCP integration — unclear if active. Not in CLAUDE.md service list.                                                                                                                             | Clarify ownership; move to `packages/` if active |\n| `infra/retirement/`    | Small                      | Retirement scripts for old buckets. Keep, but ensure `.gitignore` excludes generated outputs.                                                                                                         |\n\n---\n\n## 6. Packages to Remove or Relocate\n\n| Package                        | Issue                                                                          |\n| ------------------------------ | ------------------------------------------------------------------------------ |\n| `packages/supabase`            | Entire package exists solely for Supabase — delete after migration             |\n| `packages/hermes-spine-memory` | Purpose unclear; not in CLAUDE.md; may be legacy                               |\n| `packages/coda-pack`           | Coda integration — not in architecture; likely prototype                       |\n| `packages/knowledge-bank-ui`   | Standalone UI component for KB — unclear if active or if it belongs in `apps/` |\n| `packages/website`             | Empty (12K); marketing site is in separate `integratewise-marketing` repo      |\n| `packages/lib/src/neon.ts`     | Neon (legacy Postgres) client — delete when D1 migration is complete           |\n\n---\n\n## 7. Editor / AI Tool Cache Directories\n\nThese are in `.gitignore` but accumulate size locally. Safe to delete from disk at any time:\n\n| Dir                     | Size   | Notes                                  |\n| ----------------------- | ------ | -------------------------------------- |\n| `.opencode/`            | 57 MB  | Huge; node_modules inside              |\n| `.aider.tags.cache.v4/` | 3.3 MB | Aider AI cache                         |\n| `.v0-ref/`              | 3.2 MB | v0.dev reference                       |\n| `.playwright-mcp/`      | 1.1 MB | Playwright MCP                         |\n| `.kiro/`                | 700 KB | Kiro IDE (steering kept per gitignore) |\n| `.kimi/`                | 64 KB  | Kimi AI                                |\n| `.iw-memory/`           | 40 KB  | IW memory specs                        |\n\nRun: `rm -rf .opencode .aider.tags.cache.v4 .v0-ref .playwright-mcp .kimi`\n(Keep `.kiro/steering/` per `.gitignore` rule)\n\n---\n\n## 8. Dist Folders Committed to Git\n\n12 packages have `dist/` directories committed to the repo. These are build artifacts and should not be in git. They bloat the repo and create confusion about source of truth.\n\n```\npackages/connectors/dist        packages/rbac/dist\npackages/types/dist             packages/accelerators/dist\npackages/config/dist            packages/integratewise-mcp-tool-connector/dist\npackages/contracts/dist         packages/supabase/dist\npackages/connector-contracts/dist  packages/hermes-spine-memory/dist\npackages/lib/dist               packages/analytics/dist\n```\n\n**Action:** Add `dist/` to `.gitignore` for each package, delete committed dist folders, ensure CI builds them. (Already in root `.gitignore` as `dist/` — check if monorepo config overrides this.)\n\n---\n\n## 9. Neon / Legacy DB References\n\n`packages/lib/src/neon.ts` is a Neon (Postgres) client. Referenced by:\n\n- `packages/lib/src/circuit-breaker.ts`\n- `packages/lib/src/index.ts`\n- `packages/connector-utils/src/index.ts`\n- `apps/web/lib/circuit-breaker.ts`\n- `apps/web/lib/outbox.ts`\n- `apps/web/app/api/health/route.ts`\n- `apps/web/app/api/cron/integrity-check/route.ts`\n\nAll should be migrated to D1 per DECISION 22.\n\n---\n\n## 10. CLAUDE.md Accuracy Issues\n\nCLAUDE.md is the agent guide, so it must reflect reality. Current gaps:\n\n| Claim in CLAUDE.md                                 | Reality                                                           |\n| -------------------------------------------------- | ----------------------------------------------------------------- |\n| `apps/web` is \"Vite + React 18 SPA\"                | It's Next.js 16 App Router with Clerk                             |\n| `src/AppShell.tsx` key file                        | Does not exist                                                    |\n| `src/lib/auth-manager.ts` key file                 | Does not exist                                                    |\n| Auth is \"CF Gateway credential auth, not Supabase\" | `apps/web` still has `@supabase/ssr` and `@clerk/nextjs`          |\n| \"no bff\" in active services                        | `services/l2` has a wrangler.toml and is named `integratewise-l2` |\n\n---\n\n## Priority Order for Cleanup\n\n**Do immediately (no code risk):**\n\n1. Delete `twilight-limit-8567/` (unrelated CF demo template)\n2. Delete 54 root-level orphan `.md` files, `.txt`, `.patch` files\n3. Delete `file-mis/`\n4. Delete editor caches (`.opencode`, `.aider.tags.cache.v4`, etc.)\n5. Delete `apps/web.old/` (after confirming canonical app)\n6. Add `dist/` per-package `.gitignore` entries and remove committed dists\n\n**Do with code review:** 7. Delete `packages/supabase/` entirely 8. Delete `packages/lib/src/neon.ts` and remove all callsites 9. Migrate `packages/db/src/supabase.ts` to D1 10. Remove Supabase from `apps/web` (`@supabase/ssr`, `@supabase/supabase-js`, `supabase/` dir) 11. Remove Clerk from `apps/web` if CF Gateway credential auth is the intended path 12. Move legacy services to `services/_legacy/` or `infra/retirement/`\n\n**Do after careful audit:** 13. Clarify and either promote or delete: `services/hermes`, `services/schema-ai`, `services/core-engine`, `packages/hermes-spine-memory`, `packages/coda-pack`, `packages/knowledge-bank-ui` 14. Update CLAUDE.md to match actual `apps/web` framework and auth\n\n---\n\n_Total estimated size recoverable from easy deletes: ~90+ MB (editor caches + web.old + twilight node_modules)_\n"}