---
name: investigate-bug
description: Investigate and fix bugs based on the project's data flow, inheriting from superpowers' systematic-debugging.
keywords: bug, fix, error, crash, broken
---

# Investigate Bug

> This skill **inherits and extends** `superpowers:systematic-debugging`.
> First, invoke `superpowers:systematic-debugging` to understand the core process,
> then apply these project-specific steps.

---

## When to use this skill

- Developer requests finding / fixing a bug
- A backlog/jira ticket describes an error
- Logs, stack traces, or descriptions of incorrect behavior are provided

---

## Additional Steps after Phase 1 of systematic-debugging

### 1. Read context from ticket (if available)

Check `.aiflow/context/current.json`:
- `description` — bug description from the ticket
- `comments` — discussions, additional info
- `context.files` — related files mentioned

### 2. Trace data flow according to project architecture

Depending on the framework, trace the corresponding flow:

**Spring Boot (Java)**
```
Controller (@RestController)
  → Service (@Service / ServiceImpl)
    → Repository (JpaRepository)
      → Database
```

**Laravel (PHP)**
```
Route / Controller
  → FormRequest (validation)
    → Service / Action
      → Model / Repository
        → Database
```

**NestJS**
```
Controller (@Controller)
  → Service (@Injectable)
    → Repository / TypeORM Entity
      → Database
```

**PHP Plain (no framework)**
```
index.php (router)
  → Controller
    → Service
      → Repository (PDO)
        → Database
```

**React / Next.js**
```
Page / Route component
  → Custom Hook (useXxx)
    → API call (axios / fetch)
      → Backend endpoint
```

At each layer: log input/output to pinpoint exactly **which layer** generates the incorrect value.

### 3. Check Git history

```bash
# Who changed this file last, and why
git blame <file>

# See detailed changes over time
git log -p <file>

# Find which commit introduced the bug (if the timing is known)
git bisect start
```

Purpose: **to avoid accidentally breaking other business logic** when fixing.

### 4. After fixing — run Impact Analysis

Invoke the `impact-analysis` skill to ensure the fix doesn't affect other parts.

---

## Completion Checklist

- [ ] Read all ticket content + comments
- [ ] Reproduced the error before fixing
- [ ] Traced the exact layer causing the error
- [ ] Checked git blame to understand context
- [ ] Root cause identified clearly
- [ ] Fix is minimal — only modified necessary parts
- [ ] Tests passed (unit + integration)
- [ ] Impact analysis has been run
