# shikijs/shiki-magic-move architecture

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

- Interactive diagram: https://gitdiagram.com/shikijs/shiki-magic-move
- Repository: https://github.com/shikijs/shiki-magic-move

## Overview

##### Project type and purpose
- Project type: An open-source, framework-agnostic library for animating syntax-highlighted code blocks on the client (browser).
- Purpose: Provide a core engine plus renderer abstractions and framework-specific wrappers (Vue, React, Solid, Svelte, Web Component) that use Shiki for syntax highlighting, animate diffs of code, and ship styles. Also includes a Playground example app.

##### File structure
- Top-level:
· config (build.config.ts, eslint.config.js, netlify.toml, CI workflows)
· package.json, pnpm-workspace.yaml (monorepo style)
· src/ (core library code)
· test/ (unit tests)
· playground/ (demo app)
- src/:
· core.ts + renderer.ts — framework-agnostic engine + renderer
· framework folders (react/, vue/, solid/, svelte/, web-component/) each with:
– ShikiMagicMove.ts(x/.svelte) – main component
– ShikiMagicMovePrecompiled.ts(x/.svelte) – precompiled variant
– ShikiMagicMoveRenderer.ts(x/.svelte) – low-level renderer
– index.ts and utils.ts
· entry points (react.ts, vue.ts, etc.) that re-export each wrapper
· types.ts — shared TypeScript types
- playground/:
· Vite-based sample application demonstrating each renderer
· index.html, App.vue, and multiple renderer examples
- CI/CD:
· GitHub workflows for testing & release, Netlify config for hosting Playground

##### README for additional insights
- Describes core and renderer as framework-agnostic foundation
- Lists each wrapper’s components and usage patterns
- Notes external dependency: Shiki highlighter
- Shows how Precompiled component bypasses Shiki to animate serialized tokens
- Points to an online demo and blog post for deeper explanation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Library
    subgraph "Core Library"
        direction TB
        CoreEngine["Core Engine\n(src/core.ts)"]:::core
        Renderer["Renderer\n(src/renderer.ts)"]:::core
        SharedTypes["Shared Types\n(src/types.ts)"]:::core
        StyleCSS["Stylesheet Asset\n(src/style.css)"]:::core
        EntryIndex["Library Entry\n(src/index.ts)"]:::core
    end

    CoreEngine -->|uses| Renderer
    EntryIndex -->|exports| CoreEngine
    EntryIndex -->|exports| Renderer
    EntryIndex -->|exports| SharedTypes

    %% Framework Adapters
    subgraph "Framework Adapters"
        direction TB

        subgraph React
            direction TB
            ReactComp["Component\nShikiMagicMove.tsx"]:::adapter
            ReactPre["Precompiled\nShikiMagicMovePrecompiled.tsx"]:::adapter
            ReactRender["Renderer Adapter\nShikiMagicMoveRenderer.tsx"]:::adapter
            ReactUtils["Utils\nutils.ts"]:::adapter
            ReactEntry["Entry Point\nreact.ts"]:::adapter
        end

        subgraph Vue
            direction TB
            VueComp["Component\nShikiMagicMove.ts"]:::adapter
            VuePre["Precompiled\nShikiMagicMovePrecompiled.ts"]:::adapter
            VueRender["Renderer Adapter\nShikiMagicMoveRenderer.ts"]:::adapter
            VueUtils["Utils\nutils.ts"]:::adapter
            VueEntry["Entry Point\nvue.ts"]:::adapter
        end

        subgraph Solid
            direction TB
            SolidComp["Component\nShikiMagicMove.tsx"]:::adapter
            SolidPre["Precompiled\nShikiMagicMovePrecompiled.tsx"]:::adapter
            SolidRender["Renderer Adapter\nShikiMagicMoveRenderer.tsx"]:::adapter
            SolidUtils["Utils\nutils.ts"]:::adapter
            SolidEntry["Entry Point\nsolid.ts"]:::adapter
        end

        subgraph Svelte
            direction TB
            SvelteComp["Component\nShikiMagicMove.svelte"]:::adapter
            SveltePre["Precompiled\nShikiMagicMovePrecompiled.svelte"]:::adapter
            SvelteRender["Renderer Adapter\nShikiMagicMoveRenderer.svelte"]:::adapter
            SvelteEntry["Entry Point\nsvelte.ts"]:::adapter
        end

        subgraph WebComponent
            direction TB
            WCComp["Component\nShikiMagicMove.ts"]:::adapter
            WCPre["Precompiled\nShikiMagicMovePrecompiled.ts"]:::adapter
            WCRender["Renderer Adapter\nShikiMagicMoveRenderer.ts"]:::adapter
            WCEntry["Entry Point\nweb-component.ts"]:::adapter
        end
    end

    %% Dependencies
    subgraph "External Dependencies"
        direction TB
        Shiki["Shiki Highlighter"]:::external
    end

    %% Playground
    subgraph "Playground App"
        direction TB
        AppShell["App Shell\nApp.vue"]:::example
        PlaygroundComp["Playground Component\nPlayground.vue"]:::example
        Fixture["Fixture/Data\nfixture.ts"]:::example
        RendererExamples["Renderer Examples"]:::example
        MainEntry["Entry Script\nmain.ts"]:::example
        HTMLHost["HTML Host\nindex.html"]:::example
    end

    %% Build & CI/CD
    subgraph "Build & CI/CD"
        direction TB
        RollupConfig["Rollup Config\nbuild.config.ts"]:::tooling
        ViteConfig["Vite Config\nplayground/vite.config.ts"]:::tooling
        ESLint["ESLint Config\neslint.config.js"]:::tooling
        Workspace["pnpm-workspace.yaml"]:::tooling
        PackageJSON["package.json"]:::tooling
        CI["GitHub Actions"]:::tooling
        Netlify["Netlify Config\nnetlify.toml"]:::tooling
    end

    %% Relationships
    ReactComp -->|calls| CoreEngine
    ReactComp -->|calls| Renderer
    ReactComp -->|uses| Shiki
    ReactPre -->|bypasses| Shiki
    ReactRender -->|invokes| Renderer

    VueComp -->|calls| CoreEngine
    VueComp -->|calls| Renderer
    VueComp -->|uses| Shiki
    VuePre -->|bypasses| Shiki
    VueRender -->|invokes| Renderer

    SolidComp -->|calls| CoreEngine
    SolidComp -->|calls| Renderer
    SolidComp -->|uses| Shiki
    SolidPre -->|bypasses| Shiki
    SolidRender -->|invokes| Renderer

    SvelteComp -->|calls| CoreEngine
    SvelteComp -->|calls| Renderer
    SvelteComp -->|uses| Shiki
    SveltePre -->|bypasses| Shiki
    SvelteRender -->|invokes| Renderer

    WCComp -->|calls| CoreEngine
    WCComp -->|calls| Renderer
    WCComp -->|uses| Shiki
    WCPre -->|bypasses| Shiki
    WCRender -->|invokes| Renderer

    RendererExamples -->|imports wrappers| ReactEntry
    RendererExamples -->|imports wrappers| VueEntry
    RendererExamples -->|imports wrappers| SolidEntry
    RendererExamples -->|imports wrappers| SvelteEntry
    RendererExamples -->|imports wrappers| WCEntry

    AppShell -->|includes| PlaygroundComp
    PlaygroundComp -->|uses| Fixture
    PlaygroundComp -->|renders examples| RendererExamples
    MainEntry -->|bootstraps| AppShell
    HTMLHost -->|hosts| MainEntry

    CI -->|runs| RollupConfig
    CI -->|runs| ViteConfig
    CI -->|uses| ESLint
    CI -->|validates| PackageJSON
    Netlify -->|deploys| PlaygroundApp

    %% Click Events
    click CoreEngine "https://github.com/shikijs/shiki-magic-move/blob/main/src/core.ts"
    click Renderer "https://github.com/shikijs/shiki-magic-move/blob/main/src/renderer.ts"
    click SharedTypes "https://github.com/shikijs/shiki-magic-move/blob/main/src/types.ts"
    click StyleCSS "https://github.com/shikijs/shiki-magic-move/blob/main/src/style.css"

    click ReactComp "https://github.com/shikijs/shiki-magic-move/blob/main/src/react/ShikiMagicMove.tsx"
    click ReactPre "https://github.com/shikijs/shiki-magic-move/blob/main/src/react/ShikiMagicMovePrecompiled.tsx"
    click ReactRender "https://github.com/shikijs/shiki-magic-move/blob/main/src/react/ShikiMagicMoveRenderer.tsx"
    click ReactUtils "https://github.com/shikijs/shiki-magic-move/blob/main/src/react/utils.ts"
    click ReactEntry "https://github.com/shikijs/shiki-magic-move/blob/main/src/react.ts"

    click VueComp "https://github.com/shikijs/shiki-magic-move/blob/main/src/vue/ShikiMagicMove.ts"
    click VuePre "https://github.com/shikijs/shiki-magic-move/blob/main/src/vue/ShikiMagicMovePrecompiled.ts"
    click VueRender "https://github.com/shikijs/shiki-magic-move/blob/main/src/vue/ShikiMagicMoveRenderer.ts"
    click VueUtils "https://github.com/shikijs/shiki-magic-move/blob/main/src/vue/utils.ts"
    click VueEntry "https://github.com/shikijs/shiki-magic-move/blob/main/src/vue.ts"

    click SolidComp "https://github.com/shikijs/shiki-magic-move/blob/main/src/solid/ShikiMagicMove.tsx"
    click SolidPre "https://github.com/shikijs/shiki-magic-move/blob/main/src/solid/ShikiMagicMovePrecompiled.tsx"
    click SolidRender "https://github.com/shikijs/shiki-magic-move/blob/main/src/solid/ShikiMagicMoveRenderer.tsx"
    click SolidUtils "https://github.com/shikijs/shiki-magic-move/blob/main/src/solid/utils.ts"
    click SolidEntry "https://github.com/shikijs/shiki-magic-move/blob/main/src/solid.ts"

    click SvelteComp "https://github.com/shikijs/shiki-magic-move/blob/main/src/svelte/ShikiMagicMove.svelte"
    click SveltePre "https://github.com/shikijs/shiki-magic-move/blob/main/src/svelte/ShikiMagicMovePrecompiled.svelte"
    click SvelteRender "https://github.com/shikijs/shiki-magic-move/blob/main/src/svelte/ShikiMagicMoveRenderer.svelte"
    click SvelteEntry "https://github.com/shikijs/shiki-magic-move/blob/main/src/svelte.ts"

    click WCComp "https://github.com/shikijs/shiki-magic-move/blob/main/src/web-component/ShikiMagicMove.ts"
    click WCPre "https://github.com/shikijs/shiki-magic-move/blob/main/src/web-component/ShikiMagicMovePrecompiled.ts"
    click WCRender "https://github.com/shikijs/shiki-magic-move/blob/main/src/web-component/ShikiMagicMoveRenderer.ts"
    click WCEntry "https://github.com/shikijs/shiki-magic-move/blob/main/src/web-component.ts"

    click EntryIndex "https://github.com/shikijs/shiki-magic-move/blob/main/src/index.ts"

    click AppShell "https://github.com/shikijs/shiki-magic-move/blob/main/playground/src/App.vue"
    click PlaygroundComp "https://github.com/shikijs/shiki-magic-move/blob/main/playground/src/Playground.vue"
    click Fixture "https://github.com/shikijs/shiki-magic-move/blob/main/playground/src/fixture.ts"
    click MainEntry "https://github.com/shikijs/shiki-magic-move/blob/main/playground/src/main.ts"
    click HTMLHost "https://github.com/shikijs/shiki-magic-move/blob/main/playground/index.html"

    click RollupConfig "https://github.com/shikijs/shiki-magic-move/blob/main/build.config.ts"
    click ViteConfig "https://github.com/shikijs/shiki-magic-move/blob/main/playground/vite.config.ts"
    click ESLint "https://github.com/shikijs/shiki-magic-move/blob/main/eslint.config.js"
    click Workspace "https://github.com/shikijs/shiki-magic-move/blob/main/pnpm-workspace.yaml"
    click PackageJSON "https://github.com/shikijs/shiki-magic-move/blob/main/package.json"
    click CI "https://github.com/shikijs/shiki-magic-move/blob/main/.github/workflows/ci.yml"
    click Netlify "https://github.com/shikijs/shiki-magic-move/blob/main/netlify.toml"

    %% Styles
    classDef core fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef adapter fill:#E6FFEA,stroke:#28a745,color:#28a745
    classDef external fill:#FFF4E6,stroke:#d15704,color:#d15704
    classDef example fill:#F3E8FF,stroke:#6f42c1,color:#6f42c1
    classDef tooling fill:#EDEEF0,stroke:#586069,color:#586069
```
