# ziheliu/myers-diff architecture

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

- Interactive diagram: https://gitdiagram.com/ziheliu/myers-diff
- Repository: https://github.com/ziheliu/myers-diff

## Overview

myers-diff is a command-line tool that reads two files, computes a line-level Myers diff, and prints colored additions and removals. The runtime flow is explicit in Main and the algorithm/rendering excerpts; README documents the two-file command. The graph keeps the algorithm’s array and coordinate helpers visible. No network service or persistent store is shown.

Main entry points: [`src/main/java/com/ziheliu/Main.java`](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Main.java) (CLI entry), [`src/main/java/com/ziheliu/Difference.java`](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Difference.java) (Diff rendering), [`src/main/java/com/ziheliu/Myers.java`](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Myers.java) (Myers search), [`src/main/java/com/ziheliu/util/FileUtil.java`](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/util/FileUtil.java) (File reader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command line"]
  node_main["CLI entry<br/>[Main.java]"]
  node_reader["File reader<br/>[FileUtil.java]"]
end

subgraph group_diff["Diff engine"]
  node_difference["Diff rendering<br/>[Difference.java]"]
  node_myers["Myers search<br/>[Myers.java]"]
end

subgraph group_support["Algorithm support"]
  node_array["Gap array<br/>[MyArray.java]"]
  node_node["Path coordinate<br/>[Node.java]"]
end

node_user(("Shell user"))
node_files["Input files"]
node_terminal(("Terminal output"))

node_user -->|"runs with files"| node_main
node_main -->|"reads inputs"| node_reader
node_reader -->|"reads contents"| node_files
node_main -->|"creates diff"| node_difference
node_difference -->|"runs search"| node_myers
node_myers -->|"tracks gaps"| node_array
node_myers -->|"builds path"| node_node
node_difference -->|"reads coordinates"| node_node
node_main -->|"prints diff"| node_terminal

click node_main "https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Main.java"
click node_reader "https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/util/FileUtil.java"
click node_difference "https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Difference.java"
click node_myers "https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Myers.java"
click node_array "https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/MyArray.java"
click node_node "https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Node.java"

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_main,node_reader,node_user toneBlue
class node_difference,node_myers toneAmber
class node_array,node_node toneMint
class node_files,node_terminal toneIndigo
```

## Components

### Command line

- [CLI entry](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Main.java): `src/main/java/com/ziheliu/Main.java`
- [File reader](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/util/FileUtil.java): `src/main/java/com/ziheliu/util/FileUtil.java`

### Diff engine

- [Diff rendering](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Difference.java): `src/main/java/com/ziheliu/Difference.java`
- [Myers search](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Myers.java): `src/main/java/com/ziheliu/Myers.java`

### Algorithm support

- [Gap array](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/MyArray.java): `src/main/java/com/ziheliu/MyArray.java`
- [Path coordinate](https://github.com/ziheliu/myers-diff/blob/master/src/main/java/com/ziheliu/Node.java): `src/main/java/com/ziheliu/Node.java`

### Other components

- **Shell user**
- **Input files**
- **Terminal output**

## Connections

- Shell user → CLI entry: runs with files (evidence: `README.md`)
- CLI entry → File reader: reads inputs (evidence: `src/main/java/com/ziheliu/Main.java`)
- File reader → Input files: reads contents (evidence: `src/main/java/com/ziheliu/util/FileUtil.java`)
- CLI entry → Diff rendering: creates diff (evidence: `src/main/java/com/ziheliu/Main.java`)
- Diff rendering → Myers search: runs search (evidence: `src/main/java/com/ziheliu/Difference.java`)
- Myers search → Gap array: tracks gaps (evidence: `src/main/java/com/ziheliu/Myers.java`)
- Myers search → Path coordinate: builds path (evidence: `src/main/java/com/ziheliu/Myers.java`)
- Diff rendering → Path coordinate: reads coordinates (evidence: `src/main/java/com/ziheliu/Difference.java`)
- CLI entry → Terminal output: prints diff (evidence: `src/main/java/com/ziheliu/Main.java`)
