-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathengineers-codex.html
More file actions
1824 lines (1633 loc) · 93.7 KB
/
engineers-codex.html
File metadata and controls
1824 lines (1633 loc) · 93.7 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">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Engineer's Codex</title>
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400&family=Fira+Code:wght@300;400;500;600&family=Barlow:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #f5f0e8;
--bg2: #ede8df;
--bg3: #e4ddd0;
--ink: #1a1610;
--ink2: #3d3428;
--ink3: #6b5e4a;
--ink4: #9c8e7c;
--rule: #c8bfb0;
--rule2: #d8d0c4;
/* Accent palette — copper / verdigris / vermillion */
--copper: #b5631a;
--copper2: #8a4a12;
--copper-tint: rgba(181,99,26,0.08);
--verd: #2a7a5c;
--verd2: #1a5a42;
--verd-tint: rgba(42,122,92,0.08);
--red: #c0392b;
--red-tint: rgba(192,57,43,0.07);
--slate: #2c3e50;
--gold: #8B7355;
--mono: 'Fira Code', monospace;
--serif: 'Cormorant Garamond', Georgia, serif;
--sans: 'Barlow', system-ui, sans-serif;
}
* { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior: smooth; }
body {
background: var(--bg);
color: var(--ink);
font-family: var(--sans);
font-size: 14px;
line-height: 1.65;
overflow-x: hidden;
}
/* Paper texture */
body::before {
content:'';
position:fixed; inset:0;
background-image:
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)' opacity='0.025'/%3E%3C/svg%3E");
pointer-events:none; z-index:0; mix-blend-mode: multiply;
}
/* ── GRID LINES (blueprint feel) ── */
.blueprint-grid {
position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.4;
background-image:
linear-gradient(var(--rule2) 1px, transparent 1px),
linear-gradient(90deg, var(--rule2) 1px, transparent 1px);
background-size: 40px 40px;
mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 40%, transparent 100%);
}
/* ── NAVIGATION ── */
.topnav {
position: sticky; top: 0; z-index: 200;
background: var(--ink);
display: flex; align-items: center;
padding: 0 48px;
gap: 0;
border-bottom: 2px solid var(--copper);
overflow-x: auto;
scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }
.nav-brand {
font-family: var(--serif);
font-size: 16px;
font-weight: 700;
color: var(--copper);
letter-spacing: 0.05em;
padding: 14px 24px 14px 0;
border-right: 1px solid #3a3028;
margin-right: 8px;
white-space: nowrap;
flex-shrink: 0;
}
.topnav a {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.2em;
text-transform: uppercase;
color: #6a5a48;
text-decoration: none;
padding: 18px 16px;
transition: color 0.2s;
white-space: nowrap;
flex-shrink: 0;
}
.topnav a:hover { color: var(--copper); }
/* ── HERO ── */
.hero {
position: relative; z-index: 1;
padding: 80px 80px 60px;
border-bottom: 1px solid var(--rule);
display: grid;
grid-template-columns: 1fr 360px;
gap: 80px;
align-items: end;
}
.hero-label {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.4em;
text-transform: uppercase;
color: var(--copper);
margin-bottom: 16px;
}
.hero h1 {
font-family: var(--serif);
font-size: clamp(60px, 8vw, 112px);
font-weight: 700;
line-height: 0.88;
color: var(--ink);
margin-bottom: 20px;
}
.hero h1 em { color: var(--copper); font-style: italic; }
.hero-desc {
font-size: 16px;
color: var(--ink3);
line-height: 1.8;
max-width: 560px;
}
.hero-index {
border: 1px solid var(--rule);
background: var(--bg2);
padding: 28px;
}
.hero-index-title {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.3em;
text-transform: uppercase;
color: var(--copper);
margin-bottom: 16px;
padding-bottom: 10px;
border-bottom: 1px solid var(--rule);
}
.hero-index ol {
list-style: none;
counter-reset: idx;
display: flex;
flex-direction: column;
gap: 0;
}
.hero-index ol li {
counter-increment: idx;
display: flex;
gap: 12px;
align-items: baseline;
padding: 7px 0;
border-bottom: 1px solid var(--rule2);
}
.hero-index ol li::before {
content: counter(idx, decimal-leading-zero);
font-family: var(--mono);
font-size: 9px;
color: var(--copper);
flex-shrink: 0;
}
.hero-index ol li a {
font-size: 13px;
color: var(--ink2);
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
}
.hero-index ol li a:hover { color: var(--copper); }
.hero-index ol li .dots {
flex: 1;
border-bottom: 1px dotted var(--rule);
margin-bottom: 3px;
}
/* ── CHAPTER SYSTEM ── */
.chapter {
position: relative; z-index: 1;
border-bottom: 1px solid var(--rule);
}
.chapter-header {
padding: 60px 80px 40px;
border-bottom: 1px solid var(--rule);
display: flex;
align-items: flex-start;
gap: 32px;
}
.chapter-num {
font-family: var(--serif);
font-size: 80px;
font-weight: 700;
line-height: 0.85;
color: var(--rule);
flex-shrink: 0;
user-select: none;
}
.chapter-meta { flex: 1; }
.chapter-eyebrow {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.4em;
text-transform: uppercase;
color: var(--copper);
margin-bottom: 10px;
}
.chapter-title {
font-family: var(--serif);
font-size: clamp(32px, 4vw, 56px);
font-weight: 700;
color: var(--ink);
line-height: 1.0;
margin-bottom: 12px;
}
.chapter-title em { color: var(--copper); font-style: italic; }
.chapter-intro {
font-size: 15px;
color: var(--ink3);
max-width: 680px;
line-height: 1.8;
font-style: italic;
}
.chapter-body {
padding: 48px 80px;
}
/* ── PATTERN CARDS ── */
.pattern-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 1px;
background: var(--rule);
border: 1px solid var(--rule);
margin-bottom: 40px;
}
.pattern-card {
background: var(--bg);
padding: 28px 32px;
transition: background 0.2s;
position: relative;
}
.pattern-card:hover { background: var(--bg2); }
.pattern-card::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0;
height: 3px;
}
.pattern-card.arch::before { background: var(--copper); }
.pattern-card.ddd::before { background: var(--verd); }
.pattern-card.ai::before { background: #7B68EE; }
.pattern-card.obs::before { background: var(--slate); }
.pattern-card.sec::before { background: var(--red); }
.pattern-card.data::before { background: #d4900a; }
.pattern-card.api::before { background: #2980b9; }
.pattern-card.ft::before { background: #8e44ad; }
.pattern-name {
font-family: var(--serif);
font-size: 22px;
font-weight: 700;
color: var(--ink);
margin-bottom: 4px;
line-height: 1.1;
}
.pattern-alias {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.15em;
color: var(--ink4);
text-transform: uppercase;
margin-bottom: 12px;
}
.pattern-desc {
font-size: 13px;
color: var(--ink3);
line-height: 1.7;
margin-bottom: 14px;
}
/* ── DIAGRAM BOXES (ASCII-art style) ── */
.diagram {
background: var(--bg3);
border: 1px solid var(--rule);
padding: 16px 20px;
font-family: var(--mono);
font-size: 11px;
line-height: 1.6;
color: var(--ink3);
overflow-x: auto;
white-space: pre;
margin: 12px 0;
}
.diagram .hl { color: var(--copper); font-weight: 600; }
.diagram .hl2 { color: var(--verd); }
.diagram .hl3 { color: var(--red); }
.diagram .dim { color: var(--ink4); }
/* ── CODE ── */
pre.code {
background: var(--ink);
border: none;
padding: 18px 22px;
font-family: var(--mono);
font-size: 11.5px;
line-height: 1.75;
overflow-x: auto;
color: #8aabb0;
margin: 14px 0;
}
pre.code .kw { color: #d4956a; }
pre.code .tp { color: #7fc4c8; }
pre.code .str { color: #a0c878; }
pre.code .cm { color: #4a5a60; }
pre.code .fn { color: #c8dae0; }
pre.code .ann { color: #b8a060; }
pre.code .num { color: #e8a060; }
pre.code .op { color: #5a8090; }
/* ── TABLES ── */
.ref-table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
margin: 16px 0;
}
.ref-table thead tr {
border-bottom: 2px solid var(--copper);
}
.ref-table th {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.25em;
text-transform: uppercase;
color: var(--copper);
padding: 10px 14px;
text-align: left;
background: var(--bg2);
}
.ref-table td {
padding: 10px 14px;
border-bottom: 1px solid var(--rule2);
color: var(--ink2);
vertical-align: top;
line-height: 1.6;
}
.ref-table tr:hover td { background: var(--bg2); }
.ref-table td:first-child {
font-family: var(--mono);
font-size: 11px;
font-weight: 600;
color: var(--ink);
white-space: nowrap;
}
code {
font-family: var(--mono);
font-size: 11px;
background: var(--bg3);
border: 1px solid var(--rule);
padding: 1px 5px;
color: var(--copper2);
}
/* ── CALLOUTS ── */
.callout {
padding: 16px 20px;
margin: 16px 0;
font-size: 13px;
line-height: 1.7;
border-left: 3px solid;
}
.callout-copper { border-color: var(--copper); background: var(--copper-tint); color: var(--ink2); }
.callout-verd { border-color: var(--verd); background: var(--verd-tint); color: var(--ink2); }
.callout-red { border-color: var(--red); background: var(--red-tint); color: var(--ink2); }
.callout b {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.2em;
text-transform: uppercase;
display: block;
margin-bottom: 6px;
}
.callout-copper b { color: var(--copper); }
.callout-verd b { color: var(--verd); }
.callout-red b { color: var(--red); }
/* ── SECTION DIVIDER ── */
.section-divider {
display: flex;
align-items: center;
gap: 16px;
margin: 40px 0 28px;
}
.section-divider .label {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.3em;
text-transform: uppercase;
color: var(--copper);
white-space: nowrap;
flex-shrink: 0;
}
.section-divider::before,
.section-divider::after {
content: '';
flex: 1;
height: 1px;
background: var(--rule);
}
/* ── TWO COLUMNS ── */
.two-col {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 32px;
margin: 24px 0;
}
.three-col {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 24px;
margin: 24px 0;
}
/* ── KEY-VALUE DEFINITION BLOCKS ── */
.def-block {
background: var(--bg2);
border: 1px solid var(--rule);
padding: 20px 24px;
}
.def-block h4 {
font-family: var(--serif);
font-size: 18px;
font-weight: 700;
color: var(--ink);
margin-bottom: 6px;
}
.def-block .def-sub {
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.2em;
text-transform: uppercase;
color: var(--copper);
margin-bottom: 10px;
}
.def-block p {
font-size: 12px;
color: var(--ink3);
line-height: 1.65;
}
/* ── FORMULA / LAW BOX ── */
.law-box {
background: var(--ink);
color: #e8dfd0;
padding: 24px 28px;
margin: 20px 0;
position: relative;
}
.law-box::before {
content: attr(data-label);
position: absolute;
top: -1px; right: 20px;
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.2em;
background: var(--copper);
color: var(--ink);
padding: 3px 10px;
font-weight: 600;
}
.law-box .law-title {
font-family: var(--serif);
font-size: 24px;
font-weight: 700;
color: #e8c88a;
margin-bottom: 10px;
}
.law-box .law-body {
font-size: 13px;
line-height: 1.75;
color: #b0a898;
}
.law-box .law-body strong { color: #e8c88a; }
/* ── BADGES / TAGS ── */
.badge {
display: inline-block;
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 2px 7px;
border: 1px solid;
margin: 2px;
}
.badge-copper { color: var(--copper); border-color: var(--copper2); background: var(--copper-tint); }
.badge-verd { color: var(--verd); border-color: var(--verd2); background: var(--verd-tint); }
.badge-red { color: var(--red); border-color: #7a2020; background: var(--red-tint); }
.badge-slate { color: var(--slate); border-color: #1a2530; background: rgba(44,62,80,0.07); }
.badge-gold { color: var(--gold); border-color: #5a4a35; background: rgba(139,115,85,0.08); }
/* ── FINTECH STATE MACHINE ── */
.state-row {
display: flex;
align-items: center;
gap: 0;
flex-wrap: wrap;
margin: 16px 0;
}
.state-box {
border: 1px solid var(--rule);
background: var(--bg2);
padding: 8px 14px;
font-family: var(--mono);
font-size: 11px;
color: var(--ink2);
white-space: nowrap;
}
.state-box.terminal { background: var(--verd-tint); border-color: var(--verd2); color: var(--verd); }
.state-box.error { background: var(--red-tint); border-color: #7a2020; color: var(--red); }
.state-box.start { background: var(--copper-tint); border-color: var(--copper2); color: var(--copper); }
.state-arrow {
font-family: var(--mono);
font-size: 11px;
color: var(--ink4);
padding: 0 6px;
}
/* ── MATH / FORMULA ── */
.math {
font-family: var(--mono);
font-size: 12px;
background: var(--bg3);
border: 1px solid var(--rule);
padding: 10px 16px;
color: var(--ink2);
display: block;
margin: 8px 0;
}
.math .var { color: var(--copper); font-style: italic; }
/* ── FOOTER ── */
.footer {
position: relative; z-index: 1;
border-top: 2px solid var(--ink);
padding: 60px 80px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 48px;
}
.footer-col h4 {
font-family: var(--serif);
font-size: 22px;
font-weight: 700;
color: var(--ink);
margin-bottom: 12px;
}
.footer-col p, .footer-col li {
font-size: 13px;
color: var(--ink3);
line-height: 1.7;
}
.footer-col ul { list-style: none; }
.footer-col ul li { padding: 3px 0; border-bottom: 1px solid var(--rule2); }
/* ── RESPONSIVE ── */
@media (max-width: 900px) {
.hero { grid-template-columns: 1fr; padding: 48px 24px; gap: 32px; }
.chapter-header { padding: 40px 24px 28px; flex-direction: column; gap: 16px; }
.chapter-num { font-size: 48px; }
.chapter-body { padding: 32px 24px; }
.topnav { padding: 0 24px; }
.two-col, .three-col { grid-template-columns: 1fr; }
.footer { padding: 40px 24px; grid-template-columns: 1fr; }
}
/* ── ANIMATIONS ── */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.in { opacity: 1; transform: none; }
</style>
</head>
<body>
<div class="blueprint-grid"></div>
<!-- NAV -->
<nav class="topnav">
<div class="nav-brand">The Engineer's Codex</div>
<a href="#arch">Architecture</a>
<a href="#ddd">DDD</a>
<a href="#distributed">Distributed</a>
<a href="#ai-patterns">AI Patterns</a>
<a href="#observability">Observability</a>
<a href="#api">API Design</a>
<a href="#security">Security</a>
<a href="#data">Data Patterns</a>
<a href="#fintech">Fintech</a>
<a href="#sysdesign">Sys Design</a>
<a href="#mental">Mental Models</a>
</nav>
<!-- HERO -->
<section class="hero">
<div>
<div class="hero-label">Volume III · Architecture · Patterns · Systems · AI</div>
<h1>The<br>Engineer's<br><em>Codex</em></h1>
<p class="hero-desc">
The final layer. Everything that surrounds the code: how systems are structured, how distributed failures behave, how AI applications are architected, how fintech operations actually work, and the mental models that separate engineers from senior engineers.
</p>
</div>
<div>
<div class="hero-index">
<div class="hero-index-title">Contents</div>
<ol>
<li><a href="#arch">Architecture Patterns</a><span class="dots"></span></li>
<li><a href="#ddd">Domain-Driven Design</a><span class="dots"></span></li>
<li><a href="#distributed">Distributed Systems</a><span class="dots"></span></li>
<li><a href="#ai-patterns">AI Engineering Patterns</a><span class="dots"></span></li>
<li><a href="#observability">Observability & SRE</a><span class="dots"></span></li>
<li><a href="#api">API Design Patterns</a><span class="dots"></span></li>
<li><a href="#security">Security Patterns</a><span class="dots"></span></li>
<li><a href="#data">Data Architecture</a><span class="dots"></span></li>
<li><a href="#fintech">Fintech Specifics</a><span class="dots"></span></li>
<li><a href="#sysdesign">System Design</a><span class="dots"></span></li>
<li><a href="#mental">Mental Models</a><span class="dots"></span></li>
</ol>
</div>
</div>
</section>
<!-- ═══ CHAPTER 1: ARCHITECTURE ═══ -->
<section class="chapter reveal" id="arch">
<div class="chapter-header">
<div class="chapter-num">01</div>
<div class="chapter-meta">
<div class="chapter-eyebrow">System Structure</div>
<h2 class="chapter-title">Architecture <em>Patterns</em></h2>
<p class="chapter-intro">The vocabulary of how to arrange code, services, and responsibilities. These are the patterns interviewers ask about and that production systems live or die by.</p>
</div>
</div>
<div class="chapter-body">
<div class="section-divider"><span class="label">Structural Architectures</span></div>
<div class="pattern-grid">
<div class="pattern-card arch">
<div class="pattern-name">Hexagonal Architecture</div>
<div class="pattern-alias">Ports & Adapters · Alistair Cockburn 2005</div>
<div class="pattern-desc">The application core is surrounded by ports (interfaces) and adapters (implementations). Business logic has zero dependency on frameworks, databases, or UI. The most production-proven architecture for testable, maintainable services.</div>
<div class="diagram"><span class="hl"> [ HTTP Adapter ] [ Kafka Adapter ]
↓ ↓
┌─────────────────────────────┐
│ PORT: PaymentInputPort │
│ ┌───────────────────────┐ │
│ │ DOMAIN / USE CASES │ │
│ └───────────────────────┘ │
│ PORT: PaymentRepoPort │
└─────────────────────────────┘
↓ ↓
[ JPA Adapter ] [ InMemory Adapter ]</span></div>
<div><span class="badge badge-copper">Primary Ports</span><span class="badge badge-copper">Secondary Ports</span><span class="badge badge-verd">Testable Core</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">Clean Architecture</div>
<div class="pattern-alias">Uncle Bob · Onion Variant</div>
<div class="pattern-desc">Concentric dependency rings: Entities → Use Cases → Interface Adapters → Frameworks. Dependency Rule: source code dependencies must point inward only. The domain never imports Spring, JPA, or anything external.</div>
<div class="diagram"><span class="hl"> ┌────────────────────────────────┐
│ Frameworks & Drivers (outer) │
│ ┌──────────────────────────┐ │
│ │ Interface Adapters │ │
│ │ ┌────────────────────┐ │ │
│ │ │ Use Cases │ │ │
│ │ │ ┌──────────────┐ │ │ │
│ │ │ │ Entities │ │ │ │
│ │ │ └──────────────┘ │ │ │
│ │ └────────────────────┘ │ │
│ └──────────────────────────┘ │
└────────────────────────────────┘</span></div>
<div><span class="badge badge-copper">Dependency Rule</span><span class="badge badge-verd">Framework-Free Core</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">CQRS</div>
<div class="pattern-alias">Command Query Responsibility Segregation</div>
<div class="pattern-desc">Separate the write model (commands that change state) from the read model (queries that return data). Enables independent scaling of reads/writes, optimized read models (denormalized projections), and eliminates impedance mismatch between domain objects and query DTOs.</div>
<div class="diagram"><span class="hl"> Command Side Query Side
───────────── ──────────────
CreatePayment ─┐ PaymentSummary
UpdateStatus ─┤─→ PaymentDetail
RefundPayment ─┘ DashboardView
│ ↑
Write Store → Read Store (projection)</span></div>
<div><span class="badge badge-copper">Commands</span><span class="badge badge-copper">Queries</span><span class="badge badge-verd">Read Scaling</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">Event Sourcing</div>
<div class="pattern-alias">Store Events, Not State · Greg Young</div>
<div class="pattern-desc">The database stores the sequence of events that led to current state, not the current state itself. Current state is derived by replaying events. Natural audit log, time travel debugging, event replay to rebuild projections. Pairs naturally with CQRS. Complex; don't use without genuine need.</div>
<div class="diagram"><span class="hl"> Event Store (append-only):
┌────────────────────────────────────┐
│ 1. PaymentCreated {id, amount} │
│ 2. PaymentValidated {riskScore} │
│ 3. PaymentCharged {txRef} │
│ 4. PaymentSettled {timestamp} │
└────────────────────────────────────┘
↓ replay ↓
Current State = fold(events, initialState)</span></div>
<div><span class="badge badge-copper">Append-Only</span><span class="badge badge-copper">Replay</span><span class="badge badge-verd">Audit Trail</span><span class="badge badge-red">Complexity Cost</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">Saga Pattern</div>
<div class="pattern-alias">Distributed Transactions Without 2PC</div>
<div class="pattern-desc">A sequence of local transactions, each publishing events that trigger the next. If a step fails, compensating transactions undo completed steps. Two flavors: Choreography (services react to events) and Orchestration (a saga orchestrator directs steps). Fintech critical — payment spans multiple services.</div>
<div class="diagram"><span class="hl"> ORCHESTRATION SAGA (explicit controller):
SagaOrchestrator
→ PaymentService.reserve() ✓
→ RiskService.check() ✓
→ LedgerService.debit() ✗ ← FAILS
← LedgerService (compensate)
← PaymentService.release() ← rollback
CHOREOGRAPHY SAGA (event-driven):
PaymentCreated →→ RiskChecked →→ LedgerDebited
↓ if fails
LedgerFailedEvt →→ PaymentReleased</span></div>
<div><span class="badge badge-copper">Compensating Txn</span><span class="badge badge-verd">Eventual Consistency</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">Strangler Fig</div>
<div class="pattern-alias">Legacy Migration · Martin Fowler</div>
<div class="pattern-desc">Gradually replace a legacy monolith by wrapping it with new services. Route specific endpoints to new microservices while the monolith handles the rest. The new system "strangles" the old one over time until nothing routes to the monolith. The only responsible way to containerize legacy fintech apps.</div>
<div class="diagram"><span class="hl"> Phase 1: All → [Monolith]
Phase 2: /payments/* → [New PaymentSvc]
/users/* → [Monolith]
Phase 3: /payments/* → [New PaymentSvc]
/accounts/* → [New AccountSvc]
/reports/* → [Monolith] (shrinking)
Phase N: Monolith = empty → decommission</span></div>
<div><span class="badge badge-copper">Incremental</span><span class="badge badge-verd">Risk-Mitigated</span><span class="badge badge-gold">Job Relevant</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">Sidecar Pattern</div>
<div class="pattern-alias">Service Mesh · Envoy · Istio</div>
<div class="pattern-desc">Deploy a helper container alongside the main service container in the same pod. The sidecar handles cross-cutting concerns: mTLS, observability, rate limiting, circuit breaking. Your app code stays simple; the mesh handles reliability. Envoy proxy is the canonical sidecar. Critical for zero-trust fintech networking.</div>
<div class="diagram"><span class="hl"> ┌─── Pod ─────────────────────────────┐
│ ┌──────────────┐ ┌─────────────┐ │
│ │ Your App │ │ Envoy │ │
│ │ (Spring │←→│ Sidecar │ │
│ │ Boot) │ │ mTLS │ │
│ │ │ │ Metrics │ │
│ │ │ │ Tracing │ │
│ └──────────────┘ └─────────────┘ │
└─────────────────────────────────────┘</span></div>
<div><span class="badge badge-copper">Cross-Cutting</span><span class="badge badge-verd">mTLS</span><span class="badge badge-slate">Kubernetes Native</span></div>
</div>
<div class="pattern-card arch">
<div class="pattern-name">BFF Pattern</div>
<div class="pattern-alias">Backend For Frontend</div>
<div class="pattern-desc">Create a dedicated backend API for each frontend type (mobile app, web SPA, partner API). Each BFF aggregates and transforms data specifically for its client, avoiding the "too much / too little" problem of a generic API. Common in fintech: different data needs for mobile banking vs web dashboard vs partner integrations.</div>
<div class="diagram"><span class="hl"> [Mobile App] → [Mobile BFF] ─┐
[Web SPA] → [Web BFF] ─┤→ [Microservices]
[Partner API]→ [Partner BFF] ─┘
Each BFF: tailored aggregation, auth, rate limits</span></div>
<div><span class="badge badge-copper">Client-Specific</span><span class="badge badge-verd">API Tailoring</span></div>
</div>
</div>
<div class="callout callout-copper">
<b>💡 Architecture Interview Move</b>
When asked "how would you design a payment system?", the correct answer layers these: Hexagonal architecture for each service (testable domain), CQRS to separate payment write commands from reporting queries, Saga for multi-service payment flows, Strangler Fig if modernizing legacy, and Sidecar for the service mesh. Name-dropping one pattern shows reading; composing all five shows experience.
</div>
</div>
</section>
<!-- ═══ CHAPTER 2: DDD ═══ -->
<section class="chapter reveal" id="ddd">
<div class="chapter-header">
<div class="chapter-num">02</div>
<div class="chapter-meta">
<div class="chapter-eyebrow">Eric Evans · Vaughn Vernon</div>
<h2 class="chapter-title">Domain-Driven <em>Design</em></h2>
<p class="chapter-intro">DDD is not a framework — it's a language for having precise conversations about complex business domains. In fintech, the domain IS the competitive advantage.</p>
</div>
</div>
<div class="chapter-body">
<div class="section-divider"><span class="label">Strategic Design — The Big Picture</span></div>
<div class="three-col">
<div class="def-block">
<div class="def-sub">Strategic Pattern</div>
<h4>Bounded Context</h4>
<p>A semantic boundary within which a domain model is consistent and unambiguous. "Account" means different things in Banking (balance, transactions) vs Identity (user credentials). Each bounded context owns its model — no cross-context JPA join. Maps 1:1 to microservices in well-designed systems.</p>
</div>
<div class="def-block">
<div class="def-sub">Strategic Pattern</div>
<h4>Context Map</h4>
<p>A diagram showing how bounded contexts relate: Upstream/Downstream, Customer/Supplier, Partnership, Shared Kernel, Conformist, Anti-Corruption Layer (ACL). The ACL is critical when integrating legacy systems — translate their model into yours at the boundary, don't let their concepts pollute your domain.</p>
</div>
<div class="def-block">
<div class="def-sub">Strategic Pattern</div>
<h4>Ubiquitous Language</h4>
<p>A shared vocabulary between developers and domain experts, reflected exactly in code. If the business says "authorization" and "capture" for card payments, your code has <code>authorize()</code> and <code>capture()</code> — not <code>processStep1()</code> and <code>processStep2()</code>. The language evolves the model.</p>
</div>
</div>
<div class="section-divider"><span class="label">Tactical Design — The Building Blocks</span></div>
<div class="ref-table-wrap">
<table class="ref-table">
<thead>
<tr><th>Building Block</th><th>Identity?</th><th>Mutable?</th><th>Definition</th><th>Java Implementation</th></tr>
</thead>
<tbody>
<tr>
<td>Entity</td>
<td>✓ Yes</td>
<td>✓ Yes</td>
<td>An object defined by its identity, not its attributes. Two Payments with same amount but different IDs are different entities. Identity persists through state changes.</td>
<td><code>@Entity class Payment { private PaymentId id; ... }</code> — identity via equals/hashCode on ID only</td>
</tr>
<tr>
<td>Value Object</td>
<td>✗ No</td>
<td>✗ No</td>
<td>Defined entirely by its attributes. Two <code>Money(100, USD)</code> objects are equal and interchangeable. Immutable. No identity. Replaces primitives: use <code>Money</code>, not <code>double</code>.</td>
<td>Java <code>record Money(BigDecimal amount, Currency currency) {}</code> — records are perfect VOs</td>
</tr>
<tr>
<td>Aggregate</td>
<td>✓ (root)</td>
<td>✓ (via root)</td>
<td>A cluster of entities and VOs with a single root entity. All access to the cluster goes through the Aggregate Root. Enforces invariants at the boundary. Transactional consistency unit.</td>
<td><code>Order</code> aggregate root owns <code>OrderLine</code> entities — never access OrderLine directly from outside Order</td>
</tr>
<tr>
<td>Repository</td>
<td>—</td>
<td>—</td>
<td>Abstracts the persistence of aggregates. Returns aggregate roots only. The interface lives in the domain layer; the JPA implementation lives in the infrastructure layer. This is the Hexagonal port/adapter boundary.</td>
<td><code>interface PaymentRepo { Payment findById(PaymentId); void save(Payment); }</code></td>
</tr>
<tr>
<td>Domain Service</td>
<td>—</td>
<td>—</td>
<td>Domain logic that doesn't naturally fit one entity or VO. Cross-aggregate coordination. Stateless. If you find yourself putting logic in a utility class, it's probably a Domain Service.</td>
<td><code>class TransferService { void transfer(Account from, Account to, Money amount) }</code></td>
</tr>
<tr>
<td>Domain Event</td>
<td>✓ (implicit)</td>
<td>✗ No</td>
<td>Something that happened in the domain that other parts of the system care about. Immutable facts. Drives sagas, projections, notifications. Named in past tense: <code>PaymentAuthorized</code>, not <code>AuthorizePayment</code>.</td>
<td><code>record PaymentAuthorized(PaymentId id, Instant at, Money amount) implements DomainEvent {}</code></td>
</tr>
</tbody>
</table>
</div>
<pre class="code"><span class="cm">// DDD Aggregate in Java 21 — the full idiom</span>
<span class="kw">public class</span> <span class="tp">Payment</span> { <span class="cm">// Aggregate Root</span>
<span class="kw">private final</span> <span class="tp">PaymentId</span> id; <span class="cm">// typed identity, not String</span>
<span class="kw">private final</span> <span class="tp">Money</span> amount; <span class="cm">// Value Object, not BigDecimal</span>
<span class="kw">private</span> <span class="tp">PaymentStatus</span> status;
<span class="kw">private final</span> List<<span class="tp">DomainEvent</span>> events = <span class="kw">new</span> ArrayList<>();
<span class="cm">// Business methods express domain language, not CRUD</span>
<span class="kw">public void</span> <span class="fn">authorize</span>(<span class="tp">RiskAssessment</span> risk) {
<span class="kw">if</span> (status != <span class="tp">PaymentStatus</span>.PENDING)
<span class="kw">throw new</span> <span class="tp">InvalidPaymentStateException</span>(id, status, <span class="str">"authorize"</span>);
<span class="kw">if</span> (risk.isHighRisk() && amount.exceeds(<span class="tp">Money</span>.of(<span class="num">10000</span>, <span class="tp">USD</span>)))
<span class="kw">throw new</span> <span class="tp">RiskLimitExceededException</span>(id, risk);
<span class="kw">this</span>.status = <span class="tp">PaymentStatus</span>.AUTHORIZED;
events.add(<span class="kw">new</span> <span class="tp">PaymentAuthorized</span>(id, <span class="tp">Instant</span>.now(), amount));
}
<span class="cm">// Invariant: amount must be positive — enforced in constructor/factory</span>
<span class="kw">public static</span> <span class="tp">Payment</span> <span class="fn">create</span>(<span class="tp">Money</span> amount, <span class="tp">Merchant</span> merchant) {
<span class="kw">if</span> (!amount.isPositive()) <span class="kw">throw new</span> <span class="tp">IllegalArgumentException</span>(<span class="str">"Amount must be positive"</span>);
<span class="kw">var</span> p = <span class="kw">new</span> <span class="tp">Payment</span>(<span class="tp">PaymentId</span>.generate(), amount, merchant);
p.events.add(<span class="kw">new</span> <span class="tp">PaymentCreated</span>(p.id, amount, merchant.id()));
<span class="kw">return</span> p;
}
}</pre>
<div class="callout callout-verd">
<b>💡 DDD in Fintech — The Killer Application</b>
Fintech has the most DDD-amenable domain on earth. "Authorization," "capture," "settlement," "chargeback," "reconciliation" — these are precise, legally-defined terms that every business stakeholder uses exactly. If your code uses those same words, bugs become immediately visible to non-engineers. That's DDD's core promise.
</div>
</div>
</section>
<!-- ═══ CHAPTER 3: DISTRIBUTED SYSTEMS ═══ -->
<section class="chapter reveal" id="distributed">
<div class="chapter-header">
<div class="chapter-num">03</div>
<div class="chapter-meta">
<div class="chapter-eyebrow">Fallacies · Laws · Theorems</div>
<h2 class="chapter-title">Distributed <em>Systems</em></h2>
<p class="chapter-intro">The 8 fallacies of distributed computing are all lies you've believed at some point. These are the theorems and patterns that let you build honest, reliable systems anyway.</p>
</div>
</div>
<div class="chapter-body">
<div class="section-divider"><span class="label">The Fundamental Laws</span></div>
<div class="two-col">
<div class="law-box" data-label="THEOREM">
<div class="law-title">CAP Theorem — Brewer 2000</div>
<div class="law-body">
A distributed system can guarantee at most <strong>two</strong> of:<br>
<strong>Consistency</strong> — every read receives the most recent write<br>
<strong>Availability</strong> — every request receives a response<br>
<strong>Partition Tolerance</strong> — system continues despite network splits<br><br>
Since network partitions are <em>unavoidable</em> in production, you're really choosing between <strong>CP</strong> (consistent, possibly unavailable during partition) or <strong>AP</strong> (always available, possibly stale).<br><br>
Postgres = CP. Cassandra (default) = AP. DynamoDB = AP. ZooKeeper = CP.
</div>
</div>
<div class="law-box" data-label="REFINEMENT">
<div class="law-title">PACELC — Abadi 2012</div>
<div class="law-body">
CAP only addresses partition scenarios. PACELC extends it:<br><br>