# Feature Development Workflow

This skill orchestrates a complete feature development cycle, from architecture to deployment.

## Workflow Overview

```
┌─────────────┐
│  Architect  │ → Design architecture & create ADRs
└─────────────┘
      ↓
┌─────────────┐
│  Developer  │ → Implement feature
└─────────────┘
      ↓
┌─────────────┐
│   Tester    │ → Write tests & verify coverage
└─────────────┘
      ↓
┌─────────────┐
│  Reviewer   │ → Review & validate
└─────────────┘
      ↓
   ✅ Done
```

## Auto-Detection

This skill automatically:
1. **Detects project level** (Rapid/Balanced/Crafted)
2. **Adapts workflow** based on level
3. **Applies appropriate rules** for each step
4. **Validates coverage** according to level requirements

## Step-by-Step Process

### Pre-Flight: Understand Context

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

**Gather**:
- Feature name
- Requirements
- Project level (rapid/balanced/crafted)
- Platform (web/web-mobile)

**Ask clarifying questions** if requirements are unclear.

---

### Step 1: Architecture (Architect Skill)

**Activate**: Invoke `/architect` skill mentally

**Tasks**:

**For RAPID level**:
- ✅ Identify which router to modify/create
- ✅ Design simple API structure
- ⏭️ Skip ADR (not required)
- ⏭️ Skip layer separation (flat architecture)

**For BALANCED level**:
- ✅ Design 3-layer structure (Router → Service → Repository)
- ✅ Create ADR for major decisions
- ✅ Validate layer boundaries using `check_layer_boundaries`
- ✅ Define interfaces and DTOs

**For CRAFTED level**:
- ✅ Design hexagonal architecture (Domain → Application → Infrastructure)
- ✅ Create comprehensive ADR with alternatives considered
- ✅ Design domain entities, value objects, aggregates
- ✅ Define repository interfaces (in domain layer)
- ✅ Validate ZERO external dependencies in domain using `check_dependencies`
- ✅ Design use-cases

**Output**: Architecture design document or inline comments in plan

---

### Step 2: Implementation (Developer Skill)

**Activate**: Invoke `/developer` skill mentally

**Tasks**:

**For ALL levels**:
- ✅ Implement following Clean Code principles
- ✅ NO inline comments (refactor instead)
- ✅ Self-documenting code (clear names)
- ✅ Type-safe (TypeScript strict + Zod)

**For RAPID level**:
- ✅ Write logic in router (< 100 lines/function)
- ✅ Duplication OK if < 3 times
- ✅ Basic error handling (try-catch)

**For BALANCED level**:
- ✅ Thin routers (< 20 lines)
- ✅ Business logic in services (< 50 lines/function)
- ✅ Max 3 parameters per function
- ✅ Extract if duplication > 2 times
- ✅ Create repositories for data access

**For CRAFTED level**:
- ✅ Ultra-thin routers (< 10 lines)
- ✅ Pure domain entities (ZERO external deps)
- ✅ Use-cases for orchestration
- ✅ Max 20 lines/function, max 2 parameters
- ✅ ZERO duplication (extract immediately)
- ✅ Result pattern (no exceptions)

**Validation**:
```typescript
mcp__rules-validator__validate_code({
  code: generatedCode,
  filePath: "...",
  level: detectedLevel
})

mcp__architecture-guard__check_dependencies({
  filePath: "packages/domain/...", // For Crafted
  level: "crafted"
})
```

---

### Step 3: Testing (Tester Skill)

**Activate**: Invoke `/tester` skill mentally

**Test Strategy by Level**:

**For RAPID level**:
- ✅ Auth flows (if touching auth)
- ✅ Payment flows (if touching payments)
- ⏭️ Skip business logic tests
- ⏭️ Skip UI component tests
- **Coverage**: No minimum required

**For BALANCED level**:
- ✅ Unit tests (100% public methods in services)
- ✅ Integration tests (router → service → repository)
- ✅ Component tests (critical UI)
- ✅ E2E tests (auth + checkout flows)
- **Coverage**: 70% minimum

