The user wants a durable messaging pattern with outbox/inbox visualization and replay UI. This is a common pattern in distributed systems for reliable message delivery.
This is a visualization of the Outbox/Inbox pattern commonly used in distributed systems for reliable message delivery. The UI shows:
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>Durable Messaging Pattern</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', system-ui, sans-serif;
background: #0a0e17;
min-height: 100vh;
color: #e0e6ed;
overflow-x: hidden;
}
.background-grid {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:
linear-gradient(rgba(16, 185, 129, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(16, 185, 129, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
pointer-events: none;
z-index: 0;
}
.container {
position: relative;
z-index: 1;
max-width: 1400px;
margin: 0 auto;
padding: 30px 20px;
}
header {
text-align: center;
margin-bottom: 30px;
}
h1 {
font-size: 2.5rem;
font-weight: 700;
background: linear-gradient(135deg, #10b981, #06b6d4);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 10px;
}
.subtitle {
color: #64748b;
font-size: 1rem;
}
.stats-bar {
display: flex;
justify-content: center;
gap: 30px;
margin-bottom: 30px;
flex-wrap: wrap;
}
.stat-item {
background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(6, 182, 212, 0.1));
border: 1px solid rgba(16, 185, 129, 0.2);
border-radius: 12px;
padding: 15px 25px;
text-align: center;
min-width: 140px;
transition: transform 0.3s, box-shadow 0.3s;
}
.stat-item:hover {
transform: translateY(-3px);
box-shadow: 0 10px 30px rgba(16, 185, 129, 0.15);
}
.stat-value {
font-size: 1.8rem;
font-weight: 700;
color: #10b981;
}
.stat-label {
font-size: 0.8rem;
color: #64748b;
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 5px;
}
.messaging-layout {
display: grid;
grid-template-columns: 1fr 100px 1fr;
gap: 20px;
align-items: start;
}
@media (max-width: 900px) {
.messaging-layout {
grid-template-columns: 1fr;
}
.flow-container {
display: none;
}
}
.box-container {
background: linear-gradient(180deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.95));
border: 1px solid rgba(100, 116, 139, 0.2);
border-radius: 16px;
overflow: hidden;
}
.box-header {
padding: 20px;
border-bottom: 1px solid rgba(100, 116, 139, 0.2);
display: flex;
justify-content: space-between;
align-items: center;
}
.box-title {
display: flex;
align-items: center;
gap: 10px;
}
.box-title h2 {
font-size: 1.2rem;
font-weight: 600;
}
.box-icon {
width: 36px;
height: 36px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.outbox .box-icon {
background: linear-gradient(135deg, #f59e0b, #d97706);
}
.inbox .box-icon {
background: linear-gradient(135deg, #10b981, #059669);
}
.box-icon svg {
width: 20px;
height: 20px;
color: white;
}
.box-actions {
display: flex;
gap: 10px;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 6px;
}
.btn-primary {
background: linear-gradient(135deg, #10b981, #059669);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(16, 185, 129, 0.4);
}
.btn-secondary {
background: rgba(100, 116, 139, 0.2);
color: #94a3b8;
border: 1px solid rgba(100, 116, 139, 0.3);
}
.btn-secondary:hover {
background: rgba(100, 116, 139, 0.3);
color: #e2e8f0;
}
.btn-danger {
background: linear-gradient(135deg, #ef4444, #dc2626);
color: white;
}
.btn-danger:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(239, 68, 68, 0.4);
}
.message-list {
max-height: 500px;
overflow-y: auto;
padding: 10px;
}
.message-list::-webkit-scrollbar {
width: 6px;
}
.message-list::-webkit-scrollbar-track {
background: rgba(100, 116, 139, 0.1);
}
.message-list::-webkit-scrollbar-thumb {
background: rgba(100, 116, 139, 0.3);
border-radius: 3px;
}
.message-item {
background: rgba(30, 41, 59, 0.5);
border: 1px solid rgba(100, 116, 139, 0.15);
border-radius: 10px;
padding: 15px;
margin-bottom: 10px;
transition: all 0.3s;
animation: slideIn 0.4s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.inbox .message-item {
animation: slideInRight 0.4s ease-out;
}
@keyframes slideInRight {
from {
opacity: 0;
transform: translateX(20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.message-item:hover {
border-color: rgba(16, 185, 129, 0.3);
background: rgba(30, 41, 59, 0.8);
}
.message-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.message-id {
font-family: 'Courier New', monospace;
font-size: 0.75rem;
color: #64748b;
}
.message-status {
padding: 4px 10px;
border-radius: 20px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.status-pending {
background: rgba(251, 191, 36, 0.2);
color: #fbbf24;
border: 1px solid rgba(251, 191, 36, 0.3);
}
.status-sent {
background: rgba(59, 130, 246, 0.2);
color: #3b82f6;
border: 1px solid rgba(59, 130, 246, 0.3);
}
.status-delivered {
background: rgba(16, 185, 129, 0.2);
color: #10b981;
border: 1px solid rgba(16, 185, 129, 0.3);
}
.status-processing {
background: rgba(139, 92, 246, 0.2);
color: #8b5cf6;
border: 1px solid rgba(139, 92, 246, 0.3);
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
.status-failed {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
border: 1px solid rgba(239, 68, 68, 0.3);
}
.message-type {
font-size: 0.8rem;
color: #06b6d4;
margin-bottom: 5px;
}
.message-payload {
font-size: 0.85rem;
color: #cbd5e1;
background: rgba(0, 0, 0, 0.2);
padding: 10px;
border-radius: 6px;
margin-bottom: 10px;
word-break: break-all;
}
.message-meta {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.75rem;
color: #64748b;
}
.message-actions {
display: flex;
gap: 8px;
}
.btn-small {
padding: 5px 10px;
font-size: 0.7rem;
}
.flow-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
min-height: 400px;
position: relative;
}
.flow-line {
width: 4px;
height: 100%;
background: linear-gradient(180deg,
rgba(245, 158, 11, 0.3) 0%,
rgba(16, 185, 129, 0.5) 50%,
rgba(16, 185, 129, 0.3) 100%);
border-radius: 2px;
position: absolute;
top: 0;
opacity: 0.5;
}
.flow-particles {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
}
.particle {
position: absolute;
width: 12px;
height: 12px;
background: radial-gradient(circle, #10b981, transparent);
border-radius: 50%;
left: 50%;
transform: translateX(-50%);
animation: flowDown 2s linear infinite;
opacity: 0;
}
@keyframes flowDown {
0% {
top: 0;
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
top: 100%;
opacity: 0;
}
}
.flow-arrow {
width: 40px;
height: 40px;
background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(6, 182, 212, 0.2));
border: 1px solid rgba(16, 185, 129, 0.3);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: #10b981;
z-index: 2;
margin: 10px 0;
}
.flow-label {
font-size: 0.7rem;
color: #64748b;
text-transform: uppercase;
letter-spacing: 1px;
z-index: 2;
background: #0a0e17;
padding: 5px 10px;
border-radius: 4px;
}
.empty-state {
text-align: center;
padding: 40px 20px;
color: #64748b;
}
.empty-state svg {
width: 60px;
height: 60px;
margin-bottom: 15px;
opacity: 0.5;
}
.toast-container {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
display: flex;
flex-direction: column;
gap: 10px;
}
.toast {
background: rgba(15, 23, 42, 0.95);
border: 1px solid rgba(100, 116, 139, 0.3);
border-radius: 10px;
padding: 15px 20px;
display: flex;
align-items: center;
gap: 10px;
animation: toastIn 0.3s ease-out;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
@keyframes toastIn {
from {
opacity: 0;
transform: translateX(100px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.toast-success {
border-color: rgba(16, 185, 129, 0.5);
}
.toast-success .toast-icon {
color: #10b981;
}
.toast-error {
border-color: rgba(239, 68, 68, 0.5);
}
.toast-error .toast-icon {
color: #ef4444;
}
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(5px);
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal-overlay.active {
display: flex;
}
.modal {
background: linear-gradient(180deg, #1e293b, #0f172a);
border: 1px solid rgba(100, 116, 139, 0.3);
border-radius: 16px;
padding: 30px;
max-width: 500px;
width: 90%;
animation: modalIn 0.3s ease-out;
}
@keyframes modalIn {
from {
opacity: 0;
transform: scale(0.9);
}
to {
opacity: 1;
transform: scale(1);
}
}
.modal h3 {
font-size: 1.3rem;
margin-bottom: 20px;
color: #e2e8f0;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
font-size: 0.85rem;
color: #94a3b8;
margin-bottom: 8px;
}
.form-group input,
.form-group select,
.form-group textarea {
width: 100%;
padding: 12px;
background: rgba(0, 0, 0, 0.3);
border: 1px solid rgba(100, 116, 139, 0.3);
border-radius: 8px;
color: #e2e8f0;
font-size: 0.9rem;
transition: border-color 0.3s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
outline: none;
border-color: #10b981;
}
.form-group textarea {
min-height: 100px;
resize: vertical;
font-family: 'Courier New', monospace;
}
.modal-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 25px;
}
.replay-indicator {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 3px 8px;
background: rgba(251, 191, 36, 0.2);
border-radius: 4px;
font-size: 0.7rem;
color: #fbbf24;
margin-left: 8px;
}
.replay-count {
font-weight: 600;
}
.flying-message {
position: fixed;
background: linear-gradient(135deg, rgba(16, 185, 129, 0.9), rgba(6, 182, 212, 0.9));
border-radius: 8px;
padding: 10px 15px;
color: white;
font-size: 0.8rem;
z-index: 100;
pointer-events: none;
box-shadow: 0 5px 20px rgba(16, 185, 129, 0.4);
}
</style>
</head>
<body>
<div class="background-grid"></div>
<div class="container">
<header>
<h1>Durable Messaging System</h1>
<p class="subtitle">Outbox/Inbox Pattern with Replay Capability</p>
</header>
<div class="stats-bar">
<div class="stat-item">
<div class="stat-value" id="stat-pending">0</div>
<div class="stat-label">Pending</div>
</div>
<div class="stat-item">
<div class="stat-value" id="stat-sent">0</div>
<div class="stat-label">In Transit</div>
</div>
<div class="stat-item">
<div class="stat-value" id="stat-delivered">0</div>
<div class="stat-label">Delivered</div>
</div>
<div class="stat-item">
<div class="stat-value" id="stat-failed">0</div>
<div class="stat-label">Failed</div>
</div>
</div>
<div class="messaging-layout">
<div class="box-container outbox">
<div class="box-header">
<div class="box-title">
<div class="box-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/>
</svg>
</div>
<h2>Outbox</h2>
</div>
<div class="box-actions">
<button class="btn btn-primary" onclick="openComposeModal()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="12" y1="5" x2="12" y2="19"></line>
<line x1="5" y1="12" x2="19" y2="12"></line>
</svg>
New Message
</button>
</div>
</div>
<div class="message-list" id="outbox-list">
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/>
</svg>
<p>No messages in outbox</p>
</div>
</div>
</div>
<div class="flow-container">
<span class="flow-label">Transport</span>
<div class="flow-arrow">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="5" y1="12" x2="19" y2="12"></line>
<polyline points="12 5 19 12 12 19"></polyline>
</svg>
</div>
<div class="flow-line"></div>
<div class="flow-particles" id="flow-particles"></div>
<div class="flow-arrow">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="19 12 12 19 12 5"></polyline>
</svg>
</div>
<span class="flow-label">Consumers</span>
</div>
<div class="box-container inbox">
<div class="box-header">
<div class="box-title">
<div class="box-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="22 12 16 12 14 15 10 15 8 12 2 12"></polyline>
<path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"></path>
</svg>
</div>
<h2>Inbox</h2>
</div>
<div class="box-actions">
<button class="btn btn-secondary" onclick="clearInbox()">Clear All</button>
</div>
</div>
<div class="message-list" id="inbox-list">
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<polyline points="22 12 16 12 14 15 10 15 8 12 2 12"></polyline>
<path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"></path>
</svg>
<p>No messages received</p>
</div>
</div>
</div>
</div>
</div>
<div class="modal-overlay" id="compose-modal">
<div class="modal">
<h3>Compose New Message</h3>
<div class="form-group">
<label>Message Type</label>
<select id="msg-type">
<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.send">Send Notification</option>
</select>
</div>
<div class="form-group">
<label>Payload (JSON)</label>
<textarea id="msg-payload">{
"eventId": "evt_" + Math.random().toString(36).substr(2, 9),
"timestamp": new Date().toISOString(),
"data": {
"sample": "payload"
}
}</textarea>
</div>
<div class="modal-actions">
<button class="btn btn-secondary" onclick="closeComposeModal()">Cancel</button>
<button class="btn btn-primary" onclick="sendMessage()">Send Message</button>
</div>
</div>
</div>
<div class="toast-container" id="toast-container"></div>
<script>
// State management
const state = {
outbox: [],
inbox: [],
messageIdCounter: 1000
};
// Message types with colors
const messageTypes = {
'order.created': '#f59e0b',
'payment.processed': '#10b981',
'user.registered': '#8b5cf6',
'inventory.updated': '#3b82f6',
'notification.send': '#ec4899'
};
// Generate unique ID
function generateId() {
state.messageIdCounter++;
return `msg_${state.messageIdCounter.toString(16).toUpperCase()}`;
}
// Create message object
function createMessage(type, payload) {
return {
id: generateId(),
type: type,
payload: payload,
status: 'pending',
createdAt: new Date(),
retries: 0,
maxRetries: 3
};
}
// Update stats
function updateStats() {
const pending = state.outbox.filter(m => m.status === 'pending').length;
const sent = state.outbox.filter(m => m.status === 'sent' || m.status === 'processing').length;
const delivered = state.inbox.filter(m => m.status === 'delivered').length;
const failed = state.outbox.filter(m => m.status === 'failed').length;
animateValue('stat-pending', pending);
animateValue('stat-sent', sent);
animateValue('stat-delivered', delivered);
animateValue('stat-failed', failed);
}
function animateValue(elementId, newValue) {
const el = document.getElementById(elementId);
const current = parseInt(el.textContent);
if (current !== newValue) {
el.style.transform = 'scale(1.2)';
el.textContent = newValue;
setTimeout(() => el.style.transform = 'scale(1)', 200);
}
}
// Render outbox
function renderOutbox() {
const container = document.getElementById('outbox-list');
if (state.outbox.length === 0) {
container.innerHTML = `
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/>
</svg>
<p>No messages in outbox</p>
</div>
`;
return;
}
container.innerHTML = state.outbox.map(msg => `
<div class="message-item" id="outbox-${msg.id}">
<div class="message-header">
<span class="message-id">${msg.id}</span>
<span class="message-status status-${msg.status}">${msg.status}</span>
</div>
<div class="message-type" style="color: ${messageTypes[msg.type] || '#06b6d4'}">${msg.type}</div>
<div class="message-payload">${escapeHtml(msg.payload)}</div>
<div class="message-meta">
<span>${formatTime(msg.createdAt)}</span>
<div class="message-actions">
${msg.status === 'failed' ? `
<button class="btn btn-primary btn-small" onclick="replayMessage('${msg.id}')">
Replay
</button>
` : ''}
${msg.status === 'pending' ? `
<button class="btn btn-danger btn-small" onclick="cancelMessage('${msg.id}')">
Cancel
</button>
` : ''}
</div>
</div>
${msg.retries > 0 ? `
<div class="replay-indicator">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="23 4 23 10 17 10"></polyline>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path>
</svg>
<span class="replay-count">${msg.retries}/${msg.maxRetries}</span>
</div>
` : ''}
</div>
`).join('');
}
// Render inbox
function renderInbox() {
const container = document.getElementById('inbox-list');
if (state.inbox.length === 0) {
container.innerHTML = `
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<polyline points="22 12 16 12 14 15 10 15 8 12 2 12"></polyline>
<path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"></path>
</svg>
<p>No messages received</p>
</div>
`;
return;
}
container.innerHTML = state.inbox.map(msg => `
<div class="message-item">
<div class="message-header">
<span class="message-id">${msg.id}</span>
<span class="message-status status-${msg.status}">${msg.status}</span>
</div>
<div class="message-type" style="color: ${messageTypes[msg.type] || '#06b6d4'}">${msg.type}</div>
<div class="message-payload">${escapeHtml(msg.payload)}</div>
<div class="message-meta">
<span>Received: ${formatTime(msg.deliveredAt)}</span>
<span>from ${msg.source || 'producer-1'}</span>
</div>
</div>
`).join('');
}
// Send message
function sendMessage() {
const type = document.getElementById('msg-type').value;
let payload = document.getElementById('msg-payload').value;
try {
// Try to parse and re-stringify for formatting
payload = JSON.stringify(JSON.parse(payload), null, 2);
} catch (e) {
// Keep as-is if not valid JSON
}
const message = createMessage(type, payload);
state.outbox.unshift(message);
closeComposeModal();
renderOutbox();
updateStats();
showToast('Message queued in outbox', 'success');
// Simulate async processing
setTimeout(() => processMessage(message.id), 500);
}
// Process message (simulate async delivery)
function processMessage(messageId) {
const msg = state.outbox.find(m => m.id === messageId);
if (!msg || msg.status !== 'pending') return;
msg.status = 'processing';
renderOutbox();
updateStats();
// Create flying message animation
animateMessageTransfer(msg);
// Simulate network delay
const delay = 1000 + Math.random() * 2000;
const success = Math.random() > 0.25; // 75% success rate
setTimeout(() => {
if (success) {
deliverMessage(msg);
} else {
msg.status = 'failed';
renderOutbox();
updateStats();
showToast(`Message ${msg.id} delivery failed`, 'error');
}
}, delay);
}
// Deliver message to inbox
function deliverMessage(msg) {
msg.status = 'sent';
// Move to inbox
const inboxMsg = {
...msg,
status: 'delivered',
deliveredAt: new Date(),
source: 'producer-1'
};
state.inbox.unshift(inboxMsg);
state.outbox = state.outbox.filter(m => m.id !== msg.id);
renderOutbox();
renderInbox();
updateStats();
showToast(`Message ${msg.id} delivered successfully`, 'success');
}
// Replay failed message
function replayMessage(messageId) {
const msg = state.outbox.find(m => m.id === messageId);
if (!msg || msg.status !== 'failed') return;
if (msg.retries >= msg.maxRetries) {
showToast('Max retries exceeded', 'error');
return;
}
msg.retries++;
msg.status = 'pending';
renderOutbox();
updateStats();
showToast(`Replaying message ${msg.id} (attempt ${msg.retries})`, 'success');
setTimeout(() => processMessage(messageId), 500);
}
// Cancel pending message
function cancelMessage(messageId) {
state.outbox = state.outbox.filter(m => m.id !== messageId);
renderOutbox();
updateStats();
showToast('Message cancelled', 'success');
}
// Clear inbox
function clearInbox() {
state.inbox = [];
renderInbox();
updateStats();
showToast('Inbox cleared', 'success');
}
// Animate message transfer
function animateMessageTransfer(msg) {
const outboxEl = document.getElementById(`outbox-${msg.id}`);
if (!outboxEl) return;
const rect = outboxEl.getBoundingClientRect();
const targetEl = document.getElementById('inbox-list');
const targetRect = targetEl.getBoundingClientRect();
const flyingMsg = document.createElement('div');
flyingMsg.className = 'flying-message';
flyingMsg.textContent = msg.id;
flyingMsg.style.left = rect.right + 'px';
flyingMsg.style.top = rect.top + 'px';
document.body.appendChild(flyingMsg);
flyingMsg.animate([
{ left: rect.right + 'px', top: rect.top + 'px', opacity: 1 },
{ left: (rect.right + targetRect.left) / 2 + 'px', top: (rect.top + targetRect.top) / 2 + 'px', opacity: 1 },
{ left: targetRect.left - 100 + 'px', top: targetRect.top + 'px', opacity: 0 }
], {
duration: 800,
easing: 'ease-in-out'
}).onfinish = () => flyingMsg.remove();
// Add flow particles
addFlowParticle();
}
// Add particle to flow animation
function addFlowParticle() {
const container = document.getElementById('flow-particles');
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.animationDelay = '0s';
container.appendChild(particle);
setTimeout(() => particle.remove(), 2000);
}
// Modal functions
function openComposeModal() {
document.getElementById('compose-modal').classList.add('active');
}
function closeComposeModal() {
document.getElementById('compose-modal').classList.remove('active');
}
// Toast notification
function showToast(message, type = 'success') {
const container = document.getElementById('toast-container');
const toast = document.createElement('div');
toast.className = `toast toast-${type}`;
toast.innerHTML = `
<span class="toast-icon">
${type === 'success' ? `
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
` : `
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<line x1="15" y1="9" x2="9" y2="15"></line>
<line x1="9" y1="9" x2="15" y2="15"></line>
</svg>
`}
</span>
<span>${message}</span>
`;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateX(100px)';
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// Utility functions
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function formatTime(date) {
return new Date(date).toLocaleTimeString();
}
// Initialize with flow particles
function initFlowParticles() {
const container = document.getElementById('flow-particles');
for (let i = 0; i < 5; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.animationDelay = `${i * 0.4}s`;
container.appendChild(particle);
}
}
// Close modal on overlay click
document.getElementById('compose-modal').addEventListener('click', (e) => {
if (e.target.id === 'compose-modal') {
closeComposeModal();
}
});
// Initialize
initFlowParticles();
updateStats();
renderOutbox();
renderInbox();
// Auto-generate some demo messages
setTimeout(() => {
const demoMessages = [
{ type: 'order.created', payload: '{"orderId": "ORD-12345", "customer": "John Doe", "total": 99.99}' },
{ type: 'payment.processed', payload: '{"paymentId": "PAY-67890", "amount": 99.99, "currency": "USD"}' },
{ type: 'user.registered', payload: '{"userId": "USR-11111", "email": "user@example.com"}' }
];
demoMessages.forEach((demo, i) => {
setTimeout(() => {
const msg = createMessage(demo.type, demo.payload);
state.outbox.unshift(msg);
renderOutbox();
updateStats();
setTimeout(() => processMessage(msg.id), 300);
}, i * 2000);
});
}, 1000);
</script>
</body>
</html>