How abdheshnayak/gohtmlx works
Main Components
• CLI/Entry Point: At the top level you have main.go (and even an example/main.go) which handles the application startup and accepts parameters (for example, --src and --dist).
• Input Component / File Handler: Components in pkg/utils (e.g., files-finder.go) and possibly others that scan the source directory to locate HTML component definitions.
• HTML Component Parser: Modules in pkg/element (element.go, html.go, utils.go) that are responsible for parsing the HTML templates with the component definitions (and “+ define” syntax) and extracting the metadata (props, HTML structure).
• Transpiler / Code Generator: Found in pkg/gocode where the actual transpilation process occurs. This component transforms the parsed HTML components into structured Go code.
• Utility Components: The pkg/utils package holds helper functions (like fns.go and html-accumulator.go) that support file handling, HTML accumulation, and other miscellaneous operations.
• (Optional) Development/Example Runner: The “example” folder provides sample usage, configuration (Taskfile.yml, tailwind.config.js), and a demonstration of the generated component consumption.
Relationships and Interactions
• The CLI (main.go) accepts arguments specifying the source (HTML components) and destination directories. It then triggers the processing pipeline.
• The Input Handler traverses the source directory to identify HTML files containing component definitions.
• The Parser (in pkg/element) processes the component definitions, splitting them into their “props” and “html” sections.
• The Transpiler (in pkg/gocode) takes the output from the Parser and converts it into valid Go code, creating Go structures/functions for each component.
• Utility functions (from pkg/utils) support various ancillary tasks (such as file operations and HTML string accumulation).
• Finally, the generated Go code is used by a sample main function (as seen in the example) for rendering the final dynamic HTML.
Architectural Patterns and Design Principles
• Modularity: The separation into different packages (element, gocode, and utils) demonstrates a clean modular design, where each package handles a specific responsibility.
• Declarative to Imperative Transformation: The project uses a declarative HTML-like syntax that is transpiled into imperative Go code.
• Server-Side Rendering Focus: Unlike client-side libraries like React or JSX, this tool is designed for server-side dynamic HTML generation.
Relevant Technologies and Frameworks
• The project is written in Go, with standard Go module management (go.mod, go.sum).
• The tooling includes Taskfile for development automation and Tailwind configuration in the example (often for styling the example UI).
• The usage scenarios and example indicate that the generated Go code is consumed in standard Go applications.
Specific Elements
• CLI/Entry Point (main.go)
• Input Component / File Scanner (pkg/utils/files-finder.go)
• HTML & Component Parser (pkg/element/*)
• Transpiler / Code Generator (pkg/gocode/main.go)
• Utility/Helper Functions (pkg/utils/*)
• Example/Usage (example/main.go) to show how output is rendered.
• Any dependencies, such as external configuration (Taskfile.yml, Tailwind config) that help in the development cycle.
Detail
• Core pipeline: from component definition in HTML to rendering dynamic HTML via generated Go code.