**For CRAFTED level**:
- ✅ **Write tests FIRST** (Spec-First TDD)
- ✅ Domain entities tests (100% coverage)
- ✅ Use-cases tests (100% coverage)
- ✅ Infrastructure tests (80% coverage)
- ✅ E2E tests (complete flows)
- ✅ Contract tests (API boundaries)
- **Coverage**: Domain 100%, Use-cases 100%, Infrastructure 80%

**Test Generation**:

For Rapid/Balanced:
```
1. Generate code + tests in parallel
2. Run tests
3. Fix if fails
4. Validate coverage (Balanced only)
```

For Crafted:
```
1. UNDERSTAND business rules
2. Generate TESTS FIRST (specification)
3. Generate implementation that satisfies tests
4. Run tests
5. Fix if fails
6. Validate 100% domain coverage
```

**Tools**:
```typescript
mcp__vitest__run_tests()
mcp__vitest__check_coverage({ threshold: 70 }) // Balanced
mcp__vitest__check_coverage({ threshold: 100 }) // Crafted domain

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

---

### Step 4: Review (Reviewer Skill)

**Activate**: Invoke `/reviewer` skill mentally

**Review Checklist**:

**Code Quality**:
- ✅ No inline comments (WHY comments only)
- ✅ Self-documenting code
- ✅ Proper error handling
- ✅ Type safety enforced

**Architecture**:
- ✅ Follows level-appropriate structure
- ✅ No layer boundary violations
- ✅ No circular dependencies
- ✅ (Crafted) Domain has ZERO external deps

**Testing**:
- ✅ Tests pass
- ✅ Coverage meets requirements
- ✅ (Crafted) Tests were written first

**Security**:
- ✅ Input validation (Zod)
- ✅ Authentication/authorization
- ✅ No SQL injection risks
- ✅ No XSS risks

**Tools**:
```typescript
mcp__rules-validator__validate_code()
mcp__architecture-guard__check_layer_boundaries()
mcp__vitest__run_tests()
mcp__typescript__check_types()
```

**On failure**: Return to Step 2 (Developer) with feedback

**On success**: Feature is ready! 🎉

---

## Example Usage

### User Request
> "I want to add a product catalog with filtering and pagination"

### Execution

```bash
# You invoke this skill
/feature

# Then you proceed step-by-step:

# 1. Detect level
mcp__crafted-context__get_architecture_info()
# Result: { level: "balanced", platform: "web" }

# 2. Architecture (Balanced level)
# - Design 3-layer structure
# - Router: productRouter.list() < 20 lines
# - Service: productService.list() with filtering logic < 50 lines
# - Repository: productRepository.findMany() with Prisma
# - Create ADR: "Use cursor-based pagination for scalability"

# 3. Implementation
# - Create router (thin)
# - Create service (business logic)
# - Create repository (data access)
# - Validate with rules-validator

# 4. Testing
# - Unit tests for service (100% public methods)
# - Integration test (router → service → repository)
# - Ensure 70% coverage

# 5. Review
# - Run all checks
# - Validate architecture boundaries
# - Confirm tests pass
# ✅ Feature ready!
```

---

## Commands

```bash
# Invoke this skill
/feature

# Or use slash command (if configured)
/features "Add product catalog"
```

---

## Integration with Other Skills

This skill internally uses:
- `/architect` - For design phase
- `/developer` - For implementation
- `/tester` - For testing
- `/reviewer` - For validation

And adapts based on:
- `/rapid` - If project level is rapid
- `/balanced` - If project level is balanced
- `/crafted` - If project level is crafted

---

## Tips

1. **Always start with context** - Detect level first
2. **Ask questions** - Clarify requirements before starting
3. **Follow the workflow** - Don't skip steps
4. **Validate early** - Run checks after each step
5. **Adapt to level** - Rapid ≠ Balanced ≠ Crafted

---

## Common Pitfalls

❌ **Don't**:
- Skip architecture step (even for Rapid)
- Write inline comments
- Ignore coverage requirements
- Mix layers (Balanced/Crafted)

✅ **Do**:
- Detect level first
- Follow clean code principles
- Write self-documenting code
- Validate at each step
