File size: 13,582 Bytes
dcc845c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{
  "patterns": {
    "prd_document_separation": {
      "id": "pat-2025-01-11-001",
      "name": "Document Separation for Complex PRDs",
      "source": "user_feedback",
      "confidence": 0.95,
      "applications": 0,
      "created": "2025-01-11",
      "category": "prd_structure",
      "pattern": "For non-trivial PRDs, split into 4 files with clear purposes",
      "problem": "Single large PRD file (~500 lines) with mixed product/technical content is hard to follow",
      "solution": {
        "files": [
          {
            "name": "{name}-notes.md",
            "purpose": "Thinking process, options analysis",
            "audience": "Self + future reviewers"
          },
          {
            "name": "{name}-task-plan.md",
            "purpose": "Project tracking, phases, progress",
            "audience": "PM + development lead"
          },
          {
            "name": "{name}-prd.md",
            "purpose": "Product requirements (what & why)",
            "audience": "PM + stakeholders + developers"
          },
          {
            "name": "{name}-tech.md",
            "purpose": "Technical design (how)",
            "audience": "Developers + architects"
          }
        ]
      },
      "quality_rules": [
        "PRD focuses on problem, goals, scope, user flows",
        "Tech doc focuses on API, data flow, implementation",
        "Notes document architecture options with A/B/C analysis",
        "Task plan has checkboxes with timestamps",
        "PRD references tech doc, doesn't duplicate"
      ],
      "target_skills": ["prd-planner", "architecting-solutions"]
    },
    "state_monitoring_over_callbacks": {
      "id": "pat-2025-01-11-002",
      "name": "Direct State Monitoring vs Callbacks",
      "source": "implementation_review",
      "confidence": 0.90,
      "applications": 0,
      "created": "2025-01-11",
      "category": "react_patterns",
      "pattern": "Prefer direct state monitoring over callback chains for side effects",
      "problem": "Callback chains passed through multiple layers are hard to trace and debug",
      "solution": {
        "anti_pattern": "useActionQueue({ onRefresh: () => { /* refresh logic */ } });",
        "pattern": "const pendingCount = requests.length;\nconst prevPendingCount = usePrevious(pendingCount);\nuseEffect(() => {\n  if (pendingCount < prevPendingCount) {\n    triggerDataRefresh({ reason: 'completed' });\n  }\n}, [pendingCount, prevPendingCount]);"
      },
      "when_to_use": [
        "State changes need to trigger side effects",
        "Callback chain would be 3+ layers deep",
        "Multiple components need to react to same state change"
      ],
      "quality_rules": [
        "Use usePrevious to detect state changes instead of callbacks when feasible",
        "Keep state monitoring close to where state is consumed",
        "Use callbacks only for cross-component boundaries"
      ],
      "target_skills": ["debugger", "refactoring-specialist"]
    },
    "state_machine_over_booleans": {
      "id": "pat-2025-01-11-003",
      "name": "State Machine Over Boolean Flags",
      "source": "implementation_review",
      "confidence": 0.85,
      "applications": 0,
      "created": "2025-01-11",
      "category": "async_patterns",
      "pattern": "Use state machines for async operations with multiple phases",
      "problem": "Simple boolean flags can't represent 'waiting to run' vs 'currently running', causing race conditions",
      "solution": {
        "anti_pattern": "const inFlight = false;",
        "pattern": "enum EStatus {\n  Idle = 'idle',\n  Waiting = 'waiting',  // Scheduled but not running yet\n  Running = 'running',\n}"
      },
      "benefits": [
        "Prevents race conditions (can't schedule new request while running)",
        "Distinguishes 'waiting to run' from 'currently running'",
        "Easier to debug and log state transitions"
      ],
      "quality_rules": [
        "Use state machine for async operations with multiple phases",
        "Prevent state transitions that don't make sense",
        "Log state transitions for debugging"
      ],
      "target_skills": ["debugger", "api-designer"]
    },
    "measurable_success_criteria": {
      "id": "pat-2025-01-11-004",
      "name": "Measurable Success Criteria",
      "source": "user_feedback",
      "confidence": 0.90,
      "applications": 0,
      "created": "2025-01-11",
      "category": "prd_quality",
      "pattern": "Success criteria must include specific numbers/timings to enable verification",
      "problem": "Vague success criteria like 'data refreshes' don't enable testing or verification",
      "solution": {
        "bad_examples": [
          "Data refreshes after transaction",
          "Manual refresh works",
          "No performance regression"
        ],
        "good_examples": [
          "Dashboard data refreshes within 3-5 seconds after a pending action completes",
          "Manual refresh button triggers full refresh and shows loading state",
          "API response time under 500ms for 95th percentile"
        ]
      },
      "quality_rules": [
        "Success criteria include specific numbers/timings",
        "Each criterion is objectively verifiable",
        "Performance targets have percentiles (e.g., 95th, 99th)",
        "User-facing behavior has observable indicators"
      ],
      "target_skills": ["prd-planner", "architecting-solutions"]
    },
    "non_goals_section": {
      "id": "pat-2025-01-11-005",
      "name": "Non-Goals Section",
      "source": "user_feedback",
      "confidence": 0.90,
      "applications": 0,
      "created": "2025-01-11",
      "category": "prd_structure",
      "pattern": "Explicitly state what won't be done to prevent scope creep",
      "problem": "Without explicit non-goals, scope creeps during implementation",
      "solution": {
        "structure": "## Goals\n- [Specific achievable outcomes]\n\n## Non-Goals\n- [Explicit exclusions - things that might seem related but aren't]"
      },
      "quality_rules": [
        "Goals section has 3-5 focused items",
        "Non-goals section explicitly excludes reasonable-but-out-of-scope items",
        "Each non-goal has a brief rationale if not obvious"
      ],
      "target_skills": ["prd-planner", "architecting-solutions"]
    },
    "ui_ux_specification_granularity": {
      "id": "pat-2025-01-11-006",
      "name": "UI/UX Specification Granularity",
      "source": "retrospective",
      "confidence": 0.95,
      "applications": 0,
      "created": "2025-01-11",
      "category": "ui_patterns",
      "pattern": "UI/UX PRDs require explicit visual specifications to prevent rework",
      "problem": "Ambiguous UI specs (position, size, spacing) cause implementation rework",
      "solution": {
        "required_elements": {
          "layout_structure": ["Relative position: same row / next row / below / above", "Parent-child container relationships", "Spacing values (gap, padding, margin)"],
          "component_specs": ["Icon/Button sizes: iconSize=\"$4\" (24px)", "Text styles: size=\"$bodyMd\", color=\"$textSubdued\"", "Component variants: size=\"small\", variant=\"tertiary\""],
          "visual_comparison": "Before/After ASCII art showing layout change",
          "executable_criteria": "Checklist with exact prop values"
        },
        "examples": {
          "bad": "Refresh button next to amount",
          "good": "Refresh button in same XStack as amount with gap='$3'"
        }
      },
      "quality_rules": [
        "Relative position explicitly stated (same row/next row/below/above)",
        "Component sizes with exact values (iconSize prop or px)",
        "Spacing values defined (gap=\"$3\", mx=\"$2\")",
        "Before/After visual comparison included",
        "Success criteria are executable (verify by reading code)",
        "Mobile vs desktop differences explicitly called out"
      ],
      "target_skills": ["prd-planner", "architecting-solutions"]
    },
    "reuse_existing_infrastructure": {
      "id": "pat-2025-01-11-007",
      "name": "Reuse Existing Infrastructure",
      "source": "comparison_analysis",
      "confidence": 0.90,
      "applications": 0,
      "created": "2025-01-11",
      "category": "architecture",
      "pattern": "Always check if Context/Provider already has the data before adding new fetching",
      "problem": "Adding duplicate data fetching creates redundant network calls and complexity",
      "solution": {
        "anti_pattern": "const { pendingRequests } = useActionQueue({ workspaceId, userId, client }); // Creates new polling loop!",
        "pattern": "const { pendingRequests } = useFeatureContext(); // Shared provider already updates this"
      },
      "quality_checklist": [
        "Check if Context/Provider already has the data",
        "Verify no duplicate polling/fetching",
        "Confirm single source of truth",
        "Only add new fetching when lifecycle is truly independent"
      ],
      "benefits": ["Reduces network/background calls", "Better performance (no redundant work)", "Single source of truth", "Simpler code (fewer hooks to manage)"],
      "target_skills": ["architecting-solutions", "api-designer", "debugger"]
    },
    "click_time_vs_open_time_computation": {
      "id": "pat-2025-01-11-008",
      "name": "Click-Time vs Open-Time Computation",
      "source": "implementation_review",
      "confidence": 0.85,
      "applications": 0,
      "created": "2025-01-11",
      "category": "react_patterns",
      "pattern": "For mutable state, compute at action time, not at render/init time",
      "problem": "Open-time computation creates stale snapshots when state changes before user acts",
      "solution": {
        "anti_pattern": "const allIds = useMemo(() =>\n  actionableItems.filter(i => !inFlightIds.includes(i.id)),\n  [actionableItems, inFlightIds]\n); // Stale if inFlightIds changes before user clicks",
        "pattern": "onRunAll: (ids: string[]) => Promise<void> => {\n  const freshIds = actionableItems\n    .filter(i => !inFlightIds.includes(i.id))\n    .map(i => i.id);\n  return submitBatchAction(freshIds);\n}"
      },
      "decision_matrix": {
        "open_time": ["Immutable data", "Expensive computation"],
        "click_time": ["Mutable state", "User-dependent filters"]
      },
      "benefits": ["State is always fresh when user acts", "No stale data issues", "Simpler reasoning about state"],
      "target_skills": ["debugger", "api-designer"]
    },
    "search_before_creating_components": {
      "id": "pat-2025-01-11-009",
      "name": "Search Before Creating Components",
      "source": "prud_correction",
      "confidence": 0.90,
      "applications": 0,
      "created": "2025-01-11",
      "category": "development",
      "pattern": "ALWAYS search existing codebase before proposing new components/types",
      "problem": "Creating duplicate components creates maintenance burden and UI inconsistency",
      "solution": {
        "pre_prd_search": [
          "grep -r \"Alert\" packages/kit/src/views/ --include=\"*.tsx\"",
          "grep -r \"IAlert\\|Alert\" packages/shared/types/ --include=\"*.ts\"",
          "If found, read existing implementation"
        ],
        "decision_matrix": {
          "existing_component_matches_ui": "Reuse",
          "existing_component_needs_small_tweak": "Extend or wrap",
          "existing_component_has_wrong_responsibilities": "Create new",
          "not_sure": "Reuse first"
        }
      },
      "impact": {
        "duplicate_component": "Over-engineering, UI inconsistency",
        "reuse": "Faster implementation, shared improvements"
      },
      "target_skills": ["prd-planner", "architecting-solutions", "api-designer"]
    },
    "spacing_and_divider_debugging": {
      "id": "pat-2025-01-11-010",
      "name": "Spacing and Divider Debugging",
      "source": "bug_analysis",
      "confidence": 0.85,
      "applications": 0,
      "created": "2025-01-11",
      "category": "debugging",
      "pattern": "When debugging spacing/divider issues, audit all spacing values systematically",
      "problem": "Component spacing (mt, mb, py, padding) can create unintended visual separators that appear as extra lines",
      "solution": {
        "debugging_steps": [
          "Search for spacing-related props in components",
          "Check for StyleSheet.hairlineWidth usage (may render differently per platform)",
          "Compare components that work vs components that have issues",
          "Draw component structure to identify spacing conflicts"
        ],
        "audit_template": "| Element | Before | After | Unit | Notes |\\n|---------|--------|-------|------|-------|\\n| Trigger padding | `py=\"$3\"` | - | 12px | Accordion.Trigger |\\n| Header top margin | `mt=\"$3\"` | `mt=\"$0\"` | 12px → 0px | Remove this |"
      },
      "quality_rules": [
        "Include ASCII diagram showing component structure",
        "List exact spacing values with pixel conversions ($3 = 12px, $5 = 20px)",
        "Compare working vs broken components",
        "Note platform-specific behaviors (hairlineWidth varies)",
        "Verify fix on all platforms (iOS, Android, Desktop, Web)"
      ],
      "target_skills": ["debugger"]
    }
  },
  "meta": {
    "version": "1.0.0",
    "last_updated": "2025-01-12",
    "total_patterns": 10,
    "categories": ["prd_structure", "prd_quality", "react_patterns", "async_patterns", "ui_patterns", "architecture", "development", "debugging"]
  }
}