# jairmf/exchange-notifier architecture

> Architecture diagram of the GitHub repository jairmf/exchange-notifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jairmf/exchange-notifier
- Repository: https://github.com/jairmf/exchange-notifier

## Overview

##### Main Components
- Entry Point (index.js): The central gateway that initializes and orchestrates the different modules.
- Scheduling Module (node-schedule): A component that triggers tasks at scheduled intervals.
- Web Automation Component (Puppeteer): Handles browser automation to scrape or monitor exchange rate data.
- Email Notification Module (nodemailer): Responsible for composing and sending email alerts.
- Process Management (ecosystem.config.js): Shows configuration for running the application reliably (using PM2 or similar).

##### Relationships and Data Flow
- The main entry point (index.js) initiates a scheduled task using node-schedule.
- When the schedule triggers, the automation flow starts:
- The Puppeteer component is invoked to visit the target website and extract the necessary exchange rate information.
- Once the data is gathered, logic within the application decides if an alert should be sent.
- If an alert is triggered, the nodemailer module is called to dispatch an email notification.
- The ecosystem configuration (ecosystem.config.js) informs how the application runs in production environments, supporting aspects like automatic restarts and process monitoring.

##### Highlighting Architectural Patterns and Technologies
- Modularity: Although the project is simple, the separation of the scheduling logic, automation, and email notification logic keeps responsibilities clear.
- Integration Points: Emphasize how Puppeteer interacts with external web resources and how nodemailer integrates with external SMTP/email services.
- Process Management: Portray the “orchestrator” layer where ecosystem.config.js ties into PM2 for managing the application's lifecycle.

- Clearly labeled nodes for each of the components.
- Scheduler → Web Scraper → Decision Logic → Email Notification.
- Notations or legends to indicate asynchronous operations and external service boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Process Management Layer
    subgraph "Process Management"
        PM["Process Management (ecosystem.config.js)"]:::proc
    end

    %% Core Automation Engine (index.js encapsulates Scheduler, Scraper, Decision Logic, and Notifier)
    subgraph "Core Automation Engine"
        ENTRY["Entry Point (index.js)"]:::core
        SCHED["Scheduler (node-schedule)"]:::core
        SCRAPER["Scraper (Puppeteer)"]:::core
        DECISION["Decision Logic"]:::core
        NOTIFIER["Notifier (nodemailer)"]:::core
    end

    %% External Services Layer
    subgraph "External Services"
        WEB["Exchange Rate Website"]:::external
        SMTP["SMTP Server (Email)"]:::external
    end

    %% User/Environment Layer
    subgraph "User/Environment"
        USER["User Email Client"]:::user
    end

    %% Connections
    PM -->|"monitors"| ENTRY
    ENTRY -->|"initializes"| SCHED
    SCHED -->|"triggers"| SCRAPER
    SCRAPER -->|"scrapes data from"| WEB
    SCRAPER -->|"passes data to"| DECISION
    DECISION -->|"if alert triggered then calls"| NOTIFIER
    NOTIFIER -->|"sends email via"| SMTP
    SMTP -->|"delivers alert to"| USER

    %% Click Events
    click ENTRY "https://github.com/jairmf/exchange-notifier/blob/main/index.js"
    click PM "https://github.com/jairmf/exchange-notifier/blob/main/ecosystem.config.js"

    %% Styles
    classDef core fill:#90ee90,stroke:#006400,stroke-width:2px;
    classDef proc fill:#add8e6,stroke:#0000ff,stroke-width:2px;
    classDef external fill:#ffe4b5,stroke:#ff8c00,stroke-width:2px;
    classDef user fill:#ffb6c1,stroke:#ff1493,stroke-width:2px;
```
