Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ artifacts
.codeflow-store
.codeflow-store-test
.codeflow-sandboxes
.test-store
*.log
*.tsbuildinfo
.env.local
Expand Down
74 changes: 62 additions & 12 deletions docs/PACKAGE_DECOMPOSITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
coderag → @abhinav2203/codeflow-core
```

### `codeflow-core` Source Files (not yet isolated — extracted from `src/lib/blueprint/`)

```
src/lib/blueprint/
- schema.ts ← BlueprintGraph, BlueprintNode, BlueprintEdge, all type definitions
- repo.ts
- repo.test.ts
- utils.ts ← slugify, createNodeId, mergeFields, dedupeEdges, toPosixPath, etc.
- store-paths.ts ← getStoreRoot, sessionDirForProject, latestSessionPath, etc.
- export.ts
- export.test.ts
```

> **Note:** `codeflow-core` is the foundation. `schema.ts` defines the entire type system used by every other package. `repo.ts` uses ts-morph for TypeScript repo analysis. `export.ts` handles blueprint artifact export. These are extracted first before any other package work begins.

## Proposed New Packages

| Package | Description |
Expand Down Expand Up @@ -230,7 +245,11 @@ src/lib/server/terminal-sessions.ts → move to @abhinav2203/codeflow-core
"./checkpoint": { "types": "./dist/checkpoint.d.ts", "default": "./dist/checkpoint.js" },
"./approval": { "types": "./dist/approval.d.ts", "default": "./dist/approval.js" },
"./run": { "types": "./dist/run.d.ts", "default": "./dist/run.js" },
"./risk": { "types": "./dist/risk.d.ts", "default": "./dist/risk.js" }
"./risk": { "types": "./dist/risk.d.ts", "default": "./dist/risk.js" },
"./observability": { "types": "./dist/observability.d.ts", "default": "./dist/observability.js" },
"./branch": { "types": "./dist/branch.d.ts", "default": "./dist/branch.js" },
"./session": { "types": "./dist/session.d.ts", "default": "./dist/session.js" },
"./store": { "types": "./dist/store.d.ts", "default": "./dist/store.js" }
},
"bin": {
"codeflow-store": "./dist/bin/cli.js"
Expand Down Expand Up @@ -357,6 +376,7 @@ FROM: src/lib/blueprint/
- build.ts
- build.test.ts
- file-tree.ts (used by build for file scanning)
- typescript-workspace.ts (used by build.ts for reverse-mode ts-morph analysis)
```

**API routes to wire:**
Expand All @@ -365,6 +385,7 @@ FROM: src/lib/blueprint/
FROM: src/app/api/blueprint/route.ts
FROM: src/app/api/blueprint/route.test.ts
FROM: src/app/api/generate-blueprint/route.ts
FROM: src/app/api/generate-blueprint/route.test.ts
```

**`package.json` fields:**
Expand All @@ -374,7 +395,8 @@ FROM: src/app/api/generate-blueprint/route.ts
"name": "@abhinav2203/codeflow-prd",
"exports": {
".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
"./build": { "types": "./dist/build.d.ts", "default": "./dist/build.js" }
"./build": { "types": "./dist/build.d.ts", "default": "./dist/build.js" },
"./typescript-workspace": { "types": "./dist/typescript-workspace.d.ts", "default": "./dist/typescript-workspace.js" }
},
"bin": {
"codeflow-prd": "./dist/bin/cli.js"
Expand All @@ -387,7 +409,7 @@ FROM: src/app/api/generate-blueprint/route.ts
```

**Developer prompt:**
> "Extract the PRD ingestion layer. Move `src/lib/blueprint/{prd,prd.test,build,build.test,file-tree}.ts` and `src/app/api/blueprint/route.ts`, `src/app/api/generate-blueprint/route.ts` into `packages/codeflow-prd/src/`. The PRD parser extracts screens, APIs, classes, functions, modules, and workflows (with `->` syntax) from markdown. The build step turns parsed PRD into a BlueprintGraph. Publish as `@abhinav2203/codeflow-prd`."
> "Extract the PRD ingestion layer. Move `src/lib/blueprint/{prd,prd.test,build,build.test,file-tree,typescript-workspace}.ts` and `src/app/api/blueprint/route.ts`, `src/app/api/generate-blueprint/route.ts` into `packages/codeflow-prd/src/`. The PRD parser extracts screens, APIs, classes, functions, modules, and workflows (with `->` syntax) from markdown. The build step turns parsed PRD into a BlueprintGraph. Publish as `@abhinav2203/codeflow-prd`."

---

