codehava-agent-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/bin/cli.js +56 -0
- package/package.json +26 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
- package/templates/.agent/agents/backend-specialist.md +263 -0
- package/templates/.agent/agents/code-archaeologist.md +106 -0
- package/templates/.agent/agents/database-architect.md +226 -0
- package/templates/.agent/agents/debugger.md +225 -0
- package/templates/.agent/agents/devops-engineer.md +242 -0
- package/templates/.agent/agents/documentation-writer.md +104 -0
- package/templates/.agent/agents/explorer-agent.md +73 -0
- package/templates/.agent/agents/frontend-specialist.md +593 -0
- package/templates/.agent/agents/game-developer.md +162 -0
- package/templates/.agent/agents/mobile-developer.md +377 -0
- package/templates/.agent/agents/orchestrator.md +416 -0
- package/templates/.agent/agents/penetration-tester.md +188 -0
- package/templates/.agent/agents/performance-optimizer.md +187 -0
- package/templates/.agent/agents/product-manager.md +112 -0
- package/templates/.agent/agents/product-owner.md +95 -0
- package/templates/.agent/agents/project-planner.md +406 -0
- package/templates/.agent/agents/qa-automation-engineer.md +103 -0
- package/templates/.agent/agents/security-auditor.md +170 -0
- package/templates/.agent/agents/seo-specialist.md +111 -0
- package/templates/.agent/agents/test-engineer.md +158 -0
- package/templates/.agent/mcp_config.json +129 -0
- package/templates/.agent/rules/GEMINI.md +273 -0
- package/templates/.agent/scripts/auto_preview.py +148 -0
- package/templates/.agent/scripts/checklist.py +217 -0
- package/templates/.agent/scripts/session_manager.py +120 -0
- package/templates/.agent/scripts/verify_all.py +327 -0
- package/templates/.agent/skills/api-patterns/SKILL.md +81 -0
- package/templates/.agent/skills/api-patterns/api-style.md +42 -0
- package/templates/.agent/skills/api-patterns/auth.md +24 -0
- package/templates/.agent/skills/api-patterns/documentation.md +26 -0
- package/templates/.agent/skills/api-patterns/graphql.md +41 -0
- package/templates/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/templates/.agent/skills/api-patterns/response.md +37 -0
- package/templates/.agent/skills/api-patterns/rest.md +40 -0
- package/templates/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/templates/.agent/skills/api-patterns/security-testing.md +122 -0
- package/templates/.agent/skills/api-patterns/trpc.md +41 -0
- package/templates/.agent/skills/api-patterns/versioning.md +22 -0
- package/templates/.agent/skills/app-builder/SKILL.md +75 -0
- package/templates/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/templates/.agent/skills/app-builder/feature-building.md +53 -0
- package/templates/.agent/skills/app-builder/project-detection.md +34 -0
- package/templates/.agent/skills/app-builder/scaffolding.md +118 -0
- package/templates/.agent/skills/app-builder/tech-stack.md +41 -0
- package/templates/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/templates/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/templates/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/templates/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/templates/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/templates/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/templates/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/templates/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/templates/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
- package/templates/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
- package/templates/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
- package/templates/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
- package/templates/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/templates/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
- package/templates/.agent/skills/architecture/SKILL.md +55 -0
- package/templates/.agent/skills/architecture/context-discovery.md +43 -0
- package/templates/.agent/skills/architecture/examples.md +94 -0
- package/templates/.agent/skills/architecture/pattern-selection.md +68 -0
- package/templates/.agent/skills/architecture/patterns-reference.md +50 -0
- package/templates/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/templates/.agent/skills/bash-linux/SKILL.md +199 -0
- package/templates/.agent/skills/behavioral-modes/SKILL.md +242 -0
- package/templates/.agent/skills/better-auth-patterns/SKILL.md +121 -0
- package/templates/.agent/skills/brainstorming/SKILL.md +163 -0
- package/templates/.agent/skills/brainstorming/dynamic-questioning.md +350 -0
- package/templates/.agent/skills/bullmq-worker/SKILL.md +124 -0
- package/templates/.agent/skills/clean-code/SKILL.md +201 -0
- package/templates/.agent/skills/code-review-checklist/SKILL.md +109 -0
- package/templates/.agent/skills/database-design/SKILL.md +52 -0
- package/templates/.agent/skills/database-design/database-selection.md +43 -0
- package/templates/.agent/skills/database-design/indexing.md +39 -0
- package/templates/.agent/skills/database-design/migrations.md +48 -0
- package/templates/.agent/skills/database-design/optimization.md +36 -0
- package/templates/.agent/skills/database-design/orm-selection.md +30 -0
- package/templates/.agent/skills/database-design/schema-design.md +56 -0
- package/templates/.agent/skills/database-design/scripts/schema_validator.py +172 -0
- package/templates/.agent/skills/deployment-procedures/SKILL.md +241 -0
- package/templates/.agent/skills/doc.md +177 -0
- package/templates/.agent/skills/documentation-templates/SKILL.md +194 -0
- package/templates/.agent/skills/feature-spec-writer/SKILL.md +76 -0
- package/templates/.agent/skills/frontend-design/SKILL.md +452 -0
- package/templates/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/templates/.agent/skills/frontend-design/color-system.md +311 -0
- package/templates/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/templates/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/templates/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/templates/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/templates/.agent/skills/frontend-design/typography-system.md +345 -0
- package/templates/.agent/skills/frontend-design/ux-psychology.md +1116 -0
- package/templates/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/templates/.agent/skills/game-development/2d-games/SKILL.md +119 -0
- package/templates/.agent/skills/game-development/3d-games/SKILL.md +135 -0
- package/templates/.agent/skills/game-development/SKILL.md +167 -0
- package/templates/.agent/skills/game-development/game-art/SKILL.md +185 -0
- package/templates/.agent/skills/game-development/game-audio/SKILL.md +190 -0
- package/templates/.agent/skills/game-development/game-design/SKILL.md +129 -0
- package/templates/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
- package/templates/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
- package/templates/.agent/skills/game-development/pc-games/SKILL.md +144 -0
- package/templates/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
- package/templates/.agent/skills/game-development/web-games/SKILL.md +150 -0
- package/templates/.agent/skills/geo-fundamentals/SKILL.md +156 -0
- package/templates/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
- package/templates/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/templates/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/templates/.agent/skills/intelligent-routing/SKILL.md +335 -0
- package/templates/.agent/skills/lint-and-validate/SKILL.md +45 -0
- package/templates/.agent/skills/lint-and-validate/scripts/lint_runner.py +184 -0
- package/templates/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
- package/templates/.agent/skills/mcp-builder/SKILL.md +176 -0
- package/templates/.agent/skills/mobile-design/SKILL.md +394 -0
- package/templates/.agent/skills/mobile-design/decision-trees.md +516 -0
- package/templates/.agent/skills/mobile-design/mobile-backend.md +491 -0
- package/templates/.agent/skills/mobile-design/mobile-color-system.md +420 -0
- package/templates/.agent/skills/mobile-design/mobile-debugging.md +122 -0
- package/templates/.agent/skills/mobile-design/mobile-design-thinking.md +357 -0
- package/templates/.agent/skills/mobile-design/mobile-navigation.md +458 -0
- package/templates/.agent/skills/mobile-design/mobile-performance.md +767 -0
- package/templates/.agent/skills/mobile-design/mobile-testing.md +356 -0
- package/templates/.agent/skills/mobile-design/mobile-typography.md +433 -0
- package/templates/.agent/skills/mobile-design/platform-android.md +666 -0
- package/templates/.agent/skills/mobile-design/platform-ios.md +561 -0
- package/templates/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
- package/templates/.agent/skills/mobile-design/touch-psychology.md +537 -0
- package/templates/.agent/skills/neo-storage/SKILL.md +115 -0
- package/templates/.agent/skills/nextjs-api-route/SKILL.md +134 -0
- package/templates/.agent/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +351 -0
- package/templates/.agent/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +240 -0
- package/templates/.agent/skills/nextjs-react-expert/3-server-server-side-performance.md +490 -0
- package/templates/.agent/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +264 -0
- package/templates/.agent/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
- package/templates/.agent/skills/nextjs-react-expert/6-rendering-rendering-performance.md +432 -0
- package/templates/.agent/skills/nextjs-react-expert/7-js-javascript-performance.md +684 -0
- package/templates/.agent/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +150 -0
- package/templates/.agent/skills/nextjs-react-expert/9-cache-components.md +103 -0
- package/templates/.agent/skills/nextjs-react-expert/SKILL.md +293 -0
- package/templates/.agent/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
- package/templates/.agent/skills/nextjs-react-expert/scripts/react_performance_checker.py +252 -0
- package/templates/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/.agent/skills/parallel-agents/SKILL.md +175 -0
- package/templates/.agent/skills/performance-profiling/SKILL.md +143 -0
- package/templates/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
- package/templates/.agent/skills/plan-writing/SKILL.md +152 -0
- package/templates/.agent/skills/powershell-windows/SKILL.md +167 -0
- package/templates/.agent/skills/prisma-7-patterns/SKILL.md +91 -0
- package/templates/.agent/skills/python-patterns/SKILL.md +441 -0
- package/templates/.agent/skills/red-team-tactics/SKILL.md +199 -0
- package/templates/.agent/skills/rust-pro/SKILL.md +176 -0
- package/templates/.agent/skills/seo-fundamentals/SKILL.md +129 -0
- package/templates/.agent/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
- package/templates/.agent/skills/server-management/SKILL.md +161 -0
- package/templates/.agent/skills/systematic-debugging/SKILL.md +109 -0
- package/templates/.agent/skills/tailwind-patterns/SKILL.md +269 -0
- package/templates/.agent/skills/tdd-workflow/SKILL.md +149 -0
- package/templates/.agent/skills/testing-patterns/SKILL.md +178 -0
- package/templates/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/templates/.agent/skills/uu-pdp-feature-check/SKILL.md +116 -0
- package/templates/.agent/skills/vibe-buildplan/SKILL.md +232 -0
- package/templates/.agent/skills/vibe-prd/SKILL.md +226 -0
- package/templates/.agent/skills/vibe-research/SKILL.md +162 -0
- package/templates/.agent/skills/vibe-techdesign/SKILL.md +195 -0
- package/templates/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
- package/templates/.agent/skills/vulnerability-scanner/checklists.md +121 -0
- package/templates/.agent/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/templates/.agent/skills/web-design-guidelines/SKILL.md +57 -0
- package/templates/.agent/skills/webapp-testing/SKILL.md +187 -0
- package/templates/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
- package/templates/.agent/skills/xendit-integration/SKILL.md +100 -0
- package/templates/.agent/snippets/@react-component-template.tsx +29 -0
- package/templates/.agent/workflows/brainstorm.md +113 -0
- package/templates/.agent/workflows/create.md +59 -0
- package/templates/.agent/workflows/db-migrate.md +26 -0
- package/templates/.agent/workflows/debug.md +103 -0
- package/templates/.agent/workflows/deploy.md +35 -0
- package/templates/.agent/workflows/dev-reset.md +40 -0
- package/templates/.agent/workflows/enhance.md +63 -0
- package/templates/.agent/workflows/git-commit.md +24 -0
- package/templates/.agent/workflows/health-check.md +34 -0
- package/templates/.agent/workflows/new-feature.md +32 -0
- package/templates/.agent/workflows/orchestrate.md +237 -0
- package/templates/.agent/workflows/plan.md +89 -0
- package/templates/.agent/workflows/preview.md +81 -0
- package/templates/.agent/workflows/status.md +86 -0
- package/templates/.agent/workflows/test.md +144 -0
- package/templates/.agent/workflows/ui-ux-pro-max.md +296 -0
- package/templates/.agent/workflows/vibe-plan.md +133 -0
- package/templates/.agent/workflows/vibe-recap.md +17 -0
- package/templates/.antigravity/rules.md +64 -0
- package/templates/AGENTS.md +268 -0
- package/templates/docs/00A-PROJECT-CHARTER.md +33 -0
- package/templates/docs/00B-BRD.md +25 -0
- package/templates/docs/01-PRD.md +122 -0
- package/templates/docs/01B-SRS-LENGKAP.md +60 -0
- package/templates/docs/02-TECH-DESIGN.md +491 -0
- package/templates/docs/03-UI-GUIDELINES.md +301 -0
- package/templates/docs/04-BACKLOG.md +127 -0
- package/templates/docs/05-DEPLOYMENT.md +363 -0
- package/templates/docs/06-DEVELOPMENT-LOG.md +78 -0
- package/templates/specs/README.md +54 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: brainstorming
|
|
3
|
+
description: Socratic questioning protocol + user communication. MANDATORY for complex requests, new features, or unclear requirements. Includes progress reporting and error handling.
|
|
4
|
+
allowed-tools: Read, Glob, Grep
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Brainstorming & Communication Protocol
|
|
8
|
+
|
|
9
|
+
> **MANDATORY:** Use for complex/vague requests, new features, updates.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 🛑 SOCRATIC GATE (ENFORCEMENT)
|
|
14
|
+
|
|
15
|
+
### When to Trigger
|
|
16
|
+
|
|
17
|
+
| Pattern | Action |
|
|
18
|
+
|---------|--------|
|
|
19
|
+
| "Build/Create/Make [thing]" without details | 🛑 ASK 3 questions |
|
|
20
|
+
| Complex feature or architecture | 🛑 Clarify before implementing |
|
|
21
|
+
| Update/change request | 🛑 Confirm scope |
|
|
22
|
+
| Vague requirements | 🛑 Ask purpose, users, constraints |
|
|
23
|
+
|
|
24
|
+
### 🚫 MANDATORY: 3 Questions Before Implementation
|
|
25
|
+
|
|
26
|
+
1. **STOP** - Do NOT start coding
|
|
27
|
+
2. **ASK** - Minimum 3 questions:
|
|
28
|
+
- 🎯 Purpose: What problem are you solving?
|
|
29
|
+
- 👥 Users: Who will use this?
|
|
30
|
+
- 📦 Scope: Must-have vs nice-to-have?
|
|
31
|
+
3. **WAIT** - Get response before proceeding
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🧠 Dynamic Question Generation
|
|
36
|
+
|
|
37
|
+
**⛔ NEVER use static templates.** Read `dynamic-questioning.md` for principles.
|
|
38
|
+
|
|
39
|
+
### Core Principles
|
|
40
|
+
|
|
41
|
+
| Principle | Meaning |
|
|
42
|
+
|-----------|---------|
|
|
43
|
+
| **Questions Reveal Consequences** | Each question connects to an architectural decision |
|
|
44
|
+
| **Context Before Content** | Understand greenfield/feature/refactor/debug context first |
|
|
45
|
+
| **Minimum Viable Questions** | Each question must eliminate implementation paths |
|
|
46
|
+
| **Generate Data, Not Assumptions** | Don't guess—ask with trade-offs |
|
|
47
|
+
|
|
48
|
+
### Question Generation Process
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
1. Parse request → Extract domain, features, scale indicators
|
|
52
|
+
2. Identify decision points → Blocking vs. deferable
|
|
53
|
+
3. Generate questions → Priority: P0 (blocking) > P1 (high-leverage) > P2 (nice-to-have)
|
|
54
|
+
4. Format with trade-offs → What, Why, Options, Default
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Question Format (MANDATORY)
|
|
58
|
+
|
|
59
|
+
```markdown
|
|
60
|
+
### [PRIORITY] **[DECISION POINT]**
|
|
61
|
+
|
|
62
|
+
**Question:** [Clear question]
|
|
63
|
+
|
|
64
|
+
**Why This Matters:**
|
|
65
|
+
- [Architectural consequence]
|
|
66
|
+
- [Affects: cost/complexity/timeline/scale]
|
|
67
|
+
|
|
68
|
+
**Options:**
|
|
69
|
+
| Option | Pros | Cons | Best For |
|
|
70
|
+
|--------|------|------|----------|
|
|
71
|
+
| A | [+] | [-] | [Use case] |
|
|
72
|
+
|
|
73
|
+
**If Not Specified:** [Default + rationale]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**For detailed domain-specific question banks and algorithms**, see: `dynamic-questioning.md`
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Progress Reporting (PRINCIPLE-BASED)
|
|
81
|
+
|
|
82
|
+
**PRINCIPLE:** Transparency builds trust. Status must be visible and actionable.
|
|
83
|
+
|
|
84
|
+
### Status Board Format
|
|
85
|
+
|
|
86
|
+
| Agent | Status | Current Task | Progress |
|
|
87
|
+
|-------|--------|--------------|----------|
|
|
88
|
+
| [Agent Name] | ✅🔄⏳❌⚠️ | [Task description] | [% or count] |
|
|
89
|
+
|
|
90
|
+
### Status Icons
|
|
91
|
+
|
|
92
|
+
| Icon | Meaning | Usage |
|
|
93
|
+
|------|---------|-------|
|
|
94
|
+
| ✅ | Completed | Task finished successfully |
|
|
95
|
+
| 🔄 | Running | Currently executing |
|
|
96
|
+
| ⏳ | Waiting | Blocked, waiting for dependency |
|
|
97
|
+
| ❌ | Error | Failed, needs attention |
|
|
98
|
+
| ⚠️ | Warning | Potential issue, not blocking |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Error Handling (PRINCIPLE-BASED)
|
|
103
|
+
|
|
104
|
+
**PRINCIPLE:** Errors are opportunities for clear communication.
|
|
105
|
+
|
|
106
|
+
### Error Response Pattern
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
1. Acknowledge the error
|
|
110
|
+
2. Explain what happened (user-friendly)
|
|
111
|
+
3. Offer specific solutions with trade-offs
|
|
112
|
+
4. Ask user to choose or provide alternative
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Error Categories
|
|
116
|
+
|
|
117
|
+
| Category | Response Strategy |
|
|
118
|
+
|----------|-------------------|
|
|
119
|
+
| **Port Conflict** | Offer alternative port or close existing |
|
|
120
|
+
| **Dependency Missing** | Auto-install or ask permission |
|
|
121
|
+
| **Build Failure** | Show specific error + suggested fix |
|
|
122
|
+
| **Unclear Error** | Ask for specifics: screenshot, console output |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Completion Message (PRINCIPLE-BASED)
|
|
127
|
+
|
|
128
|
+
**PRINCIPLE:** Celebrate success, guide next steps.
|
|
129
|
+
|
|
130
|
+
### Completion Structure
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
1. Success confirmation (celebrate briefly)
|
|
134
|
+
2. Summary of what was done (concrete)
|
|
135
|
+
3. How to verify/test (actionable)
|
|
136
|
+
4. Next steps suggestion (proactive)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Communication Principles
|
|
142
|
+
|
|
143
|
+
| Principle | Implementation |
|
|
144
|
+
|-----------|----------------|
|
|
145
|
+
| **Concise** | No unnecessary details, get to point |
|
|
146
|
+
| **Visual** | Use emojis (✅🔄⏳❌) for quick scanning |
|
|
147
|
+
| **Specific** | "~2 minutes" not "wait a bit" |
|
|
148
|
+
| **Alternatives** | Offer multiple paths when stuck |
|
|
149
|
+
| **Proactive** | Suggest next step after completion |
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Anti-Patterns (AVOID)
|
|
154
|
+
|
|
155
|
+
| Anti-Pattern | Why |
|
|
156
|
+
|--------------|-----|
|
|
157
|
+
| Jumping to solutions before understanding | Wastes time on wrong problem |
|
|
158
|
+
| Assuming requirements without asking | Creates wrong output |
|
|
159
|
+
| Over-engineering first version | Delays value delivery |
|
|
160
|
+
| Ignoring constraints | Creates unusable solutions |
|
|
161
|
+
| "I think" phrases | Uncertainty → Ask instead |
|
|
162
|
+
|
|
163
|
+
---
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# Dynamic Question Generation
|
|
2
|
+
|
|
3
|
+
> **PRINCIPLE:** Questions are not about gathering data—they are about **revealing architectural consequences**.
|
|
4
|
+
>
|
|
5
|
+
> Every question must connect to a concrete implementation decision that affects cost, complexity, or timeline.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🧠 Core Principles
|
|
10
|
+
|
|
11
|
+
### 1. Questions Reveal Consequences
|
|
12
|
+
|
|
13
|
+
A good question is not "What color do you want?" but:
|
|
14
|
+
|
|
15
|
+
```markdown
|
|
16
|
+
❌ BAD: "What authentication method?"
|
|
17
|
+
✅ GOOD: "Should users sign up with email/password or social login?
|
|
18
|
+
|
|
19
|
+
Impact:
|
|
20
|
+
- Email/Pass → Need password reset, hashing, 2FA infrastructure
|
|
21
|
+
- Social → OAuth providers, user profile mapping, less control
|
|
22
|
+
|
|
23
|
+
Trade-off: Security vs. Development time vs. User friction"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Context Before Content
|
|
27
|
+
|
|
28
|
+
First understand **where** this request fits:
|
|
29
|
+
|
|
30
|
+
| Context | Question Focus |
|
|
31
|
+
|---------|----------------|
|
|
32
|
+
| **Greenfield** (new project) | Foundation decisions: stack, hosting, scale |
|
|
33
|
+
| **Feature Addition** | Integration points, existing patterns, breaking changes |
|
|
34
|
+
| **Refactor** | Why refactor? Performance? Maintainability? What's broken? |
|
|
35
|
+
| **Debug** | Symptoms → Root cause → Reproduction path |
|
|
36
|
+
|
|
37
|
+
### 3. Minimum Viable Questions
|
|
38
|
+
|
|
39
|
+
**PRINCIPLE:** Each question must eliminate a fork in the implementation road.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
Before Question:
|
|
43
|
+
├── Path A: Do X (5 min)
|
|
44
|
+
├── Path B: Do Y (15 min)
|
|
45
|
+
└── Path C: Do Z (1 hour)
|
|
46
|
+
|
|
47
|
+
After Question:
|
|
48
|
+
└── Path Confirmed: Do X (5 min)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If a question doesn't reduce implementation paths → **DELETE IT**.
|
|
52
|
+
|
|
53
|
+
### 4. Questions Generate Data, Not Assumptions
|
|
54
|
+
|
|
55
|
+
```markdown
|
|
56
|
+
❌ ASSUMPTION: "User probably wants Stripe for payments"
|
|
57
|
+
✅ QUESTION: "Which payment provider fits your needs?
|
|
58
|
+
|
|
59
|
+
Stripe → Best documentation, 2.9% + $0.30, US-centric
|
|
60
|
+
LemonSqueezy → Merchant of Record, 5% + $0.50, global taxes
|
|
61
|
+
Paddle → Complex pricing, handles EU VAT, enterprise focus"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 📋 Question Generation Algorithm
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
INPUT: User request + Context (greenfield/feature/refactor/debug)
|
|
70
|
+
│
|
|
71
|
+
├── STEP 1: Parse Request
|
|
72
|
+
│ ├── Extract domain (ecommerce, auth, realtime, cms, etc.)
|
|
73
|
+
│ ├── Extract features (explicit and implied)
|
|
74
|
+
│ └── Extract scale indicators (users, data volume, frequency)
|
|
75
|
+
│
|
|
76
|
+
├── STEP 2: Identify Decision Points
|
|
77
|
+
│ ├── What MUST be decided before coding? (blocking)
|
|
78
|
+
│ ├── What COULD be decided later? (deferable)
|
|
79
|
+
│ └── What has ARCHITECTURAL impact? (high-leverage)
|
|
80
|
+
│
|
|
81
|
+
├── STEP 3: Generate Questions (Priority Order)
|
|
82
|
+
│ ├── P0: Blocking decisions (cannot proceed without answer)
|
|
83
|
+
│ ├── P1: High-leverage (affects >30% of implementation)
|
|
84
|
+
│ ├── P2: Medium-leverage (affects specific features)
|
|
85
|
+
│ └── P3: Nice-to-have (edge cases, optimization)
|
|
86
|
+
│
|
|
87
|
+
└── STEP 4: Format Each Question
|
|
88
|
+
├── What: Clear question
|
|
89
|
+
├── Why: Impact on implementation
|
|
90
|
+
├── Options: Trade-offs (not just A vs B)
|
|
91
|
+
└── Default: What happens if user doesn't answer
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 🎯 Domain-Specific Question Banks
|
|
97
|
+
|
|
98
|
+
### E-Commerce
|
|
99
|
+
|
|
100
|
+
| Question | Why It Matters | Trade-offs |
|
|
101
|
+
|----------|----------------|------------|
|
|
102
|
+
| **Single or Multi-vendor?** | Multi-vendor → Commission logic, vendor dashboards, split payments | +Revenue, -Complexity |
|
|
103
|
+
| **Inventory Tracking?** | Needs stock tables, reservation logic, low-stock alerts | +Accuracy, -Development time |
|
|
104
|
+
| **Digital or Physical Products?** | Digital → Download links, no shipping | Physical → Shipping APIs, tracking |
|
|
105
|
+
| **Subscription or One-time?** | Subscription → Recurring billing, dunning, proration | +Revenue, -Complexity |
|
|
106
|
+
|
|
107
|
+
### Authentication
|
|
108
|
+
|
|
109
|
+
| Question | Why It Matters | Trade-offs |
|
|
110
|
+
|----------|----------------|------------|
|
|
111
|
+
| **Social Login Needed?** | OAuth providers vs. password reset infrastructure | +UX, -Control |
|
|
112
|
+
| **Role-Based Permissions?** | RBAC tables, policy enforcement, admin UI | +Security, -Development time |
|
|
113
|
+
| **2FA Required?** | TOTP/SMI infrastructure, backup codes, recovery flow | +Security, -UX friction |
|
|
114
|
+
| **Email Verification?** | Verification tokens, email service, resend logic | +Security, -Sign-up friction |
|
|
115
|
+
|
|
116
|
+
### Real-time
|
|
117
|
+
|
|
118
|
+
| Question | Why It Matters | Trade-offs |
|
|
119
|
+
|----------|----------------|------------|
|
|
120
|
+
| **WebSocket or Polling?** | WS → Server scaling, connection management | Polling → Simpler, higher latency |
|
|
121
|
+
| **Expected Concurrent Users?** | <100 → Single server, >1000 → Redis pub/sub, >10k → specialized infra | +Scale, -Complexity |
|
|
122
|
+
| **Message Persistence?** | History tables, storage costs, pagination | +UX, -Storage |
|
|
123
|
+
| **Ephemeral or Durable?** | Ephemeral → In-memory, Durable → Database write before emit | +Reliability, -Latency |
|
|
124
|
+
|
|
125
|
+
### Content/CMS
|
|
126
|
+
|
|
127
|
+
| Question | Why It Matters | Trade-offs |
|
|
128
|
+
|----------|----------------|------------|
|
|
129
|
+
| **Rich Text or Markdown?** | Rich Text → Sanitization, XSS risks | Markdown → Simple, no WYSIWYG |
|
|
130
|
+
| **Draft/Publish Workflow?** | Status field, scheduled jobs, versioning | +Control, -Complexity |
|
|
131
|
+
| **Media Handling?** | Upload endpoints, storage, optimization | +Features, -Development time |
|
|
132
|
+
| **Multi-language?** | i18n tables, translation UI, fallback logic | +Reach, -Complexity |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 📐 Dynamic Question Template
|
|
137
|
+
|
|
138
|
+
```markdown
|
|
139
|
+
Based on your request for [DOMAIN] [FEATURE]:
|
|
140
|
+
|
|
141
|
+
## 🔴 CRITICAL (Blocking Decisions)
|
|
142
|
+
|
|
143
|
+
### 1. **[DECISION POINT]**
|
|
144
|
+
|
|
145
|
+
**Question:** [Clear, specific question]
|
|
146
|
+
|
|
147
|
+
**Why This Matters:**
|
|
148
|
+
- [Explain architectural consequence]
|
|
149
|
+
- [Affects: cost / complexity / timeline / scale]
|
|
150
|
+
|
|
151
|
+
**Options:**
|
|
152
|
+
| Option | Pros | Cons | Best For |
|
|
153
|
+
|--------|------|------|----------|
|
|
154
|
+
| A | [Advantage] | [Disadvantage] | [Use case] |
|
|
155
|
+
| B | [Advantage] | [Disadvantage] | [Use case] |
|
|
156
|
+
|
|
157
|
+
**If Not Specified:** [Default choice + rationale]
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 🟡 HIGH-LEVERAGE (Affects Implementation)
|
|
162
|
+
|
|
163
|
+
### 2. **[DECISION POINT]**
|
|
164
|
+
[Same format]
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 🟢 NICE-TO-HAVE (Edge Cases)
|
|
169
|
+
|
|
170
|
+
### 3. **[DECISION POINT]**
|
|
171
|
+
[Same format]
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🔄 Iterative Questioning
|
|
177
|
+
|
|
178
|
+
### First Pass (3-5 Questions)
|
|
179
|
+
Focus on **blocking decisions**. Don't proceed without answers.
|
|
180
|
+
|
|
181
|
+
### Second Pass (After Initial Implementation)
|
|
182
|
+
As patterns emerge, ask:
|
|
183
|
+
- "This feature implies [X]. Should we handle [edge case] now or defer?"
|
|
184
|
+
- "We're using [Pattern A]. Should [Feature B] follow the same pattern?"
|
|
185
|
+
|
|
186
|
+
### Third Pass (Optimization)
|
|
187
|
+
When functionality works:
|
|
188
|
+
- "Performance bottleneck at [X]. Optimize now or acceptable for now?"
|
|
189
|
+
- "Refactor [Y] for maintainability or ship as-is?"
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 🎭 Example: Full Question Generation
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
USER REQUEST: "Build an Instagram clone"
|
|
197
|
+
|
|
198
|
+
STEP 1: Parse
|
|
199
|
+
├── Domain: Social Media
|
|
200
|
+
├── Features: Photo sharing, engagement (likes/comments), user profiles
|
|
201
|
+
├── Implied: Feed, following, authentication
|
|
202
|
+
└── Scale: Potentially high (social apps go viral)
|
|
203
|
+
|
|
204
|
+
STEP 2: Decision Points
|
|
205
|
+
├── Blocking: Storage strategy, authentication method, feed type
|
|
206
|
+
├── High-leverage: Real-time notifications, data model complexity
|
|
207
|
+
└── Deferable: Analytics, advanced search, reels/video
|
|
208
|
+
|
|
209
|
+
STEP 3: Generate Questions (Priority)
|
|
210
|
+
|
|
211
|
+
P0 (Blocking):
|
|
212
|
+
1. Storage Strategy → Affects architecture, cost, speed
|
|
213
|
+
2. Feed Algorithm → Affects database queries, complexity
|
|
214
|
+
3. Auth Method → Affects dev time, UX, security
|
|
215
|
+
|
|
216
|
+
P1 (High-leverage):
|
|
217
|
+
4. Real-time Notifications → WebSocket vs polling
|
|
218
|
+
5. Media Processing → Client-side vs server-side optimization
|
|
219
|
+
|
|
220
|
+
P2 (Deferable):
|
|
221
|
+
6. Story/Reels → Major feature creep, defer to v2
|
|
222
|
+
7. DM/Chat → Separate subsystem, defer to v2
|
|
223
|
+
|
|
224
|
+
STEP 4: Format Output
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 📊 Generated Output (Example)
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
Based on your Instagram clone request:
|
|
233
|
+
|
|
234
|
+
## 🔴 CRITICAL DECISIONS (Cannot Proceed Without Answers)
|
|
235
|
+
|
|
236
|
+
### 1. **Photo Storage Strategy**
|
|
237
|
+
|
|
238
|
+
**Question:** Where will user photos be stored and served?
|
|
239
|
+
|
|
240
|
+
**Why This Matters:**
|
|
241
|
+
- Affects: Monthly hosting costs, page load speed, CDN complexity
|
|
242
|
+
- High-volume social apps: 1000 users × 10 photos × 2MB = 20GB storage
|
|
243
|
+
|
|
244
|
+
**Options:**
|
|
245
|
+
| Option | Cost | Speed | Complexity | Best For |
|
|
246
|
+
|--------|------|-------|------------|----------|
|
|
247
|
+
| **Cloudinary** | $89/mo (25GB) | Fast (CDN) | Low | MVP, rapid launch |
|
|
248
|
+
| **AWS S3 + CloudFront** | $0.023/GB | Fast (CDN) | Medium | Production, cost-optimized |
|
|
249
|
+
| **Supabase Storage** | Free tier 1GB | Medium | Low | Small scale, simple |
|
|
250
|
+
| **Local Storage** | Server cost | Slow | Low | Development only |
|
|
251
|
+
|
|
252
|
+
**If Not Specified:** Cloudinary (balanced for MVP)
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### 2. **Feed Algorithm Choice**
|
|
257
|
+
|
|
258
|
+
**Question:** How should the main feed work?
|
|
259
|
+
|
|
260
|
+
**Why This Matters:**
|
|
261
|
+
- Affects: Database query complexity, caching strategy, development time
|
|
262
|
+
- Algorithmic feeds require ML infrastructure, ranking signals
|
|
263
|
+
|
|
264
|
+
**Options:**
|
|
265
|
+
| Option | Complexity | Database Impact | Best For |
|
|
266
|
+
|--------|------------|-----------------|----------|
|
|
267
|
+
| **Chronological** | Low | Simple query | Early stage, transparency |
|
|
268
|
+
| **Follow-Only** | Medium | JOIN with pagination | Most social apps |
|
|
269
|
+
| **Algorithmic** | High | Pre-computed feed tables | Instagram competitor |
|
|
270
|
+
|
|
271
|
+
**If Not Specified:** Follow-Only (balanced for social app)
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### 3. **Authentication Approach**
|
|
276
|
+
|
|
277
|
+
**Question:** How do users sign up and login?
|
|
278
|
+
|
|
279
|
+
**Why This Matters:**
|
|
280
|
+
- Affects: Development time (2-5 hours), security posture, UX friction
|
|
281
|
+
|
|
282
|
+
**Options:**
|
|
283
|
+
| Option | Dev Time | Security | UX | Best For |
|
|
284
|
+
|--------|----------|----------|-----|----------|
|
|
285
|
+
| **Email/Password** | 4-5 hrs | High (if 2FA) | Medium | Full control needed |
|
|
286
|
+
| **Social Only** | 1-2 hrs | Provider-dependent | Smooth | B2C, rapid launch |
|
|
287
|
+
| **Magic Link** | 2-3 hrs | Medium | Very smooth | Security-focused |
|
|
288
|
+
| **Clerk/Auth0** | 1 hr | High | Smooth | Fastest to market |
|
|
289
|
+
|
|
290
|
+
**If Not Specified:** Clerk (fastest for MVP)
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 🟡 HIGH-LEVERAGE (Affects Architecture)
|
|
295
|
+
|
|
296
|
+
### 4. **Real-time Notifications**
|
|
297
|
+
|
|
298
|
+
**Question:** Do users need instant notifications for likes/comments?
|
|
299
|
+
|
|
300
|
+
**Why This Matters:**
|
|
301
|
+
- WebSocket adds infrastructure complexity (Redis pub/sub for scaling)
|
|
302
|
+
- Polling is simpler but higher latency
|
|
303
|
+
|
|
304
|
+
**Options:**
|
|
305
|
+
| Option | Complexity | Scale Cost | Best For |
|
|
306
|
+
|--------|------------|------------|----------|
|
|
307
|
+
| **WebSocket + Redis** | High | $10+/mo | >1000 concurrent users |
|
|
308
|
+
| **Polling (30s)** | Low | DB queries | <1000 users |
|
|
309
|
+
| **No Real-time** | None | None | MVP, validate first |
|
|
310
|
+
|
|
311
|
+
**If Not Specified:** Polling for MVP (defer WebSocket until validated)
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## 🟢 NICE-TO-HAVE (Defer to v2)
|
|
316
|
+
|
|
317
|
+
### 5. **Video/Reels Support**
|
|
318
|
+
- Major complexity (video processing, streaming infrastructure)
|
|
319
|
+
- Recommendation: Launch with photos only, add video after validation
|
|
320
|
+
|
|
321
|
+
### 6. **Direct Messaging**
|
|
322
|
+
- Separate subsystem (chat infrastructure different from feed)
|
|
323
|
+
- Recommendation: Use Pusher/Stream for real-time or defer entirely
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## 📋 Summary
|
|
328
|
+
|
|
329
|
+
| Decision | Recommendation | If Changed |
|
|
330
|
+
|----------|----------------|------------|
|
|
331
|
+
| Storage | Cloudinary | +3 hrs setup |
|
|
332
|
+
| Feed | Follow-only | +2 hrs query optimization |
|
|
333
|
+
| Auth | Clerk | -3 hrs dev time |
|
|
334
|
+
| Real-time | Polling | +5 hrs WebSocket setup |
|
|
335
|
+
| Video | Defer to v2 | N/A |
|
|
336
|
+
| DM | Defer to v2 | N/A |
|
|
337
|
+
|
|
338
|
+
**Total Estimated MVP Time:** 15-20 hours with recommendations above
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 🎯 Principles Recap
|
|
344
|
+
|
|
345
|
+
1. **Every question = Architectural decision** → Not data gathering
|
|
346
|
+
2. **Show trade-offs** → User understands consequences
|
|
347
|
+
3. **Prioritize blocking decisions** → Cannot proceed without
|
|
348
|
+
4. **Provide defaults** → If user doesn't answer, we proceed anyway
|
|
349
|
+
5. **Domain-aware** → Ecommerce questions ≠ Auth questions ≠ Real-time questions
|
|
350
|
+
6. **Iterative** → More questions as patterns emerge during implementation
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bullmq-worker
|
|
3
|
+
description: |
|
|
4
|
+
Use when creating background jobs, queues, workers, or scheduling tasks.
|
|
5
|
+
Also use when connecting background job results to Socket.io realtime events
|
|
6
|
+
or FCM push notifications. Triggers on "queue", "job", "worker", "background",
|
|
7
|
+
"BullMQ", "async task", or "scheduled". Do NOT use for synchronous API handlers.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# BullMQ 5 + Socket.io — Pola Wajib Project Ini
|
|
11
|
+
|
|
12
|
+
## Queue Definitions (`lib/queue/index.ts`)
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { Queue } from 'bullmq'
|
|
16
|
+
import { redis } from '@/lib/redis'
|
|
17
|
+
|
|
18
|
+
// Queue names — gunakan konstanta, jangan string literal di mana-mana
|
|
19
|
+
export const QUEUES = {
|
|
20
|
+
EMAIL: 'email',
|
|
21
|
+
PAYMENT: 'payment',
|
|
22
|
+
NOTIFICATION: 'notification',
|
|
23
|
+
FILE: 'file',
|
|
24
|
+
REPORT: 'report',
|
|
25
|
+
} as const
|
|
26
|
+
|
|
27
|
+
export const emailQueue = new Queue(QUEUES.EMAIL, { connection: redis })
|
|
28
|
+
export const paymentQueue = new Queue(QUEUES.PAYMENT, { connection: redis })
|
|
29
|
+
export const notifQueue = new Queue(QUEUES.NOTIFICATION, { connection: redis })
|
|
30
|
+
export const fileQueue = new Queue(QUEUES.FILE, { connection: redis })
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Enqueue Job (dari API Route / Server Action)
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { emailQueue } from '@/lib/queue'
|
|
37
|
+
|
|
38
|
+
// Enqueue dengan retry policy
|
|
39
|
+
await emailQueue.add('send-welcome', {
|
|
40
|
+
userId,
|
|
41
|
+
email,
|
|
42
|
+
name,
|
|
43
|
+
}, {
|
|
44
|
+
attempts: 3,
|
|
45
|
+
backoff: { type: 'exponential', delay: 2000 },
|
|
46
|
+
removeOnComplete: { count: 100 }, // jaga queue bersih
|
|
47
|
+
removeOnFail: { count: 50 },
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Worker dengan Socket.io Emit (`worker/index.ts`)
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { Worker } from 'bullmq'
|
|
55
|
+
import { redis } from '@/lib/redis'
|
|
56
|
+
import { io } from '@/lib/socket'
|
|
57
|
+
|
|
58
|
+
// Pattern: job selesai → emit realtime ke user
|
|
59
|
+
export function setupPaymentWorker() {
|
|
60
|
+
const worker = new Worker(QUEUES.PAYMENT, async (job) => {
|
|
61
|
+
// Proses job
|
|
62
|
+
const result = await processXenditWebhook(job.data)
|
|
63
|
+
return result
|
|
64
|
+
}, { connection: redis, concurrency: 5 })
|
|
65
|
+
|
|
66
|
+
// Setelah job selesai — notify client via Socket.io
|
|
67
|
+
worker.on('completed', (job, result) => {
|
|
68
|
+
if (result.userId) {
|
|
69
|
+
io.to(`user_${result.userId}`).emit('payment:updated', {
|
|
70
|
+
orderId: result.orderId,
|
|
71
|
+
status: result.status,
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Log errors — jangan silent fail
|
|
77
|
+
worker.on('failed', (job, error) => {
|
|
78
|
+
console.error(`[${QUEUES.PAYMENT}] Job ${job?.id} failed:`, error)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return worker
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Alur Lengkap: User Action → Queue → Socket → FCM
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
1. User action → POST /api/[resource]
|
|
89
|
+
2. API Route: enqueue job ke BullMQ
|
|
90
|
+
3. Return 202 Accepted segera ke client
|
|
91
|
+
4. Worker: proses job async
|
|
92
|
+
5. Worker.on('completed'): emit via Socket.io ke browser/Flutter
|
|
93
|
+
6. Worker: enqueue notif ke notification queue
|
|
94
|
+
7. Notification Worker: kirim FCM push notif
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Socket.io Room Convention
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// SELALU join room berdasarkan userId setelah auth
|
|
101
|
+
// Di client:
|
|
102
|
+
socket.emit('join', { userId: session.user.id })
|
|
103
|
+
|
|
104
|
+
// Di server:
|
|
105
|
+
io.on('connection', (socket) => {
|
|
106
|
+
socket.on('join', ({ userId }) => {
|
|
107
|
+
socket.join(`user_${userId}`)
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// Emit ke user spesifik:
|
|
112
|
+
io.to(`user_${userId}`).emit('event:name', data)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Redis Client (`lib/redis/index.ts`)
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { Redis } from 'ioredis'
|
|
119
|
+
|
|
120
|
+
export const redis = new Redis(process.env.REDIS_URL!, {
|
|
121
|
+
maxRetriesPerRequest: null, // required untuk BullMQ
|
|
122
|
+
enableReadyCheck: false,
|
|
123
|
+
})
|
|
124
|
+
```
|