# wa-lang/wa architecture

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

- Interactive diagram: https://gitdiagram.com/wa-lang/wa
- Repository: https://github.com/wa-lang/wa

## Overview

##### Main Components

a. Core Components:
- Compiler Frontend (Parser, Scanner, Type Checker)
- Compiler Backend (Code Generator)
- Runtime System
- WebAssembly Integration Layer
- Multiple Target Platforms (Web, WASI, Arduino)

b. Supporting Systems:
- Package Management System
- Build System
- Development Tools (LSP, Debugger)
- Testing Framework

- Development Tools                                       |

- LSP Server  |  |    Debugger   |  |   Playground   |  |  Build Tools   |          |

- Compiler Pipeline                                       |

- Parser     |  |  Type Checker  |  | IR Generator   |  | Code Generator |          |

- Runtime System                                          |

- Memory Mgmt   |  |  GC System     |  |  FFI Support   |  | Native Bindings |          |

- Target Platforms                                        |

- Web       |  |     WASI      |  |    Arduino     |  |     WASM4     |          |

##### Implementation Details

Implementation aspects:
- File organization (/internal, /api, /cmd)
- Third-party dependencies (wazero, etc.)
- Testing infrastructure
- Build system integration

##### Deployment View

A separate section showing:
- Development environment setup
- Deployment targets
- Runtime requirements
- Platform-specific considerations

##### Package management flow

This design reflects the project's focus on WebAssembly targeting, multiple platform support, and developer tooling integration, while maintaining clarity about the core compiler and runtime components.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef devtools fill:#FFA500,stroke:#333,stroke-width:2px
    classDef compiler fill:#4169E1,stroke:#333,stroke-width:2px
    classDef runtime fill:#32CD32,stroke:#333,stroke-width:2px
    classDef platform fill:#8A2BE2,stroke:#333,stroke-width:2px
    classDef support fill:#808080,stroke:#333,stroke-width:2px

    %% Development Tools Layer
    subgraph DevTools
        LSP["LSP Server"]:::devtools
        Debugger["Debugger"]:::devtools
        Playground["Playground"]:::devtools
        BuildTools["Build Tools"]:::devtools
        DevUtils["Development Utilities"]:::devtools
    end

    %% Compiler Pipeline Layer
    subgraph CompilerPipeline
        Scanner["Scanner/Parser"]:::compiler
        TypeChecker["Type Checker"]:::compiler
        IRGen["IR Generator"]:::compiler
        CodeGen["Code Generator"]:::compiler
    end

    %% Runtime System Layer
    subgraph RuntimeSystem
        MemMgmt["Memory Management"]:::runtime
        GC["Garbage Collection"]:::runtime
        FFI["FFI Support"]:::runtime
        NativeBind["Native Bindings"]:::runtime
    end

    %% Target Platforms Layer
    subgraph Platforms
        Web["Web Browser"]:::platform
        WASI["WASI"]:::platform
        Arduino["Arduino"]:::platform
        WASM4["WASM4"]:::platform
    end

    %% Package Management
    PackageManager["Package Manager"]:::support

    %% Connections
    DevTools --> CompilerPipeline
    CompilerPipeline --> RuntimeSystem
    RuntimeSystem --> Platforms
    PackageManager --> CompilerPipeline

    %% Component click events
    click Scanner "https://github.com/wa-lang/wa/tree/master/internal/parser/"
    click TypeChecker "https://github.com/wa-lang/wa/tree/master/internal/types/"
    click CodeGen "https://github.com/wa-lang/wa/tree/master/internal/backends/compiler_wat/"
    click LSP "https://github.com/wa-lang/wa/tree/master/internal/lsp/"
    click Debugger "https://github.com/wa-lang/wa/tree/master/internal/dap/"
    click Playground "https://github.com/wa-lang/wa/tree/master/internal/app/appplay/"
    click BuildTools "https://github.com/wa-lang/wa/tree/master/internal/app/appbuild/"
    click RuntimeSystem "https://github.com/wa-lang/wa/tree/master/waroot/src/runtime/"
    click WASI "https://github.com/wa-lang/wa/tree/master/internal/wazero/imports/wasi_snapshot_preview1/"
    click Arduino "https://github.com/wa-lang/wa/tree/master/waroot/src/syscall/arduino/"
    click WASM4 "https://github.com/wa-lang/wa/tree/master/waroot/src/syscall/wasm4/"
    click Web "https://github.com/wa-lang/wa/tree/master/waroot/src/syscall/js/"
    click PackageManager "https://github.com/wa-lang/wa/tree/master/internal/loader/"
    click DevUtils "https://github.com/wa-lang/wa/tree/master/internal/app/appdev/"

    %% Legend
    subgraph Legend
        Dev["Development Tools"]:::devtools
        Comp["Compiler Components"]:::compiler
        Run["Runtime Components"]:::runtime
        Plat["Target Platforms"]:::platform
        Supp["Support Systems"]:::support
    end
```
