# abhimanyu003/sttr architecture

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

- Interactive diagram: https://gitdiagram.com/abhimanyu003/sttr
- Repository: https://github.com/abhimanyu003/sttr

## Overview

##### Project type and purpose
- This is a Go-based command-line application (“sttr”) that performs a wide variety of string transformation and processing operations.
- It exposes a single binary (`sttr`) with subcommands (md5, base64-encode, json-yaml, etc.) that can read from stdin, files, or shell pipes.

##### File structure
- Top-level:
- `main.go` – entrypoint, kicks off the root CLI command
- `cmd/` – Cobra commands for each operation and global commands (version, completion, interactive)
- `processors/` – core implementation of each transformation, conforming to a Processor interface
- `ui/` – interactive mode code (terminal UI)
- `utils/` – shared helper functions (e.g., text I/O)
- `hugo/` – static site for docs (built with Hugo)
- CI/CD and release tooling: `.github/workflows/`, `goreleaser.yml`, Dockerfile, install scripts

##### README for additional insights
- Usage patterns: direct invocation, piping, file I/O, chaining commands
- Supported operations are grouped by category (Encode/Decode, Hash, String, etc.)
- Installation methods and release artifacts (binaries, containers, package managers)

##### Main components
a. User Interface
- Shell user invoking `sttr` with arguments or using stdin/stdout
b. CLI Layer
- `main.go` → Cobra root command (`cmd/root.go`)
- Subcommands (`cmd/processor_*.go`, `cmd/version.go`, `cmd/completion.go`, `cmd/interactive.go`)
c. Core Processing Layer
- Processor interface (defined in `processors/processor.go`)
- Individual processor modules (ASCII85, base64, md5, etc.)
- Utilities (`utils/text.go`) used by processors
d. I/O Layer
- STDIN/STDOUT, file reads/writes
- Chaining pipes between commands
e. Documentation Site
- Hugo site (`hugo/`) for CLI reference and user docs
f. Build & Release Pipeline
- GitHub Actions (`.github/workflows/`) → Go build, tests
- goreleaser (Docker, binaries for multiple platforms)
- install scripts (`install.sh`)

##### Relationships and interactions
- User invokes CLI → Cobra root → dispatch to specific subcommand → instantiate corresponding Processor → read input (stdin/file) via utils → execute transformation → write output to stdout/file.
- In interactive mode: Cobra interactive command → ui layer → loop: get user input → pass to Processor → display in terminal UI.
- Documentation build is a separate pipeline: Hugo reads `hugo/` folder → outputs static site.
- CI/CD pipeline triggers on push/tags → runs tests in `processors/` and `cmd/` → builds binaries via goreleaser → publishes to GitHub Releases, Docker registry, package managers.

##### Architectural patterns and design principles
- Modular command pattern using Cobra
- Plugin-like Processor interface for easy addition of new transformations
- Separation of concerns: CLI parsing (cmd/), core logic (processors/), I/O helpers (utils/), UI code (ui/), docs (hugo/), build config separately
- Unix philosophy: small composable tools chaining via pipes

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "User & Shell"
    User["User / Shell"]:::external
  end

  subgraph "CLI Layer"
    Main["main.go"]:::runtime
    Root["cmd/root.go"]:::runtime
    Version["cmd/version.go"]:::runtime
    Completion["cmd/completion.go"]:::runtime
    InteractiveCmd["cmd/interactive.go"]:::runtime
    subgraph "Processor Commands"
      MD5Cmd["cmd/processor_md5.go"]:::runtime
      Base64Cmd["cmd/processor_base64-encode.go"]:::runtime
      JSONCmd["cmd/processor_json-yaml.go"]:::runtime
    end
  end

  subgraph "I/O Layer"
    Utils["utils/text.go"]:::aux
  end

  subgraph "Core Processing Layer"
    ProcInterface["processors/processor.go"]:::runtime
    subgraph "Implementations"
      Base642["processors/base64.go"]:::runtime
      MD5Imp["processors/md5.go"]:::runtime
      JSONImp["processors/json.go"]:::runtime
      MarkdownImp["processors/markdown.go"]:::runtime
      HexImp["processors/hex.go"]:::runtime
      URLImp["processors/url.go"]:::runtime
      SpacesImp["processors/spaces.go"]:::runtime
      LinesImp["processors/lines.go"]:::runtime
      RSSImp["processors/rss.go"]:::runtime
    end
  end

  subgraph "Interactive UI Mode"
    UI["ui/ui.go"]:::aux
  end

  subgraph "Documentation Site"
    Config["hugo/config.toml"]:::doc
    Content["hugo/content/"]:::doc
    Archetypes["hugo/archetypes/"]:::doc
    Themes["hugo/themes/"]:::doc
  end

  subgraph "Build & Release Pipeline"
    GHGo[".github/workflows/go.yml"]:::doc
    GHGoreleaser[".github/workflows/goreleaser.yml"]:::doc
    GoreleaserYml[".goreleaser.yml"]:::doc
    GoreDocker[".goreleaser.Dockerfile"]:::doc
    InstallSh["install.sh"]:::doc
    Dockerfile["Dockerfile"]:::doc
  end

  User -->|"invoke"| Main
  Main -->|"init Cobra"| Root
  Root -->|"version"| Version
  Root -->|"completion"| Completion
  Root -->|"interactive"| InteractiveCmd
  Root -->|"subcommand"| MD5Cmd
  Root --> Base64Cmd
  Root --> JSONCmd

  MD5Cmd -->|"use I/O"| Utils
  Base64Cmd --> Utils
  JSONCmd --> Utils

  Utils -->|"read input"| ProcInterface
  ProcInterface -->|"delegate"| Base642
  ProcInterface --> MD5Imp
  ProcInterface --> JSONImp
  ProcInterface --> MarkdownImp
  ProcInterface --> HexImp
  ProcInterface --> URLImp
  ProcInterface --> SpacesImp
  ProcInterface --> LinesImp
  ProcInterface --> RSSImp
  Base642 -->|"return output"| Utils
  MD5Imp --> Utils
  JSONImp --> Utils
  MarkdownImp --> Utils
  HexImp --> Utils
  URLImp --> Utils
  SpacesImp --> Utils
  LinesImp --> Utils
  RSSImp --> Utils
  Utils -->|"write output"| User

  InteractiveCmd -->|"launch UI"| UI
  UI -->|"input"| ProcInterface
  ProcInterface -->|"result"| UI
  UI -->|"display"| User

  GHGo -->|"run tests & build"| GoreleaserYml
  GHGoreleaser -->|"build artifacts"| GoreleaserYml
  GoreleaserYml -->|"release binaries"| Dockerfile
  GoreleaserYml -->|"release images"| GoreDocker
  GoreleaserYml -->|"run install script"| InstallSh

  GHGo -->|"build docs"| Config
  Config --> Content
  Config --> Archetypes
  Config --> Themes

  classDef runtime fill:#bbdefb,stroke:#333,stroke-width:1px
  classDef aux fill:#c8e6c9,stroke:#333,stroke-width:1px
  classDef doc fill:#e0e0e0,stroke:#333,stroke-width:1px
  classDef external fill:#ffe0b2,stroke:#333,stroke-width:1px

  click Main "https://github.com/abhimanyu003/sttr/blob/main/main.go"
  click Root "https://github.com/abhimanyu003/sttr/blob/main/cmd/root.go"
  click Version "https://github.com/abhimanyu003/sttr/blob/main/cmd/version.go"
  click Completion "https://github.com/abhimanyu003/sttr/blob/main/cmd/completion.go"
  click InteractiveCmd "https://github.com/abhimanyu003/sttr/blob/main/cmd/interactive.go"
  click MD5Cmd "https://github.com/abhimanyu003/sttr/blob/main/cmd/processor_md5.go"
  click Base64Cmd "https://github.com/abhimanyu003/sttr/blob/main/cmd/processor_base64-encode.go"
  click JSONCmd "https://github.com/abhimanyu003/sttr/blob/main/cmd/processor_json-yaml.go"
  click Utils "https://github.com/abhimanyu003/sttr/blob/main/utils/text.go"
  click ProcInterface "https://github.com/abhimanyu003/sttr/blob/main/processors/processor.go"
  click Base642 "https://github.com/abhimanyu003/sttr/blob/main/processors/base64.go"
  click MD5Imp "https://github.com/abhimanyu003/sttr/blob/main/processors/md5.go"
  click JSONImp "https://github.com/abhimanyu003/sttr/blob/main/processors/json.go"
  click MarkdownImp "https://github.com/abhimanyu003/sttr/blob/main/processors/markdown.go"
  click HexImp "https://github.com/abhimanyu003/sttr/blob/main/processors/hex.go"
  click URLImp "https://github.com/abhimanyu003/sttr/blob/main/processors/url.go"
  click SpacesImp "https://github.com/abhimanyu003/sttr/blob/main/processors/spaces.go"
  click LinesImp "https://github.com/abhimanyu003/sttr/blob/main/processors/lines.go"
  click RSSImp "https://github.com/abhimanyu003/sttr/blob/main/processors/rss.go"
  click UI "https://github.com/abhimanyu003/sttr/blob/main/ui/ui.go"
  click Config "https://github.com/abhimanyu003/sttr/blob/main/hugo/config.toml"
  click Content "https://github.com/abhimanyu003/sttr/tree/main/hugo/content/"
  click Archetypes "https://github.com/abhimanyu003/sttr/tree/main/hugo/archetypes/"
  click Themes "https://github.com/abhimanyu003/sttr/tree/main/hugo/themes/"
  click GHGo "https://github.com/abhimanyu003/sttr/blob/main/.github/workflows/go.yml"
  click GHGoreleaser "https://github.com/abhimanyu003/sttr/blob/main/.github/workflows/goreleaser.yml"
  click GoreleaserYml "https://github.com/abhimanyu003/sttr/blob/main/.goreleaser.yml"
  click GoreDocker "https://github.com/abhimanyu003/sttr/blob/main/.goreleaser.Dockerfile"
  click InstallSh "https://github.com/abhimanyu003/sttr/blob/main/install.sh"
  click Dockerfile "https://github.com/abhimanyu003/sttr/tree/main/Dockerfile"
```
