v1.2.12 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: Apache-2.0



Structuresmith is a powerful tool designed to automate the generation of project files, streamlining repository setup and more using customizable templates. It's ideal for developers looking to maintain consistency and efficiency in their project configurations.

GitHub release Go Report Card go-lint-test go-binaries container

Features 🌟

  • Template Generation: Automates the creation of project files, ensuring consistency and standardization across different projects
  • YAML Configuration: Easily define templates and file structures in YAML format.
  • Robust Validation: Ensures configuration integrity with comprehensive checks and file diffing before processing.
  • Content Flexibility: Supports a variety of content sources, including external templates, direct YAML content, and files from URLs, making it adaptable to different project requirements.

What can this tool do for you?

  1. Automated Project Setup: Streamline new project initialization with predefined templates, significantly reducing setup time.
  2. Standardization Across Projects: Ensure consistent file structures and setups across multiple projects or repositories, crucial for team coherence and project maintenance.
  3. Bootstrapping: Accelerate the creation of initial project structures for quick prototyping and development iterations.
  4. Custom Template Management: Efficiently manage and apply custom templates across various projects, especially beneficial in large teams or organizations.
  5. Configuration Auditing: Validate YAML configurations before deployment to ensure compliance with required standards and specifications, enhancing reliability and reducing configuration errors.


You can download the latest release of structuresmith with this one-liner on MacOS / Linux (amd64 + arm64):

wget -O structuresmith "$(uname -s)-$(uname -m)"

You may also download the latest pre-compiled binaries from the GitHub releases page or build structuresmith from source using Go (1.21+):

make build

CLI Usage

After installing, you can run Structuresmith with the following command-line arguments:

structuresmith -h
  • -h, --help: Shows context-sensitive help. This flag can be used with any command to get more information about its usage and options.
  • --config="anvil.yml": Specifies the path to the YAML configuration file. This flag allows you to define a custom configuration file for the tool to use.
  • --output="out": Sets the output path prefix for the generated files. This flag lets you specify where the generated files should be stored.
  • --templates="templates": Indicates the directory where template files are stored. With this flag, you can define a custom location for your template files.


Validates the YAML configuration (anvil.yml) to ensure its integrity and checks for any potential issues.

structuresmith validate --config path/to/config.yaml


Conducts a dry-run to display the file paths that would be generated, helping to preview changes without actual file creation.

structuresmith diff --config path/to/config.yaml --output output/directory --templates path/to/templates project-to-render

Example output:

delete:     .gitignore
overwrite:  .golangci.yml
overwrite:  Dockerfile
overwrite:  LICENSE
new:        foobar.txt
overwrite:  sub/bar.txt
overwrite:  sub/foo.txt
delete:     sub/nested/foo.txt


Processes and writes the templated files to the disk, applying the configurations to generate the specified project structure.

structuresmith render --config path/to/config.yaml --output output/directory --templates path/to/templates project-to-render


podman run --rm -it

GitHub Actions

Please check out the action.yml and the example workflow.

Configuration Overview

These examples showcase the versatility and capabilities of structuresmith, ranging from simple inline content to more complex configurations using template groups and nested values. Please take a look at the sample anvil.yml.

# Structuresmith YAML Configuration
# This configuration showcases the use of template groups, custom values for templating,
# and the definition of project-specific files. Modify paths and values as needed.

# Define projects to apply template groups

  # Example Go project configuration
  - name: "example/go-project"
      - groupName: "commonFiles"
      - groupName: "goProjectFiles"
          packageName: "main"   # Custom value used in Go template

  # Example for a general project using inline content
  - name: "example/general-project"
      - groupName: "commonFiles"
      - destination: "config.json"
        content: |
            "setting": "value",
            "enabled": true

# Define template groups with sets of files

  # Common files for all projects
    - destination: ".gitignore"
      source: "templates/gitignore.tmpl"  # Template for .gitignore
    - destination: ""
      source: "templates/readme.tmpl"     # Template for

# Group for specific project types, e.g., Go projects
    - destination: "main.go"
      source: "templates/main.go.tmpl"    # Main file for Go project
    - destination: "Makefile"
      source: "templates/Makefile.tmpl"   # Makefile for build commands

# Uncomment to demonstrate downloading files from URLs
#   - destination: "Dockerfile"
#     sourceUrl: ""
# Uncomment to demonstrate copying whole directories
#   - destination: "docs/"
#     source: "docs_templates/"


Example 1: Simple Inline Content for a Single Project

Description: A basic configuration creating a file with inline content.

YAML Configuration:

  - name: "simple-project"
      - destination: ""
        content: "Welcome to Simple Project"


  • out/ containing "Welcome to Simple Project".

