Let me design a comprehensive, interactive single-page application that demonstrates these concepts. I'll need to create:
Let me create a sophisticated eventing platform demo that showcases these patterns with real interactivity.
Color scheme: I'll go with a dark technical theme - maybe charcoal/slate backgrounds with cyan/teal accents for success states, amber for pending, and coral for errors. Very monitoring/ops dashboard feel.
Typography: I'll use Space Grotesk or JetBrains Mono for that technical feel.
Let me build this out comprehensively.
A sophisticated event-driven architecture demo with outbox/inbox patterns, deduplication, and replay capabilities.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Resilient Eventing Platform</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0e14;
--bg-elevated: #111820;
--bg-card: #161d27;
--fg: #e6edf3;
--fg-muted: #7d8590;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--warning: #f0a020;
--warning-dim: rgba(240, 160, 32, 0.15);
--error: #f85149;
--error-dim: rgba(248, 81, 73, 0.15);
--success: #3fb950;
--border: #21262d;
--border-light: #30363d;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
overflow-x: hidden;
}
.font-mono {
font-family: 'JetBrains Mono', monospace;
}
/* Background Pattern */
.bg-grid {
background-image:
linear-gradient(rgba(0, 212, 170, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 212, 170, 0.03) 1px, transparent 1px);
background-size: 40px 40px;
}
/* Glow Effects */
.glow-accent {
box-shadow: 0 0 40px rgba(0, 212, 170, 0.2), 0 0 80px rgba(0, 212, 170, 0.1);
}
.glow-warning {
box-shadow: 0 0 30px rgba(240, 160, 32, 0.3);
}
/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg);
}
::-webkit-scrollbar-thumb {
background: var(--border-light);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--fg-muted);
}
/* Animations */
@keyframes slideInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slideInLeft {
from {
opacity: 0;
transform: translateX(-30px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes slideInRight {
from {
opacity: 0;
transform: translateX(30px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes pulse-ring {
0% {
transform: scale(0.8);
opacity: 1;
}
100% {
transform: scale(1.8);
opacity: 0;
}
}
@keyframes flow-right {
0% {
transform: translateX(-100%);
opacity: 0;
}
50% {
opacity: 1;
}
100% {
transform: translateX(100%);
opacity: 0;
}
}
@keyframes shimmer {
0% {
background-position: -200% 0;
}
100% {
background-position: 200% 0;
}
}
.animate-slide-up {
animation: slideInUp 0.5s ease-out forwards;
}
.animate-slide-left {
animation: slideInLeft 0.5s ease-out forwards;
}
.animate-slide-right {
animation: slideInRight 0.5s ease-out forwards;
}
.event-flow-particle {
animation: flow-right 1.5s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* Event Card Styles */
.event-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
transition: all 0.2s ease;
}
.event-card:hover {
border-color: var(--border-light);
transform: translateY(-2px);
}
.event-card.processing {
border-color: var(--warning);
background: linear-gradient(90deg, var(--bg-card) 0%, var(--warning-dim) 50%, var(--bg-card) 100%);
background-size: 200% 100%;
animation: shimmer 1.5s ease-in-out infinite;
}
.event-card.success {
border-color: var(--accent);
}
.event-card.duplicate {
border-color: var(--fg-muted);
opacity: 0.6;
}
.event-card.error {
border-color: var(--error);
}
/* Status Badge */
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
border-radius: 9999px;
font-size: 12px;
font-weight: 500;
}
.status-badge.pending {
background: var(--warning-dim);
color: var(--warning);
}
.status-badge.processing {
background: var(--warning-dim);
color: var(--warning);
}
.status-badge.delivered {
background: var(--accent-dim);
color: var(--accent);
}
.status-badge.duplicate {
background: rgba(125, 133, 144, 0.2);
color: var(--fg-muted);
}
.status-badge.failed {
background: var(--error-dim);
color: var(--error);
}
/* Button Styles */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 10px 18px;
border-radius: 6px;
font-weight: 500;
font-size: 14px;
transition: all 0.15s ease;
cursor: pointer;
border: none;
outline: none;
}
.btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.btn-primary {
background: var(--accent);
color: var(--bg);
}
.btn-primary:hover {
background: #00e6b8;
transform: translateY(-1px);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-secondary {
background: var(--bg-card);
color: var(--fg);
border: 1px solid var(--border);
}
.btn-secondary:hover {
background: var(--bg-elevated);
border-color: var(--border-light);
}
.btn-icon {
padding: 8px;
background: transparent;
color: var(--fg-muted);
border-radius: 6px;
}
.btn-icon:hover {
background: var(--bg-card);
color: var(--fg);
}
/* Tab Styles */
.tab-btn {
padding: 8px 16px;
font-size: 14px;
font-weight: 500;
color: var(--fg-muted);
background: transparent;
border: none;
border-bottom: 2px solid transparent;
cursor: pointer;
transition: all 0.15s ease;
}
.tab-btn:hover {
color: var(--fg);
}
.tab-btn.active {
color: var(--accent);
border-bottom-color: var(--accent);
}
/* Flow Visualization */
.flow-container {
position: relative;
height: 80px;
background: linear-gradient(90deg, var(--bg-card) 0%, var(--bg-elevated) 50%, var(--bg-card) 100%);
border-top: 1px solid var(--border);
border-bottom: 1px solid var(--border);
overflow: hidden;
}
.flow-line {
position: absolute;
top: 50%;
left: 0;
right: 0;
height: 2px;
background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
}
.flow-particle {
position: absolute;
top: 50%;
width: 8px;
height: 8px;
background: var(--accent);
border-radius: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 10px var(--accent);
}
/* Metric Card */
.metric-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 20px;
transition: all 0.2s ease;
}
.metric-card:hover {
border-color: var(--border-light);
}
/* Modal */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
opacity: 0;
visibility: hidden;
transition: all 0.2s ease;
}
.modal-overlay.open {
opacity: 1;
visibility: visible;
}
.modal-content {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
max-width: 500px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
transform: scale(0.95);
transition: transform 0.2s ease;
}
.modal-overlay.open .modal-content {
transform: scale(1);
}
/* Pulse Animation */
.pulse-dot {
position: relative;
}
.pulse-dot::before {
content: '';
position: absolute;
inset: -4px;
border-radius: 50%;
background: currentColor;
opacity: 0.3;
animation: pulse-ring 1.5s ease-out infinite;
}
/* Panel Headers */
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid var(--border);
}
.panel-title {
display: flex;
align-items: center;
gap: 10px;
font-weight: 600;
font-size: 16px;
}
.panel-count {
background: var(--bg);
padding: 2px 8px;
border-radius: 9999px;
font-size: 12px;
font-weight: 500;
color: var(--fg-muted);
}
/* Event List */
.event-list {
max-height: 400px;
overflow-y: auto;
padding: 12px;
}
/* Delayed animation classes */
.delay-100 { animation-delay: 100ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-400 { animation-delay: 400ms; }
.delay-500 { animation-delay: 500ms; }
</style>
</head>
<body class="bg-grid">
<!-- Header -->
<header class="sticky top-0 z-50 backdrop-blur-lg bg-[var(--bg)]/80 border-b border-[var(--border)]">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-16">
<div class="flex items-center gap-4">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg bg-[var(--accent-dim)] flex items-center justify-center">
<svg class="w-6 h-6 text-[var(--accent)]" 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"/>
</svg>
</div>
<div>
<h1 class="text-lg font-semibold">EventStream</h1>
<p class="text-xs text-[var(--fg-muted)]">Resilient Eventing Platform</p>
</div>
</div>
</div>
<div class="flex items-center gap-4">
<div id="systemStatus" class="flex items-center gap-2 px-3 py-1.5 rounded-full bg-[var(--accent-dim)]">
<span class="w-2 h-2 rounded-full bg-[var(--accent)] pulse-dot"></span>
<span class="text-sm font-medium text-[var(--accent)]">System Healthy</span>
</div>
<button onclick="openNewEventModal()" class="btn btn-primary">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
New Event
</button>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Metrics Row -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8 opacity-0 animate-slide-up" style="animation-fill-mode: forwards;">
<div class="metric-card">
<div class="flex items-center gap-2 mb-2">
<svg class="w-4 h-4 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"/>
</svg>
<span class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Outbox</span>
</div>
<div class="text-3xl font-bold text-[var(--fg)]" id="outboxCount">0</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">events pending</div>
</div>
<div class="metric-card">
<div class="flex items-center gap-2 mb-2">
<svg class="w-4 h-4 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3"/>
</svg>
<span class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Inbox</span>
</div>
<div class="text-3xl font-bold text-[var(--fg)]" id="inboxCount">0</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">events received</div>
</div>
<div class="metric-card">
<div class="flex items-center gap-2 mb-2">
<svg class="w-4 h-4 text-[var(--warning)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
<span class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Duplicates</span>
</div>
<div class="text-3xl font-bold text-[var(--warning)]" id="duplicateCount">0</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">detected & blocked</div>
</div>
<div class="metric-card">
<div class="flex items-center gap-2 mb-2">
<svg class="w-4 h-4 text-[var(--success)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
<span class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Replayed</span>
</div>
<div class="text-3xl font-bold text-[var(--success)]" id="replayCount">0</div>
<div class="text-xs text-[var(--fg-muted)] mt-1">events replayed</div>
</div>
</div>
<!-- Flow Visualization -->
<div class="mb-8 opacity-0 animate-slide-up delay-100" style="animation-fill-mode: forwards;">
<div class="flow-container rounded-lg relative">
<div class="absolute inset-0 flex items-center justify-between px-8">
<div class="flex flex-col items-center">
<div class="w-12 h-12 rounded-lg bg-[var(--bg)] border border-[var(--border)] flex items-center justify-center">
<svg class="w-6 h-6 text-[var(--accent)]" 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"/>
</svg>
</div>
<span class="text-xs text-[var(--fg-muted)] mt-2">Producer</span>
</div>
<div class="flex-1 mx-8 relative h-1">
<div class="absolute inset-0 bg-[var(--border)] rounded-full"></div>
<div id="flowParticles"></div>
</div>
<div class="flex flex-col items-center">
<div class="w-12 h-12 rounded-lg bg-[var(--bg)] border border-[var(--border)] flex items-center justify-center">
<svg class="w-6 h-6 text-[var(--success)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/>
</svg>
</div>
<span class="text-xs text-[var(--fg-muted)] mt-2">Consumer</span>
</div>
</div>
</div>
</div>
<!-- Main Panels -->
<div class="grid lg:grid-cols-2 gap-6 mb-8">
<!-- Outbox Panel -->
<div class="bg-[var(--bg-elevated)] rounded-xl border border-[var(--border)] opacity-0 animate-slide-left delay-200" style="animation-fill-mode: forwards;">
<div class="panel-header">
<div class="panel-title">
<svg class="w-5 h-5 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"/>
</svg>
Outbox
<span class="panel-count" id="outboxPanelCount">0</span>
</div>
<div class="flex gap-2">
<button onclick="processNextEvent()" class="btn btn-secondary text-sm" title="Process next event">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Process
</button>
</div>
</div>
<div class="event-list" id="outboxList">
<div class="text-center py-8 text-[var(--fg-muted)]">
<svg class="w-12 h-12 mx-auto mb-3 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/>
</svg>
<p>No events in outbox</p>
<p class="text-sm mt-1">Create a new event to get started</p>
</div>
</div>
</div>
<!-- Inbox Panel -->
<div class="bg-[var(--bg-elevated)] rounded-xl border border-[var(--border)] opacity-0 animate-slide-right delay-200" style="animation-fill-mode: forwards;">
<div class="panel-header">
<div class="panel-title">
<svg class="w-5 h-5 text-[var(--success)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3"/>
</svg>
Inbox
<span class="panel-count" id="inboxPanelCount">0</span>
</div>
<div class="flex gap-2">
<button onclick="openReplayModal()" class="btn btn-secondary text-sm">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Replay
</button>
</div>
</div>
<div class="event-list" id="inboxList">
<div class="text-center py-8 text-[var(--fg-muted)]">
<svg class="w-12 h-12 mx-auto mb-3 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/>
</svg>
<p>No events in inbox</p>
<p class="text-sm mt-1">Processed events will appear here</p>
</div>
</div>
</div>
</div>
<!-- Event Log / Timeline -->
<div class="bg-[var(--bg-elevated)] rounded-xl border border-[var(--border)] opacity-0 animate-slide-up delay-300" style="animation-fill-mode: forwards;">
<div class="panel-header">
<div class="panel-title">
<svg class="w-5 h-5 text-[var(--fg-muted)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
Event Timeline
</div>
<div class="flex gap-2">
<button class="tab-btn active" data-filter="all" onclick="filterTimeline('all', this)">All</button>
<button class="tab-btn" data-filter="success" onclick="filterTimeline('success', this)">Success</button>
<button class="tab-btn" data-filter="duplicate" onclick="filterTimeline('duplicate', this)">Duplicates</button>
<button class="tab-btn" data-filter="error" onclick="filterTimeline('error', this)">Failed</button>
</div>
</div>
<div class="p-4">
<div id="timeline" class="space-y-2 max-h-64 overflow-y-auto">
<div class="text-center py-6 text-[var(--fg-muted)]">
<p>No events in timeline</p>
</div>
</div>
</div>
</div>
</main>
<!-- New Event Modal -->
<div id="newEventModal" class="modal-overlay" onclick="closeModalOnOverlay(event, 'newEventModal')">
<div class="modal-content" onclick="event.stopPropagation()">
<div class="p-6 border-b border-[var(--border)]">
<h2 class="text-lg font-semibold">Create New Event</h2>
<p class="text-sm text-[var(--fg-muted)] mt-1">Send a new event to the outbox</p>
</div>
<form onsubmit="createEvent(event)" class="p-6 space-y-4">
<div>
<label class="block text-sm font-medium mb-2" for="eventType">Event Type</label>
<select id="eventType" class="w-full bg-[var(--bg)] border border-[var(--border)] rounded-lg px-4 py-2.5 text-sm focus:outline-none focus:border-[var(--accent)]">
<option value="order.created">Order Created</option>
<option value="payment.processed">Payment Processed</option>
<option value="user.registered">User Registered</option>
<option value="inventory.updated">Inventory Updated</option>
<option value="notification.sent">Notification Sent</option>
</select>
</div>
<div>
<label class="block text-sm font-medium mb-2" for="eventPayload">Payload (JSON)</label>
<textarea id="eventPayload" rows="4" class="w-full bg-[var(--bg)] border border-[var(--border)] rounded-lg px-4 py-2.5 text-sm font-mono focus:outline-none focus:border-[var(--accent)]" placeholder='{"key": "value"}'></textarea>
</div>
<div class="flex items-center gap-3">
<input type="checkbox" id="simulateDuplicate" class="w-4 h-4 rounded border-[var(--border)] bg-[var(--bg)] accent-[var(--accent)]">
<label for="simulateDuplicate" class="text-sm">Simulate duplicate (same ID)</label>
</div>
<div class="flex items-center gap-3">
<input type="checkbox" id="simulateFailure" class="w-4 h-4 rounded border-[var(--border)] bg-[var(--bg)] accent-[var(--accent)]">
<label for="simulateFailure" class="text-sm">Simulate processing failure</label>
</div>
<div class="flex gap-3 pt-4">
<button type="button" onclick="closeModal('newEventModal')" class="btn btn-secondary flex-1">Cancel</button>
<button type="submit" class="btn btn-primary flex-1">Create Event</button>
</div>
</form>
</div>
</div>
<!-- Replay Modal -->
<div id="replayModal" class="modal-overlay" onclick="closeModalOnOverlay(event, 'replayModal')">
<div class="modal-content" onclick="event.stopPropagation()">
<div class="p-6 border-b border-[var(--border)]">
<h2 class="text-lg font-semibold">Replay Events</h2>
<p class="text-sm text-[var(--fg-muted)] mt-1">Select events to replay from the inbox</p>
</div>
<div class="p-6">
<div id="replayEventList" class="space-y-2 max-h-64 overflow-y-auto mb-4">
<div class="text-center py-6 text-[var(--fg-muted)]">
<p>No events available for replay</p>
</div>
</div>
<div class="flex gap-3">
<button onclick="closeModal('replayModal')" class="btn btn-secondary flex-1">Cancel</button>
<button onclick="replaySelectedEvents()" class="btn btn-primary flex-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Replay Selected
</button>
</div>
</div>
</div>
</div>
<!-- Event Detail Modal -->
<div id="eventDetailModal" class="modal-overlay" onclick="closeModalOnOverlay(event, 'eventDetailModal')">
<div class="modal-content" onclick="event.stopPropagation()">
<div class="p-6 border-b border-[var(--border)]">
<div class="flex items-center justify-between">
<h2 class="text-lg font-semibold">Event Details</h2>
<span id="detailStatus" class="status-badge"></span>
</div>
</div>
<div class="p-6 space-y-4">
<div>
<label class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Event ID</label>
<p id="detailId" class="font-mono text-sm mt-1"></p>
</div>
<div>
<label class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Type</label>
<p id="detailType" class="text-sm mt-1"></p>
</div>
<div>
<label class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Created</label>
<p id="detailCreated" class="text-sm mt-1"></p>
</div>
<div>
<label class="text-xs text-[var(--fg-muted)] uppercase tracking-wide">Payload</label>
<pre id="detailPayload" class="font-mono text-xs mt-1 bg-[var(--bg)] p-3 rounded-lg overflow-x-auto"></pre>
</div>
<div id="detailErrorContainer" class="hidden">
<label class="text-xs text-[var(--error)] uppercase tracking-wide">Error</label>
<p id="detailError" class="text-sm mt-1 text-[var(--error)]"></p>
</div>
</div>
<div class="p-6 border-t border-[var(--border)] flex gap-3">
<button onclick="closeModal('eventDetailModal')" class="btn btn-secondary flex-1">Close</button>
<button id="detailReplayBtn" onclick="replayFromDetail()" class="btn btn-primary flex-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Replay Event
</button>
</div>
</div>
</div>
<script>
// ==================== State Management ====================
const state = {
outbox: [],
inbox: [],
timeline: [],
duplicates: new Set(),
stats: {
outboxCount: 0,
inboxCount: 0,
duplicateCount: 0,
replayCount: 0
},
currentFilter: 'all',
selectedForReplay: new Set(),
currentDetailEvent: null,
lastCreatedEventId: null
};
// ==================== Initialization ====================
document.addEventListener('DOMContentLoaded', () => {
updateUI();
addSampleEvents();
});
function addSampleEvents() {
const sampleEvents = [
{ type: 'order.created', payload: { orderId: 'ORD-001', amount: 99.99, customer: 'alice@example.com' } },
{ type: 'payment.processed', payload: { paymentId: 'PAY-001', amount: 99.99, method: 'credit_card' } },
{ type: 'user.registered', payload: { userId: 'USR-001', email: 'bob@example.com', name: 'Bob Smith' } }
];
sampleEvents.forEach((event, index) => {
setTimeout(() => {
createEventDirect(event.type, event.payload, false, false);
}, index * 500);
});
}
// ==================== Event Creation ====================
function createEvent(e) {
e.preventDefault();
const type = document.getElementById('eventType').value;
const payloadStr = document.getElementById('eventPayload').value || '{}';
const simulateDuplicate = document.getElementById('simulateDuplicate').checked;
const simulateFailure = document.getElementById('simulateFailure').checked;
let payload;
try {
payload = JSON.parse(payloadStr);
} catch {
payload = { raw: payloadStr };
}
createEventDirect(type, payload, simulateDuplicate, simulateFailure);
closeModal('newEventModal');
// Reset form
document.getElementById('eventPayload').value = '';
document.getElementById('simulateDuplicate').checked = false;
document.getElementById('simulateFailure').checked = false;
}
function createEventDirect(type, payload, isDuplicate = false, willFail = false) {
let eventId;
if (isDuplicate && state.lastCreatedEventId) {
eventId = state.lastCreatedEventId;
} else {
eventId = generateEventId();
state.lastCreatedEventId = eventId;
}
const event = {
id: eventId,
type,
payload,
status: 'pending',
createdAt: new Date().toISOString(),
attempts: 0,
willFail
};
state.outbox.push(event);
state.stats.outboxCount = state.outbox.length;
addTimelineEntry(event, 'created', `Event ${eventId} added to outbox`);
updateUI();
createFlowParticle();
}
function generateEventId() {
return 'evt_' + Math.random().toString(36).substring(2, 11) + '_' + Date.now().toString(36);
}
// ==================== Event Processing ====================
function processNextEvent() {
const pendingEvents = state.outbox.filter(e => e.status === 'pending' || e.status === 'processing');
if (pendingEvents.length === 0) return;
const event = pendingEvents[0];
event.status = 'processing';
event.attempts++;
updateUI();
// Simulate processing delay
setTimeout(() => {
processEvent(event);
}, 1500);
}
function processEvent(event) {
// Check for duplicates
const existingInbox = state.inbox.find(e => e.id === event.id);
if (existingInbox) {
// Duplicate detected
event.status = 'duplicate';
state.duplicates.add(event.id);
state.stats.duplicateCount = state.duplicates.size;
addTimelineEntry(event, 'duplicate', `Duplicate detected: ${event.id}`);
// Remove from outbox after a delay
setTimeout(() => {
state.outbox = state.outbox.filter(e => e.id !== event.id);
state.stats.outboxCount = state.outbox.length;
updateUI();
}, 1000);
} else if (event.willFail && event.attempts < 3) {
// Simulate failure with retry
event.status = 'pending';
event.error = 'Connection timeout';
addTimelineEntry(event, 'error', `Processing failed for ${event.id} (attempt ${event.attempts})`);
} else {
// Success
event.status = 'delivered';
event.processedAt = new Date().toISOString();
// Move to inbox
state.inbox.unshift({ ...event });
state.stats.inboxCount = state.inbox.length;
// Remove from outbox
state.outbox = state.outbox.filter(e => e.id !== event.id);
state.stats.outboxCount = state.outbox.length;
addTimelineEntry(event, 'success', `Event ${event.id} delivered successfully`);
}
updateUI();
createFlowParticle();
}
// ==================== Replay Functionality ====================
function openReplayModal() {
const list = document.getElementById('replayEventList');
if (state.inbox.length === 0) {
list.innerHTML = `
<div class="text-center py-6 text-[var(--fg-muted)]">
<p>No events available for replay</p>
</div>
`;
} else {
list.innerHTML = state.inbox.map(event => `
<label class="flex items-center gap-3 p-3 rounded-lg bg-[var(--bg)] hover:bg-[var(--bg-card)] cursor-pointer transition-colors">
<input type="checkbox" class="w-4 h-4 rounded border-[var(--border)] bg-[var(--bg)] accent-[var(--accent)]"
data-event-id="${event.id}" onchange="toggleReplaySelection('${event.id}')">
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2">
<span class="font-mono text-xs text-[var(--accent)]">${event.id.substring(0, 16)}...</span>
<span class="text-xs text-[var(--fg-muted)]">${event.type}</span>
</div>
</div>
</label>
`).join('');
}
state.selectedForReplay.clear();
openModal('replayModal');
}
function toggleReplaySelection(eventId) {
if (state.selectedForReplay.has(eventId)) {
state.selectedForReplay.delete(eventId);
} else {
state.selectedForReplay.add(eventId);
}
}
function replaySelectedEvents() {
state.selectedForReplay.forEach(eventId => {
const originalEvent = state.inbox.find(e => e.id === eventId);
if (originalEvent) {
// Create a new event with the same data but new ID
const replayEvent = {
id: generateEventId(),
type: originalEvent.type,
payload: { ...originalEvent.payload, _replayOf: originalEvent.id },
status: 'pending',
createdAt: new Date().toISOString(),
attempts: 0,
isReplay: true
};
state.outbox.push(replayEvent);
state.stats.outboxCount = state.outbox.length;
state.stats.replayCount++;
addTimelineEntry(replayEvent, 'replay', `Replaying event from ${eventId}`);
}
});
closeModal('replayModal');
updateUI();
// Auto-process replayed events
setTimeout(() => {
processNextEvent();
}, 500);
}
function replayFromDetail() {
if (state.currentDetailEvent) {
const originalEvent = state.currentDetailEvent;
const replayEvent = {
id: generateEventId(),
type: originalEvent.type,
payload: { ...originalEvent.payload, _replayOf: originalEvent.id },
status: 'pending',
createdAt: new Date().toISOString(),
attempts: 0,
isReplay: true
};
state.outbox.push(replayEvent);
state.stats.outboxCount = state.outbox.length;
state.stats.replayCount++;
addTimelineEntry(replayEvent, 'replay', `Replaying event from ${originalEvent.id}`);
closeModal('eventDetailModal');
updateUI();
setTimeout(() => {
processNextEvent();
}, 500);
}
}
// ==================== Timeline ====================
function addTimelineEntry(event, type, message) {
const entry = {
id: generateEventId(),
eventId: event.id,
type,
message,
timestamp: new Date().toISOString()
};
state.timeline.unshift(entry);
// Keep only last 50 entries
if (state.timeline.length > 50) {
state.timeline = state.timeline.slice(0, 50);
}
}
function filterTimeline(filter, btn) {
state.currentFilter = filter;
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
updateTimeline();
}
function updateTimeline() {
const container = document.getElementById('timeline');
let filtered = state.timeline;
if (state.currentFilter !== 'all') {
filtered = state.timeline.filter(e => e.type === state.currentFilter);
}
if (filtered.length === 0) {
container.innerHTML = `
<div class="text-center py-6 text-[var(--fg-muted)]">
<p>No events match the current filter</p>
</div>
`;
return;
}
container.innerHTML = filtered.map(entry => {
const iconColor = {
created: 'var(--fg-muted)',
success: 'var(--accent)',
duplicate: 'var(--warning)',
error: 'var(--error)',
replay: 'var(--success)'
}[entry.type] || 'var(--fg-muted)';
const bgColor = {
created: 'var(--bg)',
success: 'var(--accent-dim)',
duplicate: 'var(--warning-dim)',
error: 'var(--error-dim)',
replay: 'rgba(63, 185, 80, 0.15)'
}[entry.type] || 'var(--bg)';
return `
<div class="flex items-center gap-3 p-3 rounded-lg transition-colors hover:bg-[var(--bg-card)]" style="background: ${bgColor}">
<div class="w-2 h-2 rounded-full flex-shrink-0" style="background: ${iconColor}"></div>
<div class="flex-1 min-w-0">
<p class="text-sm truncate">${entry.message}</p>
<p class="text-xs text-[var(--fg-muted)] font-mono">${entry.eventId}</p>
</div>
<span class="text-xs text-[var(--fg-muted)] flex-shrink-0">${formatTime(entry.timestamp)}</span>
</div>
`;
}).join('');
}
// ==================== UI Updates ====================
function updateUI() {
// Update metrics
document.getElementById('outboxCount').textContent = state.stats.outboxCount;
document.getElementById('inboxCount').textContent = state.stats.inboxCount;
document.getElementById('duplicateCount').textContent = state.stats.duplicateCount;
document.getElementById('replayCount').textContent = state.stats.replayCount;
// Update panel counts
document.getElementById('outboxPanelCount').textContent = state.outbox.length;
document.getElementById('inboxPanelCount').textContent = state.inbox.length;
// Update outbox list
updateOutboxList();
// Update inbox list
updateInboxList();
// Update timeline
updateTimeline();
}
function updateOutboxList() {
const container = document.getElementById('outboxList');
if (state.outbox.length === 0) {
container.innerHTML = `
<div class="text-center py-8 text-[var(--fg-muted)]">
<svg class="w-12 h-12 mx-auto mb-3 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/>
</svg>
<p>No events in outbox</p>
<p class="text-sm mt-1">Create a new event to get started</p>
</div>
`;
return;
}
container.innerHTML = state.outbox.map(event => `
<div class="event-card ${event.status} p-4 mb-2 cursor-pointer" onclick="showEventDetail('${event.id}', 'outbox')">
<div class="flex items-center justify-between mb-2">
<span class="font-mono text-xs text-[var(--accent)]">${event.id.substring(0, 20)}...</span>
${getStatusBadge(event.status)}
</div>
<div class="flex items-center justify-between">
<span class="text-sm font-medium">${formatEventType(event.type)}</span>
<span class="text-xs text-[var(--fg-muted)]">${formatTime(event.createdAt)}</span>
</div>
${event.attempts > 0 ? `<p class="text-xs text-[var(--warning)] mt-2">Attempt ${event.attempts}</p>` : ''}
</div>
`).join('');
}
function updateInboxList() {
const container = document.getElementById('inboxList');
if (state.inbox.length === 0) {
container.innerHTML = `
<div class="text-center py-8 text-[var(--fg-muted)]">
<svg class="w-12 h-12 mx-auto mb-3 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/>
</svg>
<p>No events in inbox</p>
<p class="text-sm mt-1">Processed events will appear here</p>
</div>
`;
return;
}
container.innerHTML = state.inbox.map(event => `
<div class="event-card ${event.status} p-4 mb-2 cursor-pointer" onclick="showEventDetail('${event.id}', 'inbox')">
<div class="flex items-center justify-between mb-2">
<span class="font-mono text-xs text-[var(--accent)]">${event.id.substring(0, 20)}...</span>
${event.isReplay ? '<span class="status-badge delivered text-xs">Replay</span>' : ''}
</div>
<div class="flex items-center justify-between">
<span class="text-sm font-medium">${formatEventType(event.type)}</span>
<span class="text-xs text-[var(--fg-muted)]">${formatTime(event.processedAt || event.createdAt)}</span>
</div>
</div>
`).join('');
}
function getStatusBadge(status) {
const badges = {
pending: '<span class="status-badge pending"><span class="w-1.5 h-1.5 rounded-full bg-current"></span>Pending</span>',
processing: '<span class="status-badge processing"><span class="w-1.5 h-1.5 rounded-full bg-current pulse-dot"></span>Processing</span>',
delivered: '<span class="status-badge delivered"><span class="w-1.5 h-1.5 rounded-full bg-current"></span>Delivered</span>',
duplicate: '<span class="status-badge duplicate"><span class="w-1.5 h-1.5 rounded-full bg-current"></span>Duplicate</span>',
failed: '<span class="status-badge failed"><span class="w-1.5 h-1.5 rounded-full bg-current"></span>Failed</span>'
};
return badges[status] || '';
}
// ==================== Event Detail ====================
function showEventDetail(eventId, source) {
const event = source === 'outbox'
? state.outbox.find(e => e.id === eventId)
: state.inbox.find(e => e.id === eventId);
if (!event) return;
state.currentDetailEvent = event;
document.getElementById('detailId').textContent = event.id;
document.getElementById('detailType').textContent = formatEventType(event.type);
document.getElementById('detailCreated').textContent = new Date(event.createdAt).toLocaleString();
document.getElementById('detailPayload').textContent = JSON.stringify(event.payload, null, 2);
document.getElementById('detailStatus').innerHTML = getStatusBadge(event.status).replace('status-badge', 'status-badge text-sm');
const errorContainer = document.getElementById('detailErrorContainer');
if (event.error) {
errorContainer.classList.remove('hidden');
document.getElementById('detailError').textContent = event.error;
} else {
errorContainer.classList.add('hidden');
}
// Show/hide replay button based on source
const replayBtn = document.getElementById('detailReplayBtn');
replayBtn.style.display = source === 'inbox' ? 'flex' : 'none';
openModal('eventDetailModal');
}
// ==================== Flow Visualization ====================
function createFlowParticle() {
const container = document.getElementById('flowParticles');
const particle = document.createElement('div');
particle.className = 'flow-particle event-flow-particle';
particle.style.left = '0';
container.appendChild(particle);
setTimeout(() => {
particle.remove();
}, 1500);
}
// ==================== Modals ====================
function openModal(modalId) {
document.getElementById(modalId).classList.add('open');
document.body.style.overflow = 'hidden';
}
function closeModal(modalId) {
document.getElementById(modalId).classList.remove('open');
document.body.style.overflow = '';
}
function closeModalOnOverlay(e, modalId) {
if (e.target === e.currentTarget) {
closeModal(modalId);
}
}
function openNewEventModal() {
openModal('newEventModal');
}
// ==================== Utilities ====================
function formatEventType(type) {
return type.split('.').map(word =>
word.charAt(0).toUpperCase() + word.slice(1)
).join(' ');
}
function formatTime(isoString) {
const date = new Date(isoString);
return date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
}
// ==================== Keyboard Navigation ====================
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
document.querySelectorAll('.modal-overlay.open').forEach(modal => {
modal.classList.remove('open');
});
document.body.style.overflow = '';
}
});
</script>
</body>
</html>