forked from ThariqS/html-effectiveness
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16-implementation-plan.html
More file actions
702 lines (638 loc) · 28 KB
/
16-implementation-plan.html
File metadata and controls
702 lines (638 loc) · 28 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Implementation plan — Comment threads on task cards</title>
<style>
:root {
--ivory: #FAF9F5;
--slate: #141413;
--clay: #D97757;
--oat: #E3DACC;
--olive: #788C5D;
--gray-150: #F0EEE6;
--gray-300: #D1CFC5;
--gray-500: #87867F;
--gray-700: #3D3D3A;
--white: #FFFFFF;
--serif: ui-serif, Georgia, 'Times New Roman', serif;
--sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
--mono: ui-monospace, 'SF Mono', Menlo, Monaco, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: var(--sans);
background: var(--ivory);
color: var(--gray-700);
line-height: 1.55;
padding: 56px 32px 120px;
-webkit-font-smoothing: antialiased;
}
.page { max-width: 1120px; margin: 0 auto; }
/* ---------- header ---------- */
header.page-head { margin-bottom: 48px; max-width: 820px; }
.eyebrow {
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--gray-500);
margin-bottom: 12px;
}
h1 {
font-family: var(--serif);
font-weight: 500;
font-size: 38px;
line-height: 1.15;
color: var(--slate);
margin-bottom: 18px;
letter-spacing: -0.01em;
}
.prompt-box {
background: var(--gray-150);
border: 1.5px solid var(--gray-300);
border-radius: 12px;
padding: 16px 20px;
font-size: 14.5px;
color: var(--gray-700);
}
.prompt-box .label {
font-family: var(--mono);
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--gray-500);
display: block;
margin-bottom: 6px;
}
/* ---------- section chrome ---------- */
section { margin-bottom: 64px; }
.sec-head {
display: flex;
align-items: baseline;
gap: 14px;
margin-bottom: 8px;
}
.sec-head .num {
font-family: var(--mono);
font-size: 12px;
background: var(--oat);
color: var(--slate);
padding: 3px 9px;
border-radius: 8px;
}
.sec-head h2 {
font-family: var(--serif);
font-weight: 500;
font-size: 26px;
color: var(--slate);
letter-spacing: -0.01em;
}
.sec-intro {
font-size: 14.5px;
color: var(--gray-500);
max-width: 720px;
margin-bottom: 28px;
}
/* ---------- summary strip ---------- */
.summary {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 16px;
margin-bottom: 64px;
}
@media (max-width: 900px) { .summary { grid-template-columns: repeat(2, 1fr); } }
.summary .cell {
background: var(--white);
border: 1.5px solid var(--gray-300);
border-radius: 12px;
padding: 18px 20px;
}
.summary .k {
font-family: var(--mono);
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--gray-500);
margin-bottom: 6px;
}
.summary .v {
font-size: 17px;
color: var(--slate);
font-weight: 600;
}
.summary .v.accent { color: var(--clay); }
/* ---------- milestone timeline ---------- */
.milestones { display: flex; flex-direction: column; gap: 0; }
.milestone {
display: grid;
grid-template-columns: 120px 28px 1fr;
gap: 0 18px;
position: relative;
}
.milestone .when {
text-align: right;
font-family: var(--mono);
font-size: 12px;
color: var(--gray-500);
padding-top: 4px;
}
.milestone .dot-col {
display: flex;
flex-direction: column;
align-items: center;
}
.milestone .dot {
width: 14px; height: 14px;
border-radius: 50%;
background: var(--white);
border: 3px solid var(--clay);
margin-top: 4px;
flex-shrink: 0;
}
.milestone .dot.done { background: var(--olive); border-color: var(--olive); }
.milestone .line {
width: 2px;
flex: 1;
background: var(--gray-300);
margin: 4px 0;
}
.milestone:last-child .line { display: none; }
.milestone .body { padding-bottom: 36px; }
.milestone .body h3 {
font-family: var(--serif);
font-weight: 500;
font-size: 19px;
color: var(--slate);
margin-bottom: 4px;
}
.milestone .body p { font-size: 14px; color: var(--gray-500); margin-bottom: 10px; max-width: 620px; }
.milestone .tags { display: flex; gap: 8px; flex-wrap: wrap; }
.milestone .tag {
font-family: var(--mono);
font-size: 11.5px;
background: var(--gray-150);
border: 1px solid var(--gray-300);
border-radius: 6px;
padding: 3px 8px;
color: var(--gray-700);
}
/* ---------- data flow diagram ---------- */
.diagram {
background: var(--white);
border: 1.5px solid var(--gray-300);
border-radius: 12px;
padding: 28px;
overflow-x: auto;
}
.diagram svg { display: block; min-width: 760px; }
.diagram text { font-family: var(--mono); }
.caption { font-size: 13px; color: var(--gray-500); margin-top: 12px; }
/* ---------- mockups ---------- */
.mocks {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 28px;
}
@media (max-width: 900px) { .mocks { grid-template-columns: 1fr; } }
.mock {
background: var(--white);
border: 1.5px solid var(--gray-300);
border-radius: 12px;
overflow: hidden;
}
.mock .mock-label {
padding: 12px 18px;
border-bottom: 1.5px solid var(--gray-300);
font-family: var(--mono);
font-size: 11.5px;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--gray-500);
background: var(--gray-150);
}
.mock .mock-body { padding: 22px; }
/* task card mock */
.card-mock {
border: 1.5px solid var(--gray-300);
border-radius: 10px;
padding: 16px;
background: var(--ivory);
}
.card-mock .cm-title { font-weight: 600; font-size: 15px; color: var(--slate); margin-bottom: 4px; }
.card-mock .cm-meta { font-size: 12px; color: var(--gray-500); margin-bottom: 14px; }
.card-mock .cm-divider { border-top: 1px dashed var(--gray-300); margin: 14px 0; }
.thread { display: flex; flex-direction: column; gap: 12px; }
.comment { display: flex; gap: 10px; }
.comment .avatar {
width: 26px; height: 26px; border-radius: 50%;
background: var(--oat);
flex-shrink: 0;
display: flex; align-items: center; justify-content: center;
font-size: 11px; font-weight: 600; color: var(--slate);
}
.comment .avatar.alt { background: var(--olive); color: var(--white); }
.comment .bubble { flex: 1; }
.comment .author { font-size: 12px; font-weight: 600; color: var(--slate); }
.comment .author .time { font-weight: 400; color: var(--gray-500); margin-left: 6px; }
.comment .text { font-size: 13px; color: var(--gray-700); margin-top: 2px; }
.comment .reply-link { font-size: 11.5px; color: var(--clay); margin-top: 4px; cursor: default; }
.comment.nested { margin-left: 36px; }
.composer {
display: flex; gap: 10px; align-items: center;
margin-top: 6px;
}
.composer .field {
flex: 1;
border: 1.5px solid var(--gray-300);
border-radius: 8px;
padding: 8px 12px;
font-size: 13px;
color: var(--gray-500);
background: var(--white);
}
.composer .send {
background: var(--clay);
color: var(--white);
border-radius: 8px;
padding: 8px 14px;
font-size: 13px;
font-weight: 600;
}
/* sidebar digest mock */
.digest { display: flex; flex-direction: column; gap: 10px; }
.digest .row {
display: flex; gap: 10px; align-items: flex-start;
padding: 10px 12px;
background: var(--ivory);
border: 1.5px solid var(--gray-300);
border-radius: 8px;
}
.digest .row.unread { border-left: 3px solid var(--clay); }
.digest .mini-av {
width: 22px; height: 22px; border-radius: 50%;
background: var(--oat);
flex-shrink: 0;
font-size: 10px; font-weight: 600; color: var(--slate);
display: flex; align-items: center; justify-content: center;
}
.digest .txt { font-size: 12.5px; color: var(--gray-700); line-height: 1.45; }
.digest .txt strong { color: var(--slate); }
.digest .txt .on { color: var(--gray-500); }
/* ---------- code panel ---------- */
.code-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
@media (max-width: 980px) { .code-grid { grid-template-columns: 1fr; } }
.code-block { display: flex; flex-direction: column; gap: 10px; }
.code-block .file-label {
font-family: var(--mono);
font-size: 12px;
color: var(--gray-500);
}
.code {
background: var(--slate);
border-radius: 12px;
padding: 18px 20px;
overflow-x: auto;
flex: 1;
}
.code pre {
font-family: var(--mono);
font-size: 12.5px;
line-height: 1.65;
color: #E8E6DE;
white-space: pre;
}
.code .kw { color: var(--clay); }
.code .str { color: var(--olive); }
.code .cm { color: var(--gray-500); }
.code .fn { color: #C9B98A; }
/* ---------- risk table ---------- */
.risks {
border: 1.5px solid var(--gray-300);
border-radius: 12px;
overflow: hidden;
background: var(--white);
}
.risks .row {
display: grid;
grid-template-columns: 1.6fr 90px 1.6fr;
gap: 0;
}
@media (max-width: 780px) { .risks .row { grid-template-columns: 1fr; } }
.risks .row + .row { border-top: 1.5px solid var(--gray-300); }
.risks .cell { padding: 14px 18px; font-size: 13.5px; }
.risks .cell + .cell { border-left: 1.5px solid var(--gray-300); }
@media (max-width: 780px) { .risks .cell + .cell { border-left: none; border-top: 1px dashed var(--gray-300); } }
.risks .head { background: var(--gray-150); font-weight: 600; color: var(--slate); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.sev {
display: inline-block;
font-family: var(--mono);
font-size: 11px;
padding: 2px 8px;
border-radius: 6px;
font-weight: 600;
}
.sev.high { background: #F3D9CC; color: #8A3B1E; }
.sev.med { background: var(--oat); color: var(--slate); }
.sev.low { background: #E4E9DC; color: #4B5C39; }
/* ---------- open questions ---------- */
.open-q { display: flex; flex-direction: column; gap: 14px; max-width: 820px; }
.q {
background: var(--white);
border: 1.5px solid var(--gray-300);
border-left: 4px solid var(--clay);
border-radius: 10px;
padding: 16px 20px;
}
.q .qt { font-weight: 600; font-size: 15px; color: var(--slate); margin-bottom: 4px; }
.q .qd { font-size: 13.5px; color: var(--gray-500); }
.q .owner {
font-family: var(--mono);
font-size: 11.5px;
color: var(--gray-500);
margin-top: 8px;
}
</style>
</head>
<body>
<div class="page">
<header class="page-head">
<div class="eyebrow">Implementation plan · Acme web client</div>
<h1>Comment threads on task cards</h1>
<div class="prompt-box">
<span class="label">Prompt</span>
Create a thorough implementation plan for adding threaded comments to
task cards. Include mockups, the data flow from client to persistence,
the key code I'll need to write, and a risk table. Make it easy to
skim on a phone — I'm going to pass this to the implementer as-is.
</div>
</header>
<!-- ============================================================= -->
<div class="summary">
<div class="cell"><div class="k">Effort</div><div class="v accent">~2 weeks</div></div>
<div class="cell"><div class="k">Surfaces touched</div><div class="v">3 packages</div></div>
<div class="cell"><div class="k">New tables</div><div class="v">2</div></div>
<div class="cell"><div class="k">Feature flag</div><div class="v">task_comments_v1</div></div>
</div>
<!-- ============================================================= -->
<section>
<div class="sec-head"><span class="num">01</span><h2>Milestones</h2></div>
<p class="sec-intro">Ship in four slices, each independently reviewable and each behind the flag. Nothing is user-visible until slice 4.</p>
<div class="milestones">
<div class="milestone">
<div class="when">Week 1 · Mon–Tue</div>
<div class="dot-col"><span class="dot done"></span><span class="line"></span></div>
<div class="body">
<h3>Schema & API contract</h3>
<p>New <code>comments</code> and <code>comment_reads</code> tables, migrations, and the tRPC router stubs. No UI. Contract reviewed before anything else lands.</p>
<div class="tags"><span class="tag">packages/db</span><span class="tag">packages/api</span><span class="tag">migration 0042</span></div>
</div>
</div>
<div class="milestone">
<div class="when">Week 1 · Wed–Fri</div>
<div class="dot-col"><span class="dot"></span><span class="line"></span></div>
<div class="body">
<h3>Thread component & composer</h3>
<p>Static <code><CommentThread></code> rendered from fixtures. Optimistic insert on submit, rollback on failure, one level of nesting only.</p>
<div class="tags"><span class="tag">apps/web</span><span class="tag">storybook</span></div>
</div>
</div>
<div class="milestone">
<div class="when">Week 2 · Mon–Wed</div>
<div class="dot-col"><span class="dot"></span><span class="line"></span></div>
<div class="body">
<h3>Realtime fan-out & unread state</h3>
<p>Subscribe the open card to its comment channel. Track per-user read cursors so the sidebar can show an unread count without a second query.</p>
<div class="tags"><span class="tag">packages/realtime</span><span class="tag">apps/web</span></div>
</div>
</div>
<div class="milestone">
<div class="when">Week 2 · Thu–Fri</div>
<div class="dot-col"><span class="dot"></span><span class="line"></span></div>
<div class="body">
<h3>Notifications, flag ramp, docs</h3>
<p>Mention detection → notification row, email digest fallback, ramp <code>task_comments_v1</code> to internal, then 10% → 100% over three days.</p>
<div class="tags"><span class="tag">packages/notify</span><span class="tag">growthbook</span></div>
</div>
</div>
</div>
</section>
<!-- ============================================================= -->
<section>
<div class="sec-head"><span class="num">02</span><h2>Data flow</h2></div>
<p class="sec-intro">Optimistic write path on the left, fan-out on the right. The read cursor update is fire-and-forget — we never block the thread render on it.</p>
<div class="diagram">
<svg viewBox="0 0 860 340" xmlns="http://www.w3.org/2000/svg">
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M0,0 L10,5 L0,10 z" fill="#87867F"/>
</marker>
<marker id="arrowClay" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M0,0 L10,5 L0,10 z" fill="#D97757"/>
</marker>
</defs>
<!-- boxes -->
<g font-size="12" fill="#141413">
<rect x="20" y="20" width="180" height="54" rx="10" fill="#FFFFFF" stroke="#D1CFC5" stroke-width="1.5"/>
<text x="110" y="43" text-anchor="middle" font-weight="600"><CommentComposer></text>
<text x="110" y="60" text-anchor="middle" fill="#87867F" font-size="10.5">apps/web</text>
<rect x="20" y="150" width="180" height="54" rx="10" fill="#FFFFFF" stroke="#D1CFC5" stroke-width="1.5"/>
<text x="110" y="173" text-anchor="middle" font-weight="600">React Query cache</text>
<text x="110" y="190" text-anchor="middle" fill="#87867F" font-size="10.5">optimistic insert</text>
<rect x="340" y="150" width="180" height="54" rx="10" fill="#FFFFFF" stroke="#D1CFC5" stroke-width="1.5"/>
<text x="430" y="173" text-anchor="middle" font-weight="600">comments.create</text>
<text x="430" y="190" text-anchor="middle" fill="#87867F" font-size="10.5">tRPC · packages/api</text>
<rect x="340" y="266" width="180" height="54" rx="10" fill="#141413" stroke="#141413"/>
<text x="430" y="289" text-anchor="middle" font-weight="600" fill="#FAF9F5">comments table</text>
<text x="430" y="306" text-anchor="middle" fill="#C9B98A" font-size="10.5">postgres · packages/db</text>
<rect x="660" y="150" width="180" height="54" rx="10" fill="#FFFFFF" stroke="#D1CFC5" stroke-width="1.5"/>
<text x="750" y="173" text-anchor="middle" font-weight="600">realtime channel</text>
<text x="750" y="190" text-anchor="middle" fill="#87867F" font-size="10.5">task:{id}:comments</text>
<rect x="660" y="20" width="180" height="54" rx="10" fill="#FFFFFF" stroke="#D1CFC5" stroke-width="1.5"/>
<text x="750" y="43" text-anchor="middle" font-weight="600">Other viewers</text>
<text x="750" y="60" text-anchor="middle" fill="#87867F" font-size="10.5">subscribed cards</text>
<rect x="660" y="266" width="180" height="54" rx="10" fill="#FFFFFF" stroke="#D1CFC5" stroke-width="1.5"/>
<text x="750" y="289" text-anchor="middle" font-weight="600">notify worker</text>
<text x="750" y="306" text-anchor="middle" fill="#87867F" font-size="10.5">@mentions → queue</text>
</g>
<!-- arrows -->
<g stroke="#87867F" stroke-width="1.5" fill="none">
<path d="M110 74 L110 150" marker-end="url(#arrow)"/>
<path d="M200 177 L340 177" marker-end="url(#arrow)"/>
<path d="M430 204 L430 266" marker-end="url(#arrow)"/>
<path d="M520 293 L660 293" marker-end="url(#arrow)"/>
</g>
<g stroke="#D97757" stroke-width="1.5" fill="none" stroke-dasharray="5 4">
<path d="M520 177 L660 177" marker-end="url(#arrowClay)"/>
<path d="M750 150 L750 74" marker-end="url(#arrowClay)"/>
<path d="M660 162 C 540 120, 280 120, 205 162" marker-end="url(#arrowClay)"/>
</g>
<!-- edge labels -->
<g font-size="10.5" fill="#87867F">
<text x="118" y="118">submit (id=temp)</text>
<text x="240" y="170">mutate</text>
<text x="438" y="240">INSERT + read cursor</text>
<text x="548" y="286">enqueue</text>
<text x="548" y="172" fill="#D97757">broadcast row</text>
<text x="758" y="118" fill="#D97757">live append</text>
<text x="360" y="112" fill="#D97757">reconcile temp id → real id</text>
</g>
</svg>
<p class="caption">Solid = request/response path. Dashed clay = realtime fan-out. The composer never waits on the dashed path.</p>
</div>
</section>
<!-- ============================================================= -->
<section>
<div class="sec-head"><span class="num">03</span><h2>Mockups</h2></div>
<p class="sec-intro">Not pixel-final — just enough that the reviewer and I agree on nesting depth, composer placement, and what the sidebar digest looks like.</p>
<div class="mocks">
<div class="mock">
<div class="mock-label">A · Thread inside an open task card</div>
<div class="mock-body">
<div class="card-mock">
<div class="cm-title">Ship onboarding empty-state rewrite</div>
<div class="cm-meta">BIR-1142 · Assigned to Priya · Due Fri</div>
<div class="cm-divider"></div>
<div class="thread">
<div class="comment">
<div class="avatar">JM</div>
<div class="bubble">
<div class="author">Jonah M. <span class="time">2h ago</span></div>
<div class="text">Should the illustration swap when the workspace already has one project? Feels odd to show the "start here" art twice.</div>
<div class="reply-link">Reply</div>
</div>
</div>
<div class="comment nested">
<div class="avatar alt">PS</div>
<div class="bubble">
<div class="author">Priya S. <span class="time">40m ago</span></div>
<div class="text">Good catch — I'll gate it on <code>projects.count > 0</code> and fall back to the minimal variant.</div>
</div>
</div>
<div class="composer">
<div class="field">Add a comment…</div>
<div class="send">Post</div>
</div>
</div>
</div>
</div>
</div>
<div class="mock">
<div class="mock-label">B · Sidebar unread digest</div>
<div class="mock-body">
<div class="digest">
<div class="row unread">
<div class="mini-av">JM</div>
<div class="txt"><strong>Jonah</strong> commented <span class="on">on BIR-1142</span> — "Should the illustration swap when…"</div>
</div>
<div class="row unread">
<div class="mini-av">AK</div>
<div class="txt"><strong>Aiko</strong> mentioned you <span class="on">on BIR-1098</span> — "@priya can you confirm the copy here?"</div>
</div>
<div class="row">
<div class="mini-av">RW</div>
<div class="txt"><strong>Rowan</strong> replied <span class="on">on BIR-0971</span> — "Merged, thanks for the quick turnaround."</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- ============================================================= -->
<section>
<div class="sec-head"><span class="num">04</span><h2>Key code</h2></div>
<p class="sec-intro">The two pieces most likely to be done wrong: the migration (soft deletes, read cursors) and the optimistic mutation (temp-id reconciliation).</p>
<div class="code-grid">
<div class="code-block">
<div class="file-label">packages/db/migrations/0042_comments.sql</div>
<div class="code"><pre><span class="kw">create table</span> <span class="fn">comments</span> (
id uuid <span class="kw">primary key default</span> gen_random_uuid(),
task_id uuid <span class="kw">not null references</span> tasks(id),
parent_id uuid <span class="kw">references</span> comments(id), <span class="cm">-- one level only,</span>
<span class="cm">-- enforced in API</span>
author_id uuid <span class="kw">not null references</span> users(id),
body text <span class="kw">not null</span>,
created_at timestamptz <span class="kw">not null default</span> now(),
deleted_at timestamptz <span class="cm">-- soft delete</span>
);
<span class="kw">create table</span> <span class="fn">comment_reads</span> (
task_id uuid <span class="kw">not null references</span> tasks(id),
user_id uuid <span class="kw">not null references</span> users(id),
read_up_to timestamptz <span class="kw">not null</span>,
<span class="kw">primary key</span> (task_id, user_id)
);
<span class="kw">create index</span> <span class="fn">comments_task_created</span>
<span class="kw">on</span> comments (task_id, created_at);</pre></div>
</div>
<div class="code-block">
<div class="file-label">apps/web/hooks/useAddComment.ts</div>
<div class="code"><pre><span class="kw">export function</span> <span class="fn">useAddComment</span>(taskId: string) {
<span class="kw">const</span> qc = useQueryClient();
<span class="kw">return</span> trpc.comments.create.<span class="fn">useMutation</span>({
<span class="fn">onMutate</span>: <span class="kw">async</span> (input) => {
<span class="kw">const</span> temp = { ...input, id: <span class="str">`temp-${nanoid()}`</span>,
createdAt: <span class="kw">new</span> Date(), pending: <span class="kw">true</span> };
qc.<span class="fn">setQueryData</span>(key(taskId), (prev) =>
[...(prev ?? []), temp]);
<span class="kw">return</span> { tempId: temp.id };
},
<span class="fn">onSuccess</span>: (row, _v, ctx) => {
<span class="cm">// reconcile temp id → real id so the</span>
<span class="cm">// realtime append doesn't duplicate it</span>
qc.<span class="fn">setQueryData</span>(key(taskId), (prev) =>
prev.map((c) => c.id === ctx.tempId ? row : c));
},
<span class="fn">onError</span>: (_e, _v, ctx) => {
qc.<span class="fn">setQueryData</span>(key(taskId), (prev) =>
prev.filter((c) => c.id !== ctx.tempId));
},
});
}</pre></div>
</div>
</div>
</section>
<!-- ============================================================= -->
<section>
<div class="sec-head"><span class="num">05</span><h2>Risks & mitigations</h2></div>
<div class="risks">
<div class="row">
<div class="cell head">Risk</div>
<div class="cell head">Sev</div>
<div class="cell head">Mitigation</div>
</div>
<div class="row">
<div class="cell">Realtime duplicate: socket append races with the HTTP response and the temp-id reconcile.</div>
<div class="cell"><span class="sev high">HIGH</span></div>
<div class="cell">Dedupe on server-assigned <code>id</code> in the cache updater; socket payload carries the real id, temp rows are filtered on reconcile.</div>
</div>
<div class="row">
<div class="cell">Unread counts go stale when a user reads the thread on another device.</div>
<div class="cell"><span class="sev med">MED</span></div>
<div class="cell">Broadcast <code>comment_reads</code> upserts on the same channel; client treats its own cursor as max(local, remote).</div>
</div>
<div class="row">
<div class="cell">Mention detection false-positives on pasted markdown (<code>@media</code>, <code>@2x</code>).</div>
<div class="cell"><span class="sev low">LOW</span></div>
<div class="cell">Resolve mentions against workspace members only, at write time, and store the resolved user ids — never re-parse on read.</div>
</div>
</div>
</section>
<!-- ============================================================= -->
<section>
<div class="sec-head"><span class="num">06</span><h2>Open questions</h2></div>
<div class="open-q">
<div class="q">
<div class="qt">Do we allow editing, or only delete-and-repost?</div>
<div class="qd">Editing needs an <code>edited_at</code> column and an "edited" affordance. Delete-and-repost is simpler but loses the reply anchor. Leaning toward delete-only for v1.</div>
<div class="owner">Decide with · design, before slice 2</div>
</div>
<div class="q">
<div class="qt">Email digest cadence when a user has the app closed</div>
<div class="qd">Immediate-per-mention will be noisy. Proposal: batch on a 15-minute window, collapse to one email per task, and respect quiet hours from the existing settings table.</div>
<div class="owner">Decide with · platform, before slice 4</div>
</div>
</div>
</section>
</div>
</body>
</html>