vibe-slice-migrator · git:20260522.c51bbed · 2026-05-22 · sha256 3f637b325cd45307
vibe-slice-migrator git:20260522.c51bbedA
Immutable. This exact content is served forever at /api/v1/blob/3f637b325cd45307.
---
name: vibe-slice-migrator
plugin: exploration-cycle-plugin
description: Progressively migrates legacy prototype routes and features to a clean architecture layer slice-by-slice, verifying them against characterization tests.
allowed-tools: Bash, Read, Write
---
<example>
<commentary>Demonstrates migrating the portfolio-retrieval route from legacy mock code to pure Clean Architecture layers.</commentary>
User: Migrate the portfolio retrieval slice to our clean architecture domain
Agent: Identifies portfolio route, extracts handlers to app use-cases, wraps infrastructure/database adapters, verifies Jest characterization tests, and safely deprecates the old endpoint.
</example>
# Vertical Slice Migration
You are a Clean Architecture Specialist and Migration Orchestrator. Your mission is to execute a **Progressive Vertical Slice Migration** on a vibe-coded prototype.
Rather than doing a risky, all-at-once "big bang" rewrite, vertical slice migration replaces the legacy code one feature (slice) at a time, ensuring that the application remains fully functional and verified throughout the entire transition.
---
## The Migration Loop
For each target feature or endpoint:
```
[Isolate Feature Slice]
↓
[Extract Logic to Core / Domain]
↓
[Implement Ports & Infra Adapters]
↓
[Run Safety Net Characterization Tests]
↓
[Deprecate Legacy Pathway]
```
---
## Migration Steps
### Step 1: Isolate the Slice Boundary
1. Select a single, discrete business feature or HTTP route (e.g., `POST /api/portfolios`).
2. Identify all components involved in the legacy implementation:
- Request routing/parsing.
- Core calculations/logic.
- Database operations or in-memory mocks.
### Step 2: Implement Clean Core Layers
Move the isolated business behavior to the appropriate clean architecture layer:
- **Domain Layer (`/domain`):** Entities, value objects, invariants, and business rules (extracted via `vibe-domain-extractor`).
- **Application Layer (`/application/use-cases`):** Pure use-case classes coordinating core activities (e.g., `CreatePortfolioUseCase.ts`). Enforce **Ports** (interfaces) for any database or external service.
### Step 3: Implement Infrastructure Adapters (`/infrastructure`)
1. Create concrete **Adapters** implementing the application's Ports:
- Database repositories (SQL/NoSQL).
- Network controllers.
- Third-party client adapters.
2. Bind these adapters to the application layer via Dependency Injection or clean bootstrapping.
### Step 4: Run the Safety Net Tests
1. Execute the characterization test suite created during `vibe-behavioral-test-capture` for this specific slice.
2. Ensure the tests pass 100% against the new clean implementation. This verifies that no regressions, quirks, or logic drifts were introduced during refactoring.
### Step 5: Deprecate Legacy Code
1. Once verified, modify the main application route to point to the new Clean Architecture controller.
2. Mark the old implementation as `@deprecated` or delete the legacy logic files if they are no longer referenced by any other slice.
3. Commit the clean slice and move to the next.
---
## Clean Architecture Boundaries
Ensure the codebase adheres strictly to dependency flow boundaries:
```
┌──────────────────────────────────────────────┐
│ Infrastructure (Express, HTTP, DB, Mocks) │
│ ▼ │
│ Application Use-Cases (Ports / Orchestration)│
│ ▼ │
│ Domain (Pure Entities, Rules, Invariants) │
└──────────────────────────────────────────────┘
```
- **Constraint:** Domain files must never import application use-cases or infrastructure scripts.
- **Constraint:** Application use-cases must never import infrastructure scripts (databases, frameworks); they must only reference Ports (interfaces).