# ggreer/the_silver_searcher architecture

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

- Interactive diagram: https://gitdiagram.com/ggreer/the_silver_searcher
- Repository: https://github.com/ggreer/the_silver_searcher

## Overview

The Silver Searcher (`ag`) is a command-line code-search tool. A user supplies a query and paths; `main` parses options, then either searches standard input or traverses paths and dispatches file work to workers. Search results are formatted for standard output, with options for context, counts, colors, columns, and editor-friendly formats. The README also documents parallel search, ignore-file support, literal and PCRE matching, and mmap-based file access. Some subsystem links below are omitted or dashed because their call sites were not shown in the excerpts.

Main entry points: [`src/search.c`](https://github.com/ggreer/the_silver_searcher/blob/master/src/search.c) (Search workers), [`src/main.c`](https://github.com/ggreer/the_silver_searcher/blob/master/src/main.c) (Program entry), [`src/options.c`](https://github.com/ggreer/the_silver_searcher/blob/master/src/options.c) (Option parsing), [`src/ignore.c`](https://github.com/ggreer/the_silver_searcher/blob/master/src/ignore.c) (Ignore filtering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and options"]
  node_main["Program entry<br/>[main.c]"]
  node_options["Option parsing<br/>[options.c]"]
end

subgraph group_traversal["File traversal"]
  node_scandir["Directory scanning<br/>[scandir.c]"]
  node_ignore["Ignore filtering<br/>[ignore.c]"]
end

subgraph group_matching["Search and matching"]
  node_search["Search workers<br/>[search.c]"]
  node_decompress["Decompression<br/>[decompress.c]"]
  node_zfile["Compressed files<br/>[zfile.c]"]
  node_util["Search utilities<br/>[util.c]"]
end

subgraph group_output["Results and output"]
  node_print["Result formatting<br/>[print.c]"]
  node_winprint["Windows output<br/>[print_w32.c]"]
end

subgraph group_support["Search support"]
  node_lang["File types<br/>[lang.c]"]
  node_hash["Hash utilities<br/>[uthash.h]"]
  node_logging["Logging<br/>[log.c]"]
end

node_user(("User"))
node_stdout["Standard output"]

node_user -->|"runs"| node_main
node_main -->|"parses options"| node_options
node_main -->|"initializes ignores"| node_ignore
node_main -->|"dispatches search"| node_search
node_main -->|"writes results"| node_stdout
node_options -->|"loads file types"| node_lang
node_options -->|"configures filters"| node_ignore
node_search -->|"uses scanner"| node_scandir
node_search -->|"formats matches"| node_print
node_ignore -->|"filters entries"| node_scandir
node_search -.->|"may decompress"| node_decompress
node_decompress -.->|"may read compressed data"| node_zfile
node_search -.->|"uses match helpers"| node_util
node_search -.->|"uses symlink tracking"| node_hash
node_print -.->|"prints results"| node_stdout
node_winprint -.->|"prints results"| node_stdout

click node_main "https://github.com/ggreer/the_silver_searcher/blob/master/src/main.c"
click node_options "https://github.com/ggreer/the_silver_searcher/blob/master/src/options.c"
click node_search "https://github.com/ggreer/the_silver_searcher/blob/master/src/search.c"
click node_scandir "https://github.com/ggreer/the_silver_searcher/blob/master/src/scandir.c"
click node_ignore "https://github.com/ggreer/the_silver_searcher/blob/master/src/ignore.c"
click node_lang "https://github.com/ggreer/the_silver_searcher/blob/master/src/lang.c"
click node_decompress "https://github.com/ggreer/the_silver_searcher/blob/master/src/decompress.c"
click node_zfile "https://github.com/ggreer/the_silver_searcher/blob/master/src/zfile.c"
click node_util "https://github.com/ggreer/the_silver_searcher/blob/master/src/util.c"
click node_hash "https://github.com/ggreer/the_silver_searcher/blob/master/src/uthash.h"
click node_print "https://github.com/ggreer/the_silver_searcher/blob/master/src/print.c"
click node_winprint "https://github.com/ggreer/the_silver_searcher/blob/master/src/print_w32.c"
click node_logging "https://github.com/ggreer/the_silver_searcher/blob/master/src/log.c"

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_options,node_user toneBlue
class node_scandir,node_ignore toneAmber
class node_search,node_decompress,node_zfile,node_util toneMint
class node_print,node_winprint toneRose
class node_lang,node_hash,node_logging,node_stdout toneIndigo
```

## Components

### CLI and options

- [Program entry](https://github.com/ggreer/the_silver_searcher/blob/master/src/main.c): `src/main.c`
- [Option parsing](https://github.com/ggreer/the_silver_searcher/blob/master/src/options.c): `src/options.c`

### File traversal

- [Directory scanning](https://github.com/ggreer/the_silver_searcher/blob/master/src/scandir.c): `src/scandir.c`
- [Ignore filtering](https://github.com/ggreer/the_silver_searcher/blob/master/src/ignore.c): `src/ignore.c`

### Search and matching

- [Search workers](https://github.com/ggreer/the_silver_searcher/blob/master/src/search.c): `src/search.c`
- [Decompression](https://github.com/ggreer/the_silver_searcher/blob/master/src/decompress.c): `src/decompress.c`
- [Compressed files](https://github.com/ggreer/the_silver_searcher/blob/master/src/zfile.c): `src/zfile.c`
- [Search utilities](https://github.com/ggreer/the_silver_searcher/blob/master/src/util.c): `src/util.c`

### Results and output

- [Result formatting](https://github.com/ggreer/the_silver_searcher/blob/master/src/print.c): `src/print.c`
- [Windows output](https://github.com/ggreer/the_silver_searcher/blob/master/src/print_w32.c): `src/print_w32.c`

### Search support

- [File types](https://github.com/ggreer/the_silver_searcher/blob/master/src/lang.c): `src/lang.c`
- [Hash utilities](https://github.com/ggreer/the_silver_searcher/blob/master/src/uthash.h): `src/uthash.h`
- [Logging](https://github.com/ggreer/the_silver_searcher/blob/master/src/log.c): `src/log.c`

### Other components

- **User**
- **Standard output**

## Connections

- User → Program entry: runs (evidence: `README.md`)
- Program entry → Option parsing: parses options (evidence: `src/main.c`)
- Program entry → Ignore filtering: initializes ignores (evidence: `src/main.c`)
- Program entry → Search workers: dispatches search (evidence: `src/main.c`)
- Program entry → Standard output: writes results (evidence: `src/main.c`)
- Option parsing → File types: loads file types (evidence: `src/options.c`)
- Option parsing → Ignore filtering: configures filters (evidence: `src/options.c`)
- Search workers → Directory scanning: uses scanner (evidence: `src/search.c`)
- Search workers → Result formatting: formats matches (evidence: `src/search.c`)
- Ignore filtering → Directory scanning: filters entries (evidence: `src/ignore.c`)
- Search workers → Decompression: may decompress
- Decompression → Compressed files: may read compressed data
- Search workers → Search utilities: uses match helpers
- Search workers → Hash utilities: uses symlink tracking
- Result formatting → Standard output: prints results
- Windows output → Standard output: prints results
