# newsand/dedup architecture

> Architecture diagram of the GitHub repository newsand/dedup, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/newsand/dedup
- Repository: https://github.com/newsand/dedup

## Overview

Deduplicator is a Go CLI for finding byte-identical files using BLAKE3, selecting one canonical copy, and reporting or acting on duplicates. The principal workflow runs from CLI command through the pipeline: discover eligible files, compare content, choose canonicals, optionally name copy-unique outputs, plan and validate actions, then execute with dry-run and audit support. README capabilities include report/scan, copy-unique, move, and delete. Pipeline orchestration is excerpted; some internal implementation links are omitted where source excerpts do not show the call.

Main entry points: [`internal/pipeline/run.go`](https://github.com/newsand/dedup/blob/main/internal/pipeline/run.go) (Pipeline), [`internal/cli/root.go`](https://github.com/newsand/dedup/blob/main/internal/cli/root.go) (Commands), [`internal/cli/runner.go`](https://github.com/newsand/dedup/blob/main/internal/cli/runner.go) (Command runner), [`internal/compare/delegate.go`](https://github.com/newsand/dedup/blob/main/internal/compare/delegate.go) (Compare delegate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and configuration"]
  node_cli["Commands<br/>[root.go]"]
  node_runner["Command runner<br/>[runner.go]"]
  node_config["Configuration<br/>[loader.go]"]
  node_main["Program entry<br/>[main.go]"]
end

subgraph group_discovery["Discovery and comparison"]
  node_pipeline["Pipeline<br/>[run.go]"]
  node_walk["Filesystem scan<br/>[walk.go]"]
  node_filetype["File detection<br/>[detect.go]"]
  node_filters["Path filters<br/>[filters.go]"]
  node_delegate["Compare delegate<br/>[delegate.go]"]
  node_registry["Comparator registry<br/>[registry.go]"]
  node_comparators["File comparators"]
  node_hash["BLAKE3 hashing<br/>[blake3.go]"]
end

subgraph group_decisions["Selection and planning"]
  node_canonical["Canonical selection<br/>[select.go]"]
  node_naming["Output naming<br/>[flatten.go]"]
  node_planner["Action planner<br/>[plan.go]"]
  node_invariants["Safety invariants<br/>[invariants.go]"]
end

subgraph group_execution["Actions and reporting"]
  node_executor["Action executor<br/>[execute.go]"]
  node_filesystem["File operations<br/>[ops.go]"]
  node_audit["Audit log<br/>[audit.go]"]
  node_report["Report output<br/>[writer.go]"]
end

node_user(("CLI user"))

node_user -->|"runs command"| node_cli
node_main -->|"executes"| node_cli
node_cli -->|"dispatches"| node_runner
node_cli -->|"loads settings"| node_config
node_runner -.->|"starts run"| node_pipeline
node_pipeline -->|"discovers files"| node_walk
node_pipeline -->|"detects types"| node_filetype
node_pipeline -->|"filters paths"| node_filters
node_pipeline -->|"compares files"| node_delegate
node_delegate -->|"resolves comparator"| node_registry
node_delegate -->|"computes keys"| node_comparators
node_comparators -.->|"hashes content"| node_hash
node_pipeline -->|"selects representatives"| node_canonical
node_pipeline -->|"builds mappings"| node_naming
node_pipeline -->|"creates plan"| node_planner
node_pipeline -->|"checks plan"| node_invariants
node_pipeline -->|"creates audit log"| node_audit
node_pipeline -->|"executes plan"| node_executor
node_executor -.->|"mutates files"| node_filesystem
node_runner -.->|"formats results"| node_report

click node_cli "https://github.com/newsand/dedup/blob/main/internal/cli/root.go"
click node_runner "https://github.com/newsand/dedup/blob/main/internal/cli/runner.go"
click node_config "https://github.com/newsand/dedup/blob/main/internal/config/loader.go"
click node_pipeline "https://github.com/newsand/dedup/blob/main/internal/pipeline/run.go"
click node_walk "https://github.com/newsand/dedup/blob/main/internal/scan/walk.go"
click node_filetype "https://github.com/newsand/dedup/blob/main/internal/filetype/detect.go"
click node_filters "https://github.com/newsand/dedup/blob/main/internal/scan/filters.go"
click node_delegate "https://github.com/newsand/dedup/blob/main/internal/compare/delegate.go"
click node_registry "https://github.com/newsand/dedup/blob/main/internal/compare/registry.go"
click node_comparators "https://github.com/newsand/dedup/blob/main/internal/compare/image_comparator.go"
click node_hash "https://github.com/newsand/dedup/blob/main/internal/hash/blake3.go"
click node_canonical "https://github.com/newsand/dedup/blob/main/internal/canonical/select.go"
click node_naming "https://github.com/newsand/dedup/blob/main/internal/naming/flatten.go"
click node_planner "https://github.com/newsand/dedup/blob/main/internal/actions/plan.go"
click node_invariants "https://github.com/newsand/dedup/blob/main/internal/actions/invariants.go"
click node_executor "https://github.com/newsand/dedup/blob/main/internal/actions/execute.go"
click node_filesystem "https://github.com/newsand/dedup/blob/main/internal/fs/ops.go"
click node_audit "https://github.com/newsand/dedup/blob/main/internal/report/audit.go"
click node_report "https://github.com/newsand/dedup/blob/main/internal/report/writer.go"
click node_main "https://github.com/newsand/dedup/blob/main/cmd/dedup/main.go"

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_cli,node_runner,node_config,node_main,node_user toneBlue
class node_pipeline,node_walk,node_filetype,node_filters,node_delegate,node_registry,node_comparators,node_hash toneAmber
class node_canonical,node_naming,node_planner,node_invariants toneMint
class node_executor,node_filesystem,node_audit,node_report toneRose
```

## Components

### CLI and configuration

- [Commands](https://github.com/newsand/dedup/blob/main/internal/cli/root.go): `internal/cli/root.go`
- [Command runner](https://github.com/newsand/dedup/blob/main/internal/cli/runner.go): `internal/cli/runner.go`
- [Configuration](https://github.com/newsand/dedup/blob/main/internal/config/loader.go): `internal/config/loader.go`
- [Program entry](https://github.com/newsand/dedup/blob/main/cmd/dedup/main.go): `cmd/dedup/main.go`

### Discovery and comparison

- [Pipeline](https://github.com/newsand/dedup/blob/main/internal/pipeline/run.go): `internal/pipeline/run.go`
- [Filesystem scan](https://github.com/newsand/dedup/blob/main/internal/scan/walk.go): `internal/scan/walk.go`
- [File detection](https://github.com/newsand/dedup/blob/main/internal/filetype/detect.go): `internal/filetype/detect.go`
- [Path filters](https://github.com/newsand/dedup/blob/main/internal/scan/filters.go): `internal/scan/filters.go`
- [Compare delegate](https://github.com/newsand/dedup/blob/main/internal/compare/delegate.go): `internal/compare/delegate.go`
- [Comparator registry](https://github.com/newsand/dedup/blob/main/internal/compare/registry.go): `internal/compare/registry.go`
- [File comparators](https://github.com/newsand/dedup/blob/main/internal/compare/image_comparator.go): `internal/compare/image_comparator.go`
- [BLAKE3 hashing](https://github.com/newsand/dedup/blob/main/internal/hash/blake3.go): `internal/hash/blake3.go`

### Selection and planning

- [Canonical selection](https://github.com/newsand/dedup/blob/main/internal/canonical/select.go): `internal/canonical/select.go`
- [Output naming](https://github.com/newsand/dedup/blob/main/internal/naming/flatten.go): `internal/naming/flatten.go`
- [Action planner](https://github.com/newsand/dedup/blob/main/internal/actions/plan.go): `internal/actions/plan.go`
- [Safety invariants](https://github.com/newsand/dedup/blob/main/internal/actions/invariants.go): `internal/actions/invariants.go`

### Actions and reporting

- [Action executor](https://github.com/newsand/dedup/blob/main/internal/actions/execute.go): `internal/actions/execute.go`
- [File operations](https://github.com/newsand/dedup/blob/main/internal/fs/ops.go): `internal/fs/ops.go`
- [Audit log](https://github.com/newsand/dedup/blob/main/internal/report/audit.go): `internal/report/audit.go`
- [Report output](https://github.com/newsand/dedup/blob/main/internal/report/writer.go): `internal/report/writer.go`

### Other components

- **CLI user**

## Connections

- CLI user → Commands: runs command (evidence: `README.md`)
- Program entry → Commands: executes (evidence: `cmd/dedup/main.go`)
- Commands → Command runner: dispatches (evidence: `internal/cli/root.go`)
- Commands → Configuration: loads settings (evidence: `internal/cli/root.go`)
- Command runner → Pipeline: starts run
- Pipeline → Filesystem scan: discovers files (evidence: `internal/pipeline/run.go`)
- Pipeline → File detection: detects types (evidence: `internal/pipeline/run.go`)
- Pipeline → Path filters: filters paths (evidence: `internal/pipeline/run.go`)
- Pipeline → Compare delegate: compares files (evidence: `internal/pipeline/run.go`)
- Compare delegate → Comparator registry: resolves comparator (evidence: `internal/compare/delegate.go`)
- Compare delegate → File comparators: computes keys (evidence: `internal/compare/delegate.go`)
- File comparators → BLAKE3 hashing: hashes content
- Pipeline → Canonical selection: selects representatives (evidence: `internal/pipeline/run.go`)
- Pipeline → Output naming: builds mappings (evidence: `internal/pipeline/run.go`)
- Pipeline → Action planner: creates plan (evidence: `internal/pipeline/run.go`)
- Pipeline → Safety invariants: checks plan (evidence: `internal/pipeline/run.go`)
- Pipeline → Audit log: creates audit log (evidence: `internal/pipeline/run.go`)
- Pipeline → Action executor: executes plan (evidence: `internal/pipeline/run.go`)
- Action executor → File operations: mutates files
- Command runner → Report output: formats results
