-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsequence-cache-miss-request.html
More file actions
1107 lines (985 loc) · 45.3 KB
/
sequence-cache-miss-request.html
File metadata and controls
1107 lines (985 loc) · 45.3 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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cache Miss Request Sequence Diagram</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
/* ==========================================================
THEME VARIABLES — switch by toggling [data-theme] on <html>
========================================================== */
:root,
[data-theme="dark"] {
--bg: #020617;
--grid: #1e293b;
--text: #ffffff;
--text-muted: #94a3b8;
--text-dim: #475569;
--panel: rgba(15, 23, 42, 0.5);
--panel-border: #1e293b;
--lane-fill: rgba(15, 23, 42, 0.22);
--lane-stroke: #334155;
--arrow: #64748b;
--arrow-emphasis: #34d399;
/* Opaque mask color used behind semi-transparent component fills
so the arrows drawn underneath are properly hidden. */
--mask: #0f172a;
--frontend-fill: rgba(8, 51, 68, 0.4);
--frontend-stroke: #22d3ee;
--backend-fill: rgba(6, 78, 59, 0.4);
--backend-stroke: #34d399;
--database-fill: rgba(76, 29, 149, 0.4);
--database-stroke: #a78bfa;
--cloud-fill: rgba(120, 53, 15, 0.3);
--cloud-stroke: #fbbf24;
--security-fill: rgba(136, 19, 55, 0.4);
--security-stroke: #fb7185;
--messagebus-fill: rgba(251, 146, 60, 0.3);
--messagebus-stroke:#fb923c;
--external-fill: rgba(30, 41, 59, 0.5);
--external-stroke: #94a3b8;
--toolbar-bg: rgba(15, 23, 42, 0.8);
--toolbar-border: #334155;
--toolbar-text: #e2e8f0;
--toolbar-hover: rgba(15, 23, 42, 0.95);
--toolbar-menu-bg: #0f172a;
}
[data-theme="light"] {
--bg: #f8fafc;
--grid: #e2e8f0;
--text: #0f172a;
--text-muted: #64748b;
--text-dim: #94a3b8;
--panel: #ffffff;
--panel-border: #e2e8f0;
--lane-fill: rgba(248, 250, 252, 0.65);
--lane-stroke: #cbd5e1;
--arrow: #94a3b8;
--arrow-emphasis: #059669;
--mask: #ffffff;
--frontend-fill: rgba(34, 211, 238, 0.15);
--frontend-stroke: #0891b2;
--backend-fill: rgba(52, 211, 153, 0.18);
--backend-stroke: #059669;
--database-fill: rgba(167, 139, 250, 0.2);
--database-stroke: #7c3aed;
--cloud-fill: rgba(251, 191, 36, 0.18);
--cloud-stroke: #d97706;
--security-fill: rgba(251, 113, 133, 0.15);
--security-stroke: #e11d48;
--messagebus-fill: rgba(251, 146, 60, 0.15);
--messagebus-stroke:#ea580c;
--external-fill: rgba(148, 163, 184, 0.18);
--external-stroke: #64748b;
--toolbar-bg: rgba(255, 255, 255, 0.92);
--toolbar-border: #cbd5e1;
--toolbar-text: #334155;
--toolbar-hover: #ffffff;
--toolbar-menu-bg: #ffffff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
background: var(--bg);
min-height: 100vh;
padding: 2rem;
color: var(--text);
transition: background 0.2s ease, color 0.2s ease;
}
.container { max-width: 1200px; margin: 0 auto; }
.header { margin-bottom: 2rem; }
.header-row {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 0.5rem;
}
.pulse-dot {
width: 12px;
height: 12px;
background: var(--frontend-stroke);
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
h1 {
font-size: 1.5rem;
font-weight: 700;
letter-spacing: -0.025em;
}
.subtitle {
color: var(--text-muted);
font-size: 0.875rem;
margin-left: 1.75rem;
}
.diagram-container {
background: var(--panel);
border-radius: 1rem;
border: 1px solid var(--panel-border);
padding: 1.5rem;
overflow-x: auto;
}
svg {
width: 100%;
min-width: min(900px, 100%);
display: block;
}
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1rem;
margin-top: 2rem;
}
.card {
background: var(--panel);
border-radius: 0.75rem;
border: 1px solid var(--panel-border);
padding: 1.25rem;
}
.card-header {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.card-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.card-dot.cyan { background: var(--frontend-stroke); }
.card-dot.emerald { background: var(--backend-stroke); }
.card-dot.violet { background: var(--database-stroke); }
.card-dot.amber { background: var(--cloud-stroke); }
.card-dot.rose { background: var(--security-stroke); }
.card-dot.orange { background: var(--messagebus-stroke); }
.card-dot.slate { background: var(--external-stroke); }
.card h3 { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.card ul {
list-style: none;
color: var(--text-muted);
font-size: 0.75rem;
}
.card li { margin-bottom: 0.375rem; }
.footer {
text-align: center;
margin-top: 1.5rem;
color: var(--text-dim);
font-size: 0.75rem;
}
/* ==========================================================
Print stylesheet — hide interactive controls, force light,
drop the grid so the diagram doesn't waste ink, use landscape
so wide diagrams fit, pack summary cards into 2 columns to
avoid an orphan card on a trailing page.
========================================================== */
@page { size: landscape; margin: 1.5cm; }
@media print {
:root, [data-theme="dark"], [data-theme="light"] {
--bg: #ffffff;
--grid: transparent;
--panel: #ffffff;
--panel-border: #e2e8f0;
--text: #0f172a;
--text-muted: #475569;
--text-dim: #94a3b8;
--mask: #ffffff;
}
body { background: #ffffff !important; padding: 0; }
.container { max-width: none; }
.toolbar, .archify-toast { display: none !important; }
.diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }
.cards { grid-template-columns: 1fr 1fr; }
/* Ensure elements break sensibly across pages */
.card { break-inside: avoid; page-break-inside: avoid; }
.diagram-container { break-inside: avoid; page-break-inside: avoid; }
h1, .subtitle { color: #0f172a; }
}
/* ==========================================================
TOOLBAR (theme toggle + export menu)
========================================================== */
.toolbar {
position: fixed;
top: 1rem;
right: 1rem;
display: flex;
gap: 0.5rem;
z-index: 100;
}
.toolbar button {
background: var(--toolbar-bg);
color: var(--toolbar-text);
border: 1px solid var(--toolbar-border);
padding: 0.5rem 0.875rem;
border-radius: 0.5rem;
font-family: inherit;
font-size: 0.75rem;
font-weight: 500;
cursor: pointer;
backdrop-filter: blur(8px);
transition: background 0.15s, border-color 0.15s;
display: inline-flex;
align-items: center;
gap: 0.375rem;
}
.toolbar button:hover {
background: var(--toolbar-hover);
border-color: var(--arrow);
}
.toolbar button:focus-visible {
outline: 2px solid var(--frontend-stroke);
outline-offset: 2px;
}
.toolbar .export-wrap { position: relative; }
.toolbar .export-menu {
position: absolute;
top: calc(100% + 0.375rem);
right: 0;
background: var(--toolbar-menu-bg);
border: 1px solid var(--toolbar-border);
border-radius: 0.5rem;
padding: 0.375rem;
min-width: 160px;
display: none;
flex-direction: column;
box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.toolbar .export-menu.open { display: flex; }
.toolbar .export-menu button {
background: transparent;
border: 0;
justify-content: space-between;
width: 100%;
text-align: left;
padding: 0.5rem 0.75rem;
}
.toolbar .export-menu button:hover {
background: var(--toolbar-hover);
}
.toolbar .export-menu .hint {
color: var(--text-dim);
font-size: 0.625rem;
}
.toolbar .export-menu hr {
border: 0;
border-top: 1px solid var(--toolbar-border);
margin: 0.25rem 0.375rem;
opacity: 0.5;
}
/* Toast — brief feedback for actions like "copied" */
.archify-toast {
position: fixed;
top: 1rem;
left: 50%;
transform: translateX(-50%) translateY(-8px);
background: var(--toolbar-menu-bg);
color: var(--text);
border: 1px solid var(--toolbar-border);
padding: 0.5rem 1rem;
border-radius: 0.5rem;
font-family: inherit;
font-size: 0.75rem;
opacity: 0;
transition: opacity 0.2s, transform 0.2s;
z-index: 200;
pointer-events: none;
box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.archify-toast.show {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
@media (max-width: 720px) {
body { padding: 1rem; }
.toolbar {
position: static;
justify-content: flex-end;
margin-bottom: 1rem;
}
.header { margin-bottom: 1.25rem; }
.header-row {
gap: 0.75rem;
align-items: flex-start;
}
h1 {
font-size: 1.25rem;
line-height: 1.25;
}
.subtitle {
margin-left: 0;
font-size: 0.8125rem;
line-height: 1.55;
}
.diagram-container {
padding: 0.75rem;
border-radius: 0.75rem;
}
.cards {
grid-template-columns: 1fr;
margin-top: 1rem;
}
}
/* ==========================================================
SVG SEMANTIC CLASSES — use these instead of inline fill/stroke
========================================================== */
.c-grid { stroke: var(--grid); fill: none; }
.c-mask { fill: var(--mask); stroke: none; }
.c-frontend { fill: var(--frontend-fill); stroke: var(--frontend-stroke); }
.c-backend { fill: var(--backend-fill); stroke: var(--backend-stroke); }
.c-database { fill: var(--database-fill); stroke: var(--database-stroke); }
.c-cloud { fill: var(--cloud-fill); stroke: var(--cloud-stroke); }
.c-security { fill: var(--security-fill); stroke: var(--security-stroke); }
.c-messagebus { fill: var(--messagebus-fill); stroke: var(--messagebus-stroke); }
.c-external { fill: var(--external-fill); stroke: var(--external-stroke); }
/* Text helpers */
.t-primary { fill: var(--text); }
.t-muted { fill: var(--text-muted); }
.t-dim { fill: var(--text-dim); }
.t-frontend { fill: var(--frontend-stroke); }
.t-backend { fill: var(--backend-stroke); }
.t-database { fill: var(--database-stroke); }
.t-cloud { fill: var(--cloud-stroke); }
.t-security { fill: var(--security-stroke); }
.t-messagebus { fill: var(--messagebus-stroke); }
.t-external { fill: var(--external-stroke); }
/* Arrows */
.a-default { stroke: var(--arrow); fill: none; }
.a-emphasis { stroke: var(--arrow-emphasis); fill: none; }
.a-security { stroke: var(--security-stroke); fill: none; stroke-dasharray: 5,5; }
.a-dashed { stroke: var(--database-stroke); fill: none; stroke-dasharray: 4,4; }
/* Arrowhead markers reference these */
.m-default { fill: var(--arrow); }
.m-emphasis { fill: var(--arrow-emphasis); }
.m-security { fill: var(--security-stroke); }
.m-dashed { fill: var(--database-stroke); }
/* Dashed boundary variants */
.c-security-group { fill: transparent; stroke: var(--security-stroke); stroke-dasharray: 4,4; }
.c-region { fill: rgba(251, 191, 36, 0.05); stroke: var(--cloud-stroke); stroke-dasharray: 8,4; }
.c-lane { fill: var(--lane-fill); stroke: var(--lane-stroke); stroke-dasharray: 6,6; }
</style>
</head>
<body>
<!-- Toolbar: theme toggle + export menu (present on every generated diagram)
Keyboard: T toggles theme, E opens export menu (when no input focused) -->
<div class="toolbar" role="toolbar" aria-label="Diagram actions">
<button id="btn-theme" type="button"
title="Toggle theme (T)"
aria-label="Toggle color theme"
aria-pressed="false">
<span id="theme-icon" aria-hidden="true">☾</span>
<span id="theme-label">Dark</span>
</button>
<div class="export-wrap">
<button id="btn-export" type="button"
title="Export diagram (E)"
aria-label="Export diagram"
aria-haspopup="menu"
aria-expanded="false"
aria-controls="export-menu">
Export <span aria-hidden="true">▾</span>
</button>
<div class="export-menu" id="export-menu" role="menu" aria-label="Export">
<button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>
<hr role="separator" aria-hidden="true">
<button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button>
<button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button>
<button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>
<hr role="separator" aria-hidden="true">
<button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button>
</div>
</div>
</div>
<div class="container">
<!-- Header -->
<div class="header">
<div class="header-row">
<div class="pulse-dot"></div>
<h1>Cache Miss Request Sequence</h1>
</div>
<p class="subtitle">Frontend request path with auth, cache fallback, persistence, and async trace</p>
</div>
<!-- Main Diagram -->
<div class="diagram-container">
<svg viewBox="0 0 820 760">
<!-- Definitions -->
<defs>
<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" class="m-default" />
</marker>
<marker id="arrowhead-emphasis" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" class="m-emphasis" />
</marker>
<marker id="arrowhead-security" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" class="m-security" />
</marker>
<marker id="arrowhead-dashed" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" class="m-dashed" />
</marker>
<pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse">
<path d="M 40 0 L 0 0 0 40" class="c-grid" stroke-width="0.5"/>
</pattern>
</defs>
<!-- Background Grid -->
<rect width="100%" height="100%" fill="url(#grid)" />
<!-- Time Segments -->
<rect x="48" y="150" width="724" height="145" rx="10" class="c-lane" stroke-width="1"/>
<text x="62" y="168" class="t-dim" font-size="9" font-weight="600">Request</text>
<rect x="48" y="315" width="724" height="190" rx="10" class="c-lane" stroke-width="1"/>
<text x="62" y="333" class="t-dim" font-size="9" font-weight="600">Fallback</text>
<rect x="48" y="525" width="724" height="140" rx="10" class="c-lane" stroke-width="1"/>
<text x="62" y="543" class="t-dim" font-size="9" font-weight="600">Response + trace</text>
<!-- Lifelines -->
<path d="M 62 142 L 62 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<path d="M 170 142 L 170 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<path d="M 278 142 L 278 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<path d="M 386 142 L 386 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<path d="M 494 142 L 494 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<path d="M 602 142 L 602 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<path d="M 710 142 L 710 695" class="a-default" stroke-width="0.8" stroke-dasharray="3,7"/>
<!-- Messages -->
<path d="M 69 185 L 163 185" class="a-default" stroke-width="1.4" marker-end="url(#arrowhead)"/>
<rect x="86.6" y="165" width="58.800000000000004" height="16" rx="3" class="c-mask"/>
<text x="116" y="175" class="t-backend" font-size="9" text-anchor="middle">open page</text>
<path d="M 177 228 L 271 228" class="a-emphasis" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>
<rect x="181.6" y="208" width="84.8" height="16" rx="3" class="c-mask"/>
<text x="224" y="218" class="t-backend" font-size="9" text-anchor="middle">GET /dashboard</text>
<path d="M 285 270 L 379 270" class="a-security" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>
<rect x="300" y="250" width="64" height="16" rx="3" class="c-mask"/>
<text x="332" y="260" class="t-security" font-size="9" text-anchor="middle">verify JWT</text>
<path d="M 379 305 L 285 305" class="a-default" stroke-width="1.4" stroke-dasharray="3,5" marker-end="url(#arrowhead)"/>
<rect x="302.6" y="285" width="58.800000000000004" height="16" rx="3" class="c-mask"/>
<text x="332" y="295" class="t-muted" font-size="9" text-anchor="middle">claims ok</text>
<path d="M 285 354 L 487 354" class="a-default" stroke-width="1.4" marker-end="url(#arrowhead)"/>
<rect x="354" y="334" width="64" height="16" rx="3" class="c-mask"/>
<text x="386" y="344" class="t-backend" font-size="9" text-anchor="middle">read cache</text>
<path d="M 487 391 L 285 391" class="a-default" stroke-width="1.4" stroke-dasharray="3,5" marker-end="url(#arrowhead)"/>
<rect x="369" y="371" width="34" height="16" rx="3" class="c-mask"/>
<text x="386" y="381" class="t-muted" font-size="9" text-anchor="middle">miss</text>
<path d="M 285 443 L 595 443" class="a-emphasis" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>
<rect x="374.2" y="423" width="131.60000000000002" height="16" rx="3" class="c-mask"/>
<text x="440" y="433" class="t-backend" font-size="9" text-anchor="middle">query profile + metrics</text>
<path d="M 595 489 L 285 489" class="a-default" stroke-width="1.4" stroke-dasharray="3,5" marker-end="url(#arrowhead)"/>
<rect x="423" y="469" width="34" height="16" rx="3" class="c-mask"/>
<text x="440" y="479" class="t-muted" font-size="9" text-anchor="middle">rows</text>
<path d="M 285 536 L 487 536" class="a-dashed" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>
<rect x="356.6" y="516" width="58.800000000000004" height="16" rx="3" class="c-mask"/>
<text x="386" y="526" class="t-messagebus" font-size="9" text-anchor="middle">set cache</text>
<path d="M 285 580 L 703 580" class="a-dashed" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>
<rect x="462" y="560" width="64" height="16" rx="3" class="c-mask"/>
<text x="494" y="570" class="t-messagebus" font-size="9" text-anchor="middle">emit trace</text>
<path d="M 271 625 L 177 625" class="a-default" stroke-width="1.4" stroke-dasharray="3,5" marker-end="url(#arrowhead)"/>
<rect x="197.2" y="605" width="53.6" height="16" rx="3" class="c-mask"/>
<text x="224" y="615" class="t-muted" font-size="9" text-anchor="middle">200 JSON</text>
<path d="M 163 662 L 69 662" class="a-default" stroke-width="1.4" stroke-dasharray="3,5" marker-end="url(#arrowhead)"/>
<rect x="94.4" y="642" width="43.2" height="16" rx="3" class="c-mask"/>
<text x="116" y="652" class="t-muted" font-size="9" text-anchor="middle">render</text>
<!-- Activations -->
<rect x="165" y="220" width="10" height="448" rx="3" class="c-mask"/>
<rect x="165" y="220" width="10" height="448" rx="3" class="c-frontend" stroke-width="1"/>
<rect x="273" y="228" width="10" height="404" rx="3" class="c-mask"/>
<rect x="273" y="228" width="10" height="404" rx="3" class="c-backend" stroke-width="1"/>
<rect x="381" y="265" width="10" height="45" rx="3" class="c-mask"/>
<rect x="381" y="265" width="10" height="45" rx="3" class="c-security" stroke-width="1"/>
<rect x="489" y="349" width="10" height="49" rx="3" class="c-mask"/>
<rect x="489" y="349" width="10" height="49" rx="3" class="c-database" stroke-width="1"/>
<rect x="597" y="438" width="10" height="58" rx="3" class="c-mask"/>
<rect x="597" y="438" width="10" height="58" rx="3" class="c-database" stroke-width="1"/>
<rect x="705" y="575" width="10" height="55" rx="3" class="c-mask"/>
<rect x="705" y="575" width="10" height="55" rx="3" class="c-messagebus" stroke-width="1"/>
<!-- Participants -->
<rect x="19" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="19" y="72" width="86" height="54" rx="6" class="c-external" stroke-width="1.5"/>
<text x="62" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">User</text>
<text x="62" y="111" class="t-muted" font-size="7" text-anchor="middle">browser session</text>
<rect x="127" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="127" y="72" width="86" height="54" rx="6" class="c-frontend" stroke-width="1.5"/>
<text x="170" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Web App</text>
<text x="170" y="111" class="t-muted" font-size="7" text-anchor="middle">React UI</text>
<rect x="235" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="235" y="72" width="86" height="54" rx="6" class="c-backend" stroke-width="1.5"/>
<text x="278" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">API</text>
<text x="278" y="111" class="t-muted" font-size="7" text-anchor="middle">request handler</text>
<rect x="343" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="343" y="72" width="86" height="54" rx="6" class="c-security" stroke-width="1.5"/>
<text x="386" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Auth</text>
<text x="386" y="111" class="t-muted" font-size="7" text-anchor="middle">JWT verify</text>
<rect x="451" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="451" y="72" width="86" height="54" rx="6" class="c-database" stroke-width="1.5"/>
<text x="494" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Redis</text>
<text x="494" y="111" class="t-muted" font-size="7" text-anchor="middle">cache</text>
<rect x="559" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="559" y="72" width="86" height="54" rx="6" class="c-database" stroke-width="1.5"/>
<text x="602" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Postgres</text>
<text x="602" y="111" class="t-muted" font-size="7" text-anchor="middle">source of truth</text>
<rect x="667" y="72" width="86" height="54" rx="6" class="c-mask"/>
<rect x="667" y="72" width="86" height="54" rx="6" class="c-messagebus" stroke-width="1.5"/>
<text x="710" y="94" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Trace</text>
<text x="710" y="111" class="t-muted" font-size="7" text-anchor="middle">async event</text>
<!-- Legend -->
<text x="150" y="686" class="t-primary" font-size="10" font-weight="600">Legend</text>
<path d="M 150 706 L 184 706" class="a-emphasis" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>
<text x="193" y="709" class="t-muted" font-size="8">request</text>
<path d="M 270 706 L 304 706" class="a-default" stroke-width="1.4" stroke-dasharray="3,5" marker-end="url(#arrowhead)"/>
<text x="313" y="709" class="t-muted" font-size="8">return</text>
<path d="M 385 706 L 419 706" class="a-security" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>
<text x="428" y="709" class="t-muted" font-size="8">security</text>
<path d="M 530 706 L 564 706" class="a-dashed" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>
<text x="573" y="709" class="t-muted" font-size="8">async trace</text>
</svg>
</div>
<!-- Info Cards -->
<div class="cards">
<div class="card">
<div class="card-header">
<div class="card-dot emerald"></div>
<h3>Happy Path</h3>
</div>
<ul>
<li>• The main request is Web App -> API -> data source -> response</li>
<li>• Return messages are quieter than forward calls</li>
<li>• Activation bars make ownership duration visible</li>
</ul>
</div>
<div class="card">
<div class="card-header">
<div class="card-dot rose"></div>
<h3>Policy + Fallback</h3>
</div>
<ul>
<li>• JWT verification is colored as a security interaction</li>
<li>• Cache miss is visible without overpowering the main path</li>
<li>• Database access only appears after cache fallback</li>
</ul>
</div>
<div class="card">
<div class="card-header">
<div class="card-dot orange"></div>
<h3>Async Trace</h3>
</div>
<ul>
<li>• Trace emission is dashed and secondary</li>
<li>• It does not block the response path</li>
<li>• The diagram separates user-facing latency from observability</li>
</ul>
</div>
</div>
<!-- Footer -->
<p class="footer">
Sequence diagram • Built with Archify • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export
</p>
</div>
<script>
/* ============================================================
Theme toggle — persists to localStorage, respects system pref
============================================================ */
var Archify = {};
Archify.theme = (function () {
var STORAGE_KEY = 'archify-theme';
var html = document.documentElement;
var btn = document.getElementById('btn-theme');
var icon = document.getElementById('theme-icon');
var label = document.getElementById('theme-label');
function resolveInitial() {
// URL param wins (useful for deterministic screenshots / share links)
try {
var param = new URLSearchParams(window.location.search).get('theme');
if (param === 'light' || param === 'dark') return param;
} catch (_) {}
var saved = localStorage.getItem(STORAGE_KEY);
if (saved === 'light' || saved === 'dark') return saved;
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
}
function apply(theme) {
html.setAttribute('data-theme', theme);
icon.textContent = theme === 'dark' ? '\u263E' : '\u263C';
label.textContent = theme === 'dark' ? 'Dark' : 'Light';
btn.setAttribute('aria-pressed', theme === 'light' ? 'true' : 'false');
}
function toggle() {
var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
apply(next);
localStorage.setItem(STORAGE_KEY, next);
}
apply(resolveInitial());
btn.addEventListener('click', toggle);
return { toggle: toggle };
})();
/* ============================================================
Export — PNG / JPEG / WebP / SVG (download) and Copy PNG (clipboard)
Raster exports are always rendered at 4x source resolution for
maximum sharpness. The trick: we set the serialized SVG's
`width`/`height` to viewBox * 4 so the browser rasterizes the
vectors at that resolution natively. drawImage then draws at
the image's natural size (no upscaling = no blur).
JPEG/WebP paint the current theme's background explicitly since
those formats have no alpha channel.
============================================================ */
(function () {
var RASTER_SCALE = 4;
function diagramFilename() {
var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();
return title.replace(/[^a-z0-9_\-]+/gi, '-')
.toLowerCase()
.replace(/^-+|-+$/g, '') || 'diagram';
}
function currentBg() {
return getComputedStyle(document.body).backgroundColor || '#ffffff';
}
/**
* Serialize the main SVG into a standalone document.
*
* Two modes:
* - Default (opts.autoTheme=false) — locks the serialized SVG to the
* viewer's current theme. Used by the raster pipeline
* (PNG/JPEG/WebP/clipboard) because canvas rasterization needs
* deterministic colors; a raster cannot react to
* prefers-color-scheme after encoding.
* - autoTheme=true — emits BOTH dark and light variable sets plus a
* `@media (prefers-color-scheme)` rule so the resulting SVG
* self-themes when embedded in GitHub READMEs or other hosts that
* expose a color scheme. Used for "Download SVG".
*/
function serializeSvg(scale, opts) {
// scale: integer multiplier for intrinsic SVG pixel dimensions used by
// the raster path. Defaults to 1 (natural size) for SVG download.
scale = scale || 1;
opts = opts || {};
var autoTheme = opts.autoTheme === true;
var svg = document.querySelector('.diagram-container svg');
var clone = svg.cloneNode(true);
var vb = svg.viewBox.baseVal;
// Scale width/height so the browser rasterizes the vectors at target
// resolution directly. viewBox stays unchanged so coordinates don't
// shift. This is the key to sharp rasters — do NOT scale later via
// canvas upscaling.
clone.setAttribute('width', vb.width * scale);
clone.setAttribute('height', vb.height * scale);
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
var hostStyle = Array.prototype.map.call(document.querySelectorAll('style'), function (s) {
return s.textContent;
}).join('\n');
var varNames = [
'--bg','--grid','--text','--text-muted','--text-dim',
'--arrow','--arrow-emphasis','--mask',
'--frontend-fill','--frontend-stroke',
'--backend-fill','--backend-stroke',
'--database-fill','--database-stroke',
'--cloud-fill','--cloud-stroke',
'--security-fill','--security-stroke',
'--messagebus-fill','--messagebus-stroke',
'--external-fill','--external-stroke'
];
// Resolve the full variable set for a given data-theme via an
// off-DOM probe, independent of what the viewer is currently set to.
function resolveVars(themeAttr) {
var probe = document.createElement('div');
probe.setAttribute('data-theme', themeAttr);
probe.style.cssText = 'position:absolute;width:0;height:0;visibility:hidden;';
document.body.appendChild(probe);
try {
var c = getComputedStyle(probe);
return varNames.map(function (n) {
return n + ': ' + c.getPropertyValue(n).trim() + ';';
}).join(' ');
} finally {
document.body.removeChild(probe);
}
}
// Prepend a local()-only @font-face block for each weight so that the
// sandboxed image-rendering context used during PNG/JPEG/WebP export
// can find JetBrains Mono if the user has it installed locally, and
// falls through cleanly to the monospace stack otherwise. The usual
// Google-Fonts <link> in the host document is unreachable from the
// serialized SVG, so url()-sourced faces would just hang.
var fontFallback = [400, 500, 600, 700].map(function (w) {
return "@font-face { font-family: 'JetBrains Mono'; font-weight: " + w +
"; src: local('JetBrains Mono'), local('JetBrainsMono-Regular'); }";
}).join('\n');
var style = document.createElementNS('http://www.w3.org/2000/svg', 'style');
var bgRect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
bgRect.setAttribute('width', '100%');
bgRect.setAttribute('height', '100%');
if (autoTheme) {
// Dual-theme SVG. Dark is the default (so hosts without
// prefers-color-scheme still render), light swaps in via media
// query, and svg[data-theme="..."] still lets downstream
// consumers force a specific theme.
var darkVars = resolveVars('dark');
var lightVars = resolveVars('light');
style.textContent =
fontFallback + "\n" +
"svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" +
hostStyle + "\n" +
":root, svg { " + darkVars + " }\n" +
"@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" +
"svg[data-theme=\"light\"] { " + lightVars + " }\n" +
"svg[data-theme=\"dark\"] { " + darkVars + " }\n" +
"rect.c-bg-rect { fill: var(--bg); }\n";
// Don't lock the serialized SVG to the viewer's current theme.
clone.removeAttribute('data-theme');
// Background follows the CSS variable, not a fixed color, so it
// swaps with the media query.
bgRect.setAttribute('class', 'c-bg-rect');
} else {
// Raster path: lock to the viewer's current theme.
var theme = document.documentElement.getAttribute('data-theme') || 'dark';
var themeHost = document.querySelector('[data-theme="' + theme + '"]') || document.documentElement;
var computed = getComputedStyle(themeHost);
var vars = varNames.map(function (n) {
return n + ': ' + computed.getPropertyValue(n).trim() + ';';
}).join(' ');
// IMPORTANT: inject the resolved variables AFTER hostStyle,
// otherwise hostStyle's ":root, [data-theme=\"dark\"] { ... }" rule
// overrides our chosen theme via later-in-cascade equal-specificity.
// Keep this order.
style.textContent =
fontFallback + "\n" +
"svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" +
hostStyle + "\n" +
":root, svg { " + vars + " }\n";
bgRect.setAttribute('fill', computed.getPropertyValue('--bg').trim() || '#ffffff');
}
clone.insertBefore(style, clone.firstChild);
clone.insertBefore(bgRect, style.nextSibling);
return {
svgString: new XMLSerializer().serializeToString(clone),
width: vb.width * scale,
height: vb.height * scale
};
}
function download(blob, filename) {
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(function () { URL.revokeObjectURL(url); }, 1000);
}
// Conservative upper bound on total canvas pixels. Older Safari on iOS
// silently produces a blank canvas above ~16 Mpx; Chrome / Firefox /
// desktop Safari are far higher but start failing on memory-constrained
// devices. We pick the largest integer scale in {4,3,2,1} whose target
// pixel count fits under this cap.
var MAX_CANVAS_PIXELS = 16 * 1024 * 1024;
function pickSafeScale(vbW, vbH) {
for (var s = RASTER_SCALE; s >= 1; s--) {
if (vbW * s * vbH * s <= MAX_CANVAS_PIXELS) return s;
}
return 1;
}
function rasterize(format) {
// Serialize at a safe scale (RASTER_SCALE=4 by default, reduced if the
// resulting canvas would exceed MAX_CANVAS_PIXELS). The SVG itself is
// rasterized at target resolution natively; drawImage draws at natural
// size — no upsampling blur.
var svg = document.querySelector('.diagram-container svg');
var vb = svg.viewBox.baseVal;
var scale = pickSafeScale(vb.width, vb.height);
var data = serializeSvg(scale);
var svgBlob = new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' });
var svgUrl = URL.createObjectURL(svgBlob);
return new Promise(function (resolve, reject) {
var img = new Image();
img.onload = function () {
var canvas = document.createElement('canvas');
canvas.width = data.width;
canvas.height = data.height;
var ctx = canvas.getContext('2d');
if (format === 'jpeg') {
ctx.fillStyle = currentBg();
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
// Draw at natural size — SVG was already rasterized at target res.
ctx.drawImage(img, 0, 0);
URL.revokeObjectURL(svgUrl);
var mime = format === 'jpeg' ? 'image/jpeg' :
format === 'webp' ? 'image/webp' : 'image/png';
var quality = format === 'png' ? undefined : 0.95;
canvas.toBlob(function (blob) {
if (!blob) reject(new Error('toBlob returned null for ' + format));
else resolve(blob);
}, mime, quality);
};
img.onerror = function (e) {
URL.revokeObjectURL(svgUrl);
reject(e);
};
img.src = svgUrl;
});
}
var menu = document.getElementById('export-menu');
var btn = document.getElementById('btn-export');
var items = function () {
return Array.prototype.slice.call(menu.querySelectorAll('button[role="menuitem"]'));
};
// ---- Clipboard support ----------------------------------------------
function canCopyImage() {
return typeof ClipboardItem !== 'undefined' &&
navigator.clipboard &&
typeof navigator.clipboard.write === 'function';
}
// ---- Raster format detection ----------------------------------------
// canvas.toBlob('image/webp') silently returns a PNG on browsers without
// WebP encoding (older Safari), so detect explicitly.
function supports(format) {
if (format === 'svg' || format === 'png') return true;
var mime = format === 'jpeg' ? 'image/jpeg' : 'image/webp';
try {
var c = document.createElement('canvas');
c.width = c.height = 2;
return c.toDataURL(mime).indexOf('data:' + mime) === 0;
} catch (_) { return false; }
}
// Gray out unsupported items.
items().forEach(function (it) {
if (it.dataset.format && !supports(it.dataset.format)) {
it.disabled = true;
it.title = 'Not supported by this browser';
it.style.opacity = '0.5';
}
if (it.dataset.action === 'copy' && !canCopyImage()) {
it.disabled = true;
it.title = 'Clipboard image write not supported by this browser';
it.style.opacity = '0.5';
}
});
// ---- Toast ----------------------------------------------------------
function toast(msg) {
var t = document.createElement('div');
t.className = 'archify-toast';
t.textContent = msg;
document.body.appendChild(t);
requestAnimationFrame(function () { t.classList.add('show'); });
setTimeout(function () {
t.classList.remove('show');
setTimeout(function () { t.remove(); }, 300);
}, 1500);
}
function open() {
menu.classList.add('open');
btn.setAttribute('aria-expanded', 'true');
var first = items().filter(function (i) { return !i.disabled; })[0];
if (first) first.focus();
}
function close(focusTrigger) {
menu.classList.remove('open');
btn.setAttribute('aria-expanded', 'false');
if (focusTrigger) btn.focus();
}
function isOpen() { return menu.classList.contains('open'); }
btn.addEventListener('click', function (e) {
e.stopPropagation();
if (isOpen()) close(false);
else open();
});
document.addEventListener('click', function (e) {
if (!menu.contains(e.target) && e.target !== btn) close(false);
});
// Keyboard navigation inside the menu.
// Menu items: Up/Down, Home/End.
// Esc closes + returns focus to trigger; Tab closes.