# xueaaaa/go-duplicate architecture

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

- Interactive diagram: https://gitdiagram.com/xueaaaa/go-duplicate
- Repository: https://github.com/xueaaaa/go-duplicate

## Overview

go-duplicate is a CLI for finding content-identical files and cleaning up redundant copies. The main workflow validates the requested directory and options, recursively scans files, narrows candidates by size and sampled fingerprint, confirms matches with full SHA-256, then reports results and optionally deletes or hard-links redundant copies. Plain and JSON reports expose scan statistics and potential savings. The graph follows calls visible in the excerpts and README; helper-level filesystem behavior for deletion and hard-linking is not shown in the sampled source.

Main entry points: [`cmd/find.go`](https://github.com/xueaaaa/go-duplicate/blob/main/cmd/find.go) (Find command), [`internal/finder/find.go`](https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/find.go) (Candidate matching), [`main.go`](https://github.com/xueaaaa/go-duplicate/blob/main/main.go) (Program entry), [`internal/file/scan.go`](https://github.com/xueaaaa/go-duplicate/blob/main/internal/file/scan.go) (Recursive scan)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI workflow"]
  node_entry["Program entry<br/>[main.go]"]
  node_commands["Find command<br/>[find.go]"]
  node_parameters["Run parameters<br/>[params.go]"]
end

subgraph group_discovery["Duplicate discovery"]
  node_scanner["Recursive scan<br/>[scan.go]"]
  node_file_record["File record<br/>[file.go]"]
  node_finder["Candidate matching<br/>[find.go]"]
  node_fingerprint["Partial fingerprint<br/>[fingerprint.go]"]
  node_full_hash["Full SHA-256<br/>[hash.go]"]
  node_duplicate_group["Duplicate groups<br/>[group.go]"]
  node_progress["Progress and FS errors"]
end

subgraph group_reporting["Reports and statistics"]
  node_stats["Scan statistics<br/>[stats.go]"]
  node_savings["Space savings"]
  node_plain_report["Plain report<br/>[plain.go]"]
  node_json_report["JSON report<br/>[json.go]"]
end

subgraph group_cleanup["Duplicate cleanup"]
  node_confirmation["Confirmation prompt<br/>[confirm.go]"]
  node_delete["Delete duplicates<br/>[delete.go]"]
  node_hardlink["Replace with hardlinks<br/>[hardlink.go]"]
end

node_user(("User"))

node_user -->|"runs CLI"| node_entry
node_entry -->|"executes command"| node_commands
node_commands -->|"sets options"| node_parameters
node_commands -->|"starts scan"| node_finder
node_finder -->|"scans tree"| node_scanner
node_scanner -->|"emits records"| node_file_record
node_finder -->|"narrows candidates"| node_fingerprint
node_finder -->|"confirms content"| node_full_hash
node_fingerprint -->|"hashes small files"| node_full_hash
node_finder -->|"forms groups"| node_duplicate_group
node_finder -->|"tracks scan progress"| node_progress
node_commands -->|"builds statistics"| node_stats
node_stats -->|"calculates savings"| node_savings
node_commands -->|"writes plain output"| node_plain_report
node_commands -->|"writes JSON output"| node_json_report
node_commands -->|"requests approval"| node_confirmation
node_commands -->|"deletes copies"| node_delete
node_commands -->|"replaces copies"| node_hardlink

click node_entry "https://github.com/xueaaaa/go-duplicate/blob/main/main.go"
click node_commands "https://github.com/xueaaaa/go-duplicate/blob/main/cmd/find.go"
click node_parameters "https://github.com/xueaaaa/go-duplicate/blob/main/internal/params/params.go"
click node_scanner "https://github.com/xueaaaa/go-duplicate/blob/main/internal/file/scan.go"
click node_file_record "https://github.com/xueaaaa/go-duplicate/blob/main/internal/file/file.go"
click node_finder "https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/find.go"
click node_fingerprint "https://github.com/xueaaaa/go-duplicate/blob/main/internal/hash/fingerprint.go"
click node_full_hash "https://github.com/xueaaaa/go-duplicate/blob/main/internal/hash/hash.go"
click node_duplicate_group "https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/group.go"
click node_progress "https://github.com/xueaaaa/go-duplicate/tree/main/internal/util"
click node_stats "https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/stats.go"
click node_savings "https://github.com/xueaaaa/go-duplicate/blob/main/internal/units/calculate_save_space.go"
click node_plain_report "https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/plain.go"
click node_json_report "https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/json.go"
click node_confirmation "https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/confirm.go"
click node_delete "https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/delete.go"
click node_hardlink "https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/hardlink.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_entry,node_commands,node_parameters,node_user toneBlue
class node_scanner,node_file_record,node_finder,node_fingerprint,node_full_hash,node_duplicate_group,node_progress toneAmber
class node_stats,node_savings,node_plain_report,node_json_report toneMint
class node_confirmation,node_delete,node_hardlink toneRose
```

## Components

### CLI workflow

- [Program entry](https://github.com/xueaaaa/go-duplicate/blob/main/main.go): `main.go`
- [Find command](https://github.com/xueaaaa/go-duplicate/blob/main/cmd/find.go): `cmd/find.go`
- [Run parameters](https://github.com/xueaaaa/go-duplicate/blob/main/internal/params/params.go): `internal/params/params.go`

### Duplicate discovery

- [Recursive scan](https://github.com/xueaaaa/go-duplicate/blob/main/internal/file/scan.go): `internal/file/scan.go`
- [File record](https://github.com/xueaaaa/go-duplicate/blob/main/internal/file/file.go): `internal/file/file.go`
- [Candidate matching](https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/find.go): `internal/finder/find.go`
- [Partial fingerprint](https://github.com/xueaaaa/go-duplicate/blob/main/internal/hash/fingerprint.go): `internal/hash/fingerprint.go`
- [Full SHA-256](https://github.com/xueaaaa/go-duplicate/blob/main/internal/hash/hash.go): `internal/hash/hash.go`
- [Duplicate groups](https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/group.go): `internal/finder/group.go`
- [Progress and FS errors](https://github.com/xueaaaa/go-duplicate/tree/main/internal/util): `internal/util`

### Reports and statistics

- [Scan statistics](https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/stats.go): `internal/output/stats.go`
- [Space savings](https://github.com/xueaaaa/go-duplicate/blob/main/internal/units/calculate_save_space.go): `internal/units/calculate_save_space.go`
- [Plain report](https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/plain.go): `internal/output/plain.go`
- [JSON report](https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/json.go): `internal/output/json.go`

### Duplicate cleanup

- [Confirmation prompt](https://github.com/xueaaaa/go-duplicate/blob/main/internal/output/confirm.go): `internal/output/confirm.go`
- [Delete duplicates](https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/delete.go): `internal/finder/delete.go`
- [Replace with hardlinks](https://github.com/xueaaaa/go-duplicate/blob/main/internal/finder/hardlink.go): `internal/finder/hardlink.go`

### Other components

- **User**

## Connections

- User → Program entry: runs CLI (evidence: `main.go`)
- Program entry → Find command: executes command (evidence: `main.go`)
- Find command → Run parameters: sets options (evidence: `cmd/find.go`)
- Find command → Candidate matching: starts scan (evidence: `cmd/find.go`)
- Candidate matching → Recursive scan: scans tree (evidence: `internal/finder/find.go`)
- Recursive scan → File record: emits records (evidence: `internal/file/scan.go`)
- Candidate matching → Partial fingerprint: narrows candidates (evidence: `internal/finder/find.go`)
- Candidate matching → Full SHA-256: confirms content (evidence: `internal/finder/find.go`)
- Partial fingerprint → Full SHA-256: hashes small files (evidence: `internal/hash/fingerprint.go`)
- Candidate matching → Duplicate groups: forms groups (evidence: `internal/finder/find.go`)
- Candidate matching → Progress and FS errors: tracks scan progress (evidence: `internal/finder/find.go`)
- Find command → Scan statistics: builds statistics (evidence: `cmd/find.go`)
- Scan statistics → Space savings: calculates savings (evidence: `internal/output/stats.go`)
- Find command → Plain report: writes plain output (evidence: `cmd/find.go`)
- Find command → JSON report: writes JSON output (evidence: `cmd/find.go`)
- Find command → Confirmation prompt: requests approval (evidence: `cmd/find.go`)
- Find command → Delete duplicates: deletes copies (evidence: `cmd/find.go`)
- Find command → Replace with hardlinks: replaces copies (evidence: `cmd/find.go`)
