# cha0ran/fd-zh architecture

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

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

## Overview

##### (implied) file structure
- Top-level:
- Cargo.toml, build.rs – Rust build and dependency files
- src/ – Rust source code, likely subdivided into modules (e.g., cli.rs, config.rs, walker.rs, matcher.rs, exec.rs, output.rs, error.rs)
- tests/ – integration/unit tests and testenv directory
- Core dependencies (from README):
- regex crate – pattern matching
- ignore crate – parsing `.gitignore` and ignore files
- walkdir or similar – file‐system traversal
- clap/structopt – CLI parsing
- threadpool or rayon – parallel traversal

##### Core components and their relationships
[User & Shell] → [CLI Parser Module] → [Configuration & Options] → [File‐System Walker / Thread Pool] → [Pattern Matcher & Ignore Filter] → [Result Stream] → {
→ [Output Formatter & Colorizer] → [STDOUT]
→ [Command Executor Module (`-x` / `-X`)] → [External Process(es)]
}

##### Important architectural patterns and design principles
- Pipeline architecture: modular stages (parse, config, traverse, match, output/exec)
- Parallelism: walk directories in parallel threads, collect matches concurrently
- Separation of concerns:
- CLI parsing separated from search logic
- I/O (file system) separated from matching logic
- Matching logic separated from output formatting and exec
- Use of Rust’s ownership and error-handling patterns for performance and safety
- Opinionated defaults encoded in a central config module

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User & Shell"]:::user
    ENV["Environment Variables\n(LS_COLORS, NO_COLOR)"]:::external
    IGN["Ignore Files\n(.fdignore, .gitignore)"]:::external

    U -->|"CLI input"| CLI["CLI Parser\n(clap/structopt)"]:::frontend
    ENV --> CLI
    IGN --> CFG["Config & Defaults\n(config.rs)"]:::config
    CLI --> CFG

    CFG -->|"Config Struct"| WALK["Directory Walker\n(thread pool)"]:::core
    WALK -->|"Paths (bounded channel)"| MATCH["Matcher & Filter\n(regex + ignore)"]:::core

    MATCH -->|"Matches"| STREAM["Result Stream"]:::core
    STREAM -->|"ANSI lines"| FMT["Formatter & Colorizer\n(output.rs)"]:::frontend
    FMT -->|"Formatted Output"| OUT["STDOUT"]:::external

    STREAM -->|"Paths"| EXE["Executor Module\n(exec.rs)"]:::core
    EXE -->|"Spawned Commands"| PROC["External Processes\n(shell)"]:::external

    OUT -->|"Piped to"| FZF["fzf / rofi / xargs"]:::integration

    classDef user fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef frontend fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef core fill:#98FB98,stroke:#333,stroke-width:1px
    classDef config fill:#FFD700,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef integration fill:#DDA0DD,stroke:#333,stroke-width:1px
```
