go-duck-cli 1.0.9 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +30 -15
  2. package/generators/ai_docs.js +130 -0
  3. package/generators/broker.js +63 -0
  4. package/generators/config.js +149 -7
  5. package/generators/devops.js +210 -43
  6. package/generators/docs.js +23 -4
  7. package/generators/elasticsearch.js +263 -0
  8. package/generators/kratos.js +229 -41
  9. package/generators/metering.js +280 -48
  10. package/generators/migrations.js +92 -198
  11. package/generators/mqtt.js +2 -39
  12. package/generators/multitenancy.js +274 -71
  13. package/generators/nats.js +39 -0
  14. package/generators/outbox.js +171 -0
  15. package/generators/postgrest.js +7 -3
  16. package/generators/postman.js +405 -0
  17. package/generators/repository.js +27 -0
  18. package/generators/router.js +27 -0
  19. package/generators/security.js +95 -14
  20. package/generators/serverless.js +147 -0
  21. package/generators/storage.js +589 -0
  22. package/generators/swagger.js +84 -60
  23. package/generators/telemetry.js +23 -32
  24. package/generators/websocket.js +55 -21
  25. package/index.js +493 -116
  26. package/package.json +6 -4
  27. package/parser/gdl.js +163 -24
  28. package/templates/docs/index.html.hbs +5 -5
  29. package/templates/docs/layout.hbs +221 -62
  30. package/templates/docs/pages/audit.hbs +83 -35
  31. package/templates/docs/pages/cli.hbs +18 -0
  32. package/templates/docs/pages/configuration.hbs +241 -0
  33. package/templates/docs/pages/datadog.hbs +46 -0
  34. package/templates/docs/pages/elasticsearch.hbs +121 -0
  35. package/templates/docs/pages/federation.hbs +241 -0
  36. package/templates/docs/pages/gdl-advanced.hbs +91 -0
  37. package/templates/docs/pages/gdl-annotations.hbs +137 -0
  38. package/templates/docs/pages/gdl-entities.hbs +134 -0
  39. package/templates/docs/pages/gdl-relationships.hbs +80 -0
  40. package/templates/docs/pages/gdl.hbs +60 -204
  41. package/templates/docs/pages/graphql.hbs +58 -44
  42. package/templates/docs/pages/grpc.hbs +53 -90
  43. package/templates/docs/pages/hybrid-store.hbs +127 -0
  44. package/templates/docs/pages/index.hbs +418 -149
  45. package/templates/docs/pages/keycloak.hbs +43 -0
  46. package/templates/docs/pages/legend.hbs +116 -0
  47. package/templates/docs/pages/mosquitto.hbs +39 -0
  48. package/templates/docs/pages/multitenancy.hbs +139 -71
  49. package/templates/docs/pages/otel.hbs +40 -0
  50. package/templates/docs/pages/realtime.hbs +38 -12
  51. package/templates/docs/pages/redis.hbs +40 -0
  52. package/templates/docs/pages/rest.hbs +120 -202
  53. package/templates/docs/pages/saga.hbs +94 -0
  54. package/templates/docs/pages/security.hbs +150 -44
  55. package/templates/docs/pages/serverless.hbs +157 -0
  56. package/templates/docs/pages/storage.hbs +127 -0
  57. package/templates/docs/pages/wizard.hbs +683 -0
  58. package/templates/docs/triple_identity_registry.png +0 -0
  59. package/templates/go/controller.go.hbs +287 -283
  60. package/templates/go/entity.go.hbs +17 -15
  61. package/templates/go/main.go.hbs +47 -180
  62. package/templates/go/migrator.go.hbs +65 -0
  63. package/templates/go/router.go.hbs +272 -0
  64. package/templates/graphql/resolver.go.hbs +53 -34
  65. package/templates/graphql/schema.graphql.hbs +17 -5
  66. package/templates/kratos/service.go.hbs +169 -34
  67. package/templates/proto/entity.proto.hbs +10 -14
  68. package/test_nested.gdl +21 -0
  69. package/templates/docs/intro.mp4 +0 -0
  70. package/test_parser.js +0 -9