Expand All @@ -409,6 +431,8 @@ FROM: src/lib/blueprint/
- metrics.test.ts
- refactor.ts
- refactor.test.ts
- conflicts.ts ← detectGraphConflicts: repo vs blueprint conflict analysis (imports analyzeTypeScriptRepo from repo.ts in codeflow-core)
- conflicts.test.ts
```

**API routes to wire:**
Expand Down Expand Up @@ -452,7 +476,7 @@ FROM: src/app/api/conflicts/route.test.ts
```

**Developer prompt:**
> "Extract the graph analysis layer. Move all `src/lib/blueprint/{cycles,smells,metrics,refactor}*.ts` files and their corresponding `src/app/api/analysis/{cycles,metrics,smells}/route.ts`, `src/app/api/refactor/{detect,heal}/route.ts`, and `src/app/api/conflicts/route.ts` (with all tests) into `packages/codeflow-analysis/src/`. Each sub-module exposes a focused analysis function. Publish as `@abhinav2203/codeflow-analysis`."
> "Extract the graph analysis layer. Move all `src/lib/blueprint/{cycles,smells,metrics,refactor,conflicts}*.ts` files and their corresponding `src/app/api/analysis/{cycles,metrics,smells}/route.ts`, `src/app/api/refactor/{detect,heal}/route.ts`, and `src/app/api/conflicts/route.ts` (with all tests) into `packages/codeflow-analysis/src/`. Each sub-module exposes a focused analysis function. Publish as `@abhinav2203/codeflow-analysis`."

---

Expand All @@ -477,6 +501,8 @@ FROM: src/lib/blueprint/
FROM: src/app/api/generate-blueprint/route.ts (NVIDIA AI generation endpoint)
```

> **Note:** `generate-blueprint` is a **single shared route** that dispatches to either PRD build (reverse mode) or AI generation (nvidia.ts) based on request parameters. Both `codeflow-prd` and `codeflow-ai` contribute to this route's implementation.

**`package.json` fields:**

```json
Expand Down Expand Up @@ -519,13 +545,15 @@ FROM: src/lib/blueprint/
- phases.test.ts
- execute.ts
- execute.test.ts
- vcr.ts
- vcr.ts ← VCR recording/replay of trace spans
- vcr.test.ts
- runtime-contracts.ts
- runtime-tests.ts
- runtime-tests.test.ts
- runtime-workspace.ts
- sandbox.ts
- mermaid.ts ← toMermaid / toMermaidClassDiagram (used by export/mermaid API route)
- mermaid.test.ts
```

**API routes to wire:**
Expand All @@ -552,7 +580,8 @@ FROM: src/app/api/code-completions/route.ts
"./execute": { "types": "./dist/execute.d.ts", "default": "./dist/execute.js" },
"./vcr": { "types": "./dist/vcr.d.ts", "default": "./dist/vcr.js" },
"./runtime-tests": { "types": "./dist/runtime-tests.d.ts", "default": "./dist/runtime-tests.js" },
"./mermaid": { "types": "./dist/mermaid.d.ts", "default": "./dist/mermaid.js" }
"./mermaid": { "types": "./dist/mermaid.d.ts", "default": "./dist/mermaid.js" },
"./sandbox": { "types": "./dist/sandbox.d.ts", "default": "./dist/sandbox.js" }
},
"bin": {
"codeflow-execution": "./dist/bin/cli.js"
Expand All @@ -566,7 +595,7 @@ FROM: src/app/api/code-completions/route.ts
```

**Developer prompt:**
> "Extract the execution engine. Move `src/lib/blueprint/{runner,plan,phases,execute,vcr,runtime-contracts,runtime-tests,runtime-workspace,sandbox}*.ts` (all files with these prefixes, with tests) and `src/app/api/executions/run/route.ts`, `src/app/api/vcr/route.ts`, `src/app/api/export/mermaid/route.ts`, `src/app/api/code-completions/route.ts` into `packages/codeflow-execution/src/`. The runner orchestrates task plans with phases. VCR records trace spans for replay. Publish as `@abhinav2203/codeflow-execution`."
> "Extract the execution engine. Move `src/lib/blueprint/{runner,plan,phases,execute,vcr,runtime-contracts,runtime-tests,runtime-workspace,sandbox,mermaid}*.ts` (all files with these prefixes, with tests) and `src/app/api/executions/run/route.ts`, `src/app/api/vcr/route.ts`, `src/app/api/export/mermaid/route.ts`, `src/app/api/code-completions/route.ts` into `packages/codeflow-execution/src/`. The runner orchestrates task plans with phases. VCR records trace spans for replay. Mermaid exports generate diagrams from blueprints. Publish as `@abhinav2203/codeflow-execution`."

---

