# wasmerio/wasmer architecture

> Architecture diagram of the GitHub repository wasmerio/wasmer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wasmerio/wasmer
- Repository: https://github.com/wasmerio/wasmer

## Overview

##### Main Components (Core Layer)
- Compiler Infrastructure (lib/compiler/)
- Runtime Engine (lib/vm/)
- API Layer (lib/api/)
- WASI Implementation (lib/wasix/)

##### Compilation Pipeline (Left Side)
- Three compiler backends as parallel paths:
- Cranelift (lib/compiler-cranelift/)
- LLVM (lib/compiler-llvm/)
- Singlepass (lib/compiler-singlepass/)
- Them to the core compiler infrastructure
- Middleware components (lib/middlewares/)

##### Runtime Components (Center)
- VM execution environment:
- Memory Management
- Function Calls
- Table Operations
- Global Variables
- Connection to the store and instance management

##### API Integration Layer (Right Side)
- Multiple language bindings:
- C API (lib/c-api/)
- JavaScript/WASM (lib/api/src/js/)
- Native Rust API
- How they connect to the core runtime

##### Extension Systems (Top)
- WASI/WASIX Implementation
- Package Management
- Cache System (lib/cache/)
- Virtual File System (lib/virtual-fs/)

##### Support Systems (Bottom)
- Testing Framework
- Benchmarking System
- Build Tools
- Documentation Generation

Use the following visual elements:
- Rectangles for main components
- Blue: Core components
- Green: Compiler backends
- Yellow: API layers
- Orange: Extension systems
- Gray: Support systems

Important Relationships to Show:
##### Compilation Flow
- Source -> Parser -> Compiler Backend -> Native Code

##### Execution Flow
- Module -> Instance -> Runtime -> Host System

##### API Integration
- Host Language -> API Binding -> Runtime Core

Annotations for:
- Version compatibility
- Security boundaries
- Performance critical paths
- Extension points

- Compilation
- Execution
- Host Integration
- System Extensions

This structure reflects Wasmer's architecture as a high-performance WebAssembly runtime with multiple compilation backends and extensive language support.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef core fill:#a8d1f0,stroke:#333
    classDef compiler fill:#90EE90,stroke:#333
    classDef api fill:#FFE4B5,stroke:#333
    classDef extension fill:#FFA07A,stroke:#333
    classDef support fill:#D3D3D3,stroke:#333

    %% Core Components
    subgraph CoreLayer["Core Layer"]
        CompInfra["Compiler Infrastructure"]:::core
        Runtime["Runtime Engine"]:::core
        APILayer["API Layer"]:::core
        WASI["WASI Implementation"]:::core
    end

    %% Compiler Pipeline
    subgraph CompilerBackends["Compiler Backends"]
        Cranelift["Cranelift Backend"]:::compiler
        LLVM["LLVM Backend"]:::compiler
        Singlepass["Singlepass Backend"]:::compiler
        Middleware["Middleware Components"]:::compiler
    end

    %% Runtime Components
    subgraph RuntimeComponents["Runtime Components"]
        MemMgmt["Memory Management"]:::core
        FuncCalls["Function Calls"]:::core
        TableOps["Table Operations"]:::core
        GlobalVars["Global Variables"]:::core
    end

    %% API Integration
    subgraph APIIntegration["API Integration"]
        CAPI["C API"]:::api
        JSAPI["JavaScript/WASM API"]:::api
        RustAPI["Native Rust API"]:::api
    end

    %% Extension Systems
    subgraph Extensions["Extension Systems"]
        PackageMgmt["Package Management"]:::extension
        Cache["Cache System"]:::extension
        VFS["Virtual File System"]:::extension
        VNet["Virtual Network"]:::extension
        VIO["Virtual I/O"]:::extension
        Types["Types System"]:::extension
    end

    %% Relationships
    CompilerBackends --> CompInfra
    CompInfra --> Runtime
    Runtime --> RuntimeComponents
    APILayer --> Runtime
    WASI --> Runtime
    APIIntegration --> APILayer
    Extensions --> Runtime

    %% Click Events
    click CompInfra "https://github.com/wasmerio/wasmer/tree/main/lib/compiler/"
    click Runtime "https://github.com/wasmerio/wasmer/tree/main/lib/vm/"
    click APILayer "https://github.com/wasmerio/wasmer/tree/main/lib/api/"
    click WASI "https://github.com/wasmerio/wasmer/tree/main/lib/wasix/"
    click Cranelift "https://github.com/wasmerio/wasmer/tree/main/lib/compiler-cranelift/"
    click LLVM "https://github.com/wasmerio/wasmer/tree/main/lib/compiler-llvm/"
    click Singlepass "https://github.com/wasmerio/wasmer/tree/main/lib/compiler-singlepass/"
    click Middleware "https://github.com/wasmerio/wasmer/tree/main/lib/middlewares/"
    click CAPI "https://github.com/wasmerio/wasmer/tree/main/lib/c-api/"
    click JSAPI "https://github.com/wasmerio/wasmer/tree/main/lib/api/src/js/"
    click RustAPI "https://github.com/wasmerio/wasmer/tree/main/lib/api/src/sys/"
    click PackageMgmt "https://github.com/wasmerio/wasmer/tree/main/lib/package/"
    click Cache "https://github.com/wasmerio/wasmer/tree/main/lib/cache/"
    click VFS "https://github.com/wasmerio/wasmer/tree/main/lib/virtual-fs/"
    click Types "https://github.com/wasmerio/wasmer/tree/main/lib/types/"
    click VNet "https://github.com/wasmerio/wasmer/tree/main/lib/virtual-net/"
    click VIO "https://github.com/wasmerio/wasmer/tree/main/lib/virtual-io/"
```
