# インフラ構成図

## 全体構成図

```mermaid
flowchart TB
    subgraph Developer["開発者環境"]
        Dev[開発者]
        LocalNix[Nix DevShell]
        Zig[Zig Build System]
    end

    subgraph GitHub["GitHub"]
        Repo[ghostty-org/ghostty]
        Actions[GitHub Actions]
        Releases[GitHub Releases]
    end

    subgraph CI_Runners["CI/CD ランナー"]
        direction TB
        LinuxRunner[Linux Runner<br/>x86_64/ARM64]
        MacRunner[macOS Runner<br/>Tahoe]
        WinRunner[Windows Runner<br/>2022]
    end

    subgraph External["外部サービス"]
        Cachix[Cachix<br/>Nixキャッシュ]
        R2[Cloudflare R2<br/>tip.files.ghostty.org]
        Apple[Apple<br/>Notarization]
        Sentry[Sentry<br/>クラッシュレポート]
    end

    subgraph Distribution["配布チャネル"]
        Flathub[Flathub<br/>Flatpak]
        SnapStore[Snap Store]
        Homebrew[Homebrew]
    end

    Dev --> LocalNix
    LocalNix --> Zig
    Dev --> Repo
    Repo --> Actions
    Actions --> LinuxRunner
    Actions --> MacRunner
    Actions --> WinRunner

    LinuxRunner --> Cachix
    MacRunner --> Cachix

    LinuxRunner --> Releases
    MacRunner --> Releases
    MacRunner --> R2
    MacRunner --> Apple

    Releases --> Flathub
    Releases --> SnapStore
    Releases --> Homebrew

    MacRunner --> Sentry
```

## CI/CD パイプライン構成図

```mermaid
flowchart LR
    subgraph Trigger["トリガー"]
        Push[Push]
        PR[Pull Request]
        Dispatch[Manual Dispatch]
    end

    subgraph Skip["スキップ判定"]
        PathFilter[paths-filter]
        SkipCheck[skip判定]
    end

    subgraph Test["テストフェーズ"]
        UnitTest[Unit Test]
        FmtCheck[Format Check]
        LintCheck[Lint Check]
    end

    subgraph Build["ビルドフェーズ"]
        direction TB
        BuildLinux[Linux Build]
        BuildMacOS[macOS Build]
        BuildWin[Windows Build]
        BuildNix[Nix Package]
        BuildFlatpak[Flatpak Build]
        BuildSnap[Snap Build]
    end

    subgraph Release["リリースフェーズ"]
        GitHubRelease[GitHub Release]
        R2Upload[R2 Upload]
        Notarize[Apple Notarization]
        SentryUpload[Sentry Upload]
    end

    Push --> PathFilter
    PR --> PathFilter
    Dispatch --> PathFilter
    PathFilter --> SkipCheck
    SkipCheck --> UnitTest
    SkipCheck --> FmtCheck
    SkipCheck --> LintCheck

    UnitTest --> BuildLinux
    UnitTest --> BuildMacOS
    UnitTest --> BuildWin
    UnitTest --> BuildNix
    UnitTest --> BuildFlatpak
    UnitTest --> BuildSnap

    BuildMacOS --> Notarize
    Notarize --> GitHubRelease
    BuildLinux --> GitHubRelease

    GitHubRelease --> R2Upload
    Notarize --> SentryUpload
```

## ビルドターゲット構成図

```mermaid
flowchart TB
    subgraph Source["ソースコード"]
        ZigSrc[Zig Source<br/>src/]
        SwiftSrc[Swift Source<br/>macos/]
    end

    subgraph Build["Zig Build System"]
        direction TB
        BuildZig[build.zig]
        Config[Config Options]
    end

    subgraph Targets["ビルドターゲット"]
        direction TB
        subgraph Desktop["デスクトップ"]
            MacApp[macOS App<br/>Ghostty.app]
            LinuxGTK[Linux GTK<br/>ghostty]
            WinExe[Windows<br/>ghostty.exe]
        end

        subgraph Library["ライブラリ"]
            LibGhostty[libghostty<br/>.so/.a]
            LibVT[libghostty-vt<br/>.so/.wasm]
            XCFramework[GhosttyKit<br/>.xcframework]
        end

        subgraph Mobile["モバイル"]
            iOS[iOS<br/>aarch64]
            Android[Android<br/>aarch64/x86_64/arm]
        end
    end

    ZigSrc --> BuildZig
    SwiftSrc --> MacApp
    BuildZig --> Config
    Config --> MacApp
    Config --> LinuxGTK
    Config --> WinExe
    Config --> LibGhostty
    Config --> LibVT
    Config --> XCFramework
    Config --> iOS
    Config --> Android
```

## Nixパッケージ構成図