@@ -0,0 +1,43 @@
1
+ <h1 class="text-4xl font-extrabold text-gray-900 mb-4">Keycloak: Identity & Access Management</h1>
2
+ <p class="text-lg text-gray-600 mb-8">Secure your microservices with industrial-strength OIDC/JWT authentication powered by Keycloak.</p>
3
+
4
+ <section class="mb-10">
5
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Centralized Identity</h2>
6
+ <p class="mb-4 text-gray-700">Identity management is a first-class citizen in GO-DUCK. Every microservice is pre-configured to validate <strong>JSON Web Tokens (JWT)</strong> issued by Keycloak. This ensures that only authenticated users and services can access your data.</p>
7
+ </section>
8
+
9
+ <section class="mb-10">
10
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">JWT Validation & Security</h2>
11
+ <p class="mb-4">The generated <code>middleware.JWTMiddleware()</code> handles several critical security tasks:</p>
12
+ <ul class="list-disc pl-8 mb-4 text-gray-700 space-y-2">
13
+ <li><strong>Digital Signature Verification</strong>: Validates the token against Keycloak's public keys (JWKS).</li>
14
+ <li><strong>Expiration Enforcement</strong>: Ensures tokens are still within their valid time window.</li>
15
+ <li><strong>Role Extraction</strong>: Seamlessly extracts user roles and injects them into the Gin context for downstream authorization.</li>
16
+ <li><strong>Context Safety</strong>: Populates <code>KeycloakID</code> in the context to prevent header spoofing in audit and metering modules.</li>
17
+ </ul>
18
+
19
+ <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 mb-6 rounded-r">
20
+ <p class="text-yellow-900"><strong>Authorization:</strong> Beyond simple authentication, the middleware extracts the <code>realm_access.roles</code> from the token. You can use these roles to implement fine-grained RBAC inside your controllers.</p>
21
+ </div>
22
+ </section>
23
+
24
+ <section class="mb-10">
25
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Configuration</h2>
26
+ <p class="mb-4 text-gray-700">Connecting your GO-DUCK app to Keycloak is a simple matter of YAML configuration:</p>
27
+ <pre><code class="language-yaml">go-duck:
28
+ security:
29
+ oidc:
30
+ issuer: "http://keycloak:8080/realms/{{appName}}"
31
+ client-id: "backend-service"
32
+ # Public key URL for token verification
33
+ jwks-url: "http://keycloak:8080/realms/{{appName}}/protocol/openid-connect/certs"</code></pre>
34
+ </section>
35
+
36
+ <section class="mb-10">
37
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">External Resources</h2>
38
+ <ul class="space-y-2">
39
+ <li><a href="https://www.keycloak.org/documentation" target="_blank" class="text-indigo-600 hover:underline">Keycloak Official Documentation &rarr;</a></li>
40
+ <li><a href="https://openid.net/connect/" target="_blank" class="text-indigo-600 hover:underline">OpenID Connect (OIDC) Standard &rarr;</a></li>
41
+ <li><a href="https://jwt.io/" target="_blank" class="text-indigo-600 hover:underline">JWT.io: Debugging & Decoding Tokens &rarr;</a></li>
42
+ </ul>
43
+ </section>
@@ -0,0 +1,116 @@
1
+ <div class="prose prose-slate max-w-none">
2
+
3
+ <!-- Page Header -->
4
+ <div class="mb-16">
5
+ <div class="flex items-center gap-4 mb-6">
6
+ <span class="w-14 h-14 rounded-2xl bg-gradient-to-tr from-orange-400 to-rose-500 text-white flex items-center justify-center shadow-lg text-2xl">🦆</span>
7
+ <div>
8
+ <p class="text-xs font-bold uppercase tracking-widest text-orange-500 mb-1">Brand Lore</p>
9
+ <h1 class="text-5xl font-black text-slate-900 tracking-tighter m-0 leading-none">The Legend of the Century</h1>
10
+ </div>
11
+ </div>
12
+ <p class="text-xl text-slate-500 leading-relaxed max-w-3xl">The epic origin story of GO-DUCK — how a Gopher, a Duck, a Bottle of Gin, and the Mark of Kratos forged the mightiest microservice generator ever conceived.</p>
13
+ <div class="mt-6 h-px bg-gradient-to-r from-orange-200 via-rose-200 to-purple-200"></div>
14
+ </div>
15
+
16
+ <!-- Story Container -->
17
+ <div class="bg-white rounded-[2.5rem] p-10 md:p-16 border border-slate-200 shadow-2xl shadow-indigo-100/50 relative overflow-hidden">
18
+ <!-- Background Accents -->
19
+ <div class="absolute top-0 right-0 w-[40rem] h-[40rem] bg-indigo-50/50 rounded-full blur-[100px] -mr-48 -mt-48 pointer-events-none"></div>
20
+ <div class="absolute bottom-0 left-0 w-[30rem] h-[30rem] bg-purple-50/50 rounded-full blur-[100px] -ml-32 -mb-32 pointer-events-none"></div>
21
+
22
+ <div class="relative z-10 space-y-20">
23
+
24
+ <!-- Chapter 1 -->
25
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
26
+ <div class="order-2 lg:order-1">
27
+ <p class="text-xs font-bold uppercase tracking-widest text-indigo-400 mb-3">Chapter I</p>
28
+ <h2 class="text-3xl font-extrabold text-slate-800 mb-5 font-serif italic text-indigo-700">The Encounter at the Crossroads</h2>
29
+ <p class="text-slate-600 leading-relaxed text-lg">In the legendary Silicon Valley of Code, a nomadic <strong>Gopher</strong>—lightning-fast and known for his tireless concurrency—crossed paths with a <strong>Duck</strong> from the Great Persistence Bayou. The Duck held the wisdom of adaptability and the secret to navigating ever-shifting business tides. They realized that while the Gopher built fast, the Duck built to survive. Together, they forged a pact to create the <strong>Generator of Kings</strong>.</p>
30
+ </div>
31
+ <div class="order-1 lg:order-2 flex justify-center">
32
+ <div class="relative group cursor-zoom-in" onclick="openLightbox('logo.png')">
33
+ <div class="absolute inset-0 bg-indigo-400 blur-3xl opacity-20 group-hover:opacity-40 transition-all duration-700 rounded-full"></div>
34
+ <img src="logo.png" alt="Partnership" class="w-80 h-80 object-contain filter drop-shadow-[0_20px_50px_rgba(0,0,0,0.2)] group-hover:scale-110 transition-transform duration-700 relative z-10">
35
+ </div>
36
+ </div>
37
+ </div>
38
+
39
+ <div class="h-px bg-gradient-to-r from-transparent via-slate-200 to-transparent"></div>
40
+
41
+ <!-- Chapter 2 -->
42
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
43
+ <div class="flex justify-center">
44
+ <div class="relative group cursor-zoom-in" onclick="openLightbox('gin_bottle.png')">
45
+ <img src="gin_bottle.png" alt="The Brew" class="w-80 h-80 object-contain filter drop-shadow-2xl group-hover:rotate-6 transition-transform duration-500">
46
+ <div class="absolute -bottom-4 -right-4 bg-white px-4 py-2 rounded-xl shadow-lg border border-slate-100 font-bold text-indigo-600 text-sm">Gin Gonic Tonic</div>
47
+ </div>
48
+ </div>
49
+ <div>
50
+ <p class="text-xs font-bold uppercase tracking-widest text-fuchsia-400 mb-3">Chapter II</p>
51
+ <h2 class="text-3xl font-extrabold text-slate-800 mb-5 font-serif italic text-fuchsia-700">The Refreshment of Performance</h2>
52
+ <p class="text-slate-600 leading-relaxed text-lg">To fuel their grand design, they sought the <strong>Legendary Bottle of Gin</strong>. This magical brew wasn't just for hydration; it transformed their web routing into a crystalline, high-performance flow. Routes became fast, middleware became transparent, and the developer experience became as refreshing as a cold tonic on a summer's day. This gave GO-DUCK its distinctive, lightweight spirit.</p>
53
+ </div>
54
+ </div>
55
+
56
+ <div class="h-px bg-gradient-to-r from-transparent via-slate-200 to-transparent"></div>
57
+
58
+ <!-- Chapter 3 -->
59
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
60
+ <div class="order-2 lg:order-1">
61
+ <p class="text-xs font-bold uppercase tracking-widest text-emerald-400 mb-3">Chapter III</p>
62
+ <h2 class="text-3xl font-extrabold text-slate-800 mb-5 font-serif italic text-emerald-700">The Armor of the Divine</h2>
63
+ <p class="text-slate-600 leading-relaxed text-lg text-pretty">But speed without strength is a house made of cards. In the digital forge of the underworld, they recovered the <strong>Mark of Kratos</strong>. By stamping this sigil onto their internal services, they achieved gRPC industrial resilience. Every service became armored with strict Protocol Buffer contracts, ensuring that no matter how hard the system scaled, it would never break under the divine weight of technical debt.</p>
64
+ </div>
65
+ <div class="order-1 lg:order-2 flex justify-center">
66
+ <div class="relative group cursor-zoom-in" onclick="openLightbox('kratos_mark.png')">
67
+ <div class="absolute inset-0 bg-emerald-400 blur-3xl opacity-20 group-hover:opacity-40 transition-opacity"></div>
68
+ <img src="kratos_mark.png" alt="The Sigil" class="w-80 h-80 object-contain relative z-10 group-hover:scale-110 transition-transform duration-700">
69
+ </div>
70
+ </div>
71
+ </div>
72
+
73
+ <div class="h-px bg-gradient-to-r from-transparent via-slate-200 to-transparent"></div>
74
+
75
+ <!-- Chapter 4 -->
76
+ <div class="text-center max-w-4xl mx-auto">
77
+ <p class="text-xs font-bold uppercase tracking-widest text-amber-400 mb-3">Chapter IV</p>
78
+ <h2 class="text-3xl font-extrabold text-slate-900 mb-6 font-serif italic">The GDL Genesis</h2>
79
+ <p class="text-slate-600 leading-relaxed text-xl mb-10">Thus, the <strong>GDL (Go-Duck Language)</strong> was hatched. A single, simple tongue that could command entire legions of code. From that day forth, every developer who whispered GDL into the CLI would see their architecture <strong>evolve</strong>—bringing the Gopher's speed, the Duck's wisdom, the Gin's clarity, and the Kratos' strength into a single, unified masterpiece.</p>
80
+ <div class="flex justify-center gap-8 mb-10">
81
+ <div class="flex flex-col items-center gap-2">
82
+ <img src="logo.png" class="h-16 w-auto opacity-60 grayscale hover:grayscale-0 hover:opacity-100 transition-all duration-300 cursor-help" title="Adaptability — The Duck & Gopher">
83
+ <span class="text-xs font-bold text-slate-400 uppercase tracking-wider">Adaptability</span>
84
+ </div>
85
+ <div class="flex flex-col items-center gap-2">
86
+ <img src="gin_bottle.png" class="h-16 w-auto opacity-60 grayscale hover:grayscale-0 hover:opacity-100 transition-all duration-300 cursor-help" title="Clarity — The Gin Bottle">
87
+ <span class="text-xs font-bold text-slate-400 uppercase tracking-wider">Clarity</span>
88
+ </div>
89
+ <div class="flex flex-col items-center gap-2">
90
+ <img src="kratos_mark.png" class="h-16 w-auto opacity-60 grayscale hover:grayscale-0 hover:opacity-100 transition-all duration-300 cursor-help" title="Resilience — The Mark of Kratos">
91
+ <span class="text-xs font-bold text-slate-400 uppercase tracking-wider">Resilience</span>
92
+ </div>
93
+ </div>
94
+ <div class="inline-flex items-center gap-3 bg-gradient-to-r from-indigo-50 to-purple-50 border border-indigo-100 px-8 py-4 rounded-2xl">
95
+ <span class="text-2xl">🦆</span>
96
+ <span class="font-bold text-indigo-900">GO-DUCK — The Generator of Kings</span>
97
+ </div>
98
+ </div>
99
+
100
+ </div>
101
+ </div>
102
+
103
+ <!-- Epilogue CTA -->
104
+ <div class="mt-12 bg-slate-900 rounded-[2.5rem] p-12 text-center text-white relative overflow-hidden">
105
+ <div class="absolute inset-0 bg-gradient-to-br from-indigo-900/40 to-transparent"></div>
106
+ <div class="relative z-10">
107
+ <p class="text-slate-400 font-mono text-sm uppercase tracking-widest mb-4">The legend continues…</p>
108
+ <h3 class="text-3xl font-black mb-6 tracking-tight italic">Ready to write your chapter?</h3>
109
+ <div class="flex flex-wrap gap-4 justify-center">
110
+ <a href="gdl.html" class="px-8 py-4 bg-indigo-600 text-white font-bold rounded-xl hover:bg-indigo-500 transition-all uppercase tracking-widest text-xs shadow-lg">Learn GDL</a>
111
+ <a href="cli.html" class="px-8 py-4 bg-white/10 text-white font-bold rounded-xl hover:bg-white/20 transition-all border border-white/20 uppercase tracking-widest text-xs backdrop-blur-md">CLI Guide</a>
112
+ </div>
113
+ </div>
114
+ </div>
115
+
116
+ </div>
@@ -0,0 +1,39 @@
1
+ <h1 class="text-4xl font-extrabold text-gray-900 mb-4">Mosquitto & Event Streaming</h1>
2
+ <p class="text-lg text-gray-600 mb-8">Architect robust, event-driven microservices using Eclipse Mosquitto for high-performance MQTT messaging.</p>
3
+
4
+ <section class="mb-10">
5
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Why MQTT?</h2>
6
+ <p class="mb-4 text-gray-700">MQTT is a lightweight, publish-subscribe network protocol that transports messages between devices. In the GO-DUCK ecosystem, we use <strong>Eclipse Mosquitto</strong> as our primary message broker for ultra-low latency event streaming and internal service notifications.</p>
7
+ </section>
8
+
9
+ <section class="mb-10">
10
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">The Messaging Package</h2>
11
+ <p class="mb-4">GO-DUCK generates a clean <code>messaging</code> package that abstracts the MQTT client (Eclipse Paho). It handles reconnect strategies, certificate-based TLS (optional), and asynchronous publishing.</p>
12
+
13
+ <div class="bg-purple-50 border-l-4 border-purple-500 p-4 mb-6 rounded-r">
14
+ <p class="text-purple-900"><strong>Audit Streaming:</strong> By default, if <code>@Audited</code> is used in GDL, GO-DUCK streams all entity change events to the MQTT topic <code>audit/logs/{{appName}}</code> for real-time consumption by external analytics or notification engines.</p>
15
+ </div>
16
+
17
+ <h3 class="font-semibold mb-2 mt-6 text-xl">Publishing an Event</h3>
18
+ <pre><code class="language-go">import "{{appName}}/messaging"
19
+
20
+ // Publishing a custom JSON event
21
+ event := map[string]interface{}{"event": "user_signed_up", "email": "dev@goduck.io"}
22
+ messaging.Publish("events/users", event)</code></pre>
23
+ </section>
24
+
25
+ <section class="mb-10">
26
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Local Development</h2>
27
+ <p class="mb-4">Your <code>docker-compose.yml</code> includes a pre-configured Mosquitto image. You can use any MQTT client (like MQTT.fx or mosquitto_pub/sub) to listen to your service events.</p>
28
+ <pre><code class="language-bash"># Subscribe to all audit events locally
29
+ mosquitto_sub -h localhost -p 1883 -t "audit/logs/#" -v</code></pre>
30
+ </section>
31
+
32
+ <section class="mb-10">
33
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">External Resources</h2>
34
+ <ul class="space-y-2">
35
+ <li><a href="https://mosquitto.org/documentation/" target="_blank" class="text-indigo-600 hover:underline">Mosquitto Official Documentation &rarr;</a></li>
36
+ <li><a href="https://mqtt.org/getting-started/" target="_blank" class="text-indigo-600 hover:underline">Getting Started with MQTT &rarr;</a></li>
37
+ <li><a href="https://github.com/eclipse/paho.mqtt.golang" target="_blank" class="text-indigo-600 hover:underline">Eclipse Paho Go Client &rarr;</a></li>
38
+ </ul>
39
+ </section>
@@ -1,83 +1,151 @@
1
- <div class="mb-10 text-center lg:text-left border-b border-slate-200 pb-8">
2
- <div class="inline-flex items-center px-3 py-1 rounded-full bg-blue-100 text-blue-700 text-xs font-semibold tracking-wide uppercase mb-4">
3
- Enterprise Architecture
1
+ <div class="prose prose-slate max-w-none">
2
+ <!-- Marketing Hero -->
3
+ <div class="flex items-center space-x-3 mb-8 text-blue-700">
4
+ <div class="p-4 bg-gradient-to-br from-blue-600 to-indigo-800 rounded-2xl shadow-lg shadow-blue-100">
5
+ <svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
6
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
7
+ </svg>
8
+ </div>
9
+ <h1 class="text-5xl font-black text-slate-900 m-0 tracking-tight leading-tight">The Federated Masterclass</h1>
4
10
  </div>
