# ddcodepl/wally architecture

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

- Interactive diagram: https://gitdiagram.com/ddcodepl/wally
- Repository: https://github.com/ddcodepl/wally

## Overview

##### Project Type and Purpose
- Wally is a Python-based utility designed to track visual and content changes on web pages. It takes screenshots (using a headless browser) and uses image processing (OpenCV, NumPy) to detect differences. It can operate in batch mode and send Slack notifications when changes occur.
- The project includes integration with Selenium (for browser automation), Firefox extensions (via xpi files) for enhanced browsing, and Docker support for deployment.

##### File Structure
- Top-Level Files:
- Dockerfile and docker-compose.yml: Provide a containerized environment for easy deployment.
- main.py: Acts as the central entry point for execution.
- requirements.txt: Lists all Python dependencies.
- README.md: Provides instructions, configuration details, and usage examples.
- Directories:
- config: Contains configuration scripts (especially config_example.py) that set up critical parameters like URLs and screen sizes.
- extensions: Contains Firefox extension packages (e.g., uBlock and IDC) which are used to customize the headless browser environment.
- utils: Contains utility modules (compare.py, slack.py, utils.py) that implement supporting functionality such as image comparison and Slack notifications.

##### Extract Insights from the README
- The README explains that the system uses a headless browser (default is Firefox with extensions) to capture screenshots, and it leverages Slack for notifications.
- It instructs that all necessary configuration should be provided in the config file, outlining tracked URLs and required screen widths.
- The project supports both local and containerized execution, indicating modularity in deployment.

##### Main Components
a. Core Components:
- Front Controller / Main Execution: Represented by main.py, which orchestrates the tasks.
- Configuration Module: Represent the config directory, highlighting the importance of config/config.py as the required configuration source.
- Browser Automation Module: This is the integration with Selenium, encapsulating how a headless browser is used to render pages and apply extensions.
- Utilities: Include components for image comparison (using NumPy and OpenCV) and sending notifications via Slack (show utilities module).
- Extensions Management: A component dedicated to loading and using Firefox extensions from the extensions directory.
b. Auxiliary Components:
- Docker Environment: Illustrate the Dockerfile and docker-compose.yml’s role in containerized deployment.
- Third-Party Dependencies: Mark libraries like Selenium, NumPy, OpenCV, and Slack connectors.

##### Relationships and Interactions
- Main.py serves as the orchestrator: it reads configuration parameters, calls utility functions for comparing images, and triggers the Selenium lifecycle to take screenshots.
- The configuration module feeds URLs, screen sizes, and extension details into main.py.
- The browser automation component (Selenium) uses the plugins found in extensions to ensure proper page rendering.
- Once screenshots are taken, the comparison utility detects changes, and if any discrepancies are found, the Slack utility is invoked to notify users.
- Docker setup encapsulates the entire workflow, ensuring the right environment is set up to run these interactions.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into configuration, main application logic, and utilities emphasizes modularity.
- Separation of Concerns: Different functionalities (web automation, image comparison, and notifications) are segregated into their own modules.
- Containerization: Docker is used to ensure consistency across deployment environments.
- Extensibility: With a dedicated extensions folder and clear configuration instructions, new browsers or plugins can be integrated without changing the core logic.

##### Detailed Outline
- “Main Application (main.py)” at the center.
- “Image Processing & Comparison (utils/compare.py, OpenCV, NumPy)” connected from the browser module, showing how screenshots are processed.
- “Notification System (utils/slack.py, Slack API)” receiving output from the comparison component.
- Optionally encapsulate the entire system within a Docker container block if emphasizing deployment.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Docker Environment"
        D1["Dockerfile"]:::docker
        D2["docker-compose.yml"]:::docker
    end

    D1 -->|"Deployment"| MA["Main Application (main.py)"]:::core
    D2 -->|"Deployment"| MA
    CFG["Configuration (config/config_example.py)"]:::config -->|"ConfigurationData"| MA
    MA -->|"TriggerScreenshot"| BA["Browser Automation (Selenium & Headless Browser)"]:::automation
    BA -->|"LoadExtensions"| EX["Extensions Management (extensions)"]:::extensions
    BA -->|"Process&Compare"| COMP["Image Processing & Comparison (utils/compare.py, OpenCV, NumPy)"]:::comparison
    COMP -->|"SendNotification"| SL["Notification System (utils/slack.py, Slack API)"]:::notification

    click MA "https://github.com/ddcodepl/wally/blob/master/main.py"
    click CFG "https://github.com/ddcodepl/wally/blob/master/config/config_example.py"
    click COMP "https://github.com/ddcodepl/wally/blob/master/utils/compare.py"
    click SL "https://github.com/ddcodepl/wally/blob/master/utils/slack.py"
    click EX "https://github.com/ddcodepl/wally/tree/master/extensions/"
    click D1 "https://github.com/ddcodepl/wally/tree/master/Dockerfile"
    click D2 "https://github.com/ddcodepl/wally/blob/master/docker-compose.yml"

    classDef docker fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef core fill:#FFEE93,stroke:#333,stroke-width:2px;
    classDef config fill:#ADFF2F,stroke:#333,stroke-width:2px;
    classDef automation fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef extensions fill:#FFE4E1,stroke:#333,stroke-width:2px;
    classDef comparison fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef notification fill:#FFD700,stroke:#333,stroke-width:2px;
```