```mermaid
flowchart TB
    subgraph FlakeInputs["Flake Inputs"]
        nixpkgs[nixpkgs-unstable]
        zigOverlay[zig-overlay]
        zon2nix[zon2nix]
        homeManager[home-manager]
    end

    subgraph FlakeOutputs["Flake Outputs"]
        DevShells[devShells]
        Packages[packages]
        Overlays[overlays]
        Apps[apps]
        Checks[checks]
    end

    subgraph Packages_Detail["packages 詳細"]
        ghosttyDebug[ghostty-debug]
        ghosttyReleaseSafe[ghostty-releasesafe]
        ghosttyReleaseFast[ghostty-releasefast]
        deps[deps<br/>Zig依存パッケージ]
    end

    subgraph Apps_Detail["apps 詳細"]
        WaylandGnome[wayland-gnome]
        WaylandPlasma[wayland-plasma6]
        X11Xfce[x11-xfce]
        VMApps[...その他VM]
    end

    nixpkgs --> DevShells
    zigOverlay --> DevShells
    zon2nix --> DevShells

    nixpkgs --> Packages
    Packages --> ghosttyDebug
    Packages --> ghosttyReleaseSafe
    Packages --> ghosttyReleaseFast
    Packages --> deps

    Apps --> WaylandGnome
    Apps --> WaylandPlasma
    Apps --> X11Xfce
    Apps --> VMApps
```

## Dockerコンテナ構成図

```mermaid
flowchart TB
    subgraph DockerImages["Docker Images"]
        subgraph LibCDocs["lib-c-docs"]
            Builder1[archlinux:latest<br/>Builder Stage]
            Runtime1[nginx:alpine<br/>Runtime Stage]
        end

        subgraph Debian["debian"]
            DebianBase[debian:13<br/>Build Environment]
        end
    end

    subgraph LibCDocsProcess["lib-c-docs ビルドプロセス"]
        Doxygen[Doxygen]
        Graphviz[Graphviz]
        HTMLDocs[HTML Documentation]
    end

    subgraph DebianProcess["Debian ビルドプロセス"]
        ZigInstall[Zig Installation]
        DebianBuild[Ghostty Build]
        DebianTest[Version Check]
    end

    Builder1 --> Doxygen
    Doxygen --> HTMLDocs
    HTMLDocs --> Runtime1

    DebianBase --> ZigInstall
    ZigInstall --> DebianBuild
    DebianBuild --> DebianTest
```

## リリース配布構成図

```mermaid
flowchart TB
    subgraph Source["ソース"]
        MainBranch[main branch]
        Tag[Release Tag]
    end

    subgraph Build["ビルド成果物"]
        SourceTarball[Source Tarball<br/>.tar.gz + .minisig]
        MacUniversal[macOS Universal<br/>.zip + .dmg]
        MacDebug[macOS Debug<br/>slow/fast]
        dSYM[Debug Symbols<br/>.dSYM.zip]
    end

    subgraph Storage["ストレージ"]
        GitHubRel[GitHub Releases]
        R2Storage[Cloudflare R2<br/>tip.files.ghostty.org]
        Appcast[Sparkle Appcast<br/>appcast.xml]
    end

    subgraph Distribution["配布"]
        DirectDownload[Direct Download<br/>ghostty.org/download]
        SparkleUpdate[Sparkle Auto-Update]
        FlatpakDist[Flathub]
        SnapDist[Snap Store]
    end

    MainBranch --> SourceTarball
    MainBranch --> MacUniversal
    MainBranch --> MacDebug
    MacUniversal --> dSYM

    SourceTarball --> GitHubRel
    MacUniversal --> GitHubRel
    MacDebug --> GitHubRel

    MacUniversal --> R2Storage
    dSYM --> R2Storage
    R2Storage --> Appcast

    GitHubRel --> DirectDownload
    Appcast --> SparkleUpdate
    GitHubRel --> FlatpakDist
    GitHubRel --> SnapDist
```

## キャッシュ戦略構成図

```mermaid
flowchart TB
    subgraph CacheSources["キャッシュソース"]
        NixStore[Nix Store<br/>/nix]
        ZigCache[Zig Cache<br/>/zig]
        XcodeCache[Xcode Cache<br/>CompilationCache]
    end

    subgraph CacheServices["キャッシュサービス"]
        CachixService[Cachix<br/>ghostty.cachix.org]
        NSCloudCache[nscloud-cache-action]
    end

    subgraph CacheFlow["キャッシュフロー"]
        direction LR
        CacheHit[Cache Hit]
        CacheMiss[Cache Miss]
        CachePush[Cache Push]
    end

    NixStore --> CachixService
    NixStore --> NSCloudCache
    ZigCache --> NSCloudCache
    XcodeCache --> NSCloudCache

    CachixService --> CacheHit
    NSCloudCache --> CacheHit
    CacheMiss --> CachePush
    CachePush --> CachixService
    CachePush --> NSCloudCache
```