5
- <h1 class="text-4xl lg:text-5xl font-extrabold text-slate-900 tracking-tight leading-tight mb-4">Dynamic Multi-Tenancy</h1>
6
- <p class="text-lg lg:text-xl text-slate-600 max-w-2xl leading-relaxed">Secure, high-performance database-per-tenant isolation with real-time connection hot-swapping.</p>
7
- </div>
8
11
 
9
- <section class="mb-12">
10
- <h2 class="text-2xl font-bold text-slate-800 mb-6 flex items-center">
11
- <span class="w-8 h-8 rounded-lg bg-blue-100 text-blue-600 flex items-center justify-center mr-3 text-sm">
12
- <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
13
- </span>
14
- The Dual-DB Architecture
15
- </h2>
16
- <p class="mb-6 text-slate-600 leading-relaxed">GO-DUCK separates management logic from customer data. Your application maintains a persistent connection to a <strong>Master Database</strong> while dynamically "Relocating" per-request traffic to isolated <strong>Tenant Databases</strong>.</p>
12
+ <p class="text-2xl text-slate-500 font-medium mb-12 leading-relaxed">
13
+ Go beyond simple multi-tenancy. Orchestrate a global empire of data silos with real-time synchronization and parallel read aggregation.
14
+ </p>
17
15
 
