Deployment architecture

Introduction#

This page describes the deployment and operational architecture of the SuperSet Telegram Notification Bot. The system is organized around a unified CLI that coordinates three distinct operational modes:

  • Telegram bot server for user interactions and administrative commands
  • FastAPI webhook server for REST APIs and health checks
  • Scheduler server for automated update cycles

The architecture emphasizes daemon mode operation, reliable process management, configurable scheduling with APScheduler, and detailed logging strategies suitable for both development and production environments.

Project structure#

The application follows a modular structure with clear separation of concerns:

  • CLI entry point orchestrating all operations
  • Core utilities for configuration and daemon management
  • Server implementations for Telegram, webhook, and scheduler
  • Runner modules encapsulating update and notification logic
  • Services and clients for external integrations

Core components#

The deployment architecture centers on four primary components:

CLI orchestration layer#

The main entry point provides a unified interface for all operational modes:

  • Command parsing with subcommands for bot, scheduler, webhook, and data operations
  • Global daemon mode flag propagation
  • Centralized logging initialization with verbose mode support
  • Graceful error handling and user interruption management

Daemon management system#

Unix-style daemonization with:

  • Double-fork process isolation
  • PID file management for process tracking
  • Signal-based graceful shutdown
  • Automatic cleanup of stale PID files
  • Separate logging redirection for daemon processes

Scheduling infrastructure#

APScheduler-based automation with:

  • Configurable update cycles across multiple IST time slots
  • Independent scheduler server decoupled from the Telegram bot
  • Job persistence and restart resilience
  • Timezone-aware scheduling with Asia/Kolkata timezone

Operational servers#

Three specialized servers with distinct responsibilities:

  • Telegram bot server with command handlers and administrative controls
  • FastAPI webhook server with health checks and notification endpoints
  • Scheduler server orchestrating automated update workflows

Architecture overview#

The system operates as a distributed set of cooperating processes, each designed for specific operational tasks:

Detailed component analysis#

CLI command processing flow#

The CLI orchestrates all operational modes through a centralized dispatch mechanism:

Daemon process lifecycle#

The daemonization process ensures reliable background operation:

Scheduling architecture with APScheduler#

The scheduler implements a detailed update automation system:

Logging strategy and configuration#

The logging system adapts to operational modes:

Server-Specific architectures#

Telegram bot server#

The Telegram bot server provides user interaction capabilities:

  • Command handlers for user registration, status checking, and statistics
  • Administrative commands for system management
  • Integration with database services for user management
  • Polling-based message reception with graceful shutdown

Webhook server#

The FastAPI-based webhook server exposes:

  • Health check endpoints for monitoring
  • Web push subscription management
  • Notification delivery endpoints
  • Statistics endpoints for operational insights
  • CORS configuration for cross-origin requests

Scheduler server#

The scheduler server orchestrates automated operations:

  • Independent from Telegram bot for reliability
  • Configurable update cycles across multiple IST time slots
  • Official data scraping at designated intervals
  • Job persistence and restart handling

Dependency analysis#

The system exhibits clear dependency relationships:

Performance considerations#

The architecture incorporates several performance optimization strategies:

Asynchronous operations#

  • APScheduler integrated with AsyncIO for non-blocking job execution
  • Telegram bot uses asynchronous polling model
  • FastAPI server uses async request handling

Resource management#

  • Connection pooling for database clients
  • Lazy initialization of services to reduce startup overhead
  • Efficient message splitting for Telegram notifications

Scalability patterns#

  • Decoupled server architecture allows independent scaling
  • Modular runner components enable selective service deployment
  • Environment-based configuration supports containerized deployments

Troubleshooting guide#

Process management issues#

Common daemon-related problems and solutions:

  • Process already running: Check PID files in data/pids/ directory
  • Stale PID files: Manual cleanup required when processes terminate unexpectedly
  • Permission errors: Verify write permissions for logs and pids directories

Logging and debugging#

  • Missing logs: Verify LOG_LEVEL environment variable and log file paths
  • Debug mode: Use -v flag for verbose output in development
  • Production logging: Ensure separate log files for bot and scheduler processes

Service dependencies#

  • Telegram connectivity: Verify TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID
  • Database connectivity: Check MONGO_CONNECTION_STR configuration
  • Scheduler jobs: Confirm timezone settings and network connectivity for external APIs

Conclusion#

The deployment architecture provides a reliable foundation for operational excellence through:

  • Clear separation of concerns across dedicated server processes
  • Reliable daemon management with proper process isolation
  • Configurable scheduling with detailed monitoring capabilities
  • Flexible logging strategies suitable for diverse operational environments
  • Modular design enabling independent scaling and maintenance

The architecture successfully balances operational simplicity with production-grade reliability, supporting both development iteration and enterprise deployment scenarios.