Expand All @@ -590,6 +619,7 @@ FROM: src/lib/opencode/
- config.test.ts
- modelFetcher.ts
- modelFetcher.test.ts
- types.ts ← OpencodeProvider, OpencodeConfig, McpServerConfig types
- api-key-validator.tsx

FROM: src/lib/server/
Expand Down Expand Up @@ -703,6 +733,8 @@ FROM: src/lib/blueprint/
FROM: src/app/api/ghost-nodes/route.ts
```

> **Note:** `heatmap.ts` is shared between `codeflow-evolution` and `codeflow-canvas`. Both packages copy this file (it's not a separate package). The heatmap CLI in `codeflow-evolution` and the heatmap overlay in `codeflow-canvas` both use this same file.

**API routes to wire:**

```text
Expand Down Expand Up @@ -782,6 +814,8 @@ FROM: src/app/api/observability/ingest/route.ts (trace overlay data)
FROM: src/app/api/observability/latest/route.ts
```

> **Note:** Observability data storage routes (`observability/ingest`, `observability/latest`) persist to `codeflow-store`. The `observability.ts` lib file (display/compute logic) lives in `codeflow-canvas` alongside traces and heatmap for graph overlay rendering.

**`package.json` fields:**

```json
Expand All @@ -793,7 +827,8 @@ FROM: src/app/api/observability/latest/route.ts
"./edit": { "types": "./dist/edit.d.ts", "default": "./dist/edit.js" },
"./traces": { "types": "./dist/traces.d.ts", "default": "./dist/traces.js" },
"./editor": { "types": "./dist/editor.d.ts", "default": "./dist/editor.js" },
"./heatmap": { "types": "./dist/heatmap.d.ts", "default": "./dist/heatmap.js" }
"./heatmap": { "types": "./dist/heatmap.d.ts", "default": "./dist/heatmap.js" },
"./observability": { "types": "./dist/observability.d.ts", "default": "./dist/observability.js" }
},
"bin": {
"codeflow-canvas": "./dist/bin/cli.js"
Expand Down Expand Up @@ -865,7 +900,22 @@ FROM: src/app/api/digital-twin/simulate/route.test.ts

---

## Shared / Copy-Once Utilities
## Unaccounted API Routes

The following API routes exist in `src/app/api/` but are NOT assigned to any package in this decomposition. They may belong to an existing package, a future package, or may need to be reassigned:

| Route | Likely Owner | Notes |
|-------|-------------|-------|
| `src/app/api/coderag/route.ts` | `coderag` (existing) | RAG embedding + retrieval |
| `src/app/api/files/get/route.ts` | TBD | File retrieval |
| `src/app/api/files/list/route.ts` | TBD | File listing |
| `src/app/api/files/post/route.ts` | TBD | File upload |
| `src/app/api/terminal/sessions/route.ts` | TBD | Terminal session management |
| `src/app/api/terminal/sessions/[sessionId]/route.ts` | TBD | Individual terminal session |

> **Action needed:** Assign these routes to appropriate packages before extraction begins. `coderag` is an existing package and should take its own route. The file and terminal routes may belong to `codeflow-store` or a new `codeflow-fs` package.

---

These files are used by multiple packages. They should be moved to `@abhinav2203/codeflow-core` (or a dedicated utility package) to avoid code duplication and logic drift. Each consuming package should import them as a normal package dependency rather than copying the source:

Expand Down Expand Up @@ -895,11 +945,11 @@ codeflow-versioning:
src/app/api/branches/{route,[id]/route,diff/route}.ts

codeflow-prd:
src/lib/blueprint/{prd,prd.test,build,build.test,file-tree}.ts
src/lib/blueprint/{prd,prd.test,build,build.test,file-tree,typescript-workspace}.ts
src/app/api/{blueprint,generate-blueprint}/route.ts

codeflow-analysis:
src/lib/blueprint/{cycles,smells,metrics,refactor}*.ts
src/lib/blueprint/{cycles,smells,metrics,refactor,conflicts}*.ts
src/app/api/analysis/{cycles,metrics,smells}/route.ts
src/app/api/{refactor/{detect,heal},conflicts}/route.ts

Expand All @@ -908,7 +958,7 @@ codeflow-ai:
src/app/api/generate-blueprint/route.ts

codeflow-execution:
src/lib/blueprint/{runner,plan,phases,execute,vcr,runtime-contracts,runtime-tests,runtime-workspace,sandbox}*.ts
src/lib/blueprint/{runner,plan,phases,execute,vcr,runtime-contracts,runtime-tests,runtime-workspace,sandbox,mermaid}*.ts
src/app/api/{executions/run,vcr,export/mermaid,code-completions}/route.ts

codeflow-opencode:
Expand Down
Loading
Loading