- Add admin PWA push notifications for order management
- Integrate TeleBot customer messaging service
- Add push notification endpoints and VAPID key support
- Implement order status notifications throughout workflow
- Add notification UI components in admin panel
- Create TeleBotMessagingService for customer updates
- Add WebPush configuration to appsettings
- Fix compilation issues (BotStatus, BotContacts DbSet)
- Add comprehensive testing documentation
Features:
- Real-time admin notifications for new orders and status changes
- Customer order progress updates via TeleBot
- Graceful failure handling for notification services
- Test endpoints for notification system validation
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
301 lines
10 KiB
Markdown
301 lines
10 KiB
Markdown
# LittleShop Performance & Notifications Improvement Plan
|
||
|
||
## 📊 Current Analysis
|
||
|
||
### ✅ What's Already Working Well
|
||
|
||
**Push Notification Infrastructure:**
|
||
- Complete VAPID-based push notification system implemented
|
||
- PWA with service worker registration and update handling
|
||
- Admin panel notification subscription/unsubscription working
|
||
- Push notification service with proper error handling and cleanup
|
||
|
||
**Performance Optimizations Already In Place:**
|
||
- Docker production optimization with resource limits
|
||
- Health checks and monitoring infrastructure
|
||
- Optimized build process with multi-stage Docker builds
|
||
- Database connection pooling and EF Core optimizations
|
||
|
||
### 🔍 Current Gaps Identified
|
||
|
||
**1. Admin PWA Push Notifications (Critical Gap)**
|
||
- ✅ Infrastructure exists but needs integration with order workflow
|
||
- ❌ Order status changes don't trigger automatic push notifications
|
||
- ❌ No real-time notifications for new orders, payments, or status updates
|
||
- ❌ Admin users not automatically notified of critical events
|
||
|
||
**2. TeleBot Customer Notifications (Critical Gap)**
|
||
- ❌ TeleBot customers don't receive order progress updates
|
||
- ❌ No automatic messaging when order status changes (Accepted → Packing → Dispatched → Delivered)
|
||
- ❌ Missing integration between OrderService updates and TeleBot messaging
|
||
|
||
**3. Performance Optimization Opportunities**
|
||
- Database query optimization for order/product listings
|
||
- Caching strategy for frequently accessed data
|
||
- Background job processing for non-critical tasks
|
||
- API response time optimization
|
||
|
||
## 🎯 Implementation Plan
|
||
|
||
### Phase 1: Admin PWA Real-Time Notifications (Priority 1)
|
||
|
||
**Objective:** Admin users get immediate push notifications for all critical events
|
||
|
||
**Tasks:**
|
||
1. **Order Event Notifications**
|
||
- New order received → Push notification to all admin users
|
||
- Payment confirmed → Notification with order details
|
||
- Payment failed/expired → Alert notification
|
||
|
||
2. **Status Change Notifications**
|
||
- Order accepted → Notification to assigned admin
|
||
- Order packed → Notification with tracking info
|
||
- Order dispatched → Confirmation notification
|
||
- Delivery confirmed → Success notification
|
||
|
||
3. **Real-Time Dashboard Updates**
|
||
- WebSocket/SignalR integration for live order updates
|
||
- Automatic refresh of order lists without page reload
|
||
- Live counters for pending orders, payments, etc.
|
||
|
||
**Implementation Steps:**
|
||
```csharp
|
||
// 1. Enhance OrderService to trigger notifications
|
||
public async Task<bool> UpdateOrderStatusAsync(Guid id, UpdateOrderStatusDto dto)
|
||
{
|
||
// Existing order update logic...
|
||
|
||
// NEW: Trigger push notifications
|
||
await _pushNotificationService.SendOrderNotificationAsync(
|
||
id,
|
||
GetStatusChangeTitle(order.Status, dto.Status),
|
||
GetStatusChangeMessage(order, dto.Status)
|
||
);
|
||
|
||
// NEW: Trigger TeleBot customer notification
|
||
await _botService.SendOrderStatusUpdateAsync(id, dto.Status);
|
||
}
|
||
```
|
||
|
||
### Phase 2: TeleBot Customer Progress Updates (Priority 1)
|
||
|
||
**Objective:** TeleBot customers receive automatic updates throughout order lifecycle
|
||
|
||
**Current TeleBot Integration Status:**
|
||
- ✅ TeleBot can view order history and details
|
||
- ❌ No automatic status update messages to customers
|
||
|
||
**Implementation Requirements:**
|
||
```csharp
|
||
// 1. Add to IBotService interface
|
||
public interface IBotService
|
||
{
|
||
Task<bool> SendOrderStatusUpdateAsync(Guid orderId, OrderStatus newStatus);
|
||
Task<bool> SendPaymentConfirmedAsync(Guid orderId);
|
||
Task<bool> SendTrackingNumberAsync(Guid orderId, string trackingNumber);
|
||
}
|
||
|
||
// 2. Integration points in OrderService
|
||
- Order created → "Order received! We'll notify you when payment is confirmed."
|
||
- Payment confirmed → "Payment received! Your order is being processed."
|
||
- Order accepted → "Order accepted and being prepared for packing."
|
||
- Order packed → "Order packed! We'll send tracking details when dispatched."
|
||
- Order dispatched → "Order dispatched! Tracking: {trackingNumber}"
|
||
- Order delivered → "Order delivered! Please consider leaving a review."
|
||
```
|
||
|
||
**Message Templates:**
|
||
```csharp
|
||
public static class TeleBotOrderMessages
|
||
{
|
||
public static string GetStatusUpdateMessage(OrderStatus status, Order order) => status switch
|
||
{
|
||
OrderStatus.PaymentReceived => $"💰 *Payment Confirmed!*\n\nYour order #{order.Id.ToString()[..8]} has been paid successfully. We'll start processing it shortly.\n\n📦 Total: £{order.TotalAmount:F2}",
|
||
|
||
OrderStatus.Accepted => $"✅ *Order Accepted!*\n\nGreat news! Your order #{order.Id.ToString()[..8]} has been accepted and is being prepared for packing.\n\n⏱️ Expected packing: Within 24 hours",
|
||
|
||
OrderStatus.Packing => $"📦 *Being Packed!*\n\nYour order #{order.Id.ToString()[..8]} is currently being packed with care.\n\n🚚 We'll send tracking details once dispatched.",
|
||
|
||
OrderStatus.Dispatched => $"🚚 *Order Dispatched!*\n\nYour order #{order.Id.ToString()[..8]} is on its way!\n\n📍 Tracking: `{order.TrackingNumber}`\n⏱️ Estimated delivery: 1-3 working days",
|
||
|
||
OrderStatus.Delivered => $"🎉 *Order Delivered!*\n\nYour order #{order.Id.ToString()[..8]} has been delivered successfully!\n\n⭐ Please consider leaving a review using /review command."
|
||
};
|
||
}
|
||
```
|
||
|
||
### Phase 3: Performance Optimization (Priority 2)
|
||
|
||
**Objective:** Optimize system performance for better user experience
|
||
|
||
**3.1 Database Query Optimization**
|
||
```csharp
|
||
// Current slow queries identified:
|
||
// 1. Order list with includes (N+1 problem)
|
||
// 2. Product list with photos (eager loading)
|
||
// 3. Category list with product counts
|
||
|
||
// Optimization strategies:
|
||
// - Add proper indexes on frequently queried columns
|
||
// - Implement pagination for large datasets
|
||
// - Use projection for list views (select only needed columns)
|
||
// - Add database query caching for static data
|
||
```
|
||
|
||
**3.2 Caching Strategy**
|
||
```csharp
|
||
// Implement distributed caching for:
|
||
// - Category lists (rarely change)
|
||
// - Product basic info (change infrequently)
|
||
// - VAPID keys and configuration
|
||
// - Order status statistics for dashboard
|
||
|
||
public interface ICacheService
|
||
{
|
||
Task<T?> GetAsync<T>(string key);
|
||
Task SetAsync<T>(string key, T value, TimeSpan? expiry = null);
|
||
Task RemoveAsync(string key);
|
||
Task RemovePatternAsync(string pattern);
|
||
}
|
||
```
|
||
|
||
**3.3 Background Job Processing**
|
||
```csharp
|
||
// Move non-critical tasks to background:
|
||
// - Push notification delivery
|
||
// - Email sending
|
||
// - Log cleanup
|
||
// - Expired subscription cleanup
|
||
// - Image optimization/resizing
|
||
|
||
// Use Hangfire (already configured) for:
|
||
[BackgroundJob]
|
||
public async Task ProcessOrderNotifications(Guid orderId, OrderStatus newStatus)
|
||
{
|
||
// Process all notifications in background
|
||
await _pushNotificationService.SendOrderNotificationAsync(...);
|
||
await _botService.SendOrderStatusUpdateAsync(...);
|
||
await _emailService.SendOrderUpdateEmailAsync(...);
|
||
}
|
||
```
|
||
|
||
### Phase 4: Real-Time Features (Priority 3)
|
||
|
||
**Objective:** Add real-time capabilities for better admin experience
|
||
|
||
**4.1 SignalR Integration**
|
||
```csharp
|
||
// Real-time features:
|
||
// - Live order status updates on admin dashboard
|
||
// - Real-time notification delivery status
|
||
// - Live customer count and activity
|
||
// - Real-time TeleBot message status
|
||
|
||
public class OrderHub : Hub
|
||
{
|
||
public async Task JoinAdminGroup()
|
||
{
|
||
await Groups.AddToGroupAsync(Context.ConnectionId, "AdminUsers");
|
||
}
|
||
|
||
public async Task NotifyOrderUpdate(Guid orderId, OrderStatus status)
|
||
{
|
||
await Clients.Group("AdminUsers").SendAsync("OrderUpdated", orderId, status);
|
||
}
|
||
}
|
||
```
|
||
|
||
**4.2 Enhanced PWA Features**
|
||
```csharp
|
||
// PWA improvements:
|
||
// - Offline support for order viewing
|
||
// - Background sync for status updates
|
||
// - Improved caching strategy
|
||
// - Better mobile experience for admin panel
|
||
```
|
||
|
||
## 📈 Performance Metrics & Monitoring
|
||
|
||
### Key Performance Indicators (KPIs)
|
||
```yaml
|
||
Response Times:
|
||
- API endpoints: < 200ms average
|
||
- Admin dashboard load: < 1 second
|
||
- Push notification delivery: < 5 seconds
|
||
- TeleBot response time: < 2 seconds
|
||
|
||
User Experience:
|
||
- Push notification delivery rate: > 95%
|
||
- TeleBot message delivery: > 98%
|
||
- Admin panel uptime: > 99.5%
|
||
- Mobile PWA performance score: > 90
|
||
|
||
Business Metrics:
|
||
- Order processing time: < 24 hours
|
||
- Customer notification coverage: 100%
|
||
- Admin response time to orders: < 1 hour
|
||
```
|
||
|
||
### Performance Monitoring Setup
|
||
```yaml
|
||
# Add to Prometheus metrics:
|
||
Counters:
|
||
- littleshop_push_notifications_sent_total
|
||
- littleshop_telebot_messages_sent_total
|
||
- littleshop_order_status_changes_total
|
||
|
||
Histograms:
|
||
- littleshop_api_request_duration_seconds
|
||
- littleshop_database_query_duration_seconds
|
||
- littleshop_notification_delivery_seconds
|
||
|
||
Gauges:
|
||
- littleshop_active_push_subscriptions
|
||
- littleshop_pending_orders_count
|
||
- littleshop_background_jobs_pending
|
||
```
|
||
|
||
## 🚀 Implementation Timeline
|
||
|
||
### Week 1: Critical Notifications
|
||
- **Day 1-2:** Enhance OrderService with notification triggers
|
||
- **Day 3-4:** Implement admin PWA push notification integration
|
||
- **Day 5-7:** Add TeleBot customer order progress messages
|
||
|
||
### Week 2: Performance & Polish
|
||
- **Day 1-3:** Database query optimization and indexing
|
||
- **Day 4-5:** Implement caching strategy
|
||
- **Day 6-7:** Background job processing setup
|
||
|
||
### Week 3: Real-Time Features
|
||
- **Day 1-3:** SignalR hub implementation
|
||
- **Day 4-5:** Enhanced PWA features
|
||
- **Day 6-7:** Performance monitoring and testing
|
||
|
||
## 🎯 Success Criteria
|
||
|
||
### Immediate (Week 1)
|
||
- ✅ Admin users receive push notifications for all order events
|
||
- ✅ TeleBot customers get automatic order status updates
|
||
- ✅ 100% notification coverage for order lifecycle
|
||
|
||
### Short-term (Week 2-3)
|
||
- ✅ API response times improved by 50%
|
||
- ✅ Real-time dashboard updates working
|
||
- ✅ Background job processing operational
|
||
- ✅ Performance monitoring fully functional
|
||
|
||
### Long-term (Month 1)
|
||
- ✅ > 95% push notification delivery rate
|
||
- ✅ < 1 hour average admin response time to orders
|
||
- ✅ Improved customer satisfaction from proactive updates
|
||
- ✅ System capable of handling 10x current order volume
|
||
|
||
---
|
||
|
||
**Ready to Begin Implementation**
|
||
|
||
This plan addresses your specific requirements:
|
||
1. ✅ Admin PWA push notifications for order management
|
||
2. ✅ TeleBot customer notifications for order progress
|
||
3. ✅ Performance optimization without premature advanced features
|
||
4. ✅ Focused on reliability and user experience improvements |