# lau-r-a/discord-canyon-checker architecture

> Architecture diagram of the GitHub repository lau-r-a/discord-canyon-checker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lau-r-a/discord-canyon-checker
- Repository: https://github.com/lau-r-a/discord-canyon-checker

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Systems
    subgraph "External Systems"
        API["Discord API"]:::external
        CW["Canyon Website"]:::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        DComp["Docker Compose"]:::infra
    end

    %% Application Layer
    subgraph "Application Layer"
        DC["DiscordController - handles Discord commands"]:::app
        SF["ServiceFacade - orchestrates operations"]:::app
        UC["UserController - manages user commands"]:::app
        CSC["CanyonScrapeController - scrapes product pages"]:::app
        SC["ScheduleController - schedules scraping"]:::app
    end

    %% Data Layer
    subgraph "Data Layer"
        GR["GenericRepository"]:::data
        UM["User Model"]:::data
        CP["CanyonProduct"]:::data
        MDB["MongoDB"]:::data
    end

    %% Infrastructure Deployments
    DComp -->|"deploys"| DC
    DComp -->|"deploys"| MDB

    %% External to Application
    API -->|"commands"| DC

    %% Application Interactions
    DC -->|"processes"| SF
    DC -->|"user_cmds"| UC
    SF -->|"handleUser"| UC
    SF -->|"triggerScrape"| CSC
    SF -->|"scheduleScrape"| SC
    SC -->|"periodicTrigger"| CSC
    CSC -->|"scrapes"| CW
    CSC -->|"results"| SF
    SF -->|"dataOps"| GR
    SF -->|"notify"| API
    UC -->|"manageUser"| UM

    %% Data Layer Interactions
    UM -->|"persist"| GR
    SF -->|"manageProduct"| CP
    CP -->|"persist"| GR
    GR -->|"databaseOps"| MDB

    %% Click Events
    click DC "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/controller/DiscordController.js"
    click CSC "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/controller/CanyonScrapeController.js"
    click SC "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/controller/ScheduleController.js"
    click SF "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/controller/ServiceFacade.js"
    click UC "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/controller/UserController.js"
    click UM "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/model/User.js"
    click CP "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/model/CanyonProduct.js"
    click GR "https://github.com/lau-r-a/discord-canyon-checker/blob/master/src/model/repositories/GenericRepository.js"

    %% Styles
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef app fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef data fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef infra fill:#F08080,stroke:#333,stroke-width:2px;
```
