# chris-greaves/pencil architecture

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

- Interactive diagram: https://gitdiagram.com/chris-greaves/pencil
- Repository: https://github.com/chris-greaves/pencil

## Overview

##### Project Type Analysis
This is a command-line utility tool focused on template processing, built in Go. The project is relatively straightforward but needs to show clear data flow and processing steps.

##### Main Components

a. Input Sources:
- Files/Folders (with .gotmpl extension or direct files)
- Command Line Arguments (-v flags for direct variables)
- Environment Variables

b. Core Processing Components:
- Command Parser (cmd package)
- Template Processor (processor package)
- Variable Manager

c. Output Handlers:
- In-place File Writer
- Template File Generator

**[Input Sources] → [Core Processing] → [Output Handlers]**

**┌─── Input Sources ────┐    ┌─── Core Processing ───┐    ┌─── Output Handlers ───┐**
- Template Files     │    │ ┌─────────────────┐   │    │ ┌─────────────────┐  │
- CLI Arguments      │ →  │ │  Command Parser │   │    │ │  In-place Writer│  │
- Environment Vars   │    │ └────────┬────────┘   │    │ └────────────────┬┘  │
- ↓            │    │                   │   │
- ┌─────────────────┐   │ →  │ ┌─────────────────┐  │
- Processor    │   │    │ │ Template Writer │  │
- ┘   │    │ └─────────────────┘  │
- ┘    └────────────────────────┘    └────────────────────┘

##### Specific Component Details

For each major component, include:

Command Parser:
- Handles CLI flags and arguments
- Processes environment variables
- Validates input parameters

Processor:
- Template parsing using Go's text/template
- Variable substitution
- Error handling

Output Handlers:
- File path management
- Content writing strategies
- Extension handling (.gotmpl)

##### Implementation Notes

- The simplicity of the single-purpose tool
- Clear data flow from input to output
- The two distinct processing modes (in-place vs. template)
- Integration points with Docker/Docker Compose

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        Files["Template Files"]:::input
        CLI["CLI Arguments"]:::input
        ENV["Environment Variables"]:::input
    end

    subgraph Core
        Parser["Command Parser"]:::core
        Processor["Template Processor"]:::core
        FuncHandler["Template Functions"]:::core
        VarManager["Variable Manager"]:::core
    end

    subgraph Output
        InPlace["In-place Writer"]:::output
        TempWriter["Template Writer"]:::output
    end

    subgraph Testing
        TestConfig["Test Config"]:::test
        TestFiles["Test Files"]:::test
        TestSuite["Test Suite"]:::test
    end

    subgraph CI
        GHActions["GitHub Actions"]:::ci
        Docker["Docker Build"]:::ci
    end

    Files --> Parser
    CLI --> Parser
    ENV --> Parser

    Parser --> VarManager
    VarManager --> Processor
    FuncHandler --> Processor

    Processor --> InPlace
    Processor --> TempWriter

    TestConfig --> TestSuite
    TestFiles --> TestSuite
    TestSuite --> Processor

    Parser --> Docker
    Processor --> Docker
    GHActions --> Docker

    %% Click Events
    click Parser "https://github.com/Chris-Greaves/pencil/blob/main/cmd/root.go"
    click Processor "https://github.com/Chris-Greaves/pencil/blob/main/processor/processor.go"
    click FuncHandler "https://github.com/Chris-Greaves/pencil/blob/main/processor/funcs.go"
    click TestConfig "https://github.com/Chris-Greaves/pencil/blob/main/test/config.yml"
    click TestFiles "https://github.com/Chris-Greaves/pencil/tree/main/test/folder"
    click TestSuite "https://github.com/Chris-Greaves/pencil/blob/main/cmd/root_test.go"
    click GHActions "https://github.com/Chris-Greaves/pencil/tree/main/.github/workflows"
    click Docker "https://github.com/Chris-Greaves/pencil/tree/main/Dockerfile"

    %% Styles
    classDef input fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef core fill:#98fb98,stroke:#333,stroke-width:2px
    classDef output fill:#ffa07a,stroke:#333,stroke-width:2px
    classDef test fill:#dda0dd,stroke:#333,stroke-width:2px
    classDef ci fill:#f0e68c,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Input Components"]:::input
        L2["Core Components"]:::core
        L3["Output Components"]:::output
        L4["Testing Components"]:::test
        L5["CI/CD Components"]:::ci
    end
```
