# Rate Limit Tiers: cupu / jago / suhu

## TL;DR

> **Quick Summary**: Seed 3 default pricing packages (cupu Rp25K, jago Rp50K, suhu Rp100K) with scaled rate limits, integrate into app startup, and update dashboard UI to show tier badges with Rupiah formatting.
>
> **Deliverables**:
> - src/lib/db/seedPackages.js - Seed script for 3 default tiers
> - Updated src/lib/auth/seedAdmin.js - Calls seedPackages on startup
> - Updated PackagesClient.jsx - Tier badges + Rp formatting
>
> **Estimated Effort**: Quick
> **Parallel Execution**: YES - 2 waves
> **Critical Path**: Task 1 -> Task 2 -> Task 3

---

## Context

### Original Request
User wants 3 rate limit tiers with Rupiah pricing:
- **cupu** (Rp 25,000) - basic tier, 25 RPM, 2M tokens/day
- **jago** (Rp 50,000) - mid tier, 50 RPM, 4M tokens/day
- **suhu** (Rp 100,000) - premium tier, 100 RPM, 8M tokens/day

### Research Findings
- packages table sudah ada di schema.js dengan semua field
- packagesRepo.js sudah ada dengan createPackage(), getAllPackages()
- seedAdmin.js sudah ada - tinggal tambah seedPackages() call
- PackagesClient.jsx sudah ada - tinggal tambah tier badges + Rp format
- rateLimitMiddleware.js sudah ada - tidak perlu diubah

---

## Work Objectives

### Must Have
- 3 packages with exact names: cupu, jago, suhu
- Prices in Rupiah: 25000, 50000, 100000
- Rate limits scale with price tier
- Seed runs automatically on app startup
- Dashboard shows tier badges with colors

### Must NOT Have
- No changes to rateLimitMiddleware.js
- No changes to schema.js
- No new database migrations
- No payment gateway integration

---

## TODOs

- [x] 1. Create seedPackages.js - seed 3 default tiers

  **What to do**:
  - Create src/lib/db/seedPackages.js
  - Import getAllPackages and createPackage from packagesRepo
  - Define DEFAULT_PACKAGES array with 3 tiers:
    - cupu: Rp 25000, 25 RPM, 5000 RPD, 500K tokens/mo, 2 credit, 2 concurrent
    - jago: Rp 50000, 50 RPM, 25000 RPD, 2M tokens/mo, 10 credit, 5 concurrent
    - suhu: Rp 100000, 100 RPM, 100000 RPD, 5M tokens/mo, 25 credit, 10 concurrent
  - Export seedPackages() function: check existing packages by name, create missing ones
  - Use let seeded = false pattern (same as seedAdmin.js)

  **Recommended Agent Profile**:
  - **Category**: quick
  - **Skills**: None needed

  **References**:
  - src/lib/db/repos/packagesRepo.js:17-60 - createPackage() signature
  - src/lib/auth/seedAdmin.js - Exact pattern to follow

  **Acceptance Criteria**:
  - [ ] File src/lib/db/seedPackages.js exists
  - [ ] Exports seedPackages() async function
  - [ ] Creates 3 packages with correct names and values
  - [ ] Idempotent - running twice creates no duplicates

  **Commit**: feat(db): seed default rate limit tiers (cupu/jago/suhu)
  **Files**: src/lib/db/seedPackages.js

- [x] 2. Update seedAdmin.js to call seedPackages

  **What to do**:
  - Open src/lib/auth/seedAdmin.js
  - Add import: import { seedPackages } from "@/lib/db/seedPackages"
  - After admin creation, call await seedPackages()
  - Wrap in try/catch so admin seeding isnt blocked

  **Recommended Agent Profile**:
  - **Category**: quick
  - **Skills**: None needed

  **References**:
  - src/lib/auth/seedAdmin.js - Full file, add seedPackages call at end

  **Acceptance Criteria**:
  - [ ] seedAdmin.js imports and calls seedPackages()
  - [ ] App starts without errors
  - [ ] Packages are created on first startup

  **Commit**: feat(auth): integrate seedPackages into startup flow
  **Files**: src/lib/auth/seedAdmin.js

- [x] 3. Update PackagesClient.jsx - tier badges + Rp formatting

  **What to do**:
  - Open src/app/(dashboard)/dashboard/packages/PackagesClient.jsx
  - Add tier detection: if package name is cupu/jago/suhu, show colored badge
  - Badge colors: cupu = gray, jago = blue, suhu = gold
  - Badge icons: cupu = eco, jago = bolt, suhu = star
  - Add formatRupiah helper: format price as "Rp XX.XXX" with dot separator
  - Update PackageRow to show tier badge next to name
  - Update price display from "X credits" to "Rp X.XXX"

  **Recommended Agent Profile**:
  - **Category**: visual-engineering
  - **Skills**: None needed

  **References**:
  - src/app/(dashboard)/dashboard/packages/PackagesClient.jsx:391-467 - PackageRow component
  - src/app/(dashboard)/dashboard/packages/PackagesClient.jsx:195-198 - formatNumber helper

  **Acceptance Criteria**:
  - [ ] cupu shows gray badge, jago shows blue, suhu shows gold
  - [ ] Price displays as "Rp 25.000" format
  - [ ] Non-tier packages still display normally

  **Commit**: feat(ui): add tier badges and Rupiah formatting to packages
  **Files**: src/app/(dashboard)/dashboard/packages/PackagesClient.jsx

---

## Final Verification Wave

- [x] F1. Plan Compliance Audit
- [x] F2. Code Quality Review
- [x] F3. Real QA
- [x] F4. Scope Fidelity Check

---

## Success Criteria

```bash
curl -s http://localhost:20123/api/packages | jq ".packages | length"  # Expected: 3
curl -s http://localhost:20123/api/packages | jq ".packages[].name"    # Expected: cupu, jago, suhu
```
