# burntsushi/ripgrep architecture

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

- Interactive diagram: https://gitdiagram.com/burntsushi/ripgrep
- Repository: https://github.com/burntsushi/ripgrep

## Overview

ripgrep is a command-line, recursive line-search tool. Its principal workflow parses search options, walks and filters paths, then searches file contents with a selected regex matcher and formats results. The architecture also exposes distinct glob, ignore, file-type, and output-format capabilities. Edges are limited to relationships supported by the README or shown excerpts; unsampled implementation details are not asserted.

Main entry points: [`crates/core/search.rs`](https://github.com/burntsushi/ripgrep/blob/master/crates/core/search.rs) (Search worker), [`crates/core/main.rs`](https://github.com/burntsushi/ripgrep/blob/master/crates/core/main.rs) (Command entry), [`crates/ignore/src/walk.rs`](https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/walk.rs) (Recursive walker), [`crates/printer/src/standard.rs`](https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/standard.rs) (Result printers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI orchestration"]
  node_entrypoint["Command entry<br/>[main.rs]"]
  node_arguments["Flags and config<br/>[defs.rs]"]
  node_cli_helpers["CLI helpers<br/>[process.rs]"]
end

subgraph group_filter["Path discovery and filtering"]
  node_walk["Recursive walker<br/>[walk.rs]"]
  node_ignore_rules["Ignore rules<br/>[dir.rs]"]
  node_gitignore["Gitignore matching<br/>[gitignore.rs]"]
  node_file_types["File type filters<br/>[types.rs]"]
  node_globset["Glob matching<br/>[glob.rs]"]
end

subgraph group_engine["Matching and search"]
  node_search_worker["Search worker<br/>[search.rs]"]
  node_haystack["Input preparation<br/>[haystack.rs]"]
  node_regex_config["Regex configuration<br/>[config.rs]"]
  node_literal_opt["Literal optimization<br/>[literal.rs]"]
  node_matcher["Matcher interface<br/>[lib.rs]"]
  node_pcre2["PCRE2 engine<br/>[matcher.rs]"]
  node_searcher["Content searcher<br/>[core.rs]"]
end

subgraph group_output["Result presentation"]
  node_printer["Result printers<br/>[standard.rs]"]
  node_json_output["JSON output<br/>[json.rs]"]
  node_hyperlinks["Hyperlink formatting<br/>[mod.rs]"]
end

node_user(("CLI user"))

node_user -->|"invokes"| node_entrypoint
node_entrypoint -->|"parses"| node_arguments
node_entrypoint -->|"runs traversal"| node_walk
node_walk -.->|"filters paths"| node_ignore_rules
node_ignore_rules -->|"uses rules"| node_gitignore
node_walk -.->|"filters types"| node_file_types
node_walk -.->|"matches globs"| node_globset
node_entrypoint -->|"dispatches search"| node_search_worker
node_search_worker -->|"prepares input"| node_haystack
node_search_worker -->|"coordinates search"| node_searcher
node_search_worker -->|"selects matcher"| node_matcher
node_search_worker -->|"sends results"| node_printer
node_regex_config -->|"extracts literals"| node_literal_opt
node_searcher -.->|"queries matches"| node_matcher
node_search_worker -.->|"may select"| node_pcre2
node_printer -.->|"offers format"| node_json_output
node_printer -.->|"formats links"| node_hyperlinks
node_search_worker -->|"reads commands"| node_cli_helpers

click node_entrypoint "https://github.com/burntsushi/ripgrep/blob/master/crates/core/main.rs"
click node_arguments "https://github.com/burntsushi/ripgrep/blob/master/crates/core/flags/defs.rs"
click node_walk "https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/walk.rs"
click node_ignore_rules "https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/dir.rs"
click node_gitignore "https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/gitignore.rs"
click node_file_types "https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/types.rs"
click node_globset "https://github.com/burntsushi/ripgrep/blob/master/crates/globset/src/glob.rs"
click node_search_worker "https://github.com/burntsushi/ripgrep/blob/master/crates/core/search.rs"
click node_haystack "https://github.com/burntsushi/ripgrep/blob/master/crates/core/haystack.rs"
click node_regex_config "https://github.com/burntsushi/ripgrep/blob/master/crates/regex/src/config.rs"
click node_literal_opt "https://github.com/burntsushi/ripgrep/blob/master/crates/regex/src/literal.rs"
click node_matcher "https://github.com/burntsushi/ripgrep/blob/master/crates/matcher/src/lib.rs"
click node_pcre2 "https://github.com/burntsushi/ripgrep/blob/master/crates/pcre2/src/matcher.rs"
click node_searcher "https://github.com/burntsushi/ripgrep/blob/master/crates/searcher/src/searcher/core.rs"
click node_printer "https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/standard.rs"
click node_json_output "https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/json.rs"
click node_hyperlinks "https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/hyperlink/mod.rs"
click node_cli_helpers "https://github.com/burntsushi/ripgrep/blob/master/crates/cli/src/process.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_entrypoint,node_arguments,node_cli_helpers,node_user toneBlue
class node_walk,node_ignore_rules,node_gitignore,node_file_types,node_globset toneAmber
class node_search_worker,node_haystack,node_regex_config,node_literal_opt,node_matcher,node_pcre2,node_searcher toneMint
class node_printer,node_json_output,node_hyperlinks toneRose
```

## Components

### CLI orchestration

- [Command entry](https://github.com/burntsushi/ripgrep/blob/master/crates/core/main.rs): `crates/core/main.rs`
- [Flags and config](https://github.com/burntsushi/ripgrep/blob/master/crates/core/flags/defs.rs): `crates/core/flags/defs.rs`
- [CLI helpers](https://github.com/burntsushi/ripgrep/blob/master/crates/cli/src/process.rs): `crates/cli/src/process.rs`

### Path discovery and filtering

- [Recursive walker](https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/walk.rs): `crates/ignore/src/walk.rs`
- [Ignore rules](https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/dir.rs): `crates/ignore/src/dir.rs`
- [Gitignore matching](https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/gitignore.rs): `crates/ignore/src/gitignore.rs`
- [File type filters](https://github.com/burntsushi/ripgrep/blob/master/crates/ignore/src/types.rs): `crates/ignore/src/types.rs`
- [Glob matching](https://github.com/burntsushi/ripgrep/blob/master/crates/globset/src/glob.rs): `crates/globset/src/glob.rs`

### Matching and search

- [Search worker](https://github.com/burntsushi/ripgrep/blob/master/crates/core/search.rs): `crates/core/search.rs`
- [Input preparation](https://github.com/burntsushi/ripgrep/blob/master/crates/core/haystack.rs): `crates/core/haystack.rs`
- [Regex configuration](https://github.com/burntsushi/ripgrep/blob/master/crates/regex/src/config.rs): `crates/regex/src/config.rs`
- [Literal optimization](https://github.com/burntsushi/ripgrep/blob/master/crates/regex/src/literal.rs): `crates/regex/src/literal.rs`
- [Matcher interface](https://github.com/burntsushi/ripgrep/blob/master/crates/matcher/src/lib.rs): `crates/matcher/src/lib.rs`
- [PCRE2 engine](https://github.com/burntsushi/ripgrep/blob/master/crates/pcre2/src/matcher.rs): `crates/pcre2/src/matcher.rs`
- [Content searcher](https://github.com/burntsushi/ripgrep/blob/master/crates/searcher/src/searcher/core.rs): `crates/searcher/src/searcher/core.rs`

### Result presentation

- [Result printers](https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/standard.rs): `crates/printer/src/standard.rs`
- [JSON output](https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/json.rs): `crates/printer/src/json.rs`
- [Hyperlink formatting](https://github.com/burntsushi/ripgrep/blob/master/crates/printer/src/hyperlink/mod.rs): `crates/printer/src/hyperlink/mod.rs`

### Other components

- **CLI user**

## Connections

- CLI user → Command entry: invokes
- Command entry → Flags and config: parses (evidence: `crates/core/main.rs`)
- Command entry → Recursive walker: runs traversal (evidence: `crates/core/main.rs`)
- Recursive walker → Ignore rules: filters paths
- Ignore rules → Gitignore matching: uses rules (evidence: `crates/ignore/src/dir.rs`)
- Recursive walker → File type filters: filters types
- Recursive walker → Glob matching: matches globs
- Command entry → Search worker: dispatches search (evidence: `crates/core/main.rs`)
- Search worker → Input preparation: prepares input (evidence: `crates/core/search.rs`)
- Search worker → Content searcher: coordinates search (evidence: `crates/core/search.rs`)
- Search worker → Matcher interface: selects matcher (evidence: `crates/core/search.rs`)
- Search worker → Result printers: sends results (evidence: `crates/core/search.rs`)
- Regex configuration → Literal optimization: extracts literals (evidence: `crates/regex/src/literal.rs`)
- Content searcher → Matcher interface: queries matches
- Search worker → PCRE2 engine: may select
- Result printers → JSON output: offers format
- Result printers → Hyperlink formatting: formats links
- Search worker → CLI helpers: reads commands (evidence: `crates/core/search.rs`)
