# theurw101/erb-to-epp architecture

> Architecture diagram of the GitHub repository theurw101/erb-to-epp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/theurw101/erb-to-epp
- Repository: https://github.com/theurw101/erb-to-epp

## Overview

#### Purpose and Entry Points
This Rust project converts Embedded Ruby (`.erb`) templates to Puppet Embedded Puppet (`.epp`) syntax. It supports a native CLI and a browser-delivered WebAssembly build. The sole implementation entry point is `src/main.rs`; the browser host is `index.html`.

#### Native CLI Boundary
The CLI accepts an input ERB path and optionally an output EPP path. It reads the source template, applies conversion stages, then writes converted text to stdout or the requested destination. Native packaging and dependencies are defined by `Cargo.toml`.

Paths:
- `src/main.rs`
- `Cargo.toml`

#### Browser / Wasm Boundary
The same Rust conversion logic is compiled with `wasm-pack --target web` and invoked from the static browser UI. The HTML page supplies the user interaction and loads the generated Wasm package; styling is separate. The web path intentionally does not expose parameter-tag generation.

Paths:
- `index.html`
- `src/main.rs`
- `themes/styles.css`

#### Template Parsing and Preservation
Conversion operates on template text while distinguishing ERB tag content from literal text. This boundary is essential: Ruby-instance-variable markers (`@`) are converted only inside template tags, preserving ordinary content such as email addresses. ERB whitespace trim delimiters (`<%-`, `-%>`) are retained through output generation.

Paths:
- `src/main.rs`

#### EPP Control-Flow Translation
Conditional ERB constructs are rewritten into EPP block syntax: `if`, `unless`, `elsif`, `else`, and `end` become brace-delimited Puppet expressions, including EPP’s `else if` form. This stage must preserve source ordering and tag delimiters while tracking opening and closing blocks.

Paths:
- `src/main.rs`

#### Expression and Iteration Translation
Expressions are normalized from Ruby-oriented to Puppet-oriented syntax: instance variables become `$` variables; missing variable sigils inside tags are added; `scope.function_versioncmp(...)` is converted to `versioncmp(...)`. Simple `.each do |...|` constructs become EPP iteration blocks, while guarded empty-hash iteration patterns gain explicit existence/type checks before iterating.

Paths:
- `src/main.rs`

#### Parameter Declaration Generation
For native conversion, discovered input variables can be emitted as an EPP parameter tag at the beginning of a new template. The generated declaration includes inferred Puppet types and variable names. This is a distinct output-enrichment stage from core text conversion and is unavailable in the WebAssembly UI.

Paths:
- `src/main.rs`

