# アーキテクチャ構成図

## 1. システム全体構成図

```mermaid
graph TB
    subgraph "Windows Terminal プロダクト"
        WT_EXE["wt.exe<br/>(エントリポイントシム)"]
        MAIN["WindowsTerminal.exe<br/>(main.cpp)"]
        WE["WindowEmperor<br/>(プロセス・ウィンドウ管理)"]
        AH["AppHost<br/>(ウィンドウホスト)"]
        IW["IslandWindow / NonClientIslandWindow<br/>(Win32ウィンドウ + XAML Islands)"]
    end

    subgraph "Console Host プロダクト"
        CONHOST["conhost.exe<br/>(Console Host)"]
        SERVER["server<br/>(ApiDispatchers, IoDispatchers)"]
        INTERACT["interactivity<br/>(win32 / onecore)"]
    end

    subgraph "共有コンポーネント"
        CORE["TerminalCore<br/>(Terminal class)"]
        PARSER["terminal/parser<br/>(StateMachine)"]
        ADAPTER["terminal/adapter<br/>(AdaptDispatch)"]
        INPUT["terminal/input<br/>(TerminalInput)"]
        BUFFER["buffer/out<br/>(TextBuffer)"]
        RENDERER_BASE["renderer/base<br/>(Renderer)"]
        TYPES["types<br/>(共通型定義)"]
        TIL["til<br/>(Terminal Implementation Library)"]
    end

    subgraph "レンダラー群"
        ATLAS["renderer/atlas<br/>(AtlasEngine - DirectX 11)"]
        GDI["renderer/gdi<br/>(GdiEngine)"]
        UIA_R["renderer/uia<br/>(UiaEngine)"]
    end

    subgraph "外部システム"
        SHELL["シェルプロセス<br/>(cmd, PowerShell, WSL等)"]
        CONDRV["condrv.sys<br/>(コンソールドライバ)"]
        DX["DirectX 11<br/>(GPU)"]
        UIA_EXT["UI Automation<br/>(スクリーンリーダー)"]
    end

    WT_EXE --> MAIN
    MAIN --> WE
    WE --> AH
    AH --> IW

    CONHOST --> SERVER
    CONHOST --> INTERACT

    IW -.->|XAML Islands| CORE
    SERVER --> BUFFER
    SERVER --> PARSER

    CORE --> PARSER
    CORE --> INPUT
    CORE --> BUFFER
    PARSER --> ADAPTER
    ADAPTER --> BUFFER

    RENDERER_BASE --> ATLAS
    RENDERER_BASE --> GDI
    RENDERER_BASE --> UIA_R

    CORE -.->|IRenderData| RENDERER_BASE
    CONHOST -.->|IRenderData| RENDERER_BASE

    ATLAS --> DX
    UIA_R --> UIA_EXT
    CONHOST --> CONDRV
    CORE -.->|ConPTY| SHELL
```

## 2. Windows Terminal レイヤー構成図

```mermaid
graph TB
    subgraph "Presentation Layer"
        direction TB
        MAIN2["main.cpp / WindowEmperor"]
        APPHOST["AppHost"]
        ISLAND["IslandWindow<br/>(XAML Islands)"]
        APPLOGIC["AppLogic"]
        TERMWIN["TerminalWindow"]
        TAB["Tab"]
        PANE["Pane (Tree)"]
        CMDPAL["CommandPalette"]
        SETTINGS_UI["TerminalSettingsEditor"]
    end

    subgraph "Control Layer"
        direction TB
        TERMCONTROL["TermControl<br/>(XAML UserControl)"]
        CTRL_INTER["ControlInteractivity<br/>(ユーザー操作処理)"]
        CTRL_CORE["ControlCore<br/>(ロジック統合)"]
    end

    subgraph "Core Layer"
        direction TB
        TERMINAL["Terminal<br/>(ITerminalApi + IRenderData + ITerminalInput)"]
        SM["StateMachine<br/>(VTパーサー)"]
        AD["AdaptDispatch<br/>(VTディスパッチャー)"]
        TI["TerminalInput<br/>(キー→VT変換)"]
        TB2["TextBuffer<br/>(テキストバッファ)"]
    end

    subgraph "Settings Model Layer"
        direction TB
        CS["CascadiaSettings"]
        PROFILE["Profile"]
        GLOBAL["GlobalAppSettings"]
        ACTIONMAP["ActionMap"]
        COLORSCHEME["ColorScheme"]
    end

    subgraph "Connection Layer"
        direction TB
        ICONN["ITerminalConnection"]
        CONPTY_CONN["ConptyConnection"]
        AZURE_CONN["AzureConnection"]
        ECHO_CONN["EchoConnection"]
    end

    subgraph "Renderer Layer"
        direction TB
        REND["Renderer"]
        ATLAS2["AtlasEngine<br/>(DirectX 11 GPU)"]
        UIA_ENG["UiaEngine<br/>(アクセシビリティ)"]
    end

    MAIN2 --> APPHOST
    APPHOST --> ISLAND
    APPHOST --> APPLOGIC
    APPLOGIC --> TERMWIN
    TERMWIN --> TAB
    TAB --> PANE
    PANE --> TERMCONTROL

    TERMCONTROL --> CTRL_INTER
    CTRL_INTER --> CTRL_CORE

    CTRL_CORE --> TERMINAL
    CTRL_CORE --> REND
    CTRL_CORE --> ICONN

    TERMINAL --> SM
    TERMINAL --> TI
    TERMINAL --> TB2
    SM --> AD
    AD --> TB2

    REND --> ATLAS2
    REND --> UIA_ENG
    TERMINAL -.->|IRenderData| REND

    ICONN --> CONPTY_CONN
    ICONN --> AZURE_CONN
    ICONN --> ECHO_CONN

    APPLOGIC --> CS
    CS --> PROFILE
    CS --> GLOBAL
    CS --> ACTIONMAP
    CS --> COLORSCHEME

    CTRL_CORE -.->|IControlSettings| CS
```