18
- <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8">
19
- <div class="p-6 rounded-2xl border border-slate-200 bg-white shadow-sm">
20
- <div class="w-12 h-12 bg-indigo-100 rounded-xl flex items-center justify-center mb-4">
21
- <svg class="w-6 h-6 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path></svg>
16
+ <!-- The Scenario: The Global dealership -->
17
+ <section class="mb-20">
18
+ <div class="bg-slate-900 rounded-[3rem] p-12 text-white shadow-2xl relative overflow-hidden">
19
+ <div class="absolute top-0 right-0 p-12 opacity-10">
20
+ <svg class="w-64 h-64" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2L4.5 20.29l.71.71L12 18l6.79 3 .71-.71z"/></svg>
21
+ </div>
22
+ <div class="relative z-10">
23
+ <h2 class="text-4xl font-black mb-6 text-blue-400">Deep Dive: The Dealership Scenario</h2>
24
+ <p class="text-xl text-slate-300 mb-8 leading-relaxed">
25
+ Imagine a car—<strong>Car ABC</strong>—owned by <strong>Customer X</strong>. Customer X regularly visits <strong>Dealership A (Home)</strong>, but today they are 1,000 miles away and visit <strong>Dealership B (Guest)</strong> for an emergency repair.
26
+ </p>
27
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
28
+ <div class="bg-slate-800/50 p-8 rounded-3xl border border-white/10">
29
+ <h4 class="text-blue-300 font-bold mb-4">Without Federation</h4>
30
+ <p class="text-sm text-slate-400">Dealership B creates a record. Dealership A knows nothing about it. When the car returns home, the service history is fragmented. The "Single Source of Truth" is broken.</p>
31
+ </div>
32
+ <div class="bg-blue-600/20 p-8 rounded-3xl border border-blue-500/30">
33
+ <h4 class="text-green-400 font-bold mb-4">With GO-DUCK Federation</h4>
34
+ <p class="text-sm text-slate-200">Dealership B saves the record. GO-DUCK automatically broadcasts this to Dealership A in the background. Both databases now hold the complete, unified history of the car.</p>
35
+ </div>
36
+ </div>
22
37
  </div>
