# gigachad80/wingrep architecture

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

- Interactive diagram: https://gitdiagram.com/gigachad80/wingrep
- Repository: https://github.com/gigachad80/wingrep

## Overview

##### Project type and purpose
- Project type: A single‐executable, command‐line utility written in Go.
- Purpose: Provide grep‐like pattern matching plus “anew”-style unique‐line merging on Windows (CMD/PowerShell).

##### File structure
- Top-level files only:
- wingrep.go (the entire CLI implementation)
- install-wingrep.ps1 (PowerShell installer script)
- go.mod (module definition)
- README.md, LICENSE
- No frontend/backend or network services—this is a standalone CLI.

##### README for insights
- No external dependencies; purely uses Go standard library.
- Key features: flag parsing, file/stdin reading, regex matching, deduplication, optional file append, stdout output.

##### Main components
a. User (CMD.exe or PowerShell)
b. Installer script (`install‐wingrep.ps1`)
c. `wingrep.exe` binary, which internally comprises:
1. Command‐line Flag Parser
2. Input Source Manager
- Reads from files (glob patterns) or STDIN stream
3. Pattern Matching Engine
- Uses Go’s `regexp` (or plain substring matching)
4. Deduplication/Merge Manager
- Maintains in-memory set of seen lines
- On `-m file` mode, loads existing file into set
5. Output Writer
- Writes matched lines to STDOUT (default)
- Appends new unique lines to merge target file (if `-m`)
6. Error/Help Handler
- Handles `-h`, misuse, file errors, dry-run `-d`, quiet mode `-q`
d. Operating System (Windows file system, pipes)

##### Relationships & data flow
- User invokes `wingrep` → Installer (once, optional) or direct binary
- CLI Launcher passes args → Flag Parser
- Parser configures Input Source Manager & Pattern Matching Engine
- Input Source Manager reads each line → passes to Pattern Matcher
- Pattern Matcher returns matches → Deduplication Manager filters uniques
- Output Writer:
- If merge mode: reads target file into Dedup Manager
- Appends new lines to file (unless dry-run or quiet)
- Emits lines to STDOUT (unless quiet)
- All file I/O via OS/File System

##### Architectural patterns & design principles
- Single‐process, streaming pipeline: no intermediate storage
- Separation of concerns: parsing, I/O, matching, deduplication, writing
- In-memory data structures (set) for deduplication
- Flag‐driven behavior toggles (Strategy Pattern)

##### Essential details without overcomplicating
- Streaming line processing
- Merge logic loading & appending
- How flags alter the flow (e.g., `-d` bypasses write, `-q` suppresses stdout)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Installer
    User["Windows User\n(CMD.exe / PowerShell)"]:::green
    Installer["Installer Script"]:::green
    User -->|"invoke installer"| Installer
    click Installer "https://github.com/gigachad80/wingrep/blob/main/install-wingrep.ps1"

    %% CLI Invocation
    User -->|"launch wingrep.exe with args"| CLI["wingrep.exe"]:::green
    click CLI "https://github.com/gigachad80/wingrep/blob/main/wingrep.go"

    subgraph "Wingrep CLI"
        Parser["Flag Parser"]:::blue
        InputMgr["Input Source Manager\n(file/stdin reader)"]:::blue
        Matcher["Pattern Matching Engine"]:::blue
        Deduper["Deduplication/Merge Manager"]:::blue
        Writer["Output Writer\n(stdout/file append)"]:::blue
        ErrorHandler["Error/Help Handler"]:::blue
    end

    CLI -->|"raw args"| Parser
    Parser -->|"configures reader & matcher"| InputMgr
    InputMgr -->|"raw lines"| Matcher
    Matcher -->|"matched lines"| Deduper
    Deduper -->|"unique lines"| Writer
    Parser -->|"flags -h,-d,-q"| ErrorHandler

    %% File System & OS
    OS["Windows OS / File System"]:::brown
    FSInput["Input Files / STDIN"]:::brown
    FSMerge["Merge Target File"]:::brown

    FSInput -->|"reads lines"| InputMgr
    OS --> FSInput

    FSMerge -->|"file load on -m"| Deduper
    OS --> FSMerge

    Writer -->|"append lines to file"| FSMerge
    Writer -->|"emit to STDOUT"| OS

    %% Module Definition and Docs
    ModDef["Module Definition"]:::brown
    Readme["README.md"]:::brown
    License["LICENSE"]:::brown

    CLI --> ModDef
    CLI --> Readme
    CLI --> License
    click ModDef "https://github.com/gigachad80/wingrep/blob/main/go.mod"
    click Readme "https://github.com/gigachad80/wingrep/blob/main/README.md"
    click License "https://github.com/gigachad80/wingrep/tree/main/LICENSE"

    %% Styles
    classDef green fill:#e0ffe0,stroke:#008000,color:#006000;
    classDef blue fill:#e0f0ff,stroke:#0050a0,color:#004080;
    classDef brown fill:#fff0e0,stroke:#a05000,color:#804000;
```
