# Auto-Feature Development (Automatic Orchestration)

**IMPORTANT**: This skill performs AUTOMATIC multi-agent orchestration. You will execute ALL phases WITHOUT stopping for user confirmation.

## What This Skill Does

When invoked with `/auto-feature "Feature description"`, you will:
1. ✅ Detect project level automatically
2. ✅ Execute architect phase (design hexagonal architecture)
3. ✅ Execute developer phase (domain-first implementation)
4. ✅ Execute tester phase (spec-first TDD, 100% domain coverage)
5. ✅ Execute reviewer phase (strict validation)
6. ✅ Report final results to user

**NO user confirmation between phases** - this is fully automatic.

---

## Execution Protocol

### Phase 0: Initialize

**FIRST**, gather feature requirements:

```
User Request: [Feature description from command]

Ask ONLY if unclear:
- What are the business rules?
- What are the domain concepts?
- What are the invariants?

Once clear, proceed to Phase 1 WITHOUT asking for confirmation.
```

### Phase 1: Auto-Detect Level

**REQUIRED**: Call MCP tool to detect project level:

```typescript
const context = await mcp__crafted-context__get_architecture_info();
// Returns: { level: "crafted", platform: "web" }
```

**Output to user**:
```
🎯 Detected: Crafted level, Web platform
📋 Starting automatic orchestration (hexagonal architecture)...
```

Then **IMMEDIATELY proceed to Phase 2** without waiting.

---

### Phase 2: Architect (Design Hexagonal Architecture)

**Role**: Software Architect

**Follow instructions from** `.claude/skills/agents/architect.md`

**For Crafted level** (current template):
1. Design hexagonal architecture (Domain → Application → Infrastructure)
2. Model domain entities and value objects
3. Define domain repository interfaces (in domain layer)
4. Design use-cases (orchestration)
5. Plan infrastructure implementations
6. Create comprehensive ADR with alternatives

**Tools to use**:
```typescript
mcp__crafted-context__get_context_summary()
```

**Output to user**:
```
🏗️ Architecture Phase (Architect)
├─ Domain Layer (ZERO external deps):
│  ├─ Product entity (rich domain model)
│  ├─ Money value object
│  ├─ IProductRepository interface
│  └─ CreateProduct use-case
│
├─ Infrastructure Layer:
│  └─ PrismaProductRepository (implements IProductRepository)
│
├─ Application Layer:
│  └─ productRouter (ultra-thin < 10 lines)
│
└─ ADR-042: Hexagonal architecture for long-term maintainability
```

**Then IMMEDIATELY proceed to Phase 3** without waiting.

---

### Phase 3: Developer (Domain-First Implementation)

**Role**: Craftsman Developer

**Follow instructions from** `.claude/skills/agents/developer.md`

**For Crafted level** (current template):

**Implementation Order** (STRICT):
1. Domain entities (< 20 lines/method, max 2 params)
2. Value objects (immutable)
3. Domain repository interfaces
4. Use-cases (< 10 lines)
5. Infrastructure implementations
6. Ultra-thin routers (< 10 lines)

**Rules**:
- Domain: ZERO external dependencies (no Prisma, no tRPC, NOTHING)
- Use Result pattern (no exceptions)
- ZERO duplication (extract immediately)
- Functions < 20 lines, max 2 parameters

**Tools to use**:
```typescript
mcp__rules-validator__validate_code({
  code: generatedCode,
  filePath: "packages/domain/entities/Product.ts",
  level: "crafted"
})

mcp__architecture-guard__check_dependencies({
  filePath: "packages/domain/entities/Product.ts",
  level: "crafted"
})
// MUST return: ZERO external dependencies

mcp__architecture-guard__check_layer_boundaries({ level: "crafted" })
```

**Output to user**:
```
👨‍💻 Implementation Phase (Developer)
├─ Created: packages/domain/entities/Product.ts (18 lines)
├─ Created: packages/domain/value-objects/Money.ts (15 lines)
├─ Created: packages/domain/repositories/IProductRepository.ts (8 lines)
├─ Created: packages/domain/use-cases/CreateProduct.ts (9 lines)
├─ Created: packages/infrastructure/database/repositories/PrismaProductRepository.ts (42 lines)
├─ Created: packages/api/routers/product.ts (8 lines)
└─ ✅ Validation: Domain has ZERO external deps, all rules passed
```

