# dinu1763/ai-image-comparison-tool architecture

> Architecture diagram of the GitHub repository dinu1763/ai-image-comparison-tool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dinu1763/ai-image-comparison-tool
- Repository: https://github.com/dinu1763/ai-image-comparison-tool

## Overview

#### Purpose and Entry Points
Adobe Visual QA Tool compares two website environments or two local images, combining pixel-level metrics with AI visual analysis and PDF reporting. Primary runtime entry point is Flask in `app.py`; browser UI is `templates/index.html` with behavior in `static/js/script.js`. Standalone image comparison is also exposed through `image_comparison_tool.py`; examples are in `example_usage.py` and `example_aem_sidekick.py`.

#### Web Application Boundary
`app.py` owns HTTP request handling, batch URL-pair orchestration, progress/report delivery, and integration of comparison and reporting services. The browser-facing boundary is:
- `app.py`
- `templates/index.html`
- `static/js/script.js`

The UI submits URL pairs, viewport, analysis type, Gemini model, and optional Chrome-extension/authentication settings. The backend processes URL pairs sequentially and returns generated report artifacts for download.

#### Website Capture and Viewport Orchestration
`viewport_comparison_tool.py` is the web-comparison pipeline. It drives Selenium/Chrome WebDriver to load each URL at desktop, tablet, or mobile dimensions; captures full-page screenshots in aligned viewport segments; and handles known delayed modal dialogs before capture. It is the boundary between web content/browser state and local image artifacts.
- `viewport_comparison_tool.py`
- `screenshot_tool.py`
- `example_aem_sidekick.py`

Chrome extensions can be loaded to support authenticated AEM/Sitekick workflows. Setup and discovery are documented/supported by:
- `AEM_SIDEKICK_SETUP.md`
- `find_chrome_extensions.bat`

#### Visual Comparison and AI Analysis
`image_comparison_tool.py` is the reusable image-analysis core used both directly from CLI/Python and by viewport comparison. It compares paired screenshots through image processing—SSIM and contour-based difference regions—and requests narrative analysis from Google Gemini Vision using the selected comparison mode/model.
- `image_comparison_tool.py`
- `viewport_comparison_tool.py`

The external AI-service boundary is the Gemini API, configured via `GEMINI_API_KEY`. README history references OpenAI options, but the current product architecture describes Gemini as the visual-analysis provider.

#### Report Assembly and Output Artifacts
`viewport_report_generator.py` converts successful viewport-comparison results into professional PDF reports. Reports include URL metadata, aggregate results, screenshot pairs/difference highlights, per-viewport SSIM, and AI findings; filenames derive from the source URL and date.
- `viewport_report_generator.py`
- `app.py`

Generated screenshots and PDFs are local filesystem artifacts, with the application expected to write reports beneath an `uploads/` location at runtime.

#### Execution Model and Dependencies
The system is a local Python service requiring Python, Chrome, network access, and sufficient disk/RAM for screenshot and PDF artifacts. Core infrastructure and libraries are declared in:
- `requirements.txt`
- `start_server.sh`
- `start_server.bat`

Material dependencies are Flask for serving, Selenium plus ChromeDriver for browser automation, Google Gemini Vision for analysis, Pillow/OpenCV/scikit-image for visual processing, and ReportLab for PDFs. ChromeDriver setup may require internet access; target pages and Gemini calls are external network dependencies.

#### Auxiliary Batch/CLI Workflows
The repository also supports non-web workflows: direct local-image comparison via `image_comparison_tool.py`, model discovery via `list_models.py`, and CSV URL inputs represented by `url.csv` and `urls.csv`. These reuse the comparison core rather than replacing the primary capture → compare → report flow.
- `image_comparison_tool.py`
- `list_models.py`
- `urls.csv`

Main entry points: [`viewport_comparison_tool.py`](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/viewport_comparison_tool.py) (Viewport comparison), [`app.py`](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/app.py) (Flask API), [`image_comparison_tool.py`](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/image_comparison_tool.py) (Image comparison core), [`static/js/script.js`](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/static/js/script.js) (UI behavior)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web Application"]
  node_browser_ui["Browser UI<br/>frontend<br/>[index.html]"]
  node_ui_logic["UI behavior<br/>javascript<br/>[script.js]"]
  node_flask_app["Flask API<br/>python service<br/>[app.py]"]
end

subgraph group_pipeline["Capture &amp; Analysis"]
  node_viewport_pipeline["Viewport comparison<br/>python pipeline"]
  node_screenshot_tool["Screenshot capture<br/>python module<br/>[screenshot_tool.py]"]
  node_chrome{{"Chrome WebDriver<br/>browser automation"}}
  node_comparison_core["Image comparison core<br/>python analysis"]
end

subgraph group_outputs["Reporting &amp; Artifacts"]
  node_pdf_generator["PDF report generator<br/>python reporting"]
  node_artifacts[("Screenshots &amp; PDFs<br/>local artifacts")]
end

node_target_sites{{"Target websites<br/>external web"}}
node_gemini{{"Gemini Vision API<br/>external AI"}}
node_local_image_cli["Local image workflow<br/>CLI / Python API"]
node_model_discovery["Model discovery<br/>CLI<br/>[list_models.py]"]
node_csv_inputs["CSV URL inputs<br/>batch input<br/>[urls.csv]"]

node_browser_ui -->|"drives"| node_ui_logic
node_ui_logic -->|"submits jobs"| node_flask_app
node_flask_app -->|"orchestrates URL pairs"| node_viewport_pipeline
node_viewport_pipeline -->|"controls"| node_chrome
node_chrome -->|"loads"| node_target_sites
node_viewport_pipeline -->|"captures segments"| node_screenshot_tool
node_screenshot_tool -->|"writes screenshots"| node_artifacts
node_viewport_pipeline -->|"compares screenshot pairs"| node_comparison_core
node_comparison_core -->|"requests visual analysis"| node_gemini
node_comparison_core -->|"supplies metrics and findings"| node_pdf_generator
node_pdf_generator -->|"writes PDFs"| node_artifacts
node_flask_app -->|"delivers reports"| node_artifacts
node_local_image_cli -->|"reuses"| node_comparison_core
node_model_discovery -->|"lists models"| node_gemini
node_csv_inputs -.->|"batch URL source"| node_flask_app

click node_browser_ui "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/templates/index.html"
click node_ui_logic "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/static/js/script.js"
click node_flask_app "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/app.py"
click node_viewport_pipeline "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/viewport_comparison_tool.py"
click node_screenshot_tool "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/screenshot_tool.py"
click node_comparison_core "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/image_comparison_tool.py"
click node_pdf_generator "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/viewport_report_generator.py"
click node_local_image_cli "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/image_comparison_tool.py"
click node_model_discovery "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/list_models.py"
click node_csv_inputs "https://github.com/dinu1763/ai-image-comparison-tool/blob/master/urls.csv"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser_ui,node_ui_logic,node_flask_app toneBlue
class node_viewport_pipeline,node_screenshot_tool,node_chrome,node_comparison_core toneAmber
class node_pdf_generator,node_artifacts toneMint
class node_target_sites,node_gemini,node_local_image_cli,node_model_discovery,node_csv_inputs toneNeutral
```

## Components

### Web Application

- [Browser UI](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/templates/index.html): frontend · Collects URL pairs, viewport, model, and auth options. · `templates/index.html`
- [UI behavior](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/static/js/script.js): javascript · `static/js/script.js`
- [Flask API](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/app.py): python service · Orchestrates sequential URL-pair jobs and report delivery. · `app.py`

### Capture & Analysis

- [Viewport comparison](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/viewport_comparison_tool.py): python pipeline · Captures aligned full-page URL screenshots by viewport. · `viewport_comparison_tool.py`
- [Screenshot capture](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/screenshot_tool.py): python module · `screenshot_tool.py`
- **Chrome WebDriver**: browser automation · Loads target pages and optional authentication extensions.
- [Image comparison core](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/image_comparison_tool.py): python analysis · Computes SSIM and difference regions and requests AI findings. · `image_comparison_tool.py`

### Reporting & Artifacts

- [PDF report generator](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/viewport_report_generator.py): python reporting · Builds reports from comparison results and visual evidence. · `viewport_report_generator.py`
- **Screenshots & PDFs**: local artifacts · Runtime output stored beneath uploads/.

### Other components

- **Target websites**: external web
- **Gemini Vision API**: external AI · Narrative visual analysis provider configured by GEMINI_API_KEY.
- [Local image workflow](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/image_comparison_tool.py): CLI / Python API · Direct paired-image comparison reusing the analysis core. · `image_comparison_tool.py`
- [Model discovery](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/list_models.py): CLI · `list_models.py`
- [CSV URL inputs](https://github.com/dinu1763/ai-image-comparison-tool/blob/master/urls.csv): batch input · `urls.csv`

## Connections

- Browser UI → UI behavior: drives
- UI behavior → Flask API: submits jobs
- Flask API → Viewport comparison: orchestrates URL pairs
- Viewport comparison → Chrome WebDriver: controls
- Chrome WebDriver → Target websites: loads
- Viewport comparison → Screenshot capture: captures segments
- Screenshot capture → Screenshots & PDFs: writes screenshots
- Viewport comparison → Image comparison core: compares screenshot pairs
- Image comparison core → Gemini Vision API: requests visual analysis
- Image comparison core → PDF report generator: supplies metrics and findings
- PDF report generator → Screenshots & PDFs: writes PDFs
- Flask API → Screenshots & PDFs: delivers reports
- Local image workflow → Image comparison core: reuses
- Model discovery → Gemini Vision API: lists models
- CSV URL inputs → Flask API: batch URL source