23
- <h3 class="text-xl font-bold text-slate-900 mb-2">Master Registry</h3>
24
- <p class="text-slate-600 text-sm leading-relaxed">The <code>tenant_roles</code> table in the Master DB acts as the "Grand Concierge," mapping authenticated user roles to physical database names at runtime.</p>
25
38
  </div>
26
- <div class="p-6 rounded-2xl border border-slate-200 bg-white shadow-sm">
27
- <div class="w-12 h-12 bg-emerald-100 rounded-xl flex items-center justify-center mb-4">
28
- <svg class="w-6 h-6 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
39
+ </section>
40
+
41
+ <!-- Annotation Logic -->
42
+ <section class="mb-20">
43
+ <h2 class="text-3xl font-black text-slate-900 mb-8 tracking-tight italic underline decoration-blue-600 underline-offset-8">Architectural Control: The Annotations</h2>
44
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-12">
45
+ <div class="space-y-6">
46
+ <h3 class="text-2xl font-bold text-slate-800">1. Standard Multi-Tenancy</h3>
47
+ <div class="bg-slate-100 p-6 rounded-2xl border border-slate-200">
48
+ <code class="text-blue-700 font-mono text-sm">entity DealershipSettings { ... }</code>
49
+ </div>
50
+ <p class="text-slate-600 text-sm">
51
+ <strong>Behavior:</strong> Stored in the tenant's primary database only. No synchronization. High performance, zero overhead.
52
+ <br><br>
53
+ <strong>Use Case:</strong> Data that belongs to a specific site, like internal employee lists or site colors.
54
+ </p>
55
+ </div>
56
+ <div class="space-y-6">
57
+ <h3 class="text-2xl font-bold text-blue-700">2. Federated Multi-Tenancy</h3>
58
+ <div class="bg-blue-50 p-6 rounded-2xl border border-blue-100">
59
+ <code class="text-blue-700 font-mono text-sm">@Federated entity ServiceHistory { ... }</code>
60
+ </div>
61
+ <p class="text-slate-600 text-sm">
62
+ <strong>Behavior:</strong> Triggers the <strong>Saga/Outbox Engine</strong>. Writes are broadcast to all authorized silos. Reads are aggregated in parallel.
63
+ <br><br>
64
+ <strong>Use Case:</strong> Critical data that must be "Everywhere," like car health, global inventory, or customer profiles.
65
+ </p>
29
66
  </div>
30
- <h3 class="text-xl font-bold text-slate-900 mb-2">Hot-Swapping Pools</h3>
31
- <p class="text-slate-600 text-sm leading-relaxed">The <code>TenantDBManager</code> uses lazy loading to open and cache connection pools for tenants only when they are active, ensuring minimal resource overhead.</p>
32
67
  </div>
33
- </div>
34
- </section>
68
+ </section>
35
69
 
36
- <section class="mb-12">
37
- <h2 class="text-2xl font-bold text-slate-800 mb-6 flex items-center">
38
- <span class="w-8 h-8 rounded-lg bg-rose-100 text-rose-600 flex items-center justify-center mr-3 text-sm">
39
- <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 00-2 2zm10-10V7a4 4 0 00-8 0v4h8z"></path></svg>
40
- </span>
41
- Security & Anti-Spoofing
42
- </h2>
43
- <p class="mb-6 text-slate-600 leading-relaxed">Header-based tenancy (<code>X-Tenant-ID</code>) is convenient but dangerous. GO-DUCK solves this by cryptographically validating the tenant context against the JWT.</p>
44
-
45
- <div class="bg-slate-900 rounded-2xl p-6 shadow-xl mb-6">
46
- <h4 class="text-emerald-400 font-mono text-sm mb-4">// Internal Verification Loop</h4>
47
- <pre class="text-slate-300 font-mono text-sm leading-relaxed">
48
- 1. Extract Roles from signed Keycloak JWT
49
- 2. Lookup authorized DB in Master mapping table
50
- 3. Compare against X-Tenant-ID header
51
- 4. If Mismatch: Return 403 Forbidden (Security Breach)
52
- 5. If Match: Activate Dynamic Connection Pool
53
- </pre>
54
- </div>
55
- </section>
70
+ <!-- TRIPLE-IDENTITY REGISTRY -->
71
+ <section class="mb-20">
72
+ <h2 class="text-3xl font-black text-slate-900 mb-8 tracking-tight italic underline decoration-blue-600 underline-offset-8">Triple-Identity Registry: Opaque Decoupling</h2>
73
+ <p class="text-slate-600 mb-8 leading-relaxed">
74
+ To prevent <strong>ID Enumeration</strong> and protect physical infrastructure paths, GO-DUCK implements a sophisticated 3-layer identity registry. This ensures that guessable database names are never leaked to the client.
75
+ </p>
56
76
 
