Component Model Concepts
The WebAssembly Component Model extends core WebAssembly in several ways. The Component Model:
- Adds consistent representation of higher-level types
- Enables interface-driven development
- Makes core WebAssembly composable: components that provide functionality and those that use them can be composed together into one resulting component.
This section introduces the core concepts behind the component model. For the rationale behind the component model, see the previous section.
Components
A WebAssembly Component is a binary that conforms to the Canonical ABI; often a WebAssembly core module extended with the features of the Component Model (higher-level types, interfaces). WebAssembly components are nestable: they may contain zero or more core modules and/or sub-components composed together. For example, a component implementing a simple calculator might be written by composing together a component that parses strings to floating-point numbers with a component that does the main arithmetic.
WebAssembly Interface Types (WIT)
WebAssembly Interface Types (WIT) is the Interface Definition Language (IDL) used to formally define functionality for WebAssembly components. WIT gives WebAssembly components the ability to express type signatures in a language-agnostic way, so any component binary can be checked, composed and executed.
Interfaces
An interface is a collection of type definitions and function declarations (function names accompanied by type signatures). Typically, a single interface describes a specific, focused bit of functionality.
For example, in wasi-cli,
three separate interfaces are used to implement stdin
, stdout
, and stderr
(streams typically available in command-line-like environments)
Worlds
A world is a collection of interfaces and types that expresses what features a component offers and what features it depends on.
For example, wasi-cli includes the command
world,
which depends on interfaces
that represent the stdin
, stdout
, and stderr
streams,
among other things.
A component implementing the command
world
must be invoked in an environment that implements those interfaces.
Packages
A package is a set of WIT files containing a related set of interfaces and worlds.
For example, the wasi-http package includes
an imports
world encapsulating the interfaces that an HTTP proxy depends on,
and a proxy
world that depends on imports
.
Platforms
In the context of WebAssembly, a host refers to a WebAssembly runtime capable of executing WebAssembly binaries. The runtime can be inside a browser or can stand alone. A guest refers to the WebAssembly binary that is executed by the host. (These terms borrow from their analogs in virtualization, where a guest is a software-based virtual machine that runs on physical hardware, which is the "host")
The Component Model introduces the idea of a platform to core WebAssembly—enabling the structured, standardized use of host functionality for WebAssembly guests. Components may import functionality that is provided by the platform on which they are executed.
WASI
The WebAssembly System Interface (WASI) defines in WIT
a family of interfaces for common system-level functions.
WASI defines a platform for component writers that mimics
existing programs that developers are familiar with
(for example, wasi-cli
or wasi-http
),
standardizing the functionality components depend on.
note
The Component Model is stewarded by the Bytecode Alliance and designed in the open.
See the WebAssembly/component-model
repository for goals, use cases, and high level design choices.