# microsoft/wsl architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/wsl
- Repository: https://github.com/microsoft/wsl

## Overview

WSL runs Linux command-line tools and applications on Windows, with Linux distributions hosted by the Windows-side service and initialized by Linux-side runtime code. A distinct product branch, wslc, provides container, image, network, volume, registry, and session commands; its session path is shown where source excerpts establish the calls. The tree also contains the Linux 9P filesystem server and guest networking components. Several runtime connections and wslc command-to-service links are not demonstrated by the available excerpts, so they are not asserted.

Main entry points: [`src/windows/service/exe/ServiceMain.cpp`](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/ServiceMain.cpp) (WSL service), [`src/windows/service/exe/WSLCSessionManager.cpp`](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/WSLCSessionManager.cpp) (Session manager), [`src/linux/init/NetworkManager.cpp`](https://github.com/microsoft/wsl/blob/master/src/linux/init/NetworkManager.cpp) (Guest networking), [`src/windows/wslc/core/Main.cpp`](https://github.com/microsoft/wsl/blob/master/src/windows/wslc/core/Main.cpp) (wslc command parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Windows host runtime"]
  node_wslcli["WSL command<br/>[main.cpp]"]
  node_service["WSL service<br/>[ServiceMain.cpp]"]
  node_distribution["Distribution registration"]
  node_vm["Virtual machine"]
  node_settings["User settings"]
  node_sessionmanager["Session manager"]
  node_plugins["Plugin manager<br/>[PluginManager.cpp]"]
end

subgraph group_guest["Linux distribution runtime"]
  node_linuxinit["Linux init<br/>[main.cpp]"]
  node_network["Guest networking<br/>[NetworkManager.cpp]"]
  node_gns["GNS notifications<br/>[GnsEngine.cpp]"]
  node_plan9["9P filesystem server<br/>[p9handler.cpp]"]
  node_netlink["Netlink operations"]
end

subgraph group_wslc["wslc container CLI"]
  node_wslccli["wslc command parser<br/>[Main.cpp]"]
  node_commands["Resource commands"]
  node_tasks["Session tasks<br/>[SessionTasks.cpp]"]
  node_sessionservice["Session service<br/>[SessionService.cpp]"]
  node_wslcservices["Resource services"]
end

subgraph group_shared["Shared runtime protocols"]
  node_sharedmsg["Init message protocol<br/>[lxinitshared.h]"]
end

node_user(("Windows user"))
node_wslcuser(("wslc user"))

node_user -->|"runs command"| node_wslcli
node_linuxinit -->|"uses protocol"| node_sharedmsg
node_gns -->|"uses manager"| node_network
node_network -.->|"manages neighbors"| node_netlink
node_wslcuser -.->|"runs command"| node_wslccli
node_wslccli -.->|"dispatches commands"| node_commands
node_commands -.->|"uses services"| node_wslcservices
node_tasks -->|"calls"| node_sessionservice
node_sessionservice -->|"creates manager"| node_sessionmanager
node_sessionmanager -->|"notifies plugins"| node_plugins
node_service -.->|"registers distributions"| node_distribution
node_service -.->|"hosts Linux"| node_vm

click node_wslcli "https://github.com/microsoft/wsl/blob/master/src/windows/wsl/main.cpp"
click node_service "https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/ServiceMain.cpp"
click node_distribution "https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/DistributionRegistration.cpp"
click node_vm "https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/HcsVirtualMachine.cpp"
click node_settings "https://github.com/microsoft/wsl/blob/master/src/windows/common/wslc/settings/WSLCUserSettings.cpp"
click node_linuxinit "https://github.com/microsoft/wsl/blob/master/src/linux/init/main.cpp"
click node_network "https://github.com/microsoft/wsl/blob/master/src/linux/init/NetworkManager.cpp"
click node_gns "https://github.com/microsoft/wsl/blob/master/src/linux/init/GnsEngine.cpp"
click node_plan9 "https://github.com/microsoft/wsl/blob/master/src/linux/plan9/p9handler.cpp"
click node_netlink "https://github.com/microsoft/wsl/blob/master/src/linux/netlinkutil/IpNeighborManager.cpp"
click node_sharedmsg "https://github.com/microsoft/wsl/blob/master/src/shared/inc/lxinitshared.h"
click node_wslccli "https://github.com/microsoft/wsl/blob/master/src/windows/wslc/core/Main.cpp"
click node_commands "https://github.com/microsoft/wsl/tree/master/src/windows/wslc/commands"
click node_tasks "https://github.com/microsoft/wsl/blob/master/src/windows/wslc/tasks/SessionTasks.cpp"
click node_sessionservice "https://github.com/microsoft/wsl/blob/master/src/windows/wslc/services/SessionService.cpp"
click node_sessionmanager "https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/WSLCSessionManager.cpp"
click node_plugins "https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/PluginManager.cpp"
click node_wslcservices "https://github.com/microsoft/wsl/tree/master/src/windows/wslc/services"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_wslcli,node_service,node_distribution,node_vm,node_settings,node_sessionmanager,node_plugins,node_user,node_wslcuser toneBlue
class node_linuxinit,node_network,node_gns,node_plan9,node_netlink toneAmber
class node_wslccli,node_commands,node_tasks,node_sessionservice,node_wslcservices toneMint
class node_sharedmsg toneRose
```

## Components

### Windows host runtime

- [WSL command](https://github.com/microsoft/wsl/blob/master/src/windows/wsl/main.cpp): `src/windows/wsl/main.cpp`
- [WSL service](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/ServiceMain.cpp): `src/windows/service/exe/ServiceMain.cpp`
- [Distribution registration](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/DistributionRegistration.cpp): `src/windows/service/exe/DistributionRegistration.cpp`
- [Virtual machine](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/HcsVirtualMachine.cpp): `src/windows/service/exe/HcsVirtualMachine.cpp`
- [User settings](https://github.com/microsoft/wsl/blob/master/src/windows/common/wslc/settings/WSLCUserSettings.cpp): `src/windows/common/wslc/settings/WSLCUserSettings.cpp`
- [Session manager](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/WSLCSessionManager.cpp): `src/windows/service/exe/WSLCSessionManager.cpp`
- [Plugin manager](https://github.com/microsoft/wsl/blob/master/src/windows/service/exe/PluginManager.cpp): `src/windows/service/exe/PluginManager.cpp`

### Linux distribution runtime

- [Linux init](https://github.com/microsoft/wsl/blob/master/src/linux/init/main.cpp): `src/linux/init/main.cpp`
- [Guest networking](https://github.com/microsoft/wsl/blob/master/src/linux/init/NetworkManager.cpp): `src/linux/init/NetworkManager.cpp`
- [GNS notifications](https://github.com/microsoft/wsl/blob/master/src/linux/init/GnsEngine.cpp): `src/linux/init/GnsEngine.cpp`
- [9P filesystem server](https://github.com/microsoft/wsl/blob/master/src/linux/plan9/p9handler.cpp): `src/linux/plan9/p9handler.cpp`
- [Netlink operations](https://github.com/microsoft/wsl/blob/master/src/linux/netlinkutil/IpNeighborManager.cpp): `src/linux/netlinkutil/IpNeighborManager.cpp`

### wslc container CLI

- [wslc command parser](https://github.com/microsoft/wsl/blob/master/src/windows/wslc/core/Main.cpp): `src/windows/wslc/core/Main.cpp`
- [Resource commands](https://github.com/microsoft/wsl/tree/master/src/windows/wslc/commands): `src/windows/wslc/commands`
- [Session tasks](https://github.com/microsoft/wsl/blob/master/src/windows/wslc/tasks/SessionTasks.cpp): `src/windows/wslc/tasks/SessionTasks.cpp`
- [Session service](https://github.com/microsoft/wsl/blob/master/src/windows/wslc/services/SessionService.cpp): `src/windows/wslc/services/SessionService.cpp`
- [Resource services](https://github.com/microsoft/wsl/tree/master/src/windows/wslc/services): `src/windows/wslc/services`

### Shared runtime protocols

- [Init message protocol](https://github.com/microsoft/wsl/blob/master/src/shared/inc/lxinitshared.h): `src/shared/inc/lxinitshared.h`

### Other components

- **Windows user**
- **wslc user**

## Connections

- Windows user → WSL command: runs command (evidence: `README.md`)
- Linux init → Init message protocol: uses protocol (evidence: `src/linux/init/main.cpp`)
- GNS notifications → Guest networking: uses manager
- Guest networking → Netlink operations: manages neighbors
- wslc user → wslc command parser: runs command
- wslc command parser → Resource commands: dispatches commands
- Resource commands → Resource services: uses services
- Session tasks → Session service: calls (evidence: `src/windows/wslc/tasks/SessionTasks.cpp`)
- Session service → Session manager: creates manager (evidence: `src/windows/wslc/services/SessionService.cpp`)
- Session manager → Plugin manager: notifies plugins (evidence: `src/windows/service/exe/WSLCSessionManager.cpp`)
- WSL service → Distribution registration: registers distributions
- WSL service → Virtual machine: hosts Linux
