-
-
Notifications
You must be signed in to change notification settings - Fork 1
Implement 3-Layer Data Persistence Architecture with Standardized Environment Variables #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement 3-Layer Data Persistence Architecture with Standardized Environment Variables #61
Conversation
…sing Co-authored-by: warengonzaga <[email protected]>
Co-authored-by: warengonzaga <[email protected]>
Co-authored-by: warengonzaga <[email protected]>
@copilot can you follow the same environment variable naming from https://github.com/unthread-telegram-bot? Make the queue hard-coded and no need to set up from environment variables. |
… hard-code queue configuration Co-authored-by: warengonzaga <[email protected]>
Done! I've updated the environment variable naming to match unthread-telegram-bot conventions:
The queue configuration is now hard-coded with default values (concurrency: 5, maxRetries: 3, retryDelayMs: 5000, etc.) and no longer uses environment variables for configuration. All documentation, Docker Compose, and code references have been updated to use the new naming convention. Commit: 6706276 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a comprehensive 3-layer data persistence architecture and queue-based webhook processing system to replace the existing Redis-only storage approach. The changes establish a robust, scalable foundation using PostgreSQL (L3), Redis cache (L2), and in-memory storage (L1) with automatic fallback capabilities.
Key changes include:
- Complete replacement of the legacy cache/memory utilities with a unified 3-layer storage system
- Implementation of queue-based webhook processing using BullMQ for reliable async event handling
- Environment variable updates to align with telegram bot conventions (PLATFORM_REDIS_URL, WEBHOOK_REDIS_URL)
Reviewed Changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
src/utils/threadUtils.ts | Updated to use BotsStore for thread-ticket mapping lookups, removed lookup function parameter |
src/utils/memory.ts | Completely removed legacy memory cache utilities |
src/utils/database.ts | Completely removed legacy Redis-only database utilities |
src/utils/customerUtils.ts | Migrated to BotsStore for customer operations, updated interface exports |
src/utils/cache.ts | Completely removed legacy Cacheable-based cache module |
src/types/discord.ts | Updated BotConfig interface with new storage environment variables |
src/services/webhook.ts | Complete rewrite implementing queue-based processing with comprehensive monitoring |
src/services/unthread.ts | Updated to use BotsStore for all storage operations, removed legacy cache dependencies |
src/services/QueueProcessor.ts | New queue processing system with retry logic, metrics, and health monitoring |
src/sdk/bots-brain/UnifiedStorage.ts | New 3-layer storage engine implementation |
src/sdk/bots-brain/BotsStore.ts | New Discord-specific storage operations built on UnifiedStorage |
src/index.ts | Updated initialization to use new storage architecture and queue system |
src/events/threadCreate.ts | Minor fix for email fallback |
src/events/messageDelete.ts | Updated to use BotsStore for deleted message caching |
src/events/interactionCreate.ts | Updated customer operations and cache clearing to use BotsStore |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR implements a comprehensive architectural overhaul of the Discord bot, replacing the legacy Redis-only storage system with a modern 3-layer data persistence architecture and introducing queue-based webhook processing for improved reliability and performance.
🏗️ Architecture Changes
New 3-Layer Storage System
The bot now implements a sophisticated storage hierarchy:
Queue-Based Webhook Processing
Replaced direct webhook handling with an asynchronous queue system:
🔧 Environment Variable Standardization
Aligned with Unthread Ecosystem
Updated environment variables to match the naming convention from
unthread-telegram-bot
:PLATFORM_REDIS_URL
- Redis cache connection for L2 storageWEBHOOK_REDIS_URL
- Redis queue connection for webhook processingDATABASE_URL
- PostgreSQL connection for L3 persistent storageSimplified Configuration
🚀 Performance Improvements
The new architecture provides significant performance benefits:
🔧 Developer Experience
Docker Compose Integration
Complete local development environment with:
Comprehensive Monitoring
New health check endpoints:
GET /health
- Overall system status with storage layer healthGET /webhook/health
- Queue system metrics and processing statisticsGET /webhook/metrics
- Detailed webhook performance dataPOST /webhook/retry
- Manual retry of failed webhook jobsEnvironment Configuration
Standardized environment variables for the new architecture:
📦 Key Components
Core Storage Engine (
src/sdk/bots-brain/UnifiedStorage.ts
)Discord-Specific Operations (
src/sdk/bots-brain/BotsStore.ts
)Queue Processing (
src/services/QueueProcessor.ts
)🗄️ Database Schema
New PostgreSQL schema with optimized indexes:
customers
- Discord user and Unthread customer mappingthread_ticket_mappings
- Discord thread to Unthread ticket relationshipsstorage_cache
- L3 persistent cache with TTL support🔄 Migration Strategy
This implementation provides a clean start approach:
🧪 Quality Assurance
The new architecture provides a solid foundation for scalable Discord bot operations with modern storage patterns, comprehensive monitoring, and improved developer experience while maintaining consistency across the Unthread bot ecosystem.
Created from VS Code via the GitHub Pull Request extension.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.