Skip to content

refactor: restructure repo into apps/services/packages monorepo#1315

Merged
jeanduplessis merged 3 commits intomainfrom
monorepo-refactor
Apr 5, 2026
Merged

refactor: restructure repo into apps/services/packages monorepo#1315
jeanduplessis merged 3 commits intomainfrom
monorepo-refactor

Conversation

@jeanduplessis
Copy link
Copy Markdown
Contributor

@jeanduplessis jeanduplessis commented Mar 20, 2026

Summary

Restructures the repository from a flat layout (where the root is both the pnpm workspace root AND the Next.js app) into a standard pnpm monorepo with apps/, services/, and packages/ directories.

Directory changes:

  • src/, public/, tests/, dev/apps/web/
  • storybook/apps/storybook/
  • kilo-app/apps/mobile/
  • cloudflare-* workers → services/* (prefix stripped)
  • cloud-agent/, cloud-agent-next/services/
  • kiloclaw/services/kiloclaw/
  • kiloclaw/packages/secret-catalog/packages/kiloclaw-secret-catalog/

Root package.json split: The root (kilocode-monorepo) is now a lean workspace host with husky, oxlint, oxfmt, and typescript. All Next.js dependencies live in apps/web (package name: web).

pnpm-workspace.yaml: Replaced 30+ explicit entries with glob patterns (apps/*, services/*, packages/* plus nested workspace overrides).

Scripts rewritten: lint-all.sh, changed-workspaces.sh, and typecheck-all.sh now resolve workspaces via pnpm ls --json instead of parsing pnpm-workspace.yaml literally. dev.sh writes .dev-port to the repo root.

All 8 CI workflows updated for the new directory structure (path filters, working directories, cache paths, sparse-checkout).

Review fixes included: CI change filter for moved web config files, deploy-production env path for Drizzle migrations, dev/local findRepoRoot() package name, broken relative imports in services/deploy-infra/builder, missing zod dependency, .oxlintrc.json override globs for services/ paths, storybook tsconfig test exclusions and missing deps, .kilocodeignore migration path correction.

Verification

  • pnpm install — workspace resolution works
  • pnpm --filter web typecheck — pass
  • pnpm --filter kilo-app typecheck — pass
  • pnpm --filter cloud-agent-next typecheck — pass
  • pnpm --filter @kilocode-backend/storybook typecheck — pass
  • pnpm --filter @kilocode/db typecheck — pass
  • scripts/typecheck-all.sh --changes-only — pass (all 29 workspace packages)
  • scripts/lint-all.sh — pass (0 errors, 4620 files)
  • pnpm format:check — pass
  • Parallel pre-push checks (format + lint + typecheck) — pass
  • scripts/changed-workspaces.sh --exclude services/cloud-agent --exclude services/cloud-agent-next --exclude apps/web — correct JSON output

Visual Changes

N/A

Reviewer Notes

  • Phase 11 (post-merge manual steps): Update Vercel dashboard "Root Directory" to apps/web for kilocode-app, kilocode-global-app, and kilocode-gateway projects. Update EAS project config if it references old kilo-app/ paths. Check Sentry source map paths.
  • oxlint concurrency quirk: services/gmail-push has a targeted override disabling no-unsafe-call/no-unsafe-member-access because oxlint's type resolution for console fails under concurrent execution with typecheck. The rules still apply to all other services.
  • 3400+ files changed but the vast majority are pure renames. Only ~25 files have content modifications.
  • The plans/monorepo-restructure-summary.md file documents the full implementation details for reference.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Mar 20, 2026

Code Review Summary

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 5
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
plans/monorepo-migration-prompt.md 78 The path mapping table puts the generic kiloclaw/ rule before the nested kiloclaw/packages/secret-catalog/ rule, so prefix-based migrations can relocate the secret-catalog package under services/kiloclaw/.
plans/monorepo-migration-prompt.md 187 The stale-path rg scan checks for cloud-agent/ but not cloud-agent-next/, so old-layout references can slip through verification.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
plans/monorepo-restructure.md 341 Root package.json script plan still omits format:check, but ci.yml continues to run pnpm run format:check in the format-check job.
apps/web/src/app/admin/api/kiloclaw-analytics/route.ts 63 The new all-events query broadens instance filtering with userId / flyAppName / flyMachineId, so multi-instance users can see sibling-instance events in this instance's telemetry tab.
apps/web/src/app/admin/components/KiloclawInstances/KiloclawInstanceDetail.tsx 2317 VolumeReassociationCard is rendered without instanceId, so its start/stop/reassociate mutations fall back to the legacy user-scoped DO and can operate on the wrong instance.
Files Reviewed (1 files)
  • plans/monorepo-migration-prompt.md - 2 issues

Reviewed by gpt-5.4-20260305 · 239,962 tokens

@jeanduplessis jeanduplessis changed the title docs: monorepo restructure plan refactor: restructure repo into apps/services/packages monorepo Apr 5, 2026
Add a detailed restructure plan (plans/monorepo-restructure.md) covering
the migration from a flat repo layout to a standard pnpm monorepo with
apps/, packages/, and services/ directories.
@jeanduplessis jeanduplessis force-pushed the monorepo-refactor branch 2 times, most recently from 64f4503 to fbd56ba Compare April 5, 2026 19:31
Migrate from a flat layout (root = pnpm workspace root AND Next.js app)
to a standard pnpm monorepo:

- apps/web: Next.js app with its own package.json (split from root)
- apps/storybook: moved from storybook/
- apps/mobile: moved from kilo-app/
- packages/: shared libraries (db, trpc, encryption, worker-utils, etc.)
- services/: Cloudflare Workers and other backend services

Key changes:
- Root package.json slimmed to lean workspace root (kilocode-monorepo)
- pnpm-workspace.yaml switched to glob patterns (apps/*, packages/*, etc.)
- All GitHub Actions workflows updated for new directory structure
- scripts/changed-workspaces.sh and lint-all.sh rewritten for glob-aware
  workspace discovery via pnpm ls
- trpc rollup config updated for new tsgo output paths
- Relative imports in services/deploy-infra/builder fixed for new depth
- .oxlintrc.json override globs and ignorePatterns updated
- Missing direct dependencies added (zod, dotenv, @jest/globals, etc.)
- CI changes job given pnpm setup for workspace discovery
| `cloudflare-deploy-infra/` | `services/deploy-infra/` |
| `cloudflare-o11y/` | `services/o11y/` |
| `cloudflare-<name>/` | `services/<name>/` |
| `kiloclaw/` | `services/kiloclaw/` |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: The generic kiloclaw/ mapping can swallow the nested secret-catalog package

Anything that applies this table as prefix substitutions will map kiloclaw/packages/secret-catalog/... to services/kiloclaw/packages/secret-catalog/... before it ever reaches the more specific row below. Reordering these entries or explicitly saying that the longest matching prefix wins avoids migrating that workspace into the wrong location.

-e '\.dev-port' \
-e '\.env\.local' \
-e 'kilo-app/' \
-e 'cloud-agent/' \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: The stale-path scan misses cloud-agent-next/ references

cloud-agent-next/ is one of the renamed top-level directories in the mapping table, but this rg command never searches for it. A migration can therefore leave old cloud-agent-next/... paths behind without tripping the verification step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants