# sharkdp/fd architecture

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

- Interactive diagram: https://gitdiagram.com/sharkdp/fd
- Repository: https://github.com/sharkdp/fd

## Overview

fd is a command-line filesystem search tool. The principal workflow is: a user supplies a pattern and search options; the program builds configuration and match expressions; parallel traversal discovers and filters entries; results are formatted and printed or dispatched to external commands. The graph also preserves documented regex/glob search, ignore and file-type controls, and command execution. Relationships use the README or source-index references and excerpts; some internal calls are not visible in the sampled source, so uncertain links are omitted.

Main entry points: [`src/main.rs`](https://github.com/sharkdp/fd/blob/master/src/main.rs) (Program entry), [`src/walk.rs`](https://github.com/sharkdp/fd/blob/master/src/walk.rs) (Parallel traversal), [`src/output.rs`](https://github.com/sharkdp/fd/blob/master/src/output.rs) (Result rendering), [`src/exec/mod.rs`](https://github.com/sharkdp/fd/blob/master/src/exec/mod.rs) (Command execution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI setup"]
  node_main["Program entry<br/>[main.rs]"]
  node_cli["Option parsing<br/>[cli.rs]"]
  node_regex["Pattern building<br/>[regex_helper.rs]"]
  node_config["Search config<br/>[config.rs]"]
end

subgraph group_search["Search engine"]
  node_walk["Parallel traversal<br/>[walk.rs]"]
  node_filesystem["Filesystem helpers<br/>[filesystem.rs]"]
end

subgraph group_details["Entry details"]
  node_entrydata["Directory entries<br/>[dir_entry.rs]"]
  node_filetypes["File type rules<br/>[filetypes.rs]"]
  node_filters["Metadata filters"]
  node_owner["Owner filter<br/>[owner.rs]"]
  node_size["Size filter<br/>[size.rs]"]
  node_time["Time filter<br/>[time.rs]"]
end

subgraph group_results["Results and actions"]
  node_output["Result rendering<br/>[output.rs]"]
  node_format["Output formatting<br/>[mod.rs]"]
  node_formatinput["Format input<br/>[input.rs]"]
  node_sanitize["Terminal safety<br/>[sanitize.rs]"]
  node_hyperlink["Path hyperlinks<br/>[hyperlink.rs]"]
  node_exec["Command execution<br/>[mod.rs]"]
  node_command["Command templates<br/>[command.rs]"]
  node_job["Execution jobs<br/>[job.rs]"]
  node_exitcodes["Exit status<br/>[exit_codes.rs]"]
end

node_user(("User"))
node_filesystem_actor[("Filesystem")]
node_external_command(("External commands"))

node_user -->|"runs search"| node_main
node_main -->|"parses options"| node_cli
node_main -->|"builds patterns"| node_regex
node_main -->|"constructs config"| node_config
node_main -->|"starts scan"| node_walk
node_main -->|"exits with"| node_exitcodes
node_walk -->|"checks paths"| node_filesystem
node_filesystem -.->|"reads entries"| node_filesystem_actor
node_walk -->|"produces entries"| node_entrydata
node_entrydata -->|"reads metadata"| node_filesystem
node_walk -->|"prints matches"| node_output
node_walk -->|"dispatches results"| node_exec
node_config -->|"configures filters"| node_filters
node_filters -->|"exports filter"| node_owner
node_filters -->|"exports filter"| node_size
node_filters -->|"exports filter"| node_time
node_config -->|"configures types"| node_filetypes
node_output -->|"formats paths"| node_format
node_format -->|"uses input"| node_formatinput
node_output -->|"sanitizes text"| node_sanitize
node_output -->|"creates links"| node_hyperlink
node_output -->|"renders entries"| node_entrydata
node_exec -->|"builds commands"| node_command
node_exec -->|"runs jobs"| node_job
node_exec -->|"launches processes"| node_external_command
node_exec -->|"tracks status"| node_exitcodes
node_walk -->|"returns status"| node_exitcodes

click node_main "https://github.com/sharkdp/fd/blob/master/src/main.rs"
click node_cli "https://github.com/sharkdp/fd/blob/master/src/cli.rs"
click node_regex "https://github.com/sharkdp/fd/blob/master/src/regex_helper.rs"
click node_config "https://github.com/sharkdp/fd/blob/master/src/config.rs"
click node_walk "https://github.com/sharkdp/fd/blob/master/src/walk.rs"
click node_filesystem "https://github.com/sharkdp/fd/blob/master/src/filesystem.rs"
click node_entrydata "https://github.com/sharkdp/fd/blob/master/src/dir_entry.rs"
click node_filetypes "https://github.com/sharkdp/fd/blob/master/src/filetypes.rs"
click node_filters "https://github.com/sharkdp/fd/tree/master/src/filter"
click node_owner "https://github.com/sharkdp/fd/blob/master/src/filter/owner.rs"
click node_size "https://github.com/sharkdp/fd/blob/master/src/filter/size.rs"
click node_time "https://github.com/sharkdp/fd/blob/master/src/filter/time.rs"
click node_output "https://github.com/sharkdp/fd/blob/master/src/output.rs"
click node_format "https://github.com/sharkdp/fd/blob/master/src/fmt/mod.rs"
click node_formatinput "https://github.com/sharkdp/fd/blob/master/src/fmt/input.rs"
click node_sanitize "https://github.com/sharkdp/fd/blob/master/src/sanitize.rs"
click node_hyperlink "https://github.com/sharkdp/fd/blob/master/src/hyperlink.rs"
click node_exec "https://github.com/sharkdp/fd/blob/master/src/exec/mod.rs"
click node_command "https://github.com/sharkdp/fd/blob/master/src/exec/command.rs"
click node_job "https://github.com/sharkdp/fd/blob/master/src/exec/job.rs"
click node_exitcodes "https://github.com/sharkdp/fd/blob/master/src/exit_codes.rs"

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_cli,node_regex,node_config,node_user toneBlue
class node_walk,node_filesystem,node_filesystem_actor toneAmber
class node_entrydata,node_filetypes,node_filters,node_owner,node_size,node_time toneMint
class node_output,node_format,node_formatinput,node_sanitize,node_hyperlink,node_exec,node_command,node_job,node_exitcodes toneRose
class node_external_command toneIndigo
```

## Components

### CLI setup

- [Program entry](https://github.com/sharkdp/fd/blob/master/src/main.rs): `src/main.rs`
- [Option parsing](https://github.com/sharkdp/fd/blob/master/src/cli.rs): `src/cli.rs`
- [Pattern building](https://github.com/sharkdp/fd/blob/master/src/regex_helper.rs): `src/regex_helper.rs`
- [Search config](https://github.com/sharkdp/fd/blob/master/src/config.rs): `src/config.rs`

### Search engine

- [Parallel traversal](https://github.com/sharkdp/fd/blob/master/src/walk.rs): `src/walk.rs`
- [Filesystem helpers](https://github.com/sharkdp/fd/blob/master/src/filesystem.rs): `src/filesystem.rs`

### Entry details

- [Directory entries](https://github.com/sharkdp/fd/blob/master/src/dir_entry.rs): `src/dir_entry.rs`
- [File type rules](https://github.com/sharkdp/fd/blob/master/src/filetypes.rs): `src/filetypes.rs`
- [Metadata filters](https://github.com/sharkdp/fd/tree/master/src/filter): `src/filter`
- [Owner filter](https://github.com/sharkdp/fd/blob/master/src/filter/owner.rs): `src/filter/owner.rs`
- [Size filter](https://github.com/sharkdp/fd/blob/master/src/filter/size.rs): `src/filter/size.rs`
- [Time filter](https://github.com/sharkdp/fd/blob/master/src/filter/time.rs): `src/filter/time.rs`

### Results and actions

- [Result rendering](https://github.com/sharkdp/fd/blob/master/src/output.rs): `src/output.rs`
- [Output formatting](https://github.com/sharkdp/fd/blob/master/src/fmt/mod.rs): `src/fmt/mod.rs`
- [Format input](https://github.com/sharkdp/fd/blob/master/src/fmt/input.rs): `src/fmt/input.rs`
- [Terminal safety](https://github.com/sharkdp/fd/blob/master/src/sanitize.rs): `src/sanitize.rs`
- [Path hyperlinks](https://github.com/sharkdp/fd/blob/master/src/hyperlink.rs): `src/hyperlink.rs`
- [Command execution](https://github.com/sharkdp/fd/blob/master/src/exec/mod.rs): `src/exec/mod.rs`
- [Command templates](https://github.com/sharkdp/fd/blob/master/src/exec/command.rs): `src/exec/command.rs`
- [Execution jobs](https://github.com/sharkdp/fd/blob/master/src/exec/job.rs): `src/exec/job.rs`
- [Exit status](https://github.com/sharkdp/fd/blob/master/src/exit_codes.rs): `src/exit_codes.rs`

### Other components

- **User**
- **Filesystem**
- **External commands**

## Connections

- User → Program entry: runs search (evidence: `README.md`)
- Program entry → Option parsing: parses options (evidence: `src/main.rs`)
- Program entry → Pattern building: builds patterns (evidence: `src/main.rs`)
- Program entry → Search config: constructs config (evidence: `src/main.rs`)
- Program entry → Parallel traversal: starts scan (evidence: `src/main.rs`)
- Program entry → Exit status: exits with (evidence: `src/main.rs`)
- Parallel traversal → Filesystem helpers: checks paths (evidence: `src/walk.rs`)
- Filesystem helpers → Filesystem: reads entries
- Parallel traversal → Directory entries: produces entries (evidence: `src/walk.rs`)
- Directory entries → Filesystem helpers: reads metadata (evidence: `src/dir_entry.rs`)
- Parallel traversal → Result rendering: prints matches (evidence: `src/walk.rs`)
- Parallel traversal → Command execution: dispatches results (evidence: `src/walk.rs`)
- Search config → Metadata filters: configures filters (evidence: `src/config.rs`)
- Metadata filters → Owner filter: exports filter (evidence: `src/filter/mod.rs`)
- Metadata filters → Size filter: exports filter (evidence: `src/filter/mod.rs`)
- Metadata filters → Time filter: exports filter (evidence: `src/filter/mod.rs`)
- Search config → File type rules: configures types (evidence: `src/config.rs`)
- Result rendering → Output formatting: formats paths (evidence: `src/output.rs`)
- Output formatting → Format input: uses input (evidence: `src/fmt/mod.rs`)
- Result rendering → Terminal safety: sanitizes text (evidence: `src/output.rs`)
- Result rendering → Path hyperlinks: creates links (evidence: `src/output.rs`)
- Result rendering → Directory entries: renders entries (evidence: `src/output.rs`)
- Command execution → Command templates: builds commands (evidence: `src/exec/mod.rs`)
- Command execution → Execution jobs: runs jobs (evidence: `src/exec/mod.rs`)
- Command execution → External commands: launches processes
- Command execution → Exit status: tracks status (evidence: `src/exec/mod.rs`)
- Parallel traversal → Exit status: returns status (evidence: `src/walk.rs`)
