# tomnomnom/anew architecture

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

- Interactive diagram: https://gitdiagram.com/tomnomnom/anew
- Repository: https://github.com/tomnomnom/anew

## Overview

##### Project type and purpose
- Type: CLI tool written in Go
- Purpose: Read lines from stdin, append only non-duplicate lines to a target file, and echo those new lines to stdout.

##### Main components
a. CLI Interface / Flag Parser
- Accepts positional argument (target filename)
- Flags: `-d` (dry-run), `-q` (quiet)
b. File Loader
- Opens and reads the existing target file into an in-memory set (hash)
c. Input Stream Reader
- Reads lines from stdin one at a time
d. Duplicate Detector
- Checks each input line against the in-memory set
- If not present, forwards line to both File Appender and Output Writer
e. File Appender
- Opens the file in append mode and writes new lines (skipped if dry-run or quiet)
f. Output Writer
- Writes new lines to stdout (skipped if quiet)
g. Packaging / Release Script
- `script/release`: shell script that builds cross-compiled binaries and prepares GitHub releases

##### Relationships & Data Flow
1. stdin → Input Stream Reader
2. CLI Interface → File Loader (to get existing lines)
3. CLI Interface → Duplicate Detector (flag settings)
4. Input Stream Reader → Duplicate Detector
5. Duplicate Detector → File Appender (conditionally)
6. Duplicate Detector → Output Writer (conditionally)
7. Packaging Script → Go Compiler & GitHub Releases

##### Architectural Patterns & Design Principles
- Linear streaming pipeline: input → process → output
- Use of in-memory hash set for O(1) membership checks
- Clear separation of concerns: parsing, I/O, processing
- Minimal external dependencies: only Go standard library

##### Technology Stack & Frameworks
- Go runtime (golang)
- Standard library modules: `flag`, `bufio`, `os`, `fmt`
- Shell script for release automation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Components"
        STDIN["stdin"]:::input
        CLI["CLI Interface / Flag Parser"]:::input
    end

    %% Processing Layer
    subgraph "Processing Components"
        Loader["File Loader"]:::processing
        Reader["Input Stream Reader"]:::processing
        Dedup["Duplicate Detector"]:::processing
    end

    %% Output Layer
    subgraph "Output Components"
        Appender["File Appender"]:::output
        Writer["Output Writer"]:::output
    end

    %% Packaging Layer
    subgraph "Packaging / Release"
        ReleaseScript["Packaging / Release Script"]:::packaging
        GoBuild["Go Compiler"]:::packaging
        GitHub["GitHub Releases"]:::packaging
    end

    %% Data Flows
    STDIN -->|reads lines| Reader
    CLI -->|parses flags & filename| Loader
    CLI -->|provides flags| Dedup
    Loader -->|loads existing lines| Dedup
    Reader -->|streams lines| Dedup
    Dedup -->|"if not duplicate\nskip on -d"| Appender
    Dedup -->|"if not duplicate\nskip on -q"| Writer
    ReleaseScript -->|invokes| GoBuild
    GoBuild -->|publishes artifacts| GitHub

    %% Click Events
    click CLI "https://github.com/tomnomnom/anew/blob/master/main.go"
    click Loader "https://github.com/tomnomnom/anew/blob/master/main.go"
    click Reader "https://github.com/tomnomnom/anew/blob/master/main.go"
    click Dedup "https://github.com/tomnomnom/anew/blob/master/main.go"
    click Appender "https://github.com/tomnomnom/anew/blob/master/main.go"
    click Writer "https://github.com/tomnomnom/anew/blob/master/main.go"
    click ReleaseScript "https://github.com/tomnomnom/anew/tree/master/script/release"

    %% Styles
    classDef input fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef processing fill:#90EE90,stroke:#000,stroke-width:1px
    classDef output fill:#FFA500,stroke:#000,stroke-width:1px
    classDef packaging fill:#D3D3D3,stroke:#000,stroke-width:1px
```
