# 🎯 Activity 2: Sprint Planning Workshop - เฉลย (Answers)

## 📋 บริบท

Activity 2 คือการวางแผนสปริ้นท์สำหรับ Sprint 1 ของโครงการจริง ซึ่งครอบคลุม 3 ส่วนหลัก

---

## 🎯 ส่วนที่ 1: ประมาณ User Story (8 นาที)

### วัตถุประสงค์

ใช้ Planning Poker เพื่อประมาณ Story Points สำหรับ USer Story ทั้งหมด

### กระบวนการ

```
1. PO (Product Owner) อ่านเรื่องราวเข้าสู่ระบบผู้ใช้

   User Story: เข้าสู่ระบบผู้ใช้

   "ในฐานะผู้ใช้ ฉันต้องการ
    เข้าสู่ระบบด้วยอีเมลและรหัสผ่าน
    เพื่อเข้าถึงบัญชี"

   Acceptance Criteria:
   - User ป้อนอีเมลและรหัสผ่าน
   - System ตรวจสอบข้อมูลประจำตัว
   - User ได้รับ JWT token
   - User redirected ไปยัง dashboard

2. ทีม (Dev, QA) อภิปราย
   - ความซับซ้อน? "ปานกลาง"
   - ต้องทำอะไร?
     ✓ API endpoint สร้าง
     ✓ Database query
     ✓ Password hashing/checking
     ✓ Token generation
     ✓ Error handling
     ✓ Unit tests

3. Planning Poker ประมาณ

   Dev A: [8] (ต้องเขียน API)
   Dev B: [5] (ใช้ library)
   QA:    [8] (ต้อง test หลายกรณี)

   ถ้าต่างกัน → อภิปรายใหม่:
   QA: "ทำไมต้อง test 3 ชั่วโมง?"
   Dev B: "เพราะต้อง test: valid login, invalid password, missing email, SQL injection..."
   QA: "อ่อ, ได้"

   Vote ใหม่:
   Dev A: [8]
   Dev B: [8]
   QA:    [8]

   ✅ ตกลงกัน = 8 points

4. ทำซ้ำสำหรับเรื่องราวทั้งหมด
```

### ตัวอย่าง: 10 เรื่องราวที่ประมาณแล้ว

```
1. User Registration (ลงทะเบียน)     - 8 จุด
2. User Login (เข้าสู่ระบบ)          - 8 จุด
3. Product Listing (รายการผลิตภัณฑ์) - 5 จุด
4. Product Details (รายละเอียด)     - 5 จุด
5. Shopping Cart (รถเข็น)             - 8 จุด
6. Checkout (ชำระเงิน)               - 13 จุด (ต้องเชื่อมต่อ payment gateway)
7. Payment Processing (ประมวลผล)    - 13 จุด (integration ซับซ้อน)
8. Order History (ประวัติคำสั่งซื้อ)  - 5 จุด
9. User Profile (โปรไฟล์)            - 5 จุด
10. Search Products (ค้นหา)           - 8 จุด

รวมทั้งหมด: 78 จุด
```

### Key Takeaway

```
✅ Planning Poker สำคัญเพราะ:
  - ทำให้ discussion เกิดขึ้น
  - ค้นหา misconceptions ก่อน sprint
  - Team alignment on complexity
  - Estimate ดีขึ้น

❌ ข้อผิดพลาดทั่วไป:
  - Estimate โดย PO เพียงคน (ไม่ถูก)
  - ไม่อภิปรายเมื่อ estimate ต่างกัน
  - Estimate ดีกว่ากว่างหรือมากเกิน
```

---

## 🎯 ส่วนที่ 2: เลือกเรื่องราวสปริ้นท์ 1 (7 นาที)

### คำนวณความสามารถ (Capacity)

```
ทีม: 5 คน
ระยะเวลา Sprint: 2 สัปดาห์ (10 วันทำงาน)
ชั่วโมงต่อวัน: 8 ชั่วโมง

ความสามารถทั้งหมด:
5 คน × 8 ชั่วโมง × 10 วัน = 400 ชั่วโมง

ลบ Overhead:
- Standup: 15 นาที × 10 วัน = 2.5 ชั่วโมง
- Sprint Review: 1 ชั่วโมง
- Sprint Retrospective: 1 ชั่วโมง
- Code Review: 4 ชั่วโมง/วัน × 10 วัน = 40 ชั่วโมง
- Interruptions (email, meetings): 1 ชั่วโมง/วัน × 10 วัน = 10 ชั่วโมง

ลบรวม: 2.5 + 1 + 1 + 40 + 10 = 54.5 ชั่วโมง

ความสามารถจริง: 400 - 54.5 = 345.5 ชั่วโมง

ประมาณเป็น 32-35 จุด:
- ถ้าเฉลี่ย 10 ชั่วโมง/จุด → 345.5 / 10 = 34.55 ≈ 35 จุด
- ถ้าเฉลี่ย 11 ชั่วโมง/จุด → 345.5 / 11 = 31.4 ≈ 31 จุด

ใช้ Conservative Estimate: 30-32 จุด (buffer 20%)
```

### เลือกเรื่องราว

```
ลำดับความสำคัญ (Priority) จาก PO:
1. User Registration (8 จุด) ← Critical
2. User Login (8 จุด) ← Critical
3. Product Listing (5 จุด) ← Important
4. Shopping Cart (8 จุด) ← Important
5. Search Products (8 จุด) ← Nice to have
... (เรื่องราวอื่นไปสปริ้นท์ 2)

เลือกสำหรับสปริ้นท์ 1:

✓ User Registration: 8 จุด
✓ User Login: 8 จุด
✓ Product Listing: 5 จุด
✓ Shopping Cart: 8 จุด

รวม: 29 จุด (ต่ำกว่า 30-32, บัฟเฟอร์ดี!)

ส่วนที่เหลือ:
- Order History: 5 จุด
- Search Products: 8 จุด
- Product Details: 5 จุด
- User Profile: 5 จุด
- Checkout: 13 จุด
- Payment Processing: 13 จุด
→ ไปสปริ้นท์ 2-3
```

### สเปรินท์ 1 Goal

```
"ให้ผู้ใช้สามารถสมัครสมาชิก เข้าสู่ระบบ
 และดูผลิตภัณฑ์ได้ พร้อมเพิ่มลงรถเข็น
 (จากเด็ก MVP - Minimum Viable Product)"
```

### Key Takeaway

```
✅ Conservative Capacity สำคัญ:
  - 20-30% buffer สำหรับ surprises
  - ทีมจะ commit มั่นใจ
  - Sprint goal achievable

❌ ข้อผิดพลาดทั่วไป:
  - เลือก 100% capacity (impossible)
  - ไม่เหลือบัฟเฟอร์
  - ทีมทำไม่เสร็จ → morale ลดลง
```

---

## 🎯 ส่วนที่ 3: สร้างงาน (5 นาที)

### Task Breakdown ตัวอย่าง: User Login (8 จุด)

```
User Story: เข้าสู่ระบบผู้ใช้ (8 จุด)

Task 1.1: สร้าง Login API Endpoint
├─ Created POST /api/auth/login
├─ Accepts: { email, password }
├─ Returns: { token, user }
├─ Assigned: Dev A
├─ Effort: 4 ชั่วโมง
├─ Dependencies: ไม่มี (ต้องทำเสร็จก่อน task อื่น)
└─ Status: Not Started

Task 1.2: ตรวจสอบรหัสผ่านและ Authentication
├─ Implement password hashing (bcrypt)
├─ Validate email/password
├─ Generate JWT token
├─ Token expiry: 24 hours
├─ Assigned: Dev B
├─ Effort: 3 ชั่วโมง
├─ Dependencies: Task 1.1 (รอ API endpoint)
└─ Status: Not Started

Task 1.3: Error Handling & Logging
├─ Handle: user not found
├─ Handle: invalid password
├─ Handle: database error
├─ Logging: all login attempts
├─ Assigned: Dev A
├─ Effort: 2 ชั่วโมง
├─ Dependencies: Task 1.1, 1.2
└─ Status: Not Started

Task 1.4: Unit Tests
├─ Test: valid login
├─ Test: invalid password
├─ Test: missing email
├─ Test: SQL injection attempt
├─ Coverage: > 80%
├─ Assigned: QA A
├─ Effort: 3 ชั่วโมง
├─ Dependencies: Task 1.1, 1.2, 1.3
└─ Status: Not Started

Task 1.5: Integration Test
├─ Test: API-to-Database flow
├─ Test: Token validation
├─ Test: User session
├─ Assigned: QA B
├─ Effort: 2 ชั่วโมง
├─ Dependencies: Task 1.1-1.4 ทั้งหมด
└─ Status: Not Started

Task 1.6: Code Review & Documentation
├─ Code reviewed by 2+ reviewers
├─ JSDoc documentation added
├─ README updated
├─ Assigned: Dev Lead
├─ Effort: 1 ชั่วโมง
├─ Dependencies: Task 1.1-1.5 complete
└─ Status: Not Started

รวมทั้งสิ้น: 4+3+2+3+2+1 = 15 ชั่วโมง (overshooting 8 จุด? 8 จุด = ~10-11 ชั่วโมง)
→ ต้องออก Task บ้าง หรือบีบบาง task

ปรับปรุง:
- Task 1.2 & 1.3: รวมเป็น 4 ชั่วโมง
- Task 1.4 & 1.5: รวมเป็น 4 ชั่วโมง

รวม: 4+4+4+1 = 13 ชั่วโมง (ยังมากกว่า 8 points)

ตัวจริง 8 จุด ≈ 10-11 ชั่วโมง แล้ว - ยอมรับแล้ว
```

