# hdck007/goat architecture

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

- Interactive diagram: https://gitdiagram.com/hdck007/goat
- Repository: https://github.com/hdck007/goat

## Overview

Main Components to Include:

##### Compiler System
- Components include:
- Parser (parser.go)
- AST Generator (ast-to-json.go)
- Transpiler (transpiler.go)

##### Core Virtual DOM Engine (goat directory)
- Components include:
- Virtual Element System (velement.go)
- Block Management (block.go)
- Rendering Engine (render.go)
- DOM Proxy (proxy.go)
- Edit Operations (edits.go)

##### WebAssembly Runtime
- This as a bridge between the Go code and the browser
- Main.wasm files in both site and compiler directories

##### Browser Environment
- DOM interaction layer

##### Three Main Flows
a. Compilation Flow:
.goat files → Parser → AST → Transpiler → Go code

b. Build Flow:
Go code → WebAssembly compilation → .wasm files

c. Runtime Flow:
Virtual DOM → DOM Proxy → Browser DOM

Key Relationships to Highlight:

##### Demonstrate the WebAssembly bridge between Go code and browser

Additional Elements:

##### Notes about the development server (planned feature)

Level of Detail:

- Keep the main components clearly separated
- File relationships without getting into code-level details
- Major interfaces between components
- Event binding system (marked as TODO)
- Prop serialization flow (marked as TODO)

Special Considerations:

##### Development server's planned position in the architecture

Remember to:
- Use clear, readable fonts
- A title and brief description
- Version information
- External dependencies
- A small section showing planned features

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    subgraph Compiler
        Parser["Parser"]:::compiler
        AST["AST Generator"]:::compiler
        Transpiler["Transpiler"]:::compiler
        CompilerEntry["Compiler Entry Point"]:::compiler
        CompilerOutput["Compiled Output"]:::compiler
    end

    subgraph VirtualDOM["Virtual DOM Engine"]
        VElement["Virtual Element System"]:::core
        BlockMgmt["Block Management"]:::core
        RenderEngine["Rendering Engine"]:::core
        DOMProxy["DOM Proxy"]:::core
        EditOps["Edit Operations"]:::core
        Utils["Utilities"]:::core
    end

    subgraph WASM["WebAssembly Runtime"]
        CompilerWASM["Compiler WASM"]:::wasm
        SiteWASM["Site WASM"]:::wasm
        WASMExec["WASM Executor"]:::wasm
    end

    subgraph Browser["Browser Environment"]
        MainSite["Main Site Entry"]:::browser
        GoatTemplate["Goat Template"]:::browser
        subgraph TodoApp["Todo App Demo"]
            TodoHTML["HTML Entry"]:::browser
            TodoLogic["Application Logic"]:::browser
            TodoWASM["WASM Build"]:::browser
        end
    end

    subgraph DevResources["Development Resources"]
        CompilerPlan["Compiler Planning"]:::docs
        DevNotes["Development Notes"]:::docs
        ProjectDocs["Project Documentation"]:::docs
    end

    %% Relationships
    Parser --> AST
    AST --> Transpiler
    Transpiler --> CompilerOutput
    CompilerEntry --> Parser

    VElement --> BlockMgmt
    BlockMgmt --> RenderEngine
    RenderEngine --> DOMProxy
    DOMProxy --> EditOps
    Utils --> VElement

    CompilerOutput --> CompilerWASM
    CompilerOutput --> SiteWASM
    WASMExec --> Browser

    TodoLogic --> TodoWASM
    TodoWASM --> TodoHTML
    GoatTemplate --> MainSite

    %% Click Events
    click Parser "https://github.com/hdck007/goat/blob/main/compiler/parser.go"
    click AST "https://github.com/hdck007/goat/blob/main/compiler/ast-to-json.go"
    click Transpiler "https://github.com/hdck007/goat/blob/main/compiler/transpiler.go"
    click CompilerEntry "https://github.com/hdck007/goat/blob/main/compiler/main.go"
    click CompilerOutput "https://github.com/hdck007/goat/tree/main/compiler/dist/"
    
    click VElement "https://github.com/hdck007/goat/blob/main/goat/velement.go"
    click BlockMgmt "https://github.com/hdck007/goat/blob/main/goat/block.go"
    click RenderEngine "https://github.com/hdck007/goat/blob/main/goat/render.go"
    click DOMProxy "https://github.com/hdck007/goat/blob/main/goat/proxy.go"
    click EditOps "https://github.com/hdck007/goat/blob/main/goat/edits.go"
    click Utils "https://github.com/hdck007/goat/blob/main/goat/utils.go"
    
    click CompilerWASM "https://github.com/hdck007/goat/blob/main/compiler/main.wasm"
    click SiteWASM "https://github.com/hdck007/goat/blob/main/site/main.wasm"
    click WASMExec "https://github.com/hdck007/goat/blob/main/site/wasm_exec.js"
    
    click MainSite "https://github.com/hdck007/goat/blob/main/site/index.html"
    click GoatTemplate "https://github.com/hdck007/goat/blob/main/site/index.goat"
    click TodoHTML "https://github.com/hdck007/goat/blob/main/site/todoapp/index.html"
    click TodoLogic "https://github.com/hdck007/goat/blob/main/site/todoapp/main.go"
    click TodoWASM "https://github.com/hdck007/goat/blob/main/site/todoapp/main.wasm"
    
    click CompilerPlan "https://github.com/hdck007/goat/blob/main/compiler/plan.md"
    click DevNotes "https://github.com/hdck007/goat/blob/main/compiler/thoughts.md"
    click ProjectDocs "https://github.com/hdck007/goat/blob/main/README.md"

    %% Styles
    classDef compiler fill:#a8dadc,stroke:#457b9d
    classDef core fill:#90be6d,stroke:#43691d
    classDef wasm fill:#f4a261,stroke:#e76f51
    classDef browser fill:#e9c46a,stroke:#bc6c25
    classDef docs fill:#bde0fe,stroke:#219ebc
```
