# bonmercato/htmlfixinator architecture

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

- Interactive diagram: https://gitdiagram.com/bonmercato/htmlfixinator
- Repository: https://github.com/bonmercato/htmlfixinator

## Overview

##### Main Components

a) Core Components:
- Filter Registry/Factory
- HTML Parser/Serializer Interface
- Filter Chain Orchestrator
- Individual Filter Implementations

b) Filter Components (represent each as a separate module):
- AttributeFilter
- CommentFilter
- ElementFilter
- EmptyFilter
- RelativeToAbsoluteFilter (RelAbs)
- NoopFilter (utility filter)

**Top Level (Public API):**
- string_to_node()
- node_to_string()
- Filter Factory
- FilterChain Builder

**Middle Level (Filter Infrastructure):**
- FilterTrait Implementation
- Chain Processing Logic
- Filter Registry

**Bottom Level (Individual Filters):**
- All concrete filter implementations

##### Component Relationships

- How the FilterChain orchestrates multiple filters
- Filter pipeline flow from input HTML to output HTML
- Demonstrate how each filter implements the FilterTrait
- Relationship between string conversion utilities and the filter system

##### Specific Design Elements

Use these visual elements:
- Blue rectangles for core components
- Green rectangles for individual filters
- Yellow diamonds for interfaces/traits

##### Key Architectural Patterns to Highlight

- Chain of Responsibility Pattern (for filter chain)
- Strategy Pattern (for individual filters)
- Builder Pattern (for filter chain construction)
- Factory Pattern (for filter creation)

##### Detailed Component Specifications

**Input/Output Layer:**
- HTML String Input
- DOM Node Conversion
- Filter Application
- HTML String Output

**Filter Infrastructure:**
- FilterTrait (interface)
- FilterChain (compositor)
- Filter Factory (creation)

**Individual Filters:**
- Each filter with its specific transformation logic
- Filter-specific configuration options

##### Implementation Details

- How filters can be composed using the chain
- Error handling paths
- Optional filter configurations
- Transformation pipeline flow

##### Notes

- Keep the focus on the filter system architecture
- Extensibility points for new filters
- Public API surface
- Thread-safety boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph IO[Input/Output Layer]
        Input[HTML String Input]
        Output[HTML String Output]
        DOM[DOM Node Conversion]
    end

    subgraph API[Public API Layer]
        LibInterface["Library Interface"]:::core
        StringToNode["string_to_node()"]
        NodeToString["node_to_string()"]
        FilterFactory["Filter Factory"]:::core
        ChainBuilder["FilterChain Builder"]:::core
    end

    subgraph Infrastructure[Filter Infrastructure]
        FilterTrait["FilterTrait Interface"]:::interface
        ChainProcessor["Chain Processing Logic"]:::core
        Registry["Filter Registry"]:::core
    end

    subgraph Filters[Individual Filters]
        direction TB
        AttributeF["AttributeFilter"]:::filter
        CommentF["CommentFilter"]:::filter
        ElementF["ElementFilter"]:::filter
        EmptyF["EmptyFilter"]:::filter
        RelAbsF["RelativeToAbsoluteFilter"]:::filter
        NoopF["NoopFilter"]:::filter
    end

    %% Relationships
    Input --> StringToNode
    StringToNode --> DOM
    DOM --> ChainProcessor
    ChainProcessor --> DOM
    DOM --> NodeToString
    NodeToString --> Output

    LibInterface --> FilterFactory
    LibInterface --> ChainBuilder
    FilterFactory --> Registry
    ChainBuilder --> ChainProcessor

    FilterTrait --> AttributeF
    FilterTrait --> CommentF
    FilterTrait --> ElementF
    FilterTrait --> EmptyF
    FilterTrait --> RelAbsF
    FilterTrait --> NoopF

    Registry --> Filters

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333
    classDef filter fill:#90EE90,stroke:#333
    classDef interface fill:#FFE5B4,stroke:#333

    %% Click events
    click LibInterface "https://github.com/BonMercato/htmlfixinator/blob/develop/src/lib.rs"
    click Registry "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters.rs"
    click ChainProcessor "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/chain.rs"
    click AttributeF "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/attribute.rs"
    click CommentF "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/comment.rs"
    click ElementF "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/element.rs"
    click EmptyF "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/empty.rs"
    click RelAbsF "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/relabs.rs"
    click NoopF "https://github.com/BonMercato/htmlfixinator/blob/develop/src/filters/noop.rs"

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Filter Component"]:::filter
        L3["Interface/Trait"]:::interface
    end
```
