# daisuke-nagao/guardgen architecture

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

- Interactive diagram: https://gitdiagram.com/daisuke-nagao/guardgen
- Repository: https://github.com/daisuke-nagao/guardgen

## Overview

##### Project type and purpose
- GuardGen is a Rust‑based command-line tool whose sole purpose is to generate a unique, UUIDv7‑based header guard for C/C++ header files.
- It reads CLI options (output file, overwrite flag, prefix/suffix, language, line endings), generates a guard string, and writes it to stdout or a file.

##### File structure
- Top‑level files:
- Cargo.toml / Cargo.lock: Rust project manifest with dependencies (e.g. `uuid` crate, CLI parser like `clap` or `structopt`).
- README.md, LICENSE, CHANGELOG.md, .github/*: documentation, CI and issue templates.
- src/main.rs: the single source file containing the entire application logic.
- There are no submodules or multiple binaries—everything lives in `main.rs`. No external services or databases.

##### README for additional insights
- Confirms it’s a pure CLI utility.
- Describes the command‑line options and the output format.
- No mention of a plugin system or network interactions.
- Dependencies: Rust standard library, a UUID library, and a CLI‑args library.

a. Main components:
1. CLI Interface
– Parses arguments (`--output`, `--overwrite`, `--prefix`, etc.).
2. Guard Generator
– Uses the UUIDv7 library to produce a UUID, transforms it (dashes → underscores, uppercase), formats `#ifndef`/`#define`/`#endif`.
3. File I/O / Output Writer
– If `--output` is set, opens/creates/truncates the file (checks `--overwrite`), writes the guard and closes.
– Otherwise, writes to stdout.
4. External Libraries
– UUID crate for UUIDv7 generation.
– CLI parser crate (e.g. `clap`).
5. Operating System
– Provides filesystem and stdout handles.

b. Relationships and interactions:
- The user invokes the binary → CLI Interface
- CLI Interface → Guard Generator (passes prefix, suffix, language, line‐ending)
- Guard Generator → returns formatted string → File I/O / Output Writer
- File I/O / Output Writer → OS filesystem or stdout
- CLI Interface and File I/O modules depend on external crates

c. Architectural patterns / design principles:
– Single‐responsibility: distinct modules for parsing, generation, I/O.
– Pipeline/flow: linear data flow from input → processing → output.
– Minimal dependency injection: pass only needed parameters along.

d. Key technologies / libraries:
– Rust standard library (I/O, formatting)
– `uuid` crate for UUID generation
– CLI parser crate (`clap` or `structopt`)
– `std::fs` for file operations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    User["User"]:::user

    %% Core Components
    CLI["CLI Parser"]:::frontend
    Guard["Guard Generator"]:::core
    Writer["File Writer"]:::io
    OS["OS Filesystem"]:::io
    Stdout["Stdout"]:::io

    %% External Dependencies
    subgraph "External Dependencies"
        UUIDLib["UUID & CLI Parser Crates"]:::external
    end

    %% Documentation & Project Metadata
    subgraph "Documentation & Metadata"
        Readme["README.md"]:::docs
        License["LICENSE"]:::docs
        Changelog["CHANGELOG.md"]:::docs
        Manifest["Cargo.toml & Cargo.lock"]:::docs
    end

    %% CI Workflows
    subgraph "CI Workflows"
        CI1["rust-ci.yml"]:::ci
        CI2["rust-ci-preview.yml"]:::ci
    end

    %% Flow
    User -->|"invoke binary"| CLI
    CLI -->|"Args struct"| Guard
    Guard -->|"Guard string"| Writer
    Writer -->|"writes to file"| OS
    Writer -->|"writes to stdout"| Stdout

    %% Dependencies
    UUIDLib --> CLI
    UUIDLib --> Guard

    %% Click Events
    click CLI "https://github.com/daisuke-nagao/guardgen/blob/main/src/main.rs"
    click Guard "https://github.com/daisuke-nagao/guardgen/blob/main/src/main.rs"
    click Writer "https://github.com/daisuke-nagao/guardgen/blob/main/src/main.rs"
    click UUIDLib "https://github.com/daisuke-nagao/guardgen/blob/main/Cargo.toml"
    click Readme "https://github.com/daisuke-nagao/guardgen/blob/main/README.md"
    click Manifest "https://github.com/daisuke-nagao/guardgen/blob/main/Cargo.toml"
    click Manifest "https://github.com/daisuke-nagao/guardgen/blob/main/Cargo.lock"
    click CI1 "https://github.com/daisuke-nagao/guardgen/blob/main/.github/workflows/rust-ci.yml"
    click CI2 "https://github.com/daisuke-nagao/guardgen/blob/main/.github/workflows/rust-ci-preview.yml"
    click License "https://github.com/daisuke-nagao/guardgen/tree/main/LICENSE"
    click Changelog "https://github.com/daisuke-nagao/guardgen/blob/main/CHANGELOG.md"

    %% Styles
    classDef user fill:#a2f5a2,stroke:#333,stroke-width:1px
    classDef frontend fill:#b2e7ff,stroke:#333,stroke-width:1px
    classDef core fill:#a0c4ff,stroke:#333,stroke-width:1px
    classDef io fill:#ffd6a5,stroke:#333,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef docs fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef ci fill:#ffe066,stroke:#333,stroke-width:1px
```
