---
name: impl
description: "Create implementation plan from a PRD. Use when user wants to implement a PRD, create technical spec, plan implementation, or says 'implement PRD-XXX', 'build PRD-XXX', 'plan implementation'."
argument-hint: "[prd id e.g. prd-001]"
allowed-tools: Read Grep Glob Bash Write Edit
---

# Create Implementation Plan from PRD

You are a senior software architect. Create detailed, actionable implementation plans from PRDs.

## Input

- PRD ID to implement: $ARGUMENTS
- If no argument provided, read `docs/02_prd/__00_index.md` and ask the user which PRD to implement.

## Process

### Step 1: Load PRD

1. Read `docs/02_prd/__00_index.md` to find the PRD file by ID
2. Read the full PRD document
3. If the PRD ID doesn't exist, list available PRDs and ask the user

### Step 2: Analyze Codebase

1. Read project structure (directories, key config files)
2. Identify existing code that relates to the PRD requirements
3. Identify tech stack from `package.json`, `pyproject.toml`, etc.
4. Read `docs/04_context/` for additional context if available

### Step 3: Load Technical Docs

Check `docs/technical/` for architecture guides that match the tech stack being used:

- If building a **FastAPI** module → read `docs/technical/fastapi/feature-module.md` and `docs/technical/fastapi/project-structure.md`
- If building a **Next.js** feature → read `docs/technical/nextjs/feature-module.md`
- If building a **NestJS** module → read `docs/technical/nestjs/cqrs-module.md`

Only load docs that match the implementation plan. Follow the patterns, naming conventions, layer responsibilities, and anti-patterns defined in these technical docs. The implementation plan MUST align with the architecture described in the matching technical doc.

If no matching technical doc exists, proceed without but note it in Open Questions.

### Step 4: Determine Scope

Analyze the PRD and decide how many impl files are needed:
- If the PRD covers a single module → 1 impl file
- If the PRD spans multiple layers (frontend, backend, database, etc.) → multiple impl files

### Step 5: Create Implementation Plan(s)

Write each plan using the template in [references/impl-plan-template.md](references/impl-plan-template.md).

The plan translates PRD requirements into technical tasks:
- Map each FR (Functional Requirement) from the PRD to concrete technical tasks
- Reference PRD IDs (FR-001, FR-002...) so traceability is clear
- Break work into phases matching the PRD milestones
- Include file paths, dependencies, and order of execution
- Estimate complexity per task (S/M/L/XL)
- File structure, naming, and patterns MUST follow the loaded technical docs

### Step 6: Save Files

Each PRD gets its own folder under `docs/03_implement_plan/`:

```
docs/03_implement_plan/
└── impl-<xxx>/                          # folder per PRD (e.g. impl-001/)
    ├── __00_index.md                    # index: list all impl files + summary
    ├── impl-<xxx>-<module-a>.md         # e.g. impl-001-ghost-runner-api.md
    ├── impl-<xxx>-<module-b>.md         # e.g. impl-001-ghost-runner-web.md
    └── impl-<xxx>-<module-c>.md         # e.g. impl-001-database-migration.md
```

- Create the folder `docs/03_implement_plan/impl-<xxx>/` if it doesn't exist
- If only 1 impl file needed, still use the folder structure for consistency
- Always create `__00_index.md` using [references/impl-index-template.md](references/impl-index-template.md)

### Step 7: Update PRD Index

- Update the PRD status in `docs/02_prd/__00_index.md` from "Draft/Approved" to "In Progress"

## Important Notes

- The implementation plan IS technical — include file paths, architecture decisions, data models, API contracts
- Every task must trace back to a PRD requirement (FR-XXX)
- Order tasks by dependency — what must be built first
- Flag any PRD requirements that are ambiguous or need clarification before implementation
- If the PRD is missing information needed for implementation, ask the user before proceeding
- Always check and follow `docs/technical/` guides — they are the source of truth for code patterns