57
- <section class="mb-12">
58
- <h2 class="text-2xl font-bold text-slate-800 mb-6 flex items-center">
59
- <span class="w-8 h-8 rounded-lg bg-amber-100 text-amber-600 flex items-center justify-center mr-3 text-sm">
60
- <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"></path></svg>
61
- </span>
62
- Tenant Provisioning API
63
- </h2>
64
- <p class="mb-6 text-slate-600 leading-relaxed">Adding a new customer is a single atomic operation. Use the management API to provision a side-by-side database instantly.</p>
77
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
78
+ <div class="p-8 bg-white border border-slate-200 rounded-[2.5rem] shadow-sm relative overflow-hidden group">
79
+ <div class="w-12 h-12 bg-blue-100 text-blue-600 rounded-xl flex items-center justify-center font-black mb-6">1</div>
80
+ <h4 class="text-lg font-black text-slate-900 mb-3">Identity Layer</h4>
81
+ <p class="text-sm text-slate-500 italic">Keycloak Realm Role (e.g. <code>dealer_tokyo</code>). This is the source of truth for authorization.</p>
82
+ </div>
83
+ <div class="p-8 bg-white border border-slate-200 rounded-[2.5rem] shadow-sm relative overflow-hidden group">
84
+ <div class="w-12 h-12 bg-indigo-100 text-indigo-600 rounded-xl flex items-center justify-center font-black mb-6">2</div>
85
+ <h4 class="text-lg font-black text-slate-900 mb-3">Opaque Layer</h4>
86
+ <p class="text-sm text-slate-500 italic">Randomly generated UUID (e.g. <code>bc72-a180...</code>) exposed via the <code>X-Tenant-ID</code> header.</p>
87
+ </div>
88
+ <div class="p-8 bg-white border border-slate-200 rounded-[2.5rem] shadow-sm relative overflow-hidden group">
89
+ <div class="w-12 h-12 bg-emerald-100 text-emerald-600 rounded-xl flex items-center justify-center font-black mb-6">3</div>
90
+ <h4 class="text-lg font-black text-slate-900 mb-3">Physical Layer</h4>
91
+ <p class="text-sm text-slate-500 italic">The actual database name (e.g. <code>dealership_silo_japan_prod</code>). Only the server knows this link.</p>
92
+ </div>
93
+ </div>
94
+ </section>
65
95
 
66
- <div class="bg-[#1e1e1e] rounded-xl overflow-hidden shadow-lg mb-4">
67
- <div class="bg-[#2d2d2d] px-4 py-2 border-b border-[#404040] flex items-center">
68
- <span class="px-2 py-0.5 rounded bg-emerald-500/20 text-emerald-400 text-[10px] font-bold mr-3">POST</span>
69
- <span class="text-xs text-slate-300 font-mono">/management/db/create</span>
96
+ <!-- The Dual-Path Secret -->
97
+ <section class="mb-20">
98
+ <div class="bg-gradient-to-br from-blue-700 to-indigo-900 rounded-[3rem] p-12 text-white shadow-2xl">
99
+ <h2 class="text-4xl font-black mb-6">The Dual-Path Orchestrator</h2>
100
+ <p class="text-lg text-blue-100 mb-10 leading-relaxed">
101
+ GO-DUCK doesn't force you into one model. Our generated middleware and controllers detect your GDL annotations and switch behavior in real-time.
102
+ </p>
103
+
104
+ <div class="space-y-8">
105
+ <div class="flex items-start space-x-6">
106
+ <div class="w-12 h-12 bg-white/10 rounded-xl flex items-center justify-center flex-shrink-0 font-black text-xl">01</div>
107
+ <div>
108
+ <h4 class="text-xl font-bold text-white mb-2">Silo-Connection-Cache</h4>
109
+ <p class="text-blue-100/70 text-sm">Prevents connection exhaustion across 100+ silos using a singleton-based cache. DB/Mongo clients are lazily initialized and kept warm.</p>
110
+ </div>
111
+ </div>
112
+ <div class="flex items-start space-x-6">
113
+ <div class="w-12 h-12 bg-white/10 rounded-xl flex items-center justify-center flex-shrink-0 font-black text-xl">02</div>
114
+ <div>
115
+ <h4 class="text-xl font-bold text-white mb-2">Parallel Read Harvest</h4>
116
+ <p class="text-blue-100/70 text-sm">When you query a <code>@Federated</code> entity, GO-DUCK launches simultaneous Go-routines to every database you own, stitching the global picture together in milliseconds.</p>
117
+ </div>
118
+ </div>
119
+ <div class="flex items-start space-x-6">
120
+ <div class="w-12 h-12 bg-white/10 rounded-xl flex items-center justify-center flex-shrink-0 font-black text-xl">03</div>
121
+ <div>
122
+ <h4 class="text-xl font-bold text-white mb-2">Transactional Atomic Broadcast</h4>
123
+ <p class="text-blue-100/70 text-sm">A write to one silo is a write to all. Using the Outbox pattern, we guarantee that even if Dealership A is offline, Dealership B's updates will eventually arrive safely.</p>
124
+ </div>
125
+ </div>
126
+ <div class="flex items-start space-x-6">
127
+ <div class="w-12 h-12 bg-white/10 rounded-xl flex items-center justify-center flex-shrink-0 font-black text-xl">04</div>
128
+ <div>
129
+ <h4 class="text-xl font-bold text-white mb-2">Precision Harvesting</h4>
130
+ <p class="text-blue-100/70 text-sm">Pass a comma-separated list of UUIDs in the <code>X-Tenant-ID</code> header. The Harvester reduces its fan-out to ONLY these silos for surgical efficiency.</p>
131
+ </div>
132
+ </div>
133
+ </div>
70
134
  </div>
71
- <div class="p-5 text-sm font-mono text-slate-300">
72
- {
73
- "role": "ROLE_ACME_CORP",
74
- "db_name": "acme_isolated_db"
75
- }
135
+ </section>
136
+
137
+ <!-- Summary FAQ -->
138
+ <section class="mb-10">
139
+ <h3 class="text-2xl font-black text-slate-800 mb-6">Elite FAQ</h3>
140
+ <div class="space-y-4">
141
+ <div class="p-6 bg-white border border-slate-200 rounded-2xl shadow-sm">
142
+ <p class="text-slate-900 font-bold mb-2 small italic">What if I assigned multiple DBs to a role but forgot @Federated?</p>
143
+ <p class="text-slate-500 text-sm leading-relaxed">GO-DUCK will only use your <strong>Primary/Default</strong> database. It will not harvest data from the other assigned silos. You must use the annotation to unlock aggregation.</p>
144
+ </div>
145
+ <div class="p-6 bg-white border border-slate-200 rounded-2xl shadow-sm">
146
+ <p class="text-slate-900 font-bold mb-2 small italic">Is there a performance hit for @Federated?</p>
147
+ <p class="text-slate-500 text-sm leading-relaxed">Reads use parallel goroutines, making them extremely fast even across silos. Writes include one extra row in the Outbox table—a small price for global consistency.</p>
148
+ </div>
76
149
  </div>
