Status Message System Implementation
Overview
Implemented a comprehensive status message system to track the lifecycle of requests from Angular frontend through Node.js to Rust backend, displaying real-time status updates in an expandable/collapsible widget at the bottom of the screen.
Components Created
1. Status Message Service
File: frontend-ng/src/app/common/status-message.service.ts
- Purpose: Centralized service to manage status messages
- Features:
- BehaviorSubject for reactive message updates
- Stores last 50 messages
- Message interface with timestamp, type, stage, and metadata
- Methods:
addMessage(),updateMessage(),clearMessages()
Message Stages:
sending- Message being sent to backendreceived- Backend received the messageprocessing- Backend processing the messagecompleted- Processing completed successfullyfailed- Processing failed
2. Status Widget Component
Files:
frontend-ng/src/app/common/status-widget/status-widget.component.tsfrontend-ng/src/app/common/status-widget/status-widget.component.htmlfrontend-ng/src/app/common/status-widget/status-widget.component.scss
Features:
- Uses Ignite UI
IgxExpansionPanelfor expand/collapse functionality - Fixed position at bottom of screen
- Auto-expands when new messages arrive
- Color-coded messages by type (info, success, warning, error)
- Material icons for visual feedback
- Timestamp display in HH:mm:ss format
- Clear all messages button
- Dark theme support
- Responsive design with max-height and scrolling
Backend Updates
3. Node.js Backend (nsqreaderwriter.js)
File: backend-node/app/jobs/nsqreaderwriter.js
Changes:
- Added status message emission before publishing to NSQ
- Sends status via WebSocket to client using
cidfield - Message includes: message text, type, stage, messageId, cid, timestamp
Status Message Example:
{
message: `Backend processing: Message ID ${requestData.id}`,
type: 'info',
stage: 'sending',
messageId: requestData.id,
cid: requestData.cid,
timestamp: new Date().toISOString()
}
4. Rust Backend (main.rs)
File: backend-rust/src/main.rs
Changes:
- Added status message publication when message is received
- Publishes to same topic as response messages
- Uses existing NSQ producer
- Includes message ID and cid for client routing
Status Message Example:
{
"message": "Rust backend received: Message ID {id}",
"type": "info",
"stage": "received",
"messageId": message.id,
"cid": message.cid,
"timestamp": "2025-11-24T...",
"stopic": "status_message"
}
Frontend Integration
5. Analytics Service Updates
File: frontend-ng/src/app/analytics.service.ts
Changes:
- Imported
StatusMessageService - Added dependency injection in constructor
- Added status message before sending request to backend
- Added listener for
status_messagetopic from backend
Message Flow:
- User triggers analytics request
- Angular service sends status: “Sending request…”
- Node.js receives, sends status: “Backend processing…”
- Rust receives, sends status: “Rust backend received…”
- All status messages appear in widget
6. App Module Updates
File: frontend-ng/src/app/app.module.ts
Changes:
- Imported
StatusWidgetComponent - Imported
IgxExpansionPanelModule - Added
StatusWidgetComponentto declarations - Added
IgxExpansionPanelModuleto imports
7. Nav Bar Integration
File: frontend-ng/src/app/nav/nav-bar.component.html
Changes:
- Added
<status-widget></status-widget>before closing</main>tag - Widget positioned at bottom of screen via CSS
WebSocket Communication Flow
┌─────────────────┐
│ Angular Client │
│ (cid = socket) │
└────────┬────────┘
│ 1. Request (with cid)
▼
┌─────────────────┐
│ Node.js NSQ │ ──→ Status: "Sending to backend"
│ Reader/Writer │
└────────┬────────┘
│ 2. Publish to NSQ
▼
┌─────────────────┐
│ Rust Backend │ ──→ Status: "Received at Rust"
│ (NSQ Topic) │
└────────┬────────┘
│ 3. Process & Publish Response
▼
┌─────────────────┐
│ Node.js NSQ │ ──→ Forward to WebSocket (using cid)
│ Reader │
└────────┬────────┘
│ 4. Emit to socket.id === cid
▼
┌─────────────────┐
│ Angular Client │ ──→ Display in Status Widget
│ Status Widget │
└─────────────────┘
UI Features
Status Widget Display
- Header: Shows count of messages and latest message preview
- Expand/Collapse: Click header or icon to toggle
- Message List:
- Icon indicating stage (send, done, sync, check_circle, error)
- Timestamp in monospace font
- Stage badge (SENDING, RECEIVED, PROCESSING, etc.)
- Message text and optional details
- Color Coding:
- Blue border: Info messages
- Green border: Success messages
- Orange border: Warning messages
- Red border: Error messages
- Actions: Clear all button to remove all messages
Styling
- Fixed at bottom of viewport (z-index: 1000)
- White background with shadow
- Max height 400px with scrolling
- Smooth transitions and hover effects
- Dark theme compatible
Testing
To test the implementation:
Frontend Build: Navigate to frontend-ng and build
cd frontend-ng npm install ng serveBackend Services: Ensure Node.js and Rust backends are running
# Node.js cd backend-node npm start # Rust cd backend-rust cargo runTrigger Request:
- Go to Analytics page
- Select an asset or portfolio
- Request analysis
- Watch status widget for messages:
- “Sending request: …” (Angular)
- “Backend processing: …” (Node.js)
- “Rust backend received: …” (Rust)
Benefits
- Visibility: Users see exactly what’s happening with their requests
- Debugging: Developers can track message flow through the system
- User Experience: Real-time feedback reduces perceived wait time
- Error Tracking: Failed stages are clearly identified
- Non-Intrusive: Widget stays collapsed until needed
- Persistent: Messages remain visible until cleared
Future Enhancements
- Filter by Type: Add buttons to filter messages by type/stage
- Export: Allow exporting messages for debugging
- Message Details: Expand individual messages to show full payload
- Sound Notifications: Optional audio alerts for errors
- Auto-Clear: Automatically remove old messages after timeout
- Search: Search through message history
- Performance Metrics: Show request duration and processing time
