# wxt-dev/wxt architecture

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

- Interactive diagram: https://gitdiagram.com/wxt-dev/wxt
- Repository: https://github.com/wxt-dev/wxt

## Overview

##### Main Components

a. Core Framework Components:
- Build System (Vite-based)
- CLI Interface
- Development Server
- Module System
- Virtual Modules
- Configuration System

b. Extension Components:
- Background Scripts
- Content Scripts
- Popup/UI Components
- Extension APIs
- Storage Management
- Messaging System

##### Key Relationships to Highlight

a. Development Flow:
- CLI → Build System → Output
- Development Server ↔ HMR System
- File Watchers ↔ Auto-reload

b. Runtime Flow:
- Extension Entry Points → Browser Extension APIs
- Content Scripts ↔ Background Scripts
- Storage System ↔ Extension Components

**┌─────────────────────────────────── WXT Framework ───────────────────────────────────┐**

- ┌─── Development Tools ────┐    ┌─── Build Pipeline ────┐    ┌─── Output ─────┐   │

- CLI Interface         │───▶│ - Vite Builder       │───▶│ - MV2 Bundle   │   │
- Dev Server           │    │ - Asset Processing   │    │ - MV3 Bundle   │   │
- HMR System           │    │ - Code Splitting     │    │ - Source Maps  │   │

- ┘    └───────────────────────┘    └─────────────────┘   │

- ┌─── Module System ───────┐    ┌─── Core Features ────┐    ┌─── Extensions ───┐   │

- Auto Imports         │    │ - TypeScript Support │    │ - Background    │   │
- Virtual Modules      │◀──▶│ - Framework Support  │◀──▶│ - Content      │   │
- Plugin System        │    │ - Auto-reload        │    │ - Popup/UI     │   │

- ┘    └───────────────────────┘    └─────────────────┘   │

- ┘

##### Important Details

a. Integration Points:
- Framework compatibility (Vue, React, Svelte)
- Browser API connections
- Development tooling hooks

- Build process flow
- Module dependencies
- Runtime communication

##### Implementation Notes

- The file-based entrypoint system
- The modular architecture
- The build optimization pipeline
- Cross-browser compatibility
- Development workflow efficiency

This system design should be implemented using a professional diagramming tool that supports:
- Clear hierarchical layouts
- Export in high resolution
- Easy maintenance and updates

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph WXT["WXT Framework"]
        subgraph DevTools["Development Tools"]
            CLI["CLI Interface"]:::cli
            DevServer["Development Server"]:::server
            HMR["HMR System"]:::hmr
            DevUtils["Development Utilities"]:::devutils
        end

        subgraph BuildPipe["Build Pipeline"]
            ViteBuilder["Vite Builder"]:::builder
            AssetProc["Asset Processing"]
            CodeSplit["Code Splitting"]
        end

        subgraph Output["Output"]
            MV2["MV2 Bundle"]
            MV3["MV3 Bundle"]
            SourceMaps["Source Maps"]
        end

        subgraph ModSys["Module System"]
            AutoImports["Auto Imports"]:::modules
            VirtualMods["Virtual Modules"]:::virtual
            PluginSys["Plugin System"]
        end

        subgraph CoreFeats["Core Features"]
            TSSupport["TypeScript Support"]
            FrameworkSupport["Framework Support"]
            Config["Configuration System"]:::config
        end

        subgraph Ext["Extensions"]
            Background["Background Scripts"]:::background
            Content["Content Scripts"]:::content
            UI["UI Components"]:::ui
            Storage["Storage Management"]:::storage
            ExtAPI["Extension APIs"]:::api
        end

        %% Relationships
        DevTools --> BuildPipe
        BuildPipe --> Output
        ModSys <--> CoreFeats
        CoreFeats <--> Ext
        
        %% Component relationships
        CLI --> DevServer
        DevServer --> HMR
        ViteBuilder --> CodeSplit
        AutoImports --> VirtualMods
        Background <--> Content
        Content <--> UI
        Storage <--> ExtAPI
    end

    %% Styling
    classDef cli fill:#a8d5ff
    classDef server fill:#a8d5ff
    classDef hmr fill:#a8d5ff
    classDef devutils fill:#a8d5ff
    classDef builder fill:#90EE90
    classDef modules fill:#DDA0DD
    classDef virtual fill:#DDA0DD
    classDef config fill:#FFE4B5
    classDef background fill:#FFB6C1
    classDef content fill:#FFB6C1
    classDef ui fill:#FFB6C1
    classDef storage fill:#FFB6C1
    classDef api fill:#FFB6C1

    %% Click events
    click CLI "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/cli/"
    click DevServer "https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/core/create-server.ts"
    click DevUtils "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/core/utils/building/"
    click ViteBuilder "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/core/builders/vite/"
    click AutoImports "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/builtin-modules/"
    click VirtualMods "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/virtual/"
    click Config "https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/core/resolve-config.ts"
    click Background "https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/sandbox/define-background.ts"
    click Content "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/client/content-scripts/"
    click UI "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/client/content-scripts/ui/"
    click Storage "https://github.com/wxt-dev/wxt/tree/main/packages/storage/src/"
    click ExtAPI "https://github.com/wxt-dev/wxt/tree/main/packages/wxt/src/browser/"
```
