# anglesharp/anglesharp.diffing architecture

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

- Interactive diagram: https://gitdiagram.com/anglesharp/anglesharp.diffing
- Repository: https://github.com/anglesharp/anglesharp.diffing

## Overview

##### Main Components

a. Core Engine Layer:
- HtmlDifferenceEngine (central component)
- DiffContext
- ComparisonSource system
- DiffResult handling

b. Strategy Layer:
- Node Strategies
- Element Strategies
- Attribute Strategies
- Text Node Strategies
- Comment Strategies

c. Diff Types Layer:
- Element Diffs
- Attribute Diffs
- Text Diffs
- Comment Diffs

**┌─────────────────────────────────────────────┐**
- Public API Layer               │
- (HtmlDiffer, DiffBuilder)           │
- ┤
- Strategy Pipeline Layer           │
- (DiffingStrategyPipeline, Matchers)     │
- ┤
- Core Engine Layer              │
- (HtmlDifferenceEngine, DiffContext)    │
- ┤
- AngleSharp Core                │
- (DOM Parsing & Manipulation)        │
- ┘

##### Key Relationships

- Input HTML → AngleSharp Core → Core Engine → Strategy Pipeline → Diff Results

##### Important Details

a. Strategy Pipeline:
- How different strategies are chained
- Three main strategy types:
- Filter Strategies
- Match Strategies
- Compare Strategies

b. Comparison Flow:
- Relationship between Control and Test nodes
- Where filtering, matching, and comparison happen

##### Specific Implementation Notes

- Use a hexagonal architecture style to show how the core engine interfaces with different strategies
- Extension points for custom strategies
- Relationship with AngleSharp's DOM implementation

##### Additional Elements

- Notes about the pipeline nature of the diffing process
- Extensibility points for custom strategies

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#333
    classDef strategy fill:#90EE90,stroke:#333
    classDef diff fill:#ffb366,stroke:#333
    classDef api fill:#ffff99,stroke:#333
    classDef external fill:#e6e6e6,stroke:#333

    %% External Dependencies
    AngleSharpCore["AngleSharp Core"]:::external

    %% Public API Layer
    subgraph API
        HtmlDiffer["HtmlDiffer"]:::api
        DiffBuilder["DiffBuilder"]:::api
    end

    %% Core Engine Layer
    subgraph CoreEngine
        HtmlDiffEngine["HtmlDifferenceEngine"]:::core
        DiffContext["DiffContext"]:::core
        ComparisonSource["ComparisonSource"]:::core
        DiffResult["DiffResult"]:::core
    end

    %% Strategy Layer
    subgraph StrategyPipeline
        Pipeline["DiffingStrategyPipeline"]:::strategy
        subgraph Strategies
            direction TB
            NodeStrat["Node Strategies"]:::strategy
            ElemStrat["Element Strategies"]:::strategy
            AttrStrat["Attribute Strategies"]:::strategy
            TextStrat["Text Node Strategies"]:::strategy
            CommentStrat["Comment Strategies"]:::strategy
        end
    end

    %% Diff Types Layer
    subgraph DiffTypes
        direction TB
        ElementDiff["Element Diffs"]:::diff
        AttributeDiff["Attribute Diffs"]:::diff
        TextDiff["Text Diffs"]:::diff
        CommentDiff["Comment Diffs"]:::diff
    end

    %% Relationships
    AngleSharpCore --> HtmlDiffEngine
    HtmlDiffer --> HtmlDiffEngine
    DiffBuilder --> HtmlDiffEngine
    HtmlDiffEngine --> DiffContext
    DiffContext --> ComparisonSource
    DiffContext --> Pipeline
    Pipeline --> NodeStrat & ElemStrat & AttrStrat & TextStrat & CommentStrat
    NodeStrat & ElemStrat & AttrStrat & TextStrat & CommentStrat --> DiffResult
    DiffResult --> ElementDiff & AttributeDiff & TextDiff & CommentDiff

    %% Click Events
    click HtmlDiffer "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/HtmlDiffer.cs"
    click DiffBuilder "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/DiffBuilder.cs"
    click HtmlDiffEngine "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/HtmlDifferenceEngine.cs"
    click DiffContext "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/DiffContext.cs"
    click ComparisonSource "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/ComparisonSource.cs"
    click DiffResult "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/DiffResult.cs"
    click NodeStrat "https://github.com/AngleSharp/AngleSharp.Diffing/tree/devel/src/AngleSharp.Diffing/Strategies/NodeStrategies/"
    click ElemStrat "https://github.com/AngleSharp/AngleSharp.Diffing/tree/devel/src/AngleSharp.Diffing/Strategies/ElementStrategies/"
    click AttrStrat "https://github.com/AngleSharp/AngleSharp.Diffing/tree/devel/src/AngleSharp.Diffing/Strategies/AttributeStrategies/"
    click TextStrat "https://github.com/AngleSharp/AngleSharp.Diffing/tree/devel/src/AngleSharp.Diffing/Strategies/TextNodeStrategies/"
    click CommentStrat "https://github.com/AngleSharp/AngleSharp.Diffing/tree/devel/src/AngleSharp.Diffing/Strategies/CommentStrategies/"
    click Pipeline "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Strategies/DiffingStrategyPipeline.cs"
    click ElementDiff "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/Diffs/ElementDiff.cs"
    click AttributeDiff "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/Diffs/AttrDiff.cs"
    click TextDiff "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/Diffs/TextDiff.cs"
    click CommentDiff "https://github.com/AngleSharp/AngleSharp.Diffing/blob/devel/src/AngleSharp.Diffing/Core/Diffs/CommentDiff.cs"

    %% Legend
    subgraph Legend
        direction TB
        API_L["Public API"]:::api
        Core_L["Core Components"]:::core
        Strategy_L["Strategy Components"]:::strategy
        Diff_L["Diff Types"]:::diff
        External_L["External Dependencies"]:::external
    end
```
