A scalable multi-client Discord service that automatically detects when your friends are playing games or listening to music and sends them relevant content.
- Multi-Client Support: Run multiple Discord clients simultaneously, each with its own configuration
- Worker Thread Architecture: Each Discord client runs in its own worker thread for improved stability and performance
- Friend Activity Monitoring: Automatically detects when friends start playing games or listening to music on Discord
- Game-Specific Content: Searches for content related to the specific game your friend is playing
- Artist-Specific Content: Detects when friends are listening to music and sends content related to the artist
- System Monitoring: Real-time monitoring of system metrics, worker status, and performance
- Customizable: Configure how many content items to send, how often to check, and more
- Test Mode: Option to run without actually sending messages, for testing
- Targeted Mode: Can focus on specific users for efficiency
- Multilanguage Support (i18n): Supports English and Portuguese languages
- Real-time Response: Sends content immediately when a friend starts playing a game or listening to music
- MongoDB Integration: Persistent storage for accounts, friends, and content history
- RESTful API: Comprehensive API for managing accounts and monitoring system status
- Secure Authentication: Email/password authentication with JWT tokens and refresh mechanism
- Role-based Access Control: Flexible permission system for controlling access to features
- Real-time Status Monitoring: Track the status of Discord clients with history
- Critical Issue Alerting: Customizable alerts for connection problems, token issues, and error rates with batch processing for scalability
- Monitoring Dashboard: Real-time metrics and status information
The project is being developed in six phases, each focusing on specific aspects of the system:
- Set up Express server with TypeScript
- Implement worker thread architecture for Discord client management
- MongoDB integration with Mongoose schemas
- Basic testing infrastructure
- Activity monitoring system
- Game activity detection
- Music activity detection
- Streaming activity detection
- Watching activity detection
- Custom activity detection
- Competing activity detection
- Activity history tracking
- Cooldown management
- Content delivery system
- Content provider interface
- Content history tracking
- Error handling and retries
- System monitoring and metrics
- Worker health checks
- Performance metrics
- Error reporting
- User authentication system with JWT
- Secure password hashing with bcrypt
- JWT token generation and validation
- Token refresh mechanism
- Password reset functionality
- Login rate limiting
- Role-based access control
- Flexible permission system
- Permission-based middleware
- Role management endpoints
- Account management endpoints
- CRUD operations for Discord accounts
- Validation and error handling
- Filtering and pagination
- Secure token storage
- Token encryption at rest
- Token validation before usage
- Client status monitoring
- Real-time status tracking
- Status history
- Automatic client recovery
- First-time setup experience
- Guided setup process
- Setup status tracking
- Security audit and testing
- Authentication and role-based security tests
- Penetration testing
- Security documentation
- React application with Vite
- Authentication UI
- Account management dashboard
- Configuration interfaces
- Admin dashboard with system statistics
- Plugin-based content providers
- Extended content types support
- Content search optimization
- Content preference system
- Content delivery tracking
- Socket.io integration
- Live status updates
- Real-time notifications
- Activity feed
- System metrics streaming
- Advanced admin dashboard
- User management features
- Performance monitoring tools
- System optimization
- Advanced content filtering
The complete project is estimated to take 105-138 developer days to implement:
- Phase 1: 15-20 days
- Phase 2: 18-25 days
- Phase 3: 20-25 days
- Phase 4: 16-22 days
- Phase 5: 16-21 days
- Phase 6: 20-25 days
The phases are designed to build upon each other:
-
Phase 1 → Phase 2: Basic API endpoints are enhanced with authentication and access control.
-
Phase 2 → Phase 3: Authentication and account management APIs are consumed by the frontend.
-
Phase 3 → Phase 4: Frontend components are enhanced to support the content abstraction system.
-
Phase 4 → Phase 5: Content delivery system is enhanced with real-time notifications.
-
Phase 5 → Phase 6: Real-time infrastructure is leveraged for admin features and monitoring.
-
Worker Thread Management:
- Reliable communication between threads
- Crash handling and recovery
- Clean shutdown procedures
-
Discord Token Security:
- Secure storage and encryption
- Safe token handling
- Access control and auditing
-
Stateful Connections:
- Managing multiple Discord connections
- Resource allocation
- Connection recovery
-
Real-time Updates:
- Efficient Socket.io implementation
- State synchronization
- Event handling at scale
-
Content Provider Architecture:
- Plugin system design
- Content type abstraction
- Delivery optimization
The application follows a multi-service architecture:
┌─────────────────────────────────────────────────┐
│ Server (Backend) │
│ │
│ ┌─────────┐ ┌──────────┐ ┌────────┐ │
│ │ Account │ │ Content │ │ Auth │ │
│ │ Service │ │ Service │ │ Service│ │
│ └─────────┘ └──────────┘ └────────┘ │
│ │
│ ┌─────────┐ ┌──────────────────────┐ │
│ │ Metrics │ │ System Monitor │ │
│ │ Service │ │ Service │ │
│ └─────────┘ └──────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ Worker Thread Manager │ │
│ │ │ │
│ │ ┌─────────────────────────────────┐ │ │
│ │ │ Discord Clients │ │ │
│ │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ │ │
│ │ │ │Bot 1│ │Bot 2│ │Bot 3│ ... │ │ │
│ │ │ └─────┘ └─────┘ └─────┘ │ │ │
│ │ └─────────────────────────────────┘ │ │
│ └─────────────────────────────────────────┘ │
└─────────────────────┬───────────────────────────┘
│
▼
┌─────────┐
│MongoDB │
└─────────┘
- Node.js (v16+)
- MongoDB (v4.4+)
- npm or yarn
- Discord account tokens
- SerpApi API key (for content search)
The application can be configured using environment variables in a .env file:
# MongoDB connection
MONGODB_URI=mongodb://localhost:27017/discord-auto-meme
# SerpApi (Google Search API) credentials
SERP_API_KEY=your_serpapi_key_here
# Discord tokens (for multiple accounts)
DISCORD_TOKEN_1=your_first_discord_token
DISCORD_TOKEN_2=your_second_discord_token
# Add more tokens as needed...
# System configuration
NODE_ENV=development
LOG_LEVEL=info- POST /api/auth/register: Register a new user
- POST /api/auth/login: Authenticate user
- POST /api/auth/refresh: Refresh access token
- POST /api/auth/forgot-password: Request password reset
- POST /api/auth/reset-password: Reset password with token
- GET /api/users: List all users (admin only)
- GET /api/users/:id: Get specific user details
- PUT /api/users/:id: Update user information
- DELETE /api/users/:id: Remove a user
- GET /api/roles: List all roles
- GET /api/roles/:id: Get specific role details
- POST /api/roles: Create a new role
- PUT /api/roles/:id: Update a role
- POST /api/roles/assign/:userId: Assign roles to a user
- GET /api/roles/my-permissions: Get current user's permissions
- GET /api/accounts: List all Discord accounts
- GET /api/accounts/:id: Get specific account details
- POST /api/accounts: Add a new Discord account
- PUT /api/accounts/:id: Update account settings
- DELETE /api/accounts/:id: Remove an account
- POST /api/accounts/:id/start: Start a Discord client
- POST /api/accounts/:id/stop: Stop a Discord client
- GET /api/accounts/:id/status: Get current account status
- GET /api/accounts/:id/status/history: Get account status history
- GET /api/dashboard/accounts: Get account statistics
- GET /api/dashboard/activity: Get recent activity data
- GET /api/dashboard/content: Get content delivery statistics
- GET /api/setup/status: Get setup completion status
- POST /api/setup/account: Add first Discord account
- POST /api/setup/complete: Mark setup as complete
- GET /health: Basic health check
- GET /api/health: Detailed system status
The application includes comprehensive testing tools:
Run a demonstration of core functionality:
npm run ts-node src/demo.tsThe demo:
- Creates test Discord accounts
- Starts Discord clients
- Monitors worker status
- Tests content search
- Collects system metrics
Test system stability and performance:
npm run ts-node src/loadTest.tsThe load test:
- Runs multiple concurrent Discord clients
- Monitors memory and CPU usage
- Performs periodic content searches
- Tracks error rates
- Generates performance metrics
Configure load test parameters in loadTest.ts:
const NUM_ACCOUNTS = 5; // Number of concurrent clients
const NUM_FRIENDS_PER_ACCOUNT = 3; // Friends per account
const TEST_DURATION_MS = 5 * 60000; // Test duration (5 minutes)
const METRICS_INTERVAL_MS = 10000; // Metrics collection interval- Clone the repository
- Install dependencies:
cd server npm install - Create
.envfile with required configuration - Start MongoDB
- Run in development mode:
npm run dev
Run unit tests:
npm testRun integration tests:
npm run test:integrationCheck for linting issues:
npm run lintFix automatic linting issues:
npm run lint:fix-
Discord API Restrictions:
- Limited presence data accessibility
- Rate limiting on API calls
- Token security considerations
-
System Resources:
- Each Discord client requires a separate worker thread
- Memory usage scales with number of active clients
- Recommended maximum of 10 concurrent clients per instance
-
Content Search:
- SerpApi free tier limited to 100 searches/month
- Content relevance depends on search query quality
- Some content may be inappropriate or irrelevant
- Password Security: Passwords are hashed using bcrypt with appropriate salt rounds
- JWT Authentication: Secure authentication using JWT tokens with proper expiration
- Token Refresh: Implemented token refresh mechanism to maintain sessions securely
- Token Revocation: System for invalidating tokens on logout, password change, or security concerns
- Rate Limiting: Protection against brute force attacks
- Role-based Access Control: Granular permissions system for access control
- Encrypted Token Storage: Discord tokens are encrypted at rest in the database
- Input Validation: Thorough validation of all API inputs
- Error Handling: Secure error handling that doesn't expose sensitive information
-
User Authentication:
- JWT-based authentication
- Role-based access control
- User management interface
-
Content Providers:
- Plugin system for different content sources
- Content filtering and moderation
- User feedback and rating system
-
Monitoring:
- Advanced metrics dashboard
- Alert system for issues
- Performance optimization tools
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.