How kavinkumar999/uptime works
Main Components
• Entry Point (src/index.ts): This is the main module that initializes the application, handles the periodic checking (every 5 seconds), and orchestrates the overall workflow.
• Configuration Module (src/config.ts): Responsible for managing environment variables and other configuration settings. This module reads values like API_ENDPOINT, TELEGRAM_BOT_TOKEN, and CHAT_ID.
• Notification Module (src/message.ts): Handles the construction and sending of notifications to the Telegram bot when the API returns a 200 OK status.
• External Libraries/Dependencies:
⁃ dotenv: For loading environment variables from a .env file.
⁃ node-fetch: For performing HTTP requests to the API endpoint.
Relationships and Interactions
• The Entry Point (src/index.ts) first loads configurations via src/config.ts.
• It then enters a loop or timer-based logic to poll the API endpoint every 5 seconds.
• When an HTTP 200 OK status is detected, src/index.ts calls the appropriate function in src/message.ts to trigger a Telegram notification.
• Data flows:
• Configurations flow from the .env file through src/config.ts into src/index.ts.
• API responses are obtained via node-fetch.
• Notifications are sent from src/message.ts using the Telegram Bot API.
Architectural Patterns/Design Principles
• Modularization: The project divides functionality into separate modules (configuration, core monitoring logic, and messaging), promoting separation of concerns.
• Single Responsibility: Each module handles one specific aspect of the functionality—configurations, API monitoring, and notifications.
• Dependency Management: Uses external libraries such as dotenv for managing environment settings and node-fetch for HTTP requests.
Instructing the Engineer
– .env Configuration (loaded via src/config.ts)
– API Endpoint Monitor (main logic in src/index.ts)
– Notification Module (src/message.ts)
– External APIs:
▪ The monitored API Endpoint (e.g., movie ticket availability)
▪ Telegram Bot API (for messaging)