# reubeno/brush architecture

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

- Interactive diagram: https://gitdiagram.com/reubeno/brush
- Repository: https://github.com/reubeno/brush

## Overview

##### Project Type & Purpose
- Project Type: A command-line shell implemented in Rust.
- Purpose: To provide a POSIX- and bash-compatible shell that can be used interactively, supports most shell script features, and includes extensive built-in functionality. It is built with a modular design to separate concerns like core shell processing, command parsing, interactive features, and built-in commands.

##### File Structure
- Top-level directories like “brush-core”, “brush-interactive”, “brush-parser”, and “brush-shell” confirm a modular, multi-crate design:
– brush-core: Implements the fundamentals and built-in commands (numerous modules under src/builtins, handling of arithmetic, environment variables, jobs, etc.)
– brush-interactive: Contains different interactive shell implementations (basic, minimal, reedline-based) for terminal I/O.
– brush-parser: Provides parsing of shell-specific language constructs (lexer/tokenizer, AST construction, handling word and pattern parsing).
– brush-shell: Mainly the executable entry point that ties together these components.
- Additional directories include “xtask” (for custom tooling or build tasks), “fuzz” (for fuzz testing), “docs”, “scripts”, and integration tests under “tests” which support CI and performance benchmarking.

##### Use the README for Further Insights
- The README confirms that the core functionalities depend on external libraries:
– reedline for interactive command input
– clap for command-line argument parsing
– tokio for asynchronous operations
– fancy-regex for regular-expression handling
– nix for OS-level interactions

a. Main Components:
- Brush-Shell (Executable)
- Acts as the primary CLI entry point and orchestrator.
- Brush-Core (Core Library)
- Implements built-in commands and core execution logic.
- Brush-Interactive (Interactive Components)
- Offers different configurations (basic, minimal, reedline) for interactive input and command line editing.
- Brush-Parser (Parsing Engine)
- Handles command parsing, tokenizing, and AST generation.
- Additional Supporting Components:
- Testing infrastructure, fuzzing modules, docs, and custom tooling (xtask).

b. Relationships & Interactions:
- That Brush-Shell (or possibly Brush-Core) calls the Brush-Parser to convert user input or scripts into structured commands.
- A testing/integration block (highlighting the integration tests directory and fuzz testing) that interacts with the main modules.

c. Architectural Patterns and Design Principles:
- Modularization: Each functionality is encapsulated within its own crate (core, interactive, parser, cli).
- Separation of Concerns: Clear division between command parsing, command execution (core logic), and user input handling.
- Dependency Inversion: The design leverages external libraries in a way that core functionalities remain decoupled from minor implementations.
- Extensibility: With the presence of multiple interactive mode implementations and a dedicated parser module, the design supports extensibility and scalability.

d. Technologies, Frameworks, or Libraries:
- Rust programming language and Cargo for dependency management.
- Tokio for asynchronous tasks.
- Reedline for terminal input and line editing (in brush-interactive).
- Clap for command-line argument parsing.
- Fancy-regex and nix crates for regex handling and OS abstraction respectively.
- Testing/benchmarking libraries such as criterion.rs and pprof-rs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Layers
    subgraph "Brush Shell Layer"
        BS["Brush-Shell (Executable)"]:::executable
    end

    subgraph "Core Components"
        BC["Brush-Core (Core Library)"]:::core
        BI["Brush-Interactive (Interactive Shell)"]:::interactive
        BP["Brush-Parser (Parsing Engine)"]:::parser
    end

    subgraph "External Libraries"
        T["Tokio"]:::external
        CP["Clap"]:::external
        RL["Reedline"]:::external
        FR["Fancy-regex"]:::external
        NX["nix"]:::external
    end

    subgraph "Support & Testing"
        TI["Testing & Integration"]:::testing
        FT["Fuzz Testing"]:::testing
        CT["Custom Tooling (xtask)"]:::tooling
    end

    %% Relationships between Main Components
    BS -->|"parses"| BP
    BS -->|"executes"| BC
    BS -->|"interactiveI/O"| BI

    %% External Library Dependencies
    BS -->|"asyncSupport"| T
    BS -->|"CLIArgsParsing"| CP
    BI -->|"terminalEditing"| RL
    BC -->|"regex_OScalls"| FR
    BC -->|"regex_OScalls"| NX

    %% Support & Testing Connections
    TI -->|"validates"| BS
    TI --> FT
    CT -->|"buildTasks"| BS

    %% Styling Classes
    classDef executable fill:#F5A623,stroke:#333,stroke-width:2px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef interactive fill:#90EE90,stroke:#333,stroke-width:2px
    classDef parser fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef testing fill:#FFD700,stroke:#333,stroke-width:2px
    classDef tooling fill:#FFA07A,stroke:#333,stroke-width:2px

    %% Click Events
    click BS "https://github.com/reubeno/brush/blob/main/brush-shell/src/main.rs"
    click BC "https://github.com/reubeno/brush/blob/main/brush-core/src/lib.rs"
    click BI "https://github.com/reubeno/brush/tree/main/brush-interactive/src/"
    click BP "https://github.com/reubeno/brush/blob/main/brush-parser/src/lib.rs"
    click TI "https://github.com/reubeno/brush/tree/main/brush-shell/tests/"
    click CT "https://github.com/reubeno/brush/blob/main/xtask/src/main.rs"
    click FT "https://github.com/reubeno/brush/tree/main/fuzz/fuzz_targets/"
```
