# bytecodealliance/wasm-micro-runtime architecture

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

- Interactive diagram: https://gitdiagram.com/bytecodealliance/wasm-micro-runtime
- Repository: https://github.com/bytecodealliance/wasm-micro-runtime

## Overview

##### Main Components Overview

a) Core Runtime Components:
- VMcore (core/iwasm/)
- Interpreter Mode
- AOT (Ahead-of-Time) Compilation Mode
- JIT (Just-in-Time) Compilation Mode (Fast JIT and LLVM JIT)
- iwasm executable (product-mini/)
- wamrc AOT compiler (wamr-compiler/)

b) Supporting Components:
- App Framework
- App Manager
- Development Tools (WAMR-IDE)

##### Key Architectural Layers

Layer 1: Host Environment Integration
**[Host Applications/Systems]**
- ↕
**[WAMR C/C++/Go/Python/Rust API Layer]**

Layer 2: Runtime Core
**[WebAssembly Modules]**
- ↓
**[Module Loading & Validation]**
- ↓
**[Execution Engines]**
- Interpreter (Fast/Classic)
- AOT Compiler
- JIT Compiler (Fast/LLVM)

Layer 3: Memory & Resource Management
**[Memory Management]**
- Linear Memory
- Stack Management
- Heap Management

##### Detailed Component Breakdown

VMcore Internal Structure:
**[VMcore]**
- Common Runtime Services
- Memory Management
- Threading Support
- Exception Handling
- Execution Engines
- Interpreter
- AOT Runtime
- JIT Runtime
- Platform Abstraction Layer

##### Cross-Cutting Concerns

As vertical bars crossing multiple layers:
- Security Features
- Platform Abstraction
- Debug Support
- Performance Monitoring

##### Platform Support

A separate section showing supported platforms:
- Linux/Windows/macOS
- IoT/Embedded (Zephyr, RT-Thread, etc.)
- Mobile (Android)
- Cloud/Edge
- SGX Environments

##### Implementation Notes

Annotations for:
- Performance-critical paths
- Security boundaries
- Platform-specific variations
- Optional features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Host_Layer
        HostApp[Host Applications/Systems]:::host
        API[WAMR API Layer]:::api
        click API "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/include/"
    end

    subgraph Runtime_Core
        ModuleLoad[Module Loading & Validation]:::core
        click ModuleLoad "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/common/"

        subgraph Execution_Engines
            Interpreter[Interpreter Engine]:::engine
            AOT[AOT Engine]:::engine
            JIT[JIT Engine]:::engine
            click Interpreter "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/interpreter/"
            click AOT "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/aot/"
            click JIT "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/fast-jit/"
        end

        subgraph Resource_Management
            MemMgmt[Memory Management]:::resource
            ThreadMgmt[Threading Support]:::resource
            click MemMgmt "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/shared/mem-alloc/"
            click ThreadMgmt "https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/shared/platform/common/posix/posix_thread.c"
        end
    end

    subgraph Supporting_Components
        AppFw[App Framework]:::support
        AppMgr[App Manager]:::support
        DevTools[Development Tools]:::support
    end

    subgraph Cross_Cutting
        Security[Security Features]:::security
        Debug[Debug Support]:::debug
        Platform[Platform Abstraction Layer]:::platform
        click Security "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/libraries/lib-rats/"
        click Debug "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/libraries/debug-engine/"
        click Platform "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/shared/platform/"
    end

    subgraph Libraries
        WASI[WASI Support]:::lib
        Socket[Socket API]:::lib
        Threading[Multi-threading Library]:::lib
        click WASI "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/libraries/libc-wasi/"
        click Socket "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/libraries/lib-socket/"
        click Threading "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/iwasm/libraries/lib-pthread/"
    end

    subgraph Platform_Support
        Linux[Linux]:::platform
        Windows[Windows]:::platform
        IoT[IoT/Embedded]:::platform
        SGX[SGX]:::platform
        Mobile[Mobile]:::platform
    end

    %% Connections
    HostApp <--> API
    API --> ModuleLoad
    ModuleLoad --> Execution_Engines
    Execution_Engines --> Resource_Management
    ModuleLoad --> Libraries
    API --> Supporting_Components

    %% Cross-cutting concerns connections
    Security -.-> Runtime_Core
    Debug -.-> Runtime_Core
    Platform -.-> Runtime_Core

    %% Style definitions
    classDef host fill:#f9f,stroke:#333
    classDef api fill:#ff9,stroke:#333
    classDef core fill:#9cf,stroke:#333
    classDef engine fill:#9cf,stroke:#333
    classDef resource fill:#9cf,stroke:#333
    classDef support fill:#9f9,stroke:#333
    classDef security fill:#f99,stroke:#333
    classDef debug fill:#999,stroke:#333
    classDef platform fill:#ddd,stroke:#333
    classDef lib fill:#ff9,stroke:#333
```