### ตัวอย่างที่ 2: Product Listing (5 จุด)

```
User Story: แสดงรายการผลิตภัณฑ์ (5 จุด)

Task 2.1: Product API Endpoint
├─ GET /api/products
├─ Return: [{ id, name, price, image }]
├─ Pagination: 20 items/page
├─ Assigned: Dev C
├─ Effort: 3 ชั่วโมง
├─ Dependencies: ไม่มี

Task 2.2: Product Listing UI
├─ Display products grid
├─ Show image, name, price
├─ Pagination controls
├─ Assigned: Frontend Dev
├─ Effort: 2 ชั่วโมง
├─ Dependencies: Task 2.1

Task 2.3: Unit Tests
├─ Test API pagination
├─ Test error handling
├─ Coverage: > 80%
├─ Assigned: QA
├─ Effort: 1 ชั่วโมง
├─ Dependencies: Task 2.1

รวม: 3+2+1 = 6 ชั่วโมง (close to 5 points ✓)
```

### Sprint 1 Task Summary

```
Sprint 1 Stories & Tasks:

1. User Registration (8 points)
   ├─ Task 1.1: Create Register API (3h) - Dev A
   ├─ Task 1.2: Email Validation (2h) - Dev B
   ├─ Task 1.3: Tests (2h) - QA
   └─ Total: 7 hours

2. User Login (8 points)
   ├─ Task 2.1: Create Login API (4h) - Dev A
   ├─ Task 2.2: Auth & Token (3h) - Dev B
   ├─ Task 2.3: Tests (2h) - QA
   └─ Total: 9 hours

3. Product Listing (5 points)
   ├─ Task 3.1: Product API (3h) - Dev C
   ├─ Task 3.2: Product UI (2h) - Frontend
   └─ Total: 5 hours

4. Shopping Cart (8 points)
   ├─ Task 4.1: Cart API (3h) - Dev D
   ├─ Task 4.2: Cart UI (3h) - Frontend
   ├─ Task 4.3: Tests (2h) - QA
   └─ Total: 8 hours

Total Tasks: 15-17 tasks
Total Hours: ~30-35 hours
Sprint Goal: 29 points
Status: ✅ Realistic & achievable
```

### Key Takeaway

```
✅ Task Breakdown ต้อง:
  - ชัดเจน (4-8 ชั่วโมง/task)
  - ระบุการพึ่งพา
  - เอา assignment เอาไป
  - Definition of Done เจ๋ก

❌ ข้อผิดพลาดทั่วไป:
  - Tasks เล็กเกินไป (30 นาทีต่อ task)
  - Tasks ใหญ่เกินไป (40+ ชั่วโมง)
  - ไม่ระบุการพึ่งพา
  - ไม่มี Definition of Done
```

---

## 📊 Sprint 1 Planning Summary

### Sprint 1 Goal

```
"ให้ผู้ใช้สามารถ:
1. สมัครสมาชิก
2. เข้าสู่ระบบ
3. ดูผลิตภัณฑ์
4. เพิ่มลงรถเข็น

โดยผ่าน API testing & Unit testing
เพื่อให้พร้อมสำหรับ Sprint 2 (Checkout & Payment)"
```

### Sprint 1 Metrics

```
Duration: 2 weeks (10 working days)
Capacity: 30-32 story points
Selected: 29 points (✓ 91% utilization)
Buffer: 3-5 points (✓ Safe margin)
Total Tasks: ~16 tasks
Team Size: 5 people

Expected Velocity: 25-29 points
(Conservative estimate for Sprint 1)
```

### Commitment

```
Team: "เราอนุญาติทำให้เสร็จ 29 points
       ในเวลา 2 สัปดาห์นี้"

PO: "ขอบคุณ! งานนี้ critical"

Tech Lead: "Risk register prepared,
           dependencies mapped"
```

### Sprint Schedule

```
Day 1 (Monday):
- 09:00-09:15: Sprint Planning (Done! ✓)
- 09:15-10:00: Development Kickoff
- 10:00-17:00: Development

Days 2-9 (Tuesday - Week 2 Thursday):
- 09:00-09:15: Daily Standup
- 09:15-10:00: Code Review & Comments
- 10:00-13:00: Development
- 14:00-17:00: Development
- 17:30: Update Burndown Chart

Day 10 (Friday):
- 09:00-09:30: Demo/Sprint Review
- 09:30-10:00: Retrospective
- 10:00: Sprint 2 Planning (next week)
```

---

## ✅ Deliverables จาก Activity 2

### 1. Sprint 1 Backlog (เอกสาร)

```markdown
# Sprint 1 Backlog

## Sprint Goal

[Sprint goal ตามที่เขียนข้างต้น]

## Selected User Stories (29 points)

1. User Registration (8 points)
2. User Login (8 points)
3. Product Listing (5 points)
4. Shopping Cart (8 points)

## Task Breakdown

[รายละเอียด tasks ทั้งหมด]

## Team Assignment

[ใครทำงานไหน]

## Dependencies

[งานที่พึ่งพากัน]

## Definition of Done

[เกณฑ์ความสำเร็จ]
```

### 2. Sprint 1 Schedule (ตารางเวลา)

```
Date          Event                Duration
Mon 5 Jan     Sprint Planning      1h
Mon-Fri 5-9   Development          40h
Daily 09:00   Daily Standup        15m
Daily 09:15   Code Review          45m
Fri 9 Jan     Sprint Review        30m
Fri 9 Jan     Retrospective        30m
```

### 3. Burndown Chart Template

```
[บันทึก story points ที่เหลือทุกวัน]

Ideal Burndown:
- Day 1: 29 points
- Day 2: 26 points
- Day 3: 23 points
- ...
- Day 10: 0 points

Actual Burndown: [เติมระหว่าง sprint]
```

### 4. Risk Register

```
Risk #1: API Integration (External)
├─ Probability: Medium
├─ Impact: High
└─ Mitigation: Mock API prepared

Risk #2: Database Performance
├─ Probability: Low
├─ Impact: High
└─ Mitigation: Index & Load test

Risk #3: Team Member Sick
├─ Probability: Low
├─ Impact: Medium
└─ Mitigation: Tasks cross-trained

Risk #4: Scope Creep
├─ Probability: High (ปกติ!)
├─ Impact: High
└─ Mitigation: SM protect scope
```

---

## 🎓 การเรียนรู้จากการวางแผน Sprint 1

### ✅ ที่ทำได้ดี

```
1. Realistic Capacity Planning
   - Calculated actual hours available
   - Subtracted overhead & interruptions
   - Conservative 20% buffer

2. Proper Task Breakdown
   - Each story → 3-6 tasks
   - Clear dependencies identified
   - Clear assignments

3. Team Alignment
   - Whole team participated in planning
   - Discussion on complex stories
   - Commitment from team

4. Risk Management
   - Risks identified upfront
   - Mitigation strategies prepared
```

### ⚠️ ที่ต้องพัฒนา

```
1. สปริ้นท์แรก = ยากสำหรับประมาณ
   - ไม่มี historical velocity
   - ต้องใช้ conservative estimates

2. ความไม่แน่นอนธรรมชาติ
   - Integration risks อาจไม่คาดหมาย
   - Learning curve ใหม่

3. Scope Control
   - PO อาจขอเพิ่มครึ่งทาง
   - SM ต้องป้องกัน!
```

### 💡 Key Success Factors

```
✅ Sprint 1 Success = depends on:
1. Conservative capacity planning (✓ done)
2. Realistic story selection (✓ done)
3. Clear task breakdown (✓ done)
4. Team commitment (✓ confirmed)
5. Daily standup discipline (→ during sprint)
6. Code review consistency (→ during sprint)
7. Risk management (✓ prepared)
8. Scope protection (→ during sprint)
```

---

## 🎯 Next Steps

### สัปดาห์ 8 (Sprint 1 Development)

```
Week 8 (Weeks 1-2 of Sprint 1):
- Development starts
- Daily standups 09:00
- Code reviews every morning
- Burndown chart updated daily
- Risk tracking
- Team communication via Slack
```

### Sprint 1 Milestones

```
Day 3: 50% tasks started
Day 5: 75% tasks in progress
Day 7: Testing starts
Day 9: Code review complete
Day 10: Sprint review & retrospective
```

### Sprint 1 Success Metrics

```
✅ All 4 stories completed
✅ 29 points delivered
✅ 100% unit test coverage
✅ Zero critical bugs in review
✅ Team morale positive
✅ No scope creep
→ Ready for Sprint 2!
```

---

## ✅ สรุป Activity 2

| ส่วน | เป้าหมาย            | ผลลัพธ์            | สถานะ  |
| ---- | ------------------- | ------------------ | ------ |
| 1    | Estimate 10 stories | 78 points total    | ✅     |
| 2    | Select 4 stories    | 29 points chosen   | ✅     |
| 3    | Break into tasks    | 16 tasks, mapped   | ✅     |
|      | **Total**           | **Sprint 1 Ready** | **✅** |

**ทีม: "Ready to start Sprint 1! 🚀"**

---