Example 2: Single File Template with Value

Description: Creating a config.txt file from a template, substituting a value. YAML Configuration:

    - destination: "config.txt"
      source: "templates/config.tmpl"
  - name: "config-project"
      - groupName: "configFile"
          setting: "Enabled"


  • out/config.txt with content from config.tmpl, where a template value like {{ .setting }} is replaced by "Enabled".

Example 3: Templated File with Nested Values

Description: Creating a file with nested template values. YAML Configuration:

    - destination: "details.txt"
      source: "templates/details.tmpl"
  - name: "detail-project"
      - groupName: "detailFile"
            name: "Alice"
            role: "Developer"


  • out/details.txt with content from details.tmpl, where template values like {{ }} are replaced by "Alice" and {{ .user.role }} by "Developer".

Example 4: Using Template Group with Overwritten Values

Description: Utilizing a template group with values defined in the group and overwritten in the project definition. YAML Configuration:

    - destination: "base.txt"
      source: "templates/base.tmpl"
        defaultText: "Default"
  - name: "base-project"
      - groupName: "baseFiles"
          defaultText: "Customized Text"


  • out/base.txt with content from base.tmpl, where the default text is overwritten by "Customized Text".

Example 5: Multiple Template Groups

Description: Combining multiple template groups in a single project. YAML Configuration:

    - destination: ""
      source: "templates/readme.tmpl"
    - destination: "extra.txt"
      source: "templates/extra.tmpl"
  - name: "multi-group-project"
      - groupName: "commonFiles"
      - groupName: "additionalFiles"


  • out/ from readme.tmpl.
  • out/extra.txt from extra.tmpl.

Example 6: Mix of Direct Files and Template Groups

Description: A project configuration using a mix of direct file definitions and template groups. YAML Configuration:

    - destination: "docs/"
      source: "templates/docs/intro.tmpl"
  - name: "mixed-project"
      - destination: "overview.txt"
        content: "Project Overview"
      - groupName: "documentationFiles"


  • out/overview.txt with "Project Overview".
  • out/docs/ generated from intro.tmpl.

Example 7: Templating a Whole Directory

Description: Applying templates to an entire directory. YAML Configuration:

    - destination: "config/"
      source: "templates/config_directory/"
        appName: "MyApp"

  - name: "directory-project"
      - groupName: "completeDirectory"


  • Directory out/config/ with files from templates/config_directory/, where template values like {{ .appName }} are replaced with "MyApp".

Example 8: Downloading Content from URLs

Description: Fetching a file from a URL and placing it into the project directory. YAML Configuration:

  - name: "download-project"
      - destination: "Dockerfile"
        sourceUrl: ""


  • out/Dockerfile containing the content fetched from the provided URL.

Lockfile .anvil.lock

Structuresmith's anvil.lock file is vital for managing project files. It keeps a record of used files and templates, tracking updates since the last use of the tool. An important feature of Structuresmith is its ability to automatically remove files from the project's output directory that are no longer present in the original project configuration. This ensures the output remains synchronized with the current project setup.

Including anvil.lock in the project's versioning is beneficial. It provides a clear history of file changes, especially important in team settings to maintain consistency and prevent conflicts in the project's files.

Templating Explained

Structuresmith leverages Go's powerful templating system, allowing you to define dynamic content in your templates. This system provides a flexible way to insert values into your files, making your templates adaptable to different contexts.

How It Works

  • Placeholders: In your templates, you can use placeholders in the form {{ .VariableName }} to insert values dynamically. These placeholders will be replaced with actual values when the template is processed.
  • YAML Configuration: Define the values for these placeholders in the YAML configuration under the values key for each template group or individual file.
  • Example: If your template contains {{ .Author }}, you can specify the author's name in the YAML configuration, and it will be replaced in the generated file.

Go Templating Syntax

  • Structuresmith uses Go's text/template package syntax. This includes conditional statements, range loops, and more, providing a rich set of features for creating complex templates.
  • For detailed information on Go's templating syntax, visit the official documentation: Go's text/template package

Contributing & License

We welcome and value your contributions to this project! πŸ‘ If you're interested in making improvements or adding features, please refer to our Contributing Guide. This guide provides comprehensive instructions on how to submit changes, set up your development environment, and more.

Please note that this project is developed in my spare time and is available for free πŸ•’πŸ’». As an open-source initiative, it is governed by the Apache 2.0 License. This license outlines your rights and obligations when using, modifying, and distributing this software.

Your involvement, whether it's through code contributions, suggestions, or feedback, is crucial for the ongoing improvement and success of this project. Together, we can ensure it remains a useful and well-maintained resource for everyone 🌍.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL