# ikramalgo/python-html-dom-comparator architecture

> Architecture diagram of the GitHub repository ikramalgo/python-html-dom-comparator, 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/ikramalgo/python-html-dom-comparator
- Repository: https://github.com/ikramalgo/python-html-dom-comparator

## Overview

##### Main Components
- Input HTML Files – Represent the two source HTML documents (dom1.html and dom2.html).
- Python Script (Core Comparator) – The central logic contained in Python.py.
- HTML Parser Module – A sub-component within the Python script responsible for turning raw HTML into DOM trees.
- Hash Calculator – Highlight that the tool uses SHA-256 hashing on parts of the DOM for integrity verification.
- Comparison Engine – This element outlines the process of traversing both trees, comparing nodes, and identifying differences.
- JSON Report Generator – Represents the final output (output.json) where all comparison results are structured and saved.

##### Relationships and Data Flow
- Both files feed into the HTML Parser, which transforms them into their respective DOM trees.
- Finally, the outcome is passed to the JSON Report Generator, which formats and writes the differences to output.json.
- Optionally, additional directions could outline error handling or notifications for missing nodes/attributes.

##### Architectural Patterns & Design Principles
- The design follows a linear data processing pipeline: from input → parse → hash → compare → output.
- It embodies separation of concerns: components for parsing, hashing, comparing, and reporting are logically isolated in the single script.
- Although implemented in one file, it is helpful to denote how each logical segment “module” interacts with others.

##### Important Technologies and Frameworks
- Python – the fundamental technology powering the script.
- HTML Parsing libraries (native or external like BeautifulSoup, if used) – these could be depicted as part of the parser module.
- JSON handling (using Python’s json module) – for report generation.
- SHA-256 hashing (e.g., hashlib library from Python) – as part of the integrity checking mechanism.

##### Additional Detailed Steps
- Clearly name and separate the two parallel flows that handle the two HTML files prior to merging them in the comparison engine.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Inputs"
        A["dom1.html"]:::data
        B["dom2.html"]:::data
    end

    subgraph "Flow for dom1"
        P1["HTML Parser (dom1)"]:::process
        D1["DOM Tree (dom1)"]:::process
        H1["SHA-256 Hash (dom1)"]:::process
    end

    subgraph "Flow for dom2"
        P2["HTML Parser (dom2)"]:::process
        D2["DOM Tree (dom2)"]:::process
        H2["SHA-256 Hash (dom2)"]:::process
    end

    subgraph "Output Phase"
        C["Comparison Engine"]:::process
        R["JSON Report Generator"]:::data
    end

    A -->|"ParseHTML"| P1
    B -->|"ParseHTML"| P2
    P1 -->|"GenerateDOM"| D1
    D1 -->|"ComputeHash"| H1
    P2 -->|"GenerateDOM"| D2
    D2 -->|"ComputeHash"| H2
    H1 -->|"MergeAndCompare"| C
    H2 -->|"MergeAndCompare"| C
    C -->|"WriteOutput"| R

    click A "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/dom1.html"
    click B "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/dom2.html"
    click P1 "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click D1 "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click H1 "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click P2 "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click D2 "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click H2 "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click C "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/Python.py"
    click R "https://github.com/ikramalgo/python-html-dom-comparator/blob/main/output.json"

    classDef data fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef process fill:#ABEBC6,stroke:#239B56,stroke-width:2px;
```
