# erdogant/undouble architecture

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

- Interactive diagram: https://gitdiagram.com/erdogant/undouble
- Repository: https://github.com/erdogant/undouble

## Overview

##### Project Context and Purpose
- Project Type: This is a Python library with a focused purpose—to detect (near-)identical images using image hashing.

##### Key Components
a. Input & File Handling Subsystem:
- This includes functionality to:
– Recursively read image files from directories.
– Accept lists of file paths or even numpy array representations of images.
- This as an Input Module that feeds data to the processing pipeline.

b. Pre-processing Module:
- This module is responsible for converting incoming images into a consistent format. Key processing steps include:
– Converting to grayscale.
– Normalizing and scaling the image.

c. Hash Computation Module:
- As indicated in the README and the core code, the system computes a hash for each pre-processed image.
- This as the “Image Hashing Engine”.

d. Grouping and Duplicate Detection:
- After computing hashes, a grouping mechanism is applied. This compares hashes with a threshold (0 in the simplest case) and groups near-identical images.
- This can be labeled “Grouping Engine” or “Duplicate Detection Module”.

e. Output & Action Module:
- This module handles two main functionalities:
– Visualization/plotting of image hash distributions and groupings.
– Moving or copying duplicate images (with the rule that the highest-resolution image is preserved and the rest moved to an “undouble” subdirectory).
- As separate but related sub-components (e.g., “Plotting & Visualization” and “File Management/Moving” modules).

f. Auxiliary Components:
- Testing and CI: Although not part of the runtime architecture, mention that automated tests and CI pipelines (GitHub workflows) ensure the integrity of components.
- Documentation: Sphinx-generated documentation verifies and explains the design and usage (build pipeline for docs).

##### Relationships and Data Flow
- From Pre-processing, images flow to the Hash Computation Module.
- The computed hashes then flow into the Grouping Engine that clusters images based on similarity.
- Finally, results are passed to the Output Module, with options for visualization and file operations.

##### Architectural Patterns & Design Principles
- Modular Design: Each core functionality (input, preprocessing, hash computation, grouping, output handling) is isolated, making it easier to maintain and extend.
- Pipeline/Sequential Processing: The process follows a clear sequential pipeline where each stage is responsible for a distinct part of the process.
- Extensibility: The design allows for plug-ins or additional modules (e.g., clustering extensions using the clustimage library mentioned in the README).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Undouble Core Library"
        I["Image Input Handler"]:::core
        P["Image Preprocessing"]:::core
        H["Image Hashing Engine"]:::core
        G["Duplicate Detection Module"]:::core
        O["Output Module (Visualization & File Management)"]:::core
        I -->|"feeds"| P
        P -->|"processes"| H
        H -->|"compares"| G
        G -->|"routes"| O
    end

    subgraph "Auxiliary Services"
        T["Automated Testing"]:::auxiliary
        D["Documentation (Sphinx)"]:::auxiliary
        C["CI/CD Pipelines"]:::auxiliary
    end

    O -->|"triggers"| T
    O -->|"updates"| D
    O -->|"integrates"| C

    click I "https://github.com/erdogant/undouble/blob/main/undouble/undouble.py"
    click P "https://github.com/erdogant/undouble/blob/main/undouble/undouble.py"
    click H "https://github.com/erdogant/undouble/blob/main/undouble/undouble.py"
    click G "https://github.com/erdogant/undouble/blob/main/undouble/undouble.py"
    click O "https://github.com/erdogant/undouble/blob/main/undouble/undouble.py"
    click T "https://github.com/erdogant/undouble/blob/main/undouble/tests/test_undouble.py"
    click D "https://github.com/erdogant/undouble/tree/main/docs/"
    click C "https://github.com/erdogant/undouble/tree/main/.github/workflows/"

    classDef core fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef auxiliary fill:#F8BBD0,stroke:#AD1457,stroke-width:2px;
```
