# SmartStack Project Detection & MCP Validation

**CRITICAL**: Before starting any code review, detect if this is a SmartStack project and run MCP validation.

## Detection

**Detect SmartStack project by checking for ANY of these:**
- `.claude/mcp-status.json` exists
- `SmartStack.Domain/` or `SmartStack.Application/` directories
- `*.sln` file containing "SmartStack"
- `package.json` with `@smartstack/` dependencies

## MCP Validation

**If SmartStack detected, run comprehensive code review via MCP:**

**Primary tool - `review_code`** (unified review):
```
mcp__smartstack__review_code
scope: "changed"   # or "all" or "staged"
checks: ["all"]    # 9 categories covered
severity: "all"    # blocking, critical, warning, info
```

**This single tool covers ALL categories:**
- Security (OWASP, secrets, SQL injection, XSS)
- Architecture (layer violations, DI bypass)
- Hardcoded values (magic numbers, URLs, feature flags)
- Tests (missing tests, test quality)
- AI Hallucinations (non-existent imports, phantom methods)
- Performance (N+1 queries, over-fetching)
- Dead Code (unused imports, functions)
- i18n (non-translated UI text)
- Accessibility (missing alt, ARIA issues)

**Optional: Additional convention checks:**
```
mcp__smartstack__validate_conventions
checks: ["all"]
```

## MCP Check Categories

**SmartStack code review categories via MCP `review_code`:**

| Category | Check ID | What it detects |
|----------|----------|-----------------|
| **Security** | SEC-xxx | Hardcoded secrets, SQL injection, XSS, missing [Authorize] |
| **Architecture** | ARCH-xxx | Layer violations (Domain->Infrastructure), DI bypass |
| **Hardcoded** | HARD-xxx | Magic numbers, hardcoded URLs, feature flags |
| **Tests** | TEST-xxx | Missing tests, useless assertions, no coverage |
| **AI Hallucinations** | AI-xxx | Non-existent imports, phantom methods, placeholders |
| **Performance** | PERF-xxx | N+1 queries, ToList before Where, over-fetching |
| **Dead Code** | DEAD-xxx | Unused imports, functions, commented code, TODOs |
| **i18n** | I18N-xxx | Hardcoded UI text, missing translations |
| **Accessibility** | A11Y-xxx | Missing alt, no aria-label, focus issues |

**Severity levels:**
- `blocking` -> Must fix before merge (security, hallucinations)
- `critical` -> Should fix ASAP (architecture, tests)
- `warning` -> Recommended fix (performance, dead code)
- `info` -> Nice to have (i18n, a11y)

## Output Integration

**Merge MCP `review_code` results into review output:**

```markdown
## Code Review Results (via MCP)

### Summary
| Metric | Value |
|--------|-------|
| Status | {PASSED/FAILED/WARNING} |
| Score | {score}/100 |
| Grade | {A/B/C/D/F} |

### Blocking Issues ({count})
| ID | Issue | File:Line | Fix |
|----|-------|-----------|-----|
| SEC-001 | {title} | `{file}:{line}` | {suggestion} |

### Critical Issues ({count})
| ID | Issue | File:Line | Fix |
|----|-------|-----------|-----|
| ARCH-001 | {title} | `{file}:{line}` | {suggestion} |

### Warnings ({count})
(List or summarize)
```

**Priority mapping from MCP:**
- `blocking` -> `[BLOCKING]` - Must fix before merge
- `critical` -> `[CRITICAL]` - Should fix ASAP
- `warning` -> `[SUGGESTION]` - Recommended
- `info` -> `[NIT]` - Nice to have