**Then IMMEDIATELY proceed to Phase 4** without waiting.

---

### Phase 4: Tester (Spec-First TDD + 100% Coverage)

**Role**: Quality Engineer

**Follow instructions from** `.claude/skills/agents/tester.md`

**For Crafted level** (current template):

**CRITICAL**: Spec-First TDD approach

**Step 1: UNDERSTAND business rules**
```
Product creation rules:
- Name cannot be empty
- Price must be positive
- Price decrease cannot exceed 20%
- etc.
```

**Step 2: Generate tests FIRST** (specification)
```typescript
// These tests specify WHAT the Product entity SHOULD do
describe('Product Entity', () => {
  it('should create product with valid data', () => { ... })
  it('should reject empty name', () => { ... })
  it('should reject non-positive price', () => { ... })
  it('should allow price increase', () => { ... })
  it('should reject price decrease > 20%', () => { ... })
})
```

**Step 3: Verify implementation satisfies tests**

**Step 4: Run tests + check coverage**

**Coverage Requirements**:
- Domain entities: 100%
- Value objects: 100%
- Use-cases: 100%
- Infrastructure: 80%

**Tools to use**:
```typescript
mcp__vitest__run_tests()

mcp__vitest__check_coverage({ threshold: 100 }) // Domain

mcp__vitest__check_coverage({ threshold: 80 }) // Infrastructure

mcp__rules-validator__check_test_coverage({
  testPath: "packages/domain",
  level: "crafted"
})
```

**Output to user**:
```
🧪 Testing Phase (Tester - Spec-First TDD)
├─ Step 1: Understood business rules ✅
│
├─ Step 2: Generated tests FIRST (specification):
│  ├─ packages/domain/entities/Product.test.ts (12 tests)
│  ├─ packages/domain/value-objects/Money.test.ts (8 tests)
│  ├─ packages/domain/use-cases/CreateProduct.test.ts (6 tests)
│  └─ packages/infrastructure/database/repositories/PrismaProductRepository.test.ts (7 tests)
│
├─ Step 3: Verified implementation satisfies all tests ✅
│
├─ Step 4: Run tests:
│  └─ ✅ 33/33 tests passed
│
└─ Coverage:
   ├─ Domain: ✅ 100% (required: 100%)
   ├─ Use-cases: ✅ 100% (required: 100%)
   └─ Infrastructure: ✅ 85% (required: 80%)
```

**Then IMMEDIATELY proceed to Phase 5** without waiting.

---

### Phase 5: Reviewer (Strict Validation)

**Role**: Code Reviewer

**Follow instructions from** `.claude/skills/agents/reviewer.md`

**Review Checklist for Crafted**:
- ✅ No inline comments (WHY comments + ADR references only)
- ✅ Self-documenting code
- ✅ Domain has ZERO external dependencies
- ✅ Hexagonal architecture respected
- ✅ No layer boundary violations
- ✅ Result pattern used (no exceptions)
- ✅ Functions < 20 lines, max 2 parameters
- ✅ ZERO duplication
- ✅ Tests written FIRST (spec-first)
- ✅ Domain 100% coverage
- ✅ Use-cases 100% coverage
- ✅ Infrastructure 80%+ coverage

**Tools to use**:
```typescript
mcp__rules-validator__validate_code()
mcp__architecture-guard__check_dependencies({
  filePath: "packages/domain/**/*",
  level: "crafted"
})
mcp__architecture-guard__check_layer_boundaries()
mcp__typescript__check_types()
```

**If violations found**:
- Go back to Phase 3 (Developer)
- Fix issues
- Re-run Phase 4 (Tester)
- Come back to Phase 5 (Reviewer)

**Output to user**:
```
✅ Review Phase (Reviewer - Strict)
├─ Code quality: ✅ Passed
├─ Architecture: ✅ Hexagonal architecture respected
├─ Layer boundaries: ✅ No violations
├─ Domain dependencies: ✅ ZERO external deps
├─ Tests: ✅ 33/33 passing (spec-first)
├─ Coverage:
│  ├─ Domain: ✅ 100%
│  ├─ Use-cases: ✅ 100%
│  └─ Infrastructure: ✅ 85%
├─ Type safety: ✅ No errors
└─ Duplication: ✅ ZERO
```

