# pwnxpl0it/cargo-scrub architecture

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

- Interactive diagram: https://gitdiagram.com/pwnxpl0it/cargo-scrub
- Repository: https://github.com/pwnxpl0it/cargo-scrub

## Overview

cargo-scrub is a Rust CLI for discovering Rust crates and optionally removing their build artifacts. The main workflow walks a directory tree, identifies crates and workspaces, filters and selects candidates, runs parallel `cargo clean` jobs (or records a dry run), then reports results. Users can instead review and clean selections in a full-screen TUI. The graph preserves configuration, logging, and output layers; links involving unsampled CLI/configuration wiring are omitted where evidence does not establish calls.

Main entry points: [`src/engine.rs`](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/engine.rs) (Scrub engine), [`src/tui/mod.rs`](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/mod.rs) (TUI event loop), [`src/main.rs`](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/main.rs) (Program entry), [`src/cleaner.rs`](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/cleaner.rs) (Crate cleaner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Command interface"]
  node_main["Program entry<br/>[main.rs]"]
  node_cli["CLI options<br/>[cli.rs]"]
end

subgraph group_discovery["Crate discovery"]
  node_walker["Directory walker<br/>[walker.rs]"]
  node_detector["Crate and workspace detection<br/>[detector.rs]"]
  node_filter["Crate filters<br/>[filter.rs]"]
end

subgraph group_cleaning["Cleaning and reports"]
  node_engine["Scrub engine<br/>[engine.rs]"]
  node_cleaner["Crate cleaner<br/>[cleaner.rs]"]
  node_report["Summary reporting<br/>[report.rs]"]
end

subgraph group_dashboard["Interactive dashboard"]
  node_tui["TUI event loop<br/>[mod.rs]"]
  node_tui_app["Dashboard state<br/>[app.rs]"]
  node_tui_events["Key mapping<br/>[events.rs]"]
  node_tui_ui["Dashboard rendering<br/>[ui.rs]"]
end

subgraph group_support["Configuration and logging"]
  node_config["Persistent options<br/>[config.rs]"]
  node_loglevel["Log levels<br/>[loglevel.rs]"]
  node_logging["Logging<br/>[logging.rs]"]
end

node_user(("Operator"))
node_cargo["Cargo clean command"]

node_user -->|"runs"| node_main
node_main -.->|"uses options"| node_cli
node_main -.->|"launches"| node_tui
node_engine -->|"walks directories"| node_walker
node_engine -->|"checks workspaces"| node_detector
node_engine -->|"filters crates"| node_filter
node_engine -->|"cleans crates"| node_cleaner
node_cleaner -->|"runs"| node_cargo
node_engine -->|"builds report"| node_report
node_config -->|"uses level"| node_loglevel
node_tui -->|"discovers and cleans"| node_engine
node_tui -->|"updates state"| node_tui_app
node_tui -->|"maps keys"| node_tui_events
node_tui -->|"draws screens"| node_tui_ui
node_tui_ui -->|"renders state"| node_tui_app

click node_main "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/main.rs"
click node_cli "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/cli.rs"
click node_engine "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/engine.rs"
click node_walker "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/walker.rs"
click node_detector "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/detector.rs"
click node_filter "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/filter.rs"
click node_cleaner "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/cleaner.rs"
click node_report "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/report.rs"
click node_config "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/config.rs"
click node_loglevel "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/loglevel.rs"
click node_logging "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/logging.rs"
click node_tui "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/mod.rs"
click node_tui_app "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/app.rs"
click node_tui_events "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/events.rs"
click node_tui_ui "https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/ui.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 toneBlue
class node_walker,node_detector,node_filter toneAmber
class node_engine,node_cleaner,node_report toneMint
class node_tui,node_tui_app,node_tui_events,node_tui_ui toneRose
class node_config,node_loglevel,node_logging,node_user,node_cargo toneIndigo
```

## Components

### Command interface

- [Program entry](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/main.rs): `src/main.rs`
- [CLI options](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/cli.rs): `src/cli.rs`

### Crate discovery

- [Directory walker](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/walker.rs): `src/walker.rs`
- [Crate and workspace detection](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/detector.rs): `src/detector.rs`
- [Crate filters](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/filter.rs): `src/filter.rs`

### Cleaning and reports

- [Scrub engine](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/engine.rs): `src/engine.rs`
- [Crate cleaner](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/cleaner.rs): `src/cleaner.rs`
- [Summary reporting](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/report.rs): `src/report.rs`

### Interactive dashboard

- [TUI event loop](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/mod.rs): `src/tui/mod.rs`
- [Dashboard state](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/app.rs): `src/tui/app.rs`
- [Key mapping](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/events.rs): `src/tui/events.rs`
- [Dashboard rendering](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/tui/ui.rs): `src/tui/ui.rs`

### Configuration and logging

- [Persistent options](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/config.rs): `src/config.rs`
- [Log levels](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/loglevel.rs): `src/loglevel.rs`
- [Logging](https://github.com/pwnxpl0it/cargo-scrub/blob/master/src/logging.rs): `src/logging.rs`

### Other components

- **Operator**
- **Cargo clean command**

## Connections

- Operator → Program entry: runs (evidence: `README.md`)
- Program entry → CLI options: uses options (evidence: `src/main.rs`)
- Program entry → TUI event loop: launches (evidence: `src/main.rs`)
- Scrub engine → Directory walker: walks directories (evidence: `src/engine.rs`)
- Scrub engine → Crate and workspace detection: checks workspaces (evidence: `src/engine.rs`)
- Scrub engine → Crate filters: filters crates (evidence: `src/engine.rs`)
- Scrub engine → Crate cleaner: cleans crates (evidence: `src/engine.rs`)
- Crate cleaner → Cargo clean command: runs (evidence: `src/cleaner.rs`)
- Scrub engine → Summary reporting: builds report (evidence: `src/engine.rs`)
- Persistent options → Log levels: uses level (evidence: `src/config.rs`)
- TUI event loop → Scrub engine: discovers and cleans (evidence: `src/tui/mod.rs`)
- TUI event loop → Dashboard state: updates state (evidence: `src/tui/mod.rs`)
- TUI event loop → Key mapping: maps keys (evidence: `src/tui/mod.rs`)
- TUI event loop → Dashboard rendering: draws screens (evidence: `src/tui/mod.rs`)
- Dashboard rendering → Dashboard state: renders state (evidence: `src/tui/ui.rs`)