## 3. データフロー図（ユーザー入力 -> シェル -> 画面描画）

```mermaid
sequenceDiagram
    participant User as ユーザー
    participant IW as IslandWindow
    participant TC as TermControl
    participant CI as ControlInteractivity
    participant CC as ControlCore
    participant T as Terminal
    participant TI as TerminalInput
    participant Conn as ConptyConnection
    participant Shell as シェルプロセス
    participant SM as StateMachine
    participant AD as AdaptDispatch
    participant TB as TextBuffer
    participant R as Renderer
    participant AE as AtlasEngine

    Note over User, AE: --- ユーザー入力の流れ ---
    User->>IW: キーボード入力 (WM_KEYDOWN)
    IW->>TC: KeyDown イベント
    TC->>CI: _KeyHandler()
    CI->>CC: TrySendKeyEvent()
    CC->>T: SendKeyEvent()
    T->>TI: HandleKey()
    TI-->>T: VTシーケンス文字列
    T-->>CC: _pfnWriteInput コールバック
    CC->>Conn: WriteInput()
    Conn->>Shell: パイプ書き込み

    Note over User, AE: --- シェル出力の流れ ---
    Shell->>Conn: パイプ出力
    Conn-->>CC: TerminalOutput イベント
    CC->>T: Write()
    T->>SM: ProcessString()
    SM->>AD: アクションディスパッチ
    AD->>TB: テキスト書き込み・属性設定
    TB-->>R: 無効化通知
    R->>AE: PaintFrame()
    AE->>User: DirectX 画面描画
```

## 4. Console Host データフロー図

```mermaid
sequenceDiagram
    participant Client as クライアントプロセス
    participant ConDrv as condrv.sys
    participant IoDisp as IoDispatchers
    participant ApiDisp as ApiDispatchers
    participant Host as host (conhost)
    participant TB as TextBuffer
    participant SM as StateMachine
    participant AD as AdaptDispatch
    participant R as Renderer
    participant GDI as GdiEngine / AtlasEngine

    Client->>ConDrv: WriteConsole / ReadConsole API
    ConDrv->>IoDisp: I/O リクエスト
    IoDisp->>ApiDisp: API ディスパッチ
    ApiDisp->>Host: API ルーチン実行

    alt VT出力が有効
        Host->>SM: VTシーケンスパース
        SM->>AD: アクションディスパッチ
        AD->>TB: テキスト書き込み
    else レガシー出力
        Host->>TB: 直接テキスト書き込み
    end

    TB-->>R: 無効化通知
    R->>GDI: 画面描画
```

## 5. コンポーネント依存関係図

```mermaid
graph LR
    subgraph "Windows Terminal"
        WT[WindowsTerminal]
        TA[TerminalApp]
        TCO[TerminalControl]
        TSM[TerminalSettingsModel]
        TSE[TerminalSettingsEditor]
        TCONN[TerminalConnection]
        TCORE[TerminalCore]
        REM[Remoting]
    end

    subgraph "Console Host"
        HOST[host]
        SRV[server]
        INT[interactivity]
        CONPTY[winconpty]
        PROP[propslib / propsheet]
    end

    subgraph "共有コンポーネント"
        PARS[terminal/parser]
        ADPT[terminal/adapter]
        INPT[terminal/input]
        BUF[buffer/out]
        RBASE[renderer/base]
        RATL[renderer/atlas]
        RGDI[renderer/gdi]
        RUIA[renderer/uia]
        TYP[types]
    end

    WT --> TA
    TA --> TCO
    TA --> TSM
    TA --> REM
    TCO --> TCORE
    TCO --> TCONN
    TCO --> RATL
    TCO --> RUIA
    TSE --> TSM
    TCORE --> PARS
    TCORE --> INPT
    TCORE --> BUF
    TCONN --> CONPTY

    HOST --> SRV
    HOST --> INT
    HOST --> BUF
    HOST --> PARS
    HOST --> CONPTY
    HOST --> PROP
    SRV --> BUF

    PARS --> ADPT
    ADPT --> BUF

    RBASE --> RATL
    RBASE --> RGDI
    RBASE --> RUIA

    TCO --> RBASE
    HOST --> RBASE
    HOST --> RATL
    HOST --> RGDI

    TCORE --> TYP
    BUF --> TYP
    RBASE --> TYP
```

## 6. ペインツリー構造図

```mermaid
graph TB
    subgraph "Tab"
        ROOT["Pane (Root)<br/>SplitState: Vertical"]
        LEFT["Pane (Left)<br/>SplitState: None"]
        RIGHT["Pane (Right)<br/>SplitState: Horizontal"]
        RT["Pane (Right-Top)<br/>SplitState: None"]
        RB["Pane (Right-Bottom)<br/>SplitState: None"]
    end

    ROOT --> LEFT
    ROOT --> RIGHT
    RIGHT --> RT
    RIGHT --> RB

    LEFT --- TC1["TerminalPaneContent<br/>-> TermControl<br/>-> ControlCore<br/>-> Terminal"]
    RT --- TC2["TerminalPaneContent<br/>-> TermControl<br/>-> ControlCore<br/>-> Terminal"]
    RB --- TC3["TerminalPaneContent<br/>-> TermControl<br/>-> ControlCore<br/>-> Terminal"]
```
