How lau-r-a/discord-canyon-checker works
Main Components
• Discord Bot Integration: Represented by the DiscordController (handling incoming Discord commands such as /add_url, /list_url, /delete_url, and /help). This component connects with the Discord API using provided tokens and application IDs.
• Web Scraping Module: The CanyonScrapeController is responsible for scraping Canyon product pages for availability information.
• Scheduler Component: The ScheduleController manages the periodic execution of the scrape based on the MINUTES_TO_WAIT environment variable.
• Service Facade: The ServiceFacade acts as an intermediary between various controllers, ensuring coordinated business logic.
• User & Product Management: UserController and data models (CanyonProduct.js and User.js) manage the registration of URLs, product size notifications, and user data.
• Database Layer: While not directly visible in the code (since only models and a generic repository are in there), the use of environment parameters for MongoDB (MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD) clearly implies a MongoDB backend to store scraped data, user settings, and configurations.
• Repositories and Data Access: Under the model directory is a GenericRepository that suggests a clear separation between data access logic and business logic.
• External Dependencies: The system interacts with external systems—the Discord API for sending and receiving messages and the target Canyon product pages for scraping.
Relationships and Interactions
• User inputs (commands) are received by the DiscordController, which then calls specific controllers (such as UserController or ServiceFacade) depending on the command.
• The ServiceFacade coordinates actions between scraping operations (CanyonScrapeController) and scheduling (ScheduleController) as well as updates to the database.
• The ScheduleController triggers the scraping process at regular intervals.
• The scraping process accesses the external Canyon product pages and, based on the results, updates or notifies via the DiscordController.
• Underlying all these, data is persisted or queried via models and the GenericRepository to and from the MongoDB database.
Architectural Patterns and Design Principles
• Separation of Concerns: Controllers and models are clearly separated, ensuring that business logic (ServiceFacade) is decoupled from both presentation (Discord commands) and data storage.
• Modular Architecture: Each controller and model is encapsulated in its own file, offering extensibility and ease of testing.
• Use of Environment Variables: For configuration, making the application portable (especially given that Docker is used for deployment).
Relevant Technologies and Frameworks
• Node.js – the project is a Node.js application.
• Docker – using Dockerfile and docker-compose to containerize and orchestrate the service along with its MongoDB backend.
• MongoDB – as inferred from environment parameters.
• Discord API – for the Discord bot functionality, requiring a bot token and application ID.