77
- </div>
78
- <ul class="space-y-3 text-slate-600 text-sm">
79
- <li class="flex items-center"><svg class="w-4 h-4 text-emerald-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> Executing physical <code>CREATE DATABASE</code></li>
80
- <li class="flex items-center"><svg class="w-4 h-4 text-emerald-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> Mapping role to DB in <code>tenant_roles</code> Master table</li>
81
- <li class="flex items-center"><svg class="w-4 h-4 text-emerald-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> Triggering automated Liquibase migrations on new DB</li>
82
- </ul>
83
- </section>
150
+ </section>
151
+ </div>
@@ -0,0 +1,40 @@
1
+ <h1 class="text-4xl font-extrabold text-gray-900 mb-4">OpenTelemetry (OTel) & Jaeger</h1>
2
+ <p class="text-lg text-gray-600 mb-8">Master the art of distributed tracing to debug complex inter-service communications in real-time.</p>
3
+
4
+ <section class="mb-10">
5
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">What is OpenTelemetry?</h2>
6
+ <p class="mb-4 text-gray-700">OpenTelemetry is a collection of tools, APIs, and SDKs used to instrument, generate, collect, and export telemetry data (metrics, logs, and traces). GO-DUCK implements a <strong>"Full-Stack Tracing"</strong> strategy.</p>
7
+ </section>
8
+
9
+ <section class="mb-10">
10
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">The Trace Pipeline</h2>
11
+ <p class="mb-4">Trace context is automatically propagated across your entire stack:</p>
12
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6 text-center">
13
+ <div class="p-4 bg-gray-50 border rounded font-semibold text-indigo-700">HTTP Router (Gin)</div>
14
+ <div class="p-4 bg-gray-50 border rounded font-semibold text-indigo-700">Service/Controller</div>
15
+ <div class="p-4 bg-gray-50 border rounded font-semibold text-indigo-700">Database (GORM)</div>
16
+ </div>
17
+
18
+ <div class="bg-indigo-50 border-l-4 border-indigo-500 p-4 mb-6 rounded-r">
19
+ <p class="text-indigo-900">Each database query is automatically tagged with the <code>trace_id</code> of the incoming HTTP request. This allows you to identify exactly which REST call caused a slow SQL query.</p>
20
+ </div>
21
+
22
+ <h3 class="font-semibold mb-2 mt-6 text-xl">The OTel Collector</h3>
23
+ <p class="mb-4">GO-DUCK apps don't speak directly to tracing backends. Instead, they export via gRPC to an <strong>otel-collector</strong> sidecar. This collector acts as a buffer and can fan-out data to Jaeger, Datadog, or Honeycomb simultaneously.</p>
24
+ </section>
25
+
26
+ <section class="mb-10">
27
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Visualizing with Jaeger</h2>
28
+ <p class="mb-4 text-gray-700">In local development, GO-DUCK spins up a Jaeger instance. It provides a web-based UI to search and visualize your traces.</p>
29
+ <pre><code class="language-bash"># Open Jaeger UI locally
30
+ open http://localhost:16686</code></pre>
31
+ </section>
32
+
33
+ <section class="mb-10">
34
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">External Resources</h2>
35
+ <ul class="space-y-2">
36
+ <li><a href="https://opentelemetry.io/docs/" target="_blank" class="text-indigo-600 hover:underline">OpenTelemetry Official Docs &rarr;</a></li>
37
+ <li><a href="https://www.jaegertracing.io/docs/" target="_blank" class="text-indigo-600 hover:underline">Jaeger Tracing Documentation &rarr;</a></li>
38
+ <li><a href="https://opentelemetry.io/docs/collector/" target="_blank" class="text-indigo-600 hover:underline">OTel Collector Guide &rarr;</a></li>
39
+ </ul>
40
+ </section>
@@ -13,31 +13,57 @@
13
13
  <pre><code class="language-javascript">const token = "eyJhbGciOi..."; // Valid Keycloak Access Token
14
14
 
15
15
  // Phase 1: Authentication happens precisely on the handshake (WSS Handshake via query param)
16
- const ws = new WebSocket(\`ws://localhost:8080/ws?token=\${token}\`);
16
+ const ws = new WebSocket(`ws://localhost:8080/ws?token=${token}`);
17
17
 
18
18
  ws.onopen = () => {
19
- // Phase 2: Send HMAC-SHA256 Encrypted / Signed Messages!
19
+ // Phase 2: Send HMAC-SHA256 Signed Messages
20
+ // The Signature is the HMAC-SHA256 of (Method + Path + Payload) using your API Key
20
21
  ws.send(JSON.stringify({
21
22
  TraceID: "uuid-v4-frontend-req",
22
23
  Method: "GET",
23
24
  Path: "/api/{{toLowerCase (defaultStr (lookup entities "0.name") "entity")}}s",
24
25
  Payload: "{}",
25
- Signature: "2d7a221f7dbb2..." // Signature ensures Message Integrity
26
+ Signature: "2d7a221f7dbb2..."
26
27
  }));
27
28
  };
28
29
 
29
30
  ws.onmessage = (event) => console.log("Received via WS:", event.data);</code></pre>
31
+
32
+ <div class="mt-8 p-6 bg-slate-900 rounded-2xl border border-slate-700">
33
+ <h4 class="text-white font-bold mb-4 flex items-center">
34
+ <svg class="w-5 h-5 mr-2 text-emerald-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path></svg>
35
+ Message Integrity (HMAC-SHA256)
36
+ </h4>
37
+ <p class="text-sm text-slate-400 mb-4">To prevent man-in-the-middle tampering on full-duplex streams, GO-DUCK requires every WebSocket envelope to be digitally signed.</p>
38
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-xs font-mono">
39
+ <div class="p-3 bg-slate-800 rounded-lg text-slate-300">
40
+ <span class="text-emerald-400 font-bold block mb-1">Algorithm</span>
41
+ HMAC-SHA256
42
+ </div>
43
+ <div class="p-3 bg-slate-800 rounded-lg text-slate-300">
44
+ <span class="text-emerald-400 font-bold block mb-1">Signed Data</span>
45
+ method + path + payload
46
+ </div>
47
+ </div>
48
+ </div>
30
49
  </section>
31
50
 
32
51
  <section class="mb-10">
33
- <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">2. Asynchronous MQTT Streaming</h2>
34
- <p class="mb-4">Rather than relying entirely on synchronous API calls, every successful <code>CREATE / UPDATE / DELETE</code> on any GDL generated model emits an event to the unified MQTT broker configured in the `docker-compose.yml`.</p>
52
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">2. Unified Messaging Hub (MQTT & NATS)</h2>
53
+ <p class="mb-4">GO-DUCK features a <strong>Multi-Broker Messaging Hub</strong>. Every successful <code>CREATE / UPDATE / DELETE</code> on any model is simultaneously broadcast to both brokers if enabled.</p>
35
54
 
36
- <h3 class="font-semibold mb-2">How to listen for specific webhooks</h3>
37
- <pre><code class="language-bash"># mosquitto_sub listening to any mutation globally inside the microservice
38
- mosquitto_sub -h localhost -p 1883 -t "go-duck/events/#" -u dev_user -P dev_password
39
-
40
- # To listen ONLY when the {{capitalize (defaultStr (lookup entities "0.name") "Entity")}} object gets created
41
- mosquitto_sub -h localhost -p 1883 -t "go-duck/events/{{toLowerCase (defaultStr (lookup entities "0.name") "entity")}}/CREATE" -u dev_user -P dev_password
42
- </code></pre>
55
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
56
+ <div class="bg-gray-50 p-6 rounded-xl border border-gray-200">
57
+ <h4 class="font-bold text-blue-600 mb-2 font-mono">MQTT (Real-time UI)</h4>
58
+ <p class="text-sm text-gray-600 mb-4">Topic Pattern: <code>go-duck/events/{entity}/{action}</code></p>
59
+ <pre class="text-xs bg-slate-900 text-white p-3 rounded"><code># Listen to Car Deletions
60
+ mosquitto_sub -t "go-duck/events/car/DELETE"</code></pre>
61
+ </div>
62
+ <div class="bg-gray-50 p-6 rounded-xl border border-gray-200">
63
+ <h4 class="font-bold text-green-600 mb-2 font-mono">NATS (High-Perf CQRS)</h4>
64
+ <p class="text-sm text-gray-600 mb-4">Subject Pattern: <code>go.duck.events.{entity}.{action}</code></p>
65
+ <pre class="text-xs bg-slate-900 text-white p-3 rounded"><code># Listen to any Car mutations
66
+ nats sub "go.duck.events.car.>"</code></pre>
67
+ </div>
68
+ </div>
43
69
  </section>
@@ -0,0 +1,40 @@
1
+ <h1 class="text-4xl font-extrabold text-gray-900 mb-4">Redis: Distributed Caching & Beyond</h1>
2
+ <p class="text-lg text-gray-600 mb-8">Optimize your microservice performance with blitz-fast distributed caching using Redis.</p>
3
+
4
+ <section class="mb-10">
5
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Cache Architecture</h2>
6
+ <p class="mb-4 text-gray-700">GO-DUCK implements a <strong>"Cache-Aside"</strong> strategy. This ensures that your application remains resilient: if Redis is down, the application automatically falls back to the database without crashing, thanks to our integrated <strong>Circuit Breakers</strong> (via Sony/Gobreaker).</p>
7
+ </section>
8
+
9
+ <section class="mb-10">
10
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Multi-Tenant Isolation</h2>
11
+ <p class="mb-4">Standard caching in a multi-tenant app is dangerous. GO-DUCK solves this by **Tenant-Prefixing** every key automatically. Your cache keys look like <code>tenant_abc:User:123</code>, preventing data leaks across tenants.</p>
12
+
13
+ <div class="bg-red-50 border-l-4 border-red-500 p-4 mb-6 rounded-r">
14
+ <p class="text-red-900"><strong>Automatic Invalidation:</strong> Our repository layer handles cache invalidation. When you update or delete an entity via the REST/gRPC API, the corresponding Redis key is purged instantly to maintain data consistency.</p>
15
+ </div>
16
+
17
+ <h3 class="font-semibold mb-2 mt-6 text-xl">Direct Cache Usage</h3>
18
+ <pre><code class="language-go">import "{{appName}}/cache"
19
+
20
+ // Store a value for 10 minutes
21
+ cache.Set(ctx, "my-key", myStruct, 10 * time.Minute)
22
+
23
+ // Retrieve and deserialize
24
+ var target MyStruct
25
+ err := cache.Get(ctx, "my-key", &target)</code></pre>
26
+ </section>
27
+
28
+ <section class="mb-10">
29
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">Resilience with Redis</h2>
30
+ <p class="mb-4 text-gray-700">All Redis calls are wrapped in a <strong>Circuit Breaker</strong>. If Redis experiences high latency or connection resets, the circuit opens, and your Go application skips the cache layers to protect the system from cascading failure.</p>
31
+ </section>
32
+
33
+ <section class="mb-10">
34
+ <h2 class="text-2xl font-bold text-gray-800 mb-4 border-b pb-2">External Resources</h2>
35
+ <ul class="space-y-2">
36
+ <li><a href="https://redis.io/documentation" target="_blank" class="text-indigo-600 hover:underline">Redis Official Documentation &rarr;</a></li>
37
+ <li><a href="https://github.com/go-redis/redis" target="_blank" class="text-indigo-600 hover:underline">Go-Redis Client Library &rarr;</a></li>
38
+ <li><a href="https://redis.com/blog/cache-aside-pattern-explained/" target="_blank" class="text-indigo-600 hover:underline">The Cache-Aside Pattern &rarr;</a></li>
39
+ </ul>
40
+ </section>