Architecture & design

Introduction#

Service-oriented layout for the SuperSet Telegram Notification Bot. Data comes in from SuperSet, email groups, and official pages. Notifications go out on Telegram and Web Push. Daemon mode for production, FastAPI when something external needs to poke the system.

Project structure#

The repository follows a layered, feature-based organization:

  • Core: configuration and daemon utilities
  • Clients: low-level integrations (MongoDB, Telegram API, Google Groups IMAP)
  • Services: domain services implementing business logic (notifications, placement processing, official data scraping)
  • Servers: HTTP servers (Telegram bot, webhook, scheduler)
  • Runners: orchestration modules for update and notification dispatch
  • Data: local JSON datasets and MongoDB storage artifacts

Core components#

  • Configuration and Environment: centralized settings with typed validation and logging initialization
  • Daemon Utilities: process forking, PID management, and graceful shutdown
  • Clients:
  • DBClient: MongoDB connection and collection access
  • TelegramClient: Telegram Bot API wrapper with retries and rate-limit handling
  • GoogleGroupsClient: IMAP-based email fetching with forwarded metadata extraction
  • Services:
  • DatabaseService: MongoDB operations for notices, jobs, placement offers, users, policies, and official data
  • NotificationService: channel-agnostic orchestrator for broadcasting to Telegram and Web Push
  • TelegramService: Telegram channel implementation with formatting and broadcasting
  • PlacementService: LLM-powered placement offer extraction pipeline with privacy sanitization
  • EmailNoticeService: LLM-powered notice classification and extraction with policy detection
  • OfficialPlacementService: web scraping of official placement data with deduplication
  • Servers:
  • BotServer: Telegram bot with commands and user management
  • WebhookServer: FastAPI endpoints for push subscriptions, notifications, and stats
  • SchedulerServer: APScheduler-based automation for periodic updates and official data scraping
  • Runners:
  • UpdateRunner: orchestrates fetching and processing from SuperSet and email sources
  • NotificationRunner: dispatches unsent notices to channels

Architecture overview#

SOA with DI. Clients wrap SuperSet, email, and MongoDB. Services hold business logic. CLI starts servers and one-shot scripts; daemon helpers keep processes in the background.

Detailed component analysis#

DatabaseService#

  • Responsibilities: CRUD operations for notices, jobs, placement offers, users, policies, and official placement data; statistical queries; MongoDB connection lifecycle
  • Patterns: dependency injection via DBClient; collection delegation; transaction-like operations with error handling and logging
  • Persistence: MongoDB collections for each domain entity; deduplication and indexing considerations for notices and placement offers

NotificationService and TelegramService#

  • NotificationService: channel-agnostic orchestrator; broadcasts to enabled channels; tracks unsent notices and marks them after successful delivery
  • TelegramService: channel implementation with message formatting (HTML/Markdown), long message splitting, rate limiting, and user broadcasting

PlacementService (LLM-powered)#

  • Implements a LangGraph pipeline for placement offer extraction:
  • Classification: keyword-based confidence scoring
  • Extraction: LLM-based JSON schema extraction with retry
  • Validation: schema validation and enrichment
  • Privacy: sanitization of headers and forwarded metadata
  • Integrates with GoogleGroupsClient for email ingestion and DatabaseService for persistence

EmailNoticeService (LLM-powered)#

  • Classifies and extracts structured notices from Google Groups emails
  • Detects placement policy updates and delegates to PlacementPolicyService
  • Formats notices for consistent delivery and persists to database

OfficialPlacementService#

  • Scrapes official JIIT placement page, parses tabs and tables, and stores deduplicated results
  • Uses DatabaseService for persistence and timestamp updates

Servers and orchestration#

  • BotServer: Telegram bot with commands and user management; DI for services
  • WebhookServer: FastAPI app exposing health, push subscription, notification, and stats endpoints; DI for services
    • SchedulerServer: APScheduler-based automation for periodic updates and official data scraping

Dependency analysis#

  • Configuration and daemon utilities are foundational and consumed by all servers and CLI commands
  • Clients encapsulate external integrations and are injected into services
  • Services depend on clients and each other minimally, so tests stay small and modules stay swappable
  • Servers orchestrate services and expose APIs; they rely on DI factories to wire dependencies
  • Runners coordinate update and notification dispatch, mirroring CLI commands

Performance considerations#

  • Asynchronous processing: Telegram bot and webhook server use async frameworks; scheduler uses APScheduler for non-blocking jobs
  • Retry and backoff: TelegramClient implements exponential backoff for rate-limited responses; PlacementService and EmailNoticeService include retry logic for LLM extraction
  • Connection pooling and lifecycle: DBClient manages MongoDB connections; services close connections after operations to prevent leaks
  • Rate limiting: TelegramService applies small delays between broadcasts to avoid throttling
  • Scheduling cadence: SchedulerServer runs at midnight and hourly 8 AM through 11 PM IST, plus an official scrape at noon IST. Overnight 1 AM through 7 AM is idle.
  • Scalability: Modular design allows horizontal scaling of servers and runners; database sharding and indexing can be introduced at the MongoDB layer

[No sources needed since this section provides general guidance]

Troubleshooting guide#

  • Configuration issues: verify environment variables for MongoDB, Telegram, Google API, and VAPID keys; Settings validates and loads from .env
  • Daemon mode: PID files and logging are managed by daemon utilities; use status/stop commands to inspect and terminate processes
  • Email fetching: GoogleGroupsClient requires proper credentials and app password; IMAP connectivity and folder selection are handled internally
  • Telegram delivery: TelegramClient logs failures and retries; check rate limits and parse modes; fallback to plain text if formatted messages fail
  • Database connectivity: DBClient tests connection with ping; ensure connection string and network access to MongoDB
  • Scheduler jobs: SchedulerServer logs errors and continues; review logs for specific job failures and adjust schedules as needed

Conclusion#

Clients fetch, services process, runners orchestrate, servers talk to the outside world. Daemon mode, FastAPI, and APScheduler cover how it actually runs. DI is why you can test a service without standing up Telegram.