System Architecture
The Streamer Alerts Bot is a real-time monitoring system that polls streaming platforms and sends Discord notifications when streamers go live. The architecture follows a modular, event-driven design with clear separation of concerns.Core Components
The bot uses no API keys - it relies on public endpoints and HTML parsing to fetch stream status, making setup simpler and avoiding rate limits.
Component Breakdown
1. StreamerBot (Discord Client)
The extended Discord.js client that manages bot lifecycle and state. Responsibilities:- Initialize Discord connection with required intents
- Register and store slash commands
- Update bot activity status (e.g., “Watching 25 streamers | 10 servers”)
- Provide centralized command registry
~/workspace/source/src/client/StreamerBot.ts
2. StreamPoller (Polling Engine)
The core polling service that checks stream status at regular intervals. Responsibilities:- Run 60-second polling loop
- Fetch live status from platform checkers
- Detect new streams and title changes
- Manage duplicate alert prevention cache
- Update streamer data in database
- Interval-based polling: Uses
setIntervalwithPOLL_INTERVAL(60,000ms) - Per-guild processing: Iterates through all guilds with tracked streamers
- Caching layer: In-memory
Maptracks last known state to prevent duplicates
The poller runs immediately on startup, then continues every 60 seconds. This ensures users see alerts quickly after bot restart.
~/workspace/source/src/services/StreamPoller.ts
3. AlertService (Notification Dispatcher)
Handles sending formatted Discord messages to notification channels. Responsibilities:- Fetch Discord channel by ID
- Create rich embeds with stream information
- Add interactive buttons (“Watch” links)
- Handle messaging errors gracefully
- Platform-colored embed with streamer info
- Stream title, viewers, followers, start time
- Thumbnail preview image
- Action button linking to stream
~/workspace/source/src/services/AlertService.ts
4. Database (JSON File Storage)
Simple file-based persistence using JSON. Storage Model:- Load on startup from
data/guilds.json - Maintain in-memory cache (
Map<guildId, GuildSettings>) - Save to disk on every modification
- Automatic directory creation if missing
~/workspace/source/src/database/index.ts
5. Platform Checkers
Modular platform-specific parsers for fetching stream status. Supported Platforms:- Kick: HTML parsing
- Twitch: Public GraphQL API
- YouTube: HTML parsing
- Rumble: HTML parsing
- TikTok: HTML parsing
~/workspace/source/src/platforms/index.ts
Data Flow
Bot Startup Sequence
~/workspace/source/src/index.ts:10-36
Alert Trigger Flow
Technology Stack
Core Dependencies
| Package | Version | Purpose |
|---|---|---|
discord.js | v14 | Discord API wrapper |
typescript | Latest | Type safety |
dotenv | Latest | Environment variables |
cheerio | Latest | HTML parsing for platforms |
Runtime Requirements
- Node.js: v18 or higher (for native fetch API)
- Intents:
Guilds,GuildMessages - Permissions: Send Messages, Embed Links, Use External Emojis
Design Principles
1. Type Safety
Full TypeScript coverage with strict mode enabled. All API interactions are typed.2. Modularity
Each component is isolated:- Platform checkers are plug-and-play
- Database is abstracted behind functions
- Services don’t depend on each other directly
3. Error Resilience
- Per-streamer error handling (one failure doesn’t crash the loop)
- Graceful degradation when channels are deleted
- Comprehensive logging at all levels
4. Simplicity
- No external database required
- No API keys or OAuth flows
- Single environment variable (Discord token)
- JSON file storage is human-readable and git-friendly
The bot is designed to be self-contained and easy to deploy. Everything runs in a single process with minimal external dependencies.
Performance Considerations
Polling Efficiency
- 60-second interval balances freshness with API load
- Sequential processing per guild prevents rate limiting
- In-memory cache eliminates database reads during polling
- Batch updates reduce disk I/O
Scalability
The current architecture supports:- Hundreds of guilds: Database is in-memory, disk writes are async
- Thousands of streamers: Polling is staggered across the interval
- Concurrent alerts: Discord rate limits are handled by discord.js
Future Optimizations
- Database migration to SQLite or PostgreSQL
- Parallel platform checking with rate limiting
- Redis cache for distributed deployments
- Webhook-based alerts (when platforms support it)
Security
Stored Data
- No user tokens or API keys stored
- Only public streamer information cached
- Guild settings are server-specific (no cross-server data leaks)
Input Validation
- Discord handles command parameter validation
- Platform checkers validate usernames
- Database IDs use safe format:
platform:username
Error Handling
- Uncaught exceptions logged and exit process
- Unhandled promise rejections logged (non-fatal)
- Per-operation try-catch blocks prevent cascading failures
~/workspace/source/src/index.ts:38-46