# ditherz/bashcat architecture

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

- Interactive diagram: https://gitdiagram.com/ditherz/bashcat
- Repository: https://github.com/ditherz/bashcat

## Overview

1. **Repository purpose**
   - This repo is a small command-line utility, not a service or application platform.
   - The core deliverable is a single executable Bash script, `bashcat`, which acts as a pure-Bash replacement for `lolcat` with the same CLI shape and similar terminal behavior.

2. **Core runtime boundary**
   - The architecture is centered on one shell entrypoint: the `bashcat` script.
   - It runs under Bash 4+ and uses a minimal Python 3 helper internally for math/UTF-8-safe processing.
   - There is no daemon, server, package manager integration, or persistent state outside shell session exports.

3. **Input-to-output pipeline**
   - `bashcat` reads either files passed on the command line or stdin when no file is provided.
   - It then transforms the text into colored terminal output and writes directly to stdout.
   - The output path is intentionally stream-oriented, so it behaves like a filter in Unix pipelines.

4. **Text processing and colorization subsystem**
   - The key logic is the per-character rainbow renderer.
   - README details indicate it is UTF-8 safe, meaning text is split by codepoints rather than raw bytes.
   - Color generation supports frequency, spread, seed, and gradient angle controls, so the script computes color state per character rather than applying a single block style.

5. **Terminal behavior and gating**
   - The script includes terminal-awareness: it detects TTY vs piped output and disables color unless forced with `-f`.
   - It also respects `NO_COLOR`, which short-circuits colorization and passes input through unchanged.
   - This boundary matters for architecture because it separates “formatting logic” from “preserve raw text” behavior.

6. **Animation mode**
   - The `-a` mode introduces a frame-based animation path with configurable frame count and FPS.
   - That implies a separate rendering loop or repeated repaint logic distinct from the normal single-pass filter path.
   - In architecture terms, animation is an alternate output mode layered on top of the same color computation core.

7. **Shell integration / environment export**
   - `bashcat --env` is a separate mode that prints shell definitions for `eval`.
   - This exports variables like `BASHCAT_FG`, `BASHCAT_BG`, and helper/pill variables into the interactive shell.
   - That means the repo has a second consumer path: not only terminal output, but also shell-session integration for downstream scripts and aliases.

8. **Installer subsystem**
   - `install.sh` is the operational packaging boundary.
   - Its job is to install the `bashcat` script into `~/.local/bin`, adjust permissions, and append the shell integration line to `~/.zshrc`.
   - The uninstall path removes the binary and strips the injected eval line, so the installer owns environment setup/teardown, not the main script.

9. **Repository contents and non-code assets**
   - `assets/` contains banner and screenshot files used for documentation and presentation only.
   - `CHANGELOG.md` and `README.md` are release/documentation artifacts; they do not participate in runtime behavior.
   - This is a compact repo with very little architectural surface area beyond the CLI script and installer.

10. **External dependencies and why they matter**
   - The utility is designed to avoid heavy dependencies, but it does rely on Bash and a small Python 3 snippet for portability and correct Unicode handling.
   - `git` is only needed for the one-line installer path, not for normal execution.
   - These dependencies are important because they define the repo’s deployment model: lightweight local installation rather than compiled distribution.

11. **How to diagram it**
   - A good architecture diagram would show:
     - stdin/files feeding the `bashcat` script,
     - the script branching into normal colorization, animation, or `--env` shell-export mode,
     - terminal stdout as the primary sink,
     - and `install.sh` as a separate provisioning path that places the script into the user’s shell PATH and modifies the shell rc file.
   - The main boundary is “runtime filter” versus “installation and shell bootstrap.”

12. **Overall shape**
   - This is essentially a single-binary-style CLI project implemented in shell, with one supporting installer and a small amount of documentation/assets.
   - The architecture is intentionally simple: one executable, one install script, one shell-session integration mechanism, and no backend infrastructure.

Main entry points: [`bashcat`](https://github.com/ditherz/bashcat/tree/main/bashcat) (bashcat), [`install.sh`](https://github.com/ditherz/bashcat/blob/main/install.sh) (install.sh), [`README.md`](https://github.com/ditherz/bashcat/blob/main/README.md) (README), [`assets/bashcat-banner.txt`](https://github.com/ditherz/bashcat/blob/main/assets/bashcat-banner.txt) (Assets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_input["Input<br/>stdin/files"]
  node_bashcat["bashcat<br/>bash cli"]
  node_gate{{"Color gate<br/>tty/NO_COLOR"}}
  node_render["Rainbow render<br/>char renderer"]
  node_anim(("Animation<br/>frame loop"))
  node_envmode["Env export<br/>shell defs"]
  node_pyhelper["Python helper<br/>python3 snippet"]
  node_stdout["Terminal output<br/>stdout"]
end

subgraph group_provisioning["Provisioning"]
  node_installer["install.sh<br/>installer<br/>[install.sh]"]
  node_binpath["User bin<br/>local bin"]
  node_shellrc["Shell rc<br/>zshrc hook"]
end

subgraph group_docs["Docs & assets"]
  node_assets["Assets<br/>presentation files<br/>[bashcat-banner.txt]"]
  node_readme["README<br/>docs<br/>[README.md]"]
  node_changelog["Changelog<br/>release notes<br/>[CHANGELOG.md]"]
end

node_input -->|"read"| node_bashcat
node_bashcat -->|"check"| node_gate
node_gate -->|"allow"| node_render
node_gate -->|"pass-through"| node_stdout
node_render -->|"use"| node_pyhelper
node_render -->|"write"| node_stdout
node_bashcat -->|"mode -a"| node_anim
node_anim -->|"repaint"| node_render
node_bashcat -->|"--env"| node_envmode
node_envmode -->|"print"| node_stdout
node_installer -->|"install"| node_binpath
node_installer -->|"bootstrap"| node_shellrc
node_installer -->|"deploy"| node_bashcat
node_readme -->|"document"| node_bashcat
node_assets -->|"support"| node_readme
node_changelog -->|"release context"| node_readme

click node_bashcat "https://github.com/ditherz/bashcat/tree/main/bashcat"
click node_installer "https://github.com/ditherz/bashcat/blob/main/install.sh"
click node_assets "https://github.com/ditherz/bashcat/blob/main/assets/bashcat-banner.txt"
click node_readme "https://github.com/ditherz/bashcat/blob/main/README.md"
click node_changelog "https://github.com/ditherz/bashcat/blob/main/CHANGELOG.md"

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_input,node_bashcat,node_gate,node_render,node_anim,node_envmode,node_pyhelper,node_stdout toneBlue
class node_installer,node_binpath,node_shellrc toneAmber
class node_assets,node_readme,node_changelog toneMint
```

## Components

### Runtime

Main CLI filter and rendering pipeline

- **Input**: stdin/files · Text from command line files or standard input
- [bashcat](https://github.com/ditherz/bashcat/tree/main/bashcat): bash cli · Main executable entrypoint and mode dispatcher · `bashcat`
- **Color gate**: tty/NO_COLOR · Disables or forces coloring based on terminal state and environment
- **Rainbow render**: char renderer · Per-character UTF-8 safe color computation and output formatting
- **Animation**: frame loop · Repeated repaint path for animated output mode
- **Env export**: shell defs · Prints shell variables and helper definitions for eval
- **Python helper**: python3 snippet · Small Unicode-safe helper used for text and math processing
- **Terminal output**: stdout · Primary streaming sink for colored text or pass-through text

### Provisioning

Install and shell bootstrap path

- [install.sh](https://github.com/ditherz/bashcat/blob/main/install.sh): installer · Installs the script, sets permissions, and wires shell startup · `install.sh`
- **User bin**: local bin · Target location in the user's PATH for the installed executable
- **Shell rc**: zshrc hook · Appended eval line for interactive shell integration

### Docs & assets

Documentation and presentation files

- [Assets](https://github.com/ditherz/bashcat/blob/main/assets/bashcat-banner.txt): presentation files · Banner and screenshot assets used for documentation only · `assets/bashcat-banner.txt`
- [README](https://github.com/ditherz/bashcat/blob/main/README.md): docs · Usage, behavior, and installation documentation · `README.md`
- [Changelog](https://github.com/ditherz/bashcat/blob/main/CHANGELOG.md): release notes · Release history and project notes · `CHANGELOG.md`

## Connections

- Input → bashcat: read · Feeds files or stdin into the CLI filter
- bashcat → Color gate: check · Applies TTY and NO_COLOR gating before formatting
- Color gate → Rainbow render: allow · Routes color-enabled input into the renderer
- Color gate → Terminal output: pass-through · Sends raw text unchanged when color is disabled
- Rainbow render → Python helper: use · Delegates Unicode-safe processing and numeric helpers
- Rainbow render → Terminal output: write · Streams colored output to the terminal
- bashcat → Animation: mode -a · Switches to frame-based animated rendering
- Animation → Rainbow render: repaint · Reuses color computation across animation frames
- bashcat → Env export: --env · Emits shell definitions for eval in the caller's session
- Env export → Terminal output: print · Outputs exported variables and helper definitions
- install.sh → User bin: install · Copies bashcat into the user's PATH location
- install.sh → Shell rc: bootstrap · Adds shell integration line for interactive use
- install.sh → bashcat: deploy · Installs the executable script
- README → bashcat: document · Describes the CLI behavior and modes
- Assets → README: support · Provides presentation material referenced by docs
- Changelog → README: release context · Tracks project changes alongside the usage guide