Main entry points: [`src/main.rs`](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs) (Tag-aware parsing), [`index.html`](https://github.com/theurw101/erb-to-epp/blob/main/index.html) (Browser UI), [`Cargo.toml`](https://github.com/theurw101/erb-to-epp/blob/main/Cargo.toml) (Cargo package), [`themes/styles.css`](https://github.com/theurw101/erb-to-epp/blob/main/themes/styles.css) (UI styles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_native["Native CLI"]
  node_cargo["Cargo package<br/>Rust package<br/>[Cargo.toml]"]
  node_cli["CLI entry<br/>native command<br/>[main.rs]"]
  node_input["ERB source<br/>template input"]
  node_parameter_generation["Parameter generation<br/>native enrichment<br/>[main.rs]"]
  node_native_output["EPP output<br/>stdout or file"]
end

subgraph group_core["Conversion Core"]
  node_core_entry["Conversion entry<br/>shared Rust logic<br/>[main.rs]"]
  node_tag_parser["Tag-aware parsing<br/>template parser<br/>[main.rs]"]
  node_literal_preservation["Literal preservation<br/>text preservation<br/>[main.rs]"]
  node_control_flow["Control-flow rewrite<br/>EPP translator<br/>[main.rs]"]
  node_expression_rewrite["Expression rewrite<br/>Puppet translator<br/>[main.rs]"]
  node_iteration_rewrite["Iteration rewrite<br/>EPP translator<br/>[main.rs]"]
end

subgraph group_web["Browser / Wasm"]
  node_browser_ui["Browser UI<br/>static host<br/>[index.html]"]
  node_wasm_module{{"Wasm conversion module<br/>web build<br/>[main.rs]"}}
  node_styles["UI styles<br/>stylesheet<br/>[styles.css]"]
end

node_cargo -->|"packages"| node_cli
node_input -->|"input path"| node_cli
node_cli -->|"converts"| node_core_entry
node_core_entry -->|"parses"| node_tag_parser
node_tag_parser -->|"preserves literals"| node_literal_preservation
node_tag_parser -->|"translates control tags"| node_control_flow
node_tag_parser -->|"translates expressions"| node_expression_rewrite
node_expression_rewrite -->|"rewrites loops"| node_iteration_rewrite
node_literal_preservation -->|"converted template"| node_parameter_generation
node_control_flow -->|"converted tags"| node_parameter_generation
node_iteration_rewrite -->|"converted loops"| node_parameter_generation
node_parameter_generation -->|"writes"| node_native_output
node_browser_ui -->|"loads and invokes"| node_wasm_module
node_wasm_module -->|"uses shared conversion"| node_core_entry
node_styles -->|"styles"| node_browser_ui
node_core_entry -.->|"Web output without parameters"| node_native_output

click node_cargo "https://github.com/theurw101/erb-to-epp/blob/main/Cargo.toml"
click node_cli "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_core_entry "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_tag_parser "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_literal_preservation "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_control_flow "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_expression_rewrite "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_iteration_rewrite "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_parameter_generation "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_browser_ui "https://github.com/theurw101/erb-to-epp/blob/main/index.html"
click node_wasm_module "https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs"
click node_styles "https://github.com/theurw101/erb-to-epp/blob/main/themes/styles.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cargo,node_cli,node_input,node_parameter_generation,node_native_output toneBlue
class node_core_entry,node_tag_parser,node_literal_preservation,node_control_flow,node_expression_rewrite,node_iteration_rewrite toneAmber
class node_browser_ui,node_wasm_module,node_styles toneMint
```

## Components

### Native CLI

- [Cargo package](https://github.com/theurw101/erb-to-epp/blob/main/Cargo.toml): Rust package · Defines native dependencies and Wasm build inputs. · `Cargo.toml`
- [CLI entry](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): native command · Accepts ERB input and optional EPP output paths. · `src/main.rs`
- **ERB source**: template input
- [Parameter generation](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): native enrichment · Infers variables and prepends an EPP parameter tag. · `src/main.rs`
- **EPP output**: stdout or file

### Conversion Core

- [Conversion entry](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): shared Rust logic · Shared by native and WebAssembly execution. · `src/main.rs`
- [Tag-aware parsing](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): template parser · Separates ERB tags from literal text. · `src/main.rs`
- [Literal preservation](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): text preservation · Keeps non-tag text and ERB trim delimiters intact. · `src/main.rs`
- [Control-flow rewrite](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): EPP translator · Converts conditional tags into brace-delimited EPP blocks. · `src/main.rs`
- [Expression rewrite](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): Puppet translator · Normalizes variables and versioncmp calls inside tags. · `src/main.rs`
- [Iteration rewrite](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): EPP translator · Converts each loops and guards empty-hash iteration. · `src/main.rs`

### Browser / Wasm

- [Browser UI](https://github.com/theurw101/erb-to-epp/blob/main/index.html): static host · Collects template input and invokes the generated Wasm package. · `index.html`
- [Wasm conversion module](https://github.com/theurw101/erb-to-epp/blob/main/src/main.rs): web build · Compiles the shared Rust converter with wasm-pack. · `src/main.rs`
- [UI styles](https://github.com/theurw101/erb-to-epp/blob/main/themes/styles.css): stylesheet · `themes/styles.css`

## Connections

- Cargo package → CLI entry: packages
- ERB source → CLI entry: input path
- CLI entry → Conversion entry: converts
- Conversion entry → Tag-aware parsing: parses
- Tag-aware parsing → Literal preservation: preserves literals
- Tag-aware parsing → Control-flow rewrite: translates control tags
- Tag-aware parsing → Expression rewrite: translates expressions
- Expression rewrite → Iteration rewrite: rewrites loops
- Literal preservation → Parameter generation: converted template
- Control-flow rewrite → Parameter generation: converted tags
- Iteration rewrite → Parameter generation: converted loops
- Parameter generation → EPP output: writes
- Browser UI → Wasm conversion module: loads and invokes
- Wasm conversion module → Conversion entry: uses shared conversion
- UI styles → Browser UI: styles
- Conversion entry → EPP output: Web output without parameters
