# hrmsk66/terraformify architecture

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

- Interactive diagram: https://gitdiagram.com/hrmsk66/terraformify
- Repository: https://github.com/hrmsk66/terraformify

## Overview

##### Main Components
- Entry Point/CLI Handler: At the very top is the main executable (main.go) that boots up the application and routes commands.
- Command Modules: Under the cmd directory, there are multiple command files (like compute.go, service.go, vcl.go, version.go) which correspond to different CLI commands and functionalities.
- Core Logic Packages (pkg):
- pkg/cli: Handles processing and execution of the CLI commands.
- pkg/file: Manages file operations such as reading existing files and generating new Terraform files. Note that within pkg/file/, there is a “static” folder which may store template or provider configuration files.
- pkg/naming: Likely manages naming conventions for resources.
- pkg/prop: Possibly used for property/parameter handling.
- pkg/terraform: Contains logic specific to generating or formatting Terraform configurations.
- pkg/tfconf: Handles cleanup or configuration adjustments for Terraform files.
- pkg/tfstate: Deals with reading/modifying the Terraform state.
- Documentation and Testing: The docs and tests directories provide supporting documentation (like usage) and integration tests that ensure the system operates correctly.
- CI/CD and Build Scripts: The .github directory (workflows, dependabot config) and the Makefile indicate automation for linting, releases, and potentially build and test processes.

##### Relationships and Data Flow
- The CLI handling layer interacts with the submodules:
- It makes use of modules in pkg/file to read existing configuration files and write new Terraform files.
- It invokes modules in pkg/terraform to generate the proper Terraform file content corresponding to the desired Fastly service resource.
- The pkg/tfconf and pkg/tfstate modules are called as needed to adjust or validate the configuration and state, ensuring that preexisting TF files are handled correctly.
- The pkg/naming and pkg/prop modules serve to apply consistent naming conventions and handle properties or parameters for the generated configurations.
- External Dependencies: The tool integrates with Fastly’s API (via the provided API token) to read service details. Although not shown as an explicit service in the file tree, the README provides instructions on configuring API access.
- Flow from user input (command-line arguments) → main.go → CLI command-specific processing.
- Data passing between the CLI module and file, terraform, tfconf, and tfstate modules.
- Interaction with external Fastly services (data retrieval using the API key).

##### Architectural Patterns and Technologies
- Separation of Concerns: The modular organization (with cmd and pkg directories) clearly separates the command-line interface from business logic (Terraform file generation, file system operations, and state management).
- Layered Architecture: The entry point aggregates CLI input logic (in cmd and pkg/cli) and then delegates to specialized packages for domain-specific functions.
- Utilization of Go Modules: With go.mod and go.sum, indicating dependency management according to established Golang practices.
- CI/CD Integration: GitHub workflows for linting and releasing that ensure code quality and streamlined development.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User / CLI Terminal"]
    MAIN["CLI Entry (main.go)"]:::entry
    CLI["CLI Handler (pkg/cli)"]:::cli
    CMD["Command Handlers (cmd/)"]:::command
    FileOps["File Operations (pkg/file)"]:::business
    Static["Template Storage (pkg/file/static)"]:::business
    Terraform["Terraform File Generator (pkg/terraform)"]:::business
    Tfconf["Configuration Cleanup (pkg/tfconf)"]:::business
    Tfstate["Terraform State Management (pkg/tfstate)"]:::business
    Naming["Naming Convention Handler (pkg/naming)"]:::business
    Prop["Property/Parameter Management (pkg/prop)"]:::business
    Fastly["Fastly API"]:::external
    Docs["Documentation (docs/USAGE.md)"]:::support
    CI["CI/CD & Build Scripts (.github/ & Makefile)"]:::support

    User -->|"sends_command"| MAIN
    MAIN -->|"routes_command"| CLI
    CLI -->|"invokes"| CMD
    CLI -->|"calls"| FileOps
    FileOps -->|"uses_templates"| Static
    CLI -->|"generates"| Terraform
    CLI -->|"cleans_config"| Tfconf
    CLI -->|"manages_state"| Tfstate
    CLI -->|"applies_naming"| Naming
    CLI -->|"handles_params"| Prop
    CLI -->|"fetches_service"| Fastly
    MAIN -->|"references_usage"| Docs
    MAIN -->|"triggers_build"| CI

    click MAIN "https://github.com/hrmsk66/terraformify/blob/main/main.go"
    click CMD "https://github.com/hrmsk66/terraformify/tree/main/cmd/"
    click CLI "https://github.com/hrmsk66/terraformify/blob/main/pkg/cli/cli.go"
    click FileOps "https://github.com/hrmsk66/terraformify/blob/main/pkg/file/file.go"
    click Static "https://github.com/hrmsk66/terraformify/tree/main/pkg/file/static/"
    click Naming "https://github.com/hrmsk66/terraformify/blob/main/pkg/naming/naming.go"
    click Prop "https://github.com/hrmsk66/terraformify/blob/main/pkg/prop/prop.go"
    click Terraform "https://github.com/hrmsk66/terraformify/blob/main/pkg/terraform/terraform.go"
    click Tfconf "https://github.com/hrmsk66/terraformify/tree/main/pkg/tfconf/"
    click Tfstate "https://github.com/hrmsk66/terraformify/tree/main/pkg/tfstate/"
    click Docs "https://github.com/hrmsk66/terraformify/blob/main/docs/USAGE.md"
    click CI "https://github.com/hrmsk66/terraformify/tree/main/.github/"

    classDef entry fill:#277da1,stroke:#333,stroke-width:2px;
    classDef cli fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef command fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef business fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef external fill:#577590,stroke:#333,stroke-width:2px;
    classDef support fill:#f94144,stroke:#333,stroke-width:2px;
```
