# wez/wezterm architecture

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

- Interactive diagram: https://gitdiagram.com/wez/wezterm
- Repository: https://github.com/wez/wezterm

## Overview

##### Main Components Overview
The system should be divided into these major components:

a) Core Components:
- Terminal Engine (term/)
- Multiplexer System (mux/)
- GUI Frontend (wezterm-gui/)
- Font Handling (wezterm-font/)
- Configuration System (config/)

b) Protocol/Communication Components:
- SSH Implementation (wezterm-ssh/)
- Unix Domain Sockets (wezterm-uds/)
- Mux Server (wezterm-mux-server/)

c) Platform-Specific Components:
- Window Management (window/)
- OS-specific implementations (window/src/os/)
- Windows
- macOS
- X11
- Wayland

##### Component Relationships

**[GUI Frontend] ─────┐**
- ▼
**[Configuration] ──► [Terminal Engine] ◄─── [Font System]**

- ▼
**[Window System] ◄── [Multiplexer] ◄────── [SSH/Remote]**

- ▼
**[OS-Specific Backends]**

##### Specific Implementation Details

- Rust-native components (core functionality)
- Platform-specific implementations
- External dependencies (GPU, fonts)
- Protocol implementations (SSH, IPC)

##### Component Responsibilities

Detail each major component's role:
- wezterm-gui: Main application window, input handling, rendering
- term: Terminal emulation, escape sequence processing
- mux: Session management, window/pane organization
- wezterm-font: Font loading, shaping, and rendering
- window: Cross-platform window management abstraction

##### External Interfaces

Connections to:
- GPU/Graphics APIs
- Operating System services
- Font systems
- Network services (SSH)

- Clear labels for all elements

This structure reflects WezTerm's architecture as a modern, GPU-accelerated terminal emulator with clean separation of concerns and platform-specific implementations isolated behind common interfaces.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Style definitions
    classDef frontend fill:#a8d1f0,stroke:#333
    classDef terminal fill:#c3e6cb,stroke:#333
    classDef mux fill:#ffeeba,stroke:#333
    classDef font fill:#f5c6cb,stroke:#333
    classDef config fill:#d6d8db,stroke:#333
    classDef comms fill:#bee5eb,stroke:#333
    classDef platform fill:#e2c8df,stroke:#333
    classDef resource fill:#fddfdf,stroke:#333
    classDef external fill:#f8f9fa,stroke:#333

    %% Frontend Layer
    subgraph Frontend
        GUI["GUI System"]
        WindowMgmt["Window Management"]
        RenderPipe["WebGPU Rendering Pipeline"]
        InputHandler["Input Handling"]
        TabUI["Tab Bar & UI Elements"]
        Overlay["Overlay System"]
    end

    %% Terminal Layer
    subgraph TerminalCore
        TermState["Terminal State Manager"]
        Screen["Screen Buffer"]
        ColorMgr["Color Management"]
        InputProc["Input Processing"]
        VTParse["VT Sequence Parser"]
    end

    %% Multiplexer Layer
    subgraph Multiplexer
        Sessions["Session Manager"]
        PaneTab["Pane/Tab Organization"]
        DomainMgr["Domain Manager"]
        MuxArch["Client-Server Architecture"]
    end

    %% Font System
    subgraph FontSystem
        FontLoad["Font Loading"]
        TextShape["HarfBuzz Text Shaping"]
        GlyphRaster["Glyph Rasterization"]
        FontFallback["Font Fallback System"]
    end

    %% Configuration System
    subgraph Config
        LuaConfig["Lua Configuration"]
        DynConfig["Dynamic Config Reload"]
        KeyBind["Key Binding Manager"]
        ColorScheme["Color Schemes"]
    end

    %% Communication Layer
    subgraph Communication
        UDS["Unix Domain Sockets"]
        SSHImpl["SSH Implementation"]
        TLSSupport["TLS Support"]
        MuxServer["Mux Server"]
    end

    %% Platform Integration
    subgraph Platform
        OSWindow["OS Window Handling"]
        Clipboard["Clipboard Manager"]
        Notifications["Native Notifications"]
        ShellInteg["Shell Integration"]
    end

    %% Resource Management
    subgraph Resources
        GPURes["GPU Resources"]
        MemMgmt["Memory Management"]
        ProcMgmt["Process Management"]
        FDMgmt["File Descriptor Management"]
        RateLimit["Rate Limiting"]
    end

    %% Vertical Relationships
    Frontend --> TerminalCore
    TerminalCore --> Multiplexer
    Multiplexer --> FontSystem
    FontSystem --> Config
    Config --> Communication
    Communication --> Platform
    Platform --> Resources

    %% Internal relationships maintained
    GUI --> WindowMgmt
    GUI --> RenderPipe
    GUI --> InputHandler
    GUI --> TabUI
    GUI --> Overlay

    TermState --> Screen
    TermState --> ColorMgr
    TermState --> InputProc
    TermState --> VTParse

    Sessions --> PaneTab
    Sessions --> DomainMgr
    Sessions --> MuxArch

    FontLoad --> TextShape
    FontLoad --> GlyphRaster
    FontLoad --> FontFallback

    LuaConfig --> DynConfig
    LuaConfig --> KeyBind
    LuaConfig --> ColorScheme

    UDS --> MuxServer
    SSHImpl --> TLSSupport
    MuxServer --> DomainMgr

    OSWindow --> Clipboard
    OSWindow --> Notifications
    OSWindow --> ShellInteg

    GPURes --> RenderPipe
    MemMgmt --> Screen
    ProcMgmt --> Sessions
    FDMgmt --> UDS
    RateLimit --> MuxServer

    %% Click events
    click GUI "https://github.com/wez/wezterm/tree/main/wezterm-gui/src/"
    click RenderPipe "https://github.com/wez/wezterm/blob/main/wezterm-gui/src/termwindow/webgpu.rs"
    click OSWindow "https://github.com/wez/wezterm/tree/main/window/src/os/"
    click TermState "https://github.com/wez/wezterm/blob/main/term/src/terminal.rs"
    click Screen "https://github.com/wez/wezterm/blob/main/term/src/screen.rs"
    click VTParse "https://github.com/wez/wezterm/tree/main/vtparse/src/"
    click Sessions "https://github.com/wez/wezterm/tree/main/mux/src/"
    click DomainMgr "https://github.com/wez/wezterm/blob/main/mux/src/domain.rs"
    click PaneTab "https://github.com/wez/wezterm/blob/main/mux/src/pane.rs"
    click FontLoad "https://github.com/wez/wezterm/tree/main/wezterm-font/src/"
    click TextShape "https://github.com/wez/wezterm/blob/main/wezterm-font/src/shaper/harfbuzz.rs"
    click GlyphRaster "https://github.com/wez/wezterm/tree/main/wezterm-font/src/rasterizer/"
    click LuaConfig "https://github.com/wez/wezterm/blob/main/config/src/lua.rs"
    click DynConfig "https://github.com/wez/wezterm/blob/main/config/src/config.rs"
    click UDS "https://github.com/wez/wezterm/tree/main/wezterm-uds/src/"
    click SSHImpl "https://github.com/wez/wezterm/tree/main/wezterm-ssh/src/"
    click MuxServer "https://github.com/wez/wezterm/tree/main/wezterm-mux-server/src/"
    click TLSSupport "https://github.com/wez/wezterm/tree/main/async_ossl/src/"
    click ProcMgmt "https://github.com/wez/wezterm/tree/main/procinfo/src/"
    click FDMgmt "https://github.com/wez/wezterm/tree/main/filedescriptor/src/"
    click RateLimit "https://github.com/wez/wezterm/tree/main/ratelim/src/"

    %% Style applications
    class GUI,WindowMgmt,RenderPipe,InputHandler,TabUI,Overlay frontend
    class TermState,Screen,ColorMgr,InputProc,VTParse terminal
    class Sessions,PaneTab,DomainMgr,MuxArch mux
    class FontLoad,TextShape,GlyphRaster,FontFallback font
    class LuaConfig,DynConfig,KeyBind,ColorScheme config
    class UDS,SSHImpl,TLSSupport,MuxServer comms
    class OSWindow,Clipboard,Notifications,ShellInteg platform
    class GPURes,MemMgmt,ProcMgmt,FDMgmt,RateLimit resource
```
