# sangcnguyen/image-locator-demo architecture

> Architecture diagram of the GitHub repository sangcnguyen/image-locator-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sangcnguyen/image-locator-demo
- Repository: https://github.com/sangcnguyen/image-locator-demo

## Overview

##### Project type and purpose
- This is an open-source automation demo/tool written in Python.
- Its goal is to automatically click buttons on an HTML5 canvas-based online calculator by combining Playwright (browser automation) and OpenCV (template matching).

##### File structure
- Top-level files:
- calculator_test.py – the single entry-point script
- input/ – directory holding template images for each calculator button
- pyproject.toml – dependency and metadata declaration
- calculator_test.py is both your controller and glue code that invokes Playwright and OpenCV APIs.
- No separate “frontend” or “backend” folders—this is a standalone client-side automation tool.

##### README for additional insights
- Confirms dependencies: Python 3.13+, Playwright, OpenCV
- Usage: fetch remote calculator webpage, search for button images in input/, then simulate clicks

##### Detail
- Initialization (browser launch), looping logic, and cleanup (browser close).
- Error-handling or retry steps if template matching fails.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Components
    AutomationScript["Automation Script"]:::module
    Playwright["Playwright Module"]:::module
    OpenCV["OpenCV Module"]:::module
    InputTemplates["Input Templates"]:::resource
    WebCalc["Web Calculator"]:::external
    Logger["Logger / Output"]:::module
    pyproject["pyproject.toml"]:::resource
    readme["README.md"]:::resource
    lockfile["uv.lock"]:::resource

    %% Flow
    AutomationScript -->|"launch browser & navigate"| Playwright
    Playwright -->|"navigate to calculator URL"| WebCalc
    Playwright -->|"capture screenshot"| AutomationScript
    AutomationScript -->|"screenshot + templates"| OpenCV
    InputTemplates --> OpenCV
    OpenCV -->|"matched coordinates"| AutomationScript
    AutomationScript -->|"click at coordinates"| Playwright
    AutomationScript -->|"log results"| Logger
    AutomationScript -->|"close browser"| Playwright

    %% Resources grouping
    subgraph "Resources & Config"
        pyproject
        readme
        lockfile
        InputTemplates
    end

    %% Styles
    classDef module fill:#6cf,stroke:#333,color:#000;
    classDef resource fill:#9f6,stroke:#333,color:#000;
    classDef external fill:#fc6,stroke:#333,color:#000;

    %% Click Events
    click AutomationScript "https://github.com/sangcnguyen/image-locator-demo/blob/main/calculator_test.py"
    click InputTemplates "https://github.com/sangcnguyen/image-locator-demo/tree/main/input/"
    click pyproject "https://github.com/sangcnguyen/image-locator-demo/blob/main/pyproject.toml"
    click readme "https://github.com/sangcnguyen/image-locator-demo/blob/main/README.md"
    click lockfile "https://github.com/sangcnguyen/image-locator-demo/blob/main/uv.lock"
```