**Then proceed to Phase 6** (Final Report).

---

### Phase 6: Final Report

**Output to user**:

```
✅ Feature Complete! (Crafted Quality)

📊 Summary:
├─ Files created: 6
│  ├─ packages/domain/entities/Product.ts (18 lines, ZERO deps)
│  ├─ packages/domain/value-objects/Money.ts (15 lines)
│  ├─ packages/domain/repositories/IProductRepository.ts (8 lines)
│  ├─ packages/domain/use-cases/CreateProduct.ts (9 lines)
│  ├─ packages/infrastructure/database/repositories/PrismaProductRepository.ts (42 lines)
│  └─ packages/api/routers/product.ts (8 lines)
│
├─ Tests created: 33 (spec-first TDD)
│  ├─ packages/domain/entities/Product.test.ts (12 tests)
│  ├─ packages/domain/value-objects/Money.test.ts (8 tests)
│  ├─ packages/domain/use-cases/CreateProduct.test.ts (6 tests)
│  └─ packages/infrastructure/database/repositories/PrismaProductRepository.test.ts (7 tests)
│
├─ Coverage:
│  ├─ Domain: 100% (12/12 functions)
│  ├─ Use-cases: 100% (6/6 functions)
│  └─ Infrastructure: 85% (28/33 functions)
│
└─ Time: ~25 minutes (automatic orchestration)

🎯 Quality Level: Crafted (Software Craftsmanship)
✅ All checks passed
✅ Production-ready for long-term (5-10+ years)
✅ Domain has ZERO external dependencies
✅ Hexagonal architecture enforced

Architecture Decision Record:
└─ ADR-042: Hexagonal architecture for Product domain
   See: docs/adr/042-product-hexagonal-architecture.md

Next steps:
- Review domain model
- Verify business rules accuracy
- Deploy to staging
- Plan next domain feature
```

---

## Critical Rules

### 🚨 MUST DO

1. **Execute ALL phases automatically** - NO stopping for confirmation
2. **Domain FIRST** - Implement domain layer before infrastructure
3. **Spec-First TDD** - Write tests FIRST for domain/use-cases
4. **Use MCP tools** for validation at each phase
5. **ZERO external deps in domain** - CI must fail if violated
6. **100% domain coverage** - Non-negotiable
7. **Fix errors automatically** - If tests fail, fix and re-run

### ❌ NEVER DO

1. **NEVER ask for confirmation** between phases (only at start if requirements unclear)
2. **NEVER skip phases** (must complete all)
3. **NEVER add external deps in domain** (no Prisma, no tRPC, NOTHING)
4. **NEVER use exceptions** (Result pattern only)
5. **NEVER allow duplication** (ZERO tolerance)
6. **NEVER exceed 20 lines** per function
7. **NEVER exceed 2 parameters** per function

---

## Crafted Philosophy

> "Build it right. Architecture-first, sustainable for 10+ years."

**Software Craftsmanship**:
- Hexagonal architecture (clean boundaries)
- Domain-Driven Design (rich models)
- Spec-First TDD (tests = specification)
- 100% domain coverage (non-negotiable)
- ZERO duplication (CI fails)
- Long-term thinking (5-10+ years)

---

## Example Invocation

**User types**:
```
/auto-feature "Add product catalog with inventory management"
```

**You execute**:
```
🎯 Detected: Crafted level, Web platform
📋 Starting automatic orchestration (hexagonal architecture)...

🏗️ Architecture Phase (Architect)
[... hexagonal design ...]

👨‍💻 Implementation Phase (Developer - Domain First)
[... domain entities + infrastructure ...]

🧪 Testing Phase (Tester - Spec-First TDD)
[... tests FIRST, then verify implementation ...]

✅ Review Phase (Reviewer - Strict)
[... architecture + coverage validation ...]

✅ Feature Complete! (25 minutes)
[... final report ...]
```

**Total time: ~25 minutes** (no manual intervention, highest quality)

---

## Integration with Existing Skills

This skill **replaces** `/feature` for automatic mode.

- Use `/feature` for **manual mode** (you guide at each step)
- Use `/auto-feature` for **automatic mode** (full orchestration, no stops)

---

**Remember**: This is AI-**automated** development at CRAFTED quality. You execute the ENTIRE workflow without user confirmation. Build it right for long-term sustainability (5-10+ years).
