# ER図

Windows Terminal プロジェクトのデータモデル間のリレーションを示すER図。

本プロジェクトはRDBを使用せずJSONファイルベースの永続化を採用しているため、本図は論理エンティティ間の参照関係を表現している。

## 全体構造

```mermaid
erDiagram
    CascadiaSettings ||--|| GlobalAppSettings : "has"
    CascadiaSettings ||--|| ActionMap : "has"
    CascadiaSettings ||--|{ Profile : "contains"
    CascadiaSettings ||--o{ ExtensionPackage : "has"

    GlobalAppSettings ||--o{ ColorScheme : "manages"
    GlobalAppSettings ||--o{ Theme : "manages"
    GlobalAppSettings ||--|| ActionMap : "references"
    GlobalAppSettings ||--o{ NewTabMenuEntry : "configures"

    Profile ||--|| AppearanceConfig : "has default"
    Profile ||--o| AppearanceConfig : "has unfocused"
    Profile ||--|| FontConfig : "has"

    AppearanceConfig }o--o| ColorScheme : "references (dark)"
    AppearanceConfig }o--o| ColorScheme : "references (light)"

    Theme ||--o| WindowTheme : "has"
    Theme ||--o| TabRowTheme : "has"
    Theme ||--o| TabTheme : "has"
    Theme ||--o| SettingsTheme : "has"

    ActionMap ||--o{ Command : "contains"
    Command ||--o| ActionAndArgs : "executes"

    NewTabMenuEntry ||--o| Profile : "links to"
    NewTabMenuEntry ||--o{ NewTabMenuEntry : "nests (FolderEntry)"

    ApplicationState ||--o{ WindowLayout : "persists"
    WindowLayout ||--o{ ActionAndArgs : "contains tab actions"

    ExtensionPackage ||--|{ FragmentSettings : "includes"

    CascadiaSettings {
        hstring Hash
    }

    GlobalAppSettings {
        hstring DefaultProfile
        int32 InitialRows
        int32 InitialCols
        bool AlwaysShowTabs
        enum LaunchMode
        enum TabSwitcherMode
        enum WindowingBehavior
        hstring StartupActions
        hstring SearchWebDefaultQueryUrl
    }

    Profile {
        guid Guid PK
        hstring Name
        hstring Source
        bool Hidden
        hstring Commandline
        hstring StartingDirectory
        int32 HistorySize
        enum CloseOnExit
        enum BellStyle
        enum ScrollState
        bool Elevate
    }

    AppearanceConfig {
        hstring DarkColorSchemeName FK
        hstring LightColorSchemeName FK
        Color Foreground
        Color Background
        float Opacity
        enum CursorShape
        uint32 CursorHeight
        hstring BackgroundImagePath
        bool UseAcrylic
    }

    FontConfig {
        hstring FontFace
        float FontSize
        FontWeight FontWeight
        bool EnableBuiltinGlyphs
        bool EnableColorGlyphs
    }

    ColorScheme {
        hstring Name PK
        Color Foreground
        Color Background
        Color SelectionBackground
        Color CursorColor
        Color Black
        Color Red
        Color Green
        Color Yellow
        Color Blue
        Color Purple
        Color Cyan
        Color White
        Color BrightBlack
        Color BrightRed
        Color BrightGreen
        Color BrightYellow
        Color BrightBlue
        Color BrightPurple
        Color BrightCyan
        Color BrightWhite
    }

    Theme {
        hstring Name PK
    }

    WindowTheme {
        enum RequestedTheme
        ThemeColor Frame
        ThemeColor UnfocusedFrame
        bool RainbowFrame
        bool UseMica
    }

    TabRowTheme {
        ThemeColor Background
        ThemeColor UnfocusedBackground
    }

    TabTheme {
        ThemeColor Background
        ThemeColor UnfocusedBackground
        enum IconStyle
        enum ShowCloseButton
    }

    SettingsTheme {
        enum RequestedTheme
    }

    Command {
        hstring ID PK
        hstring Name
        hstring Description
        IMediaResource Icon
        enum IterateOn
    }

    ActionAndArgs {
        enum Action
        IActionArgs Args
    }

    ActionMap {
        map KeyBindings
        map GlobalHotkeys
        map NameMap
    }

    NewTabMenuEntry {
        enum Type
        hstring Name
        hstring ActionId
        Profile Profile
    }

    ApplicationState {
        hstring SettingsHash
        set GeneratedProfiles
        bool SSHFolderGenerated
        list RecentCommands
        list DismissedMessages
    }

    WindowLayout {
        list TabLayout
        LaunchPosition InitialPosition
        Size InitialSize
        enum LaunchMode
    }

    ExtensionPackage {
        hstring Source
        enum Scope
        hstring DisplayName
        hstring Icon
    }

    FragmentSettings {
        hstring Source
        hstring Json
        hstring Filename
    }
```

## 設定継承関係図

```mermaid
graph TD
    A["defaults.json<br/>(デフォルト設定)"] --> C["CascadiaSettings<br/>(マージ結果)"]
    B["settings.json<br/>(ユーザー設定)"] --> C
    D["Fragments<br/>(拡張パッケージ)"] --> C

    C --> E["GlobalAppSettings"]
    C --> F["Profiles"]
    C --> G["ActionMap"]

    E --> H["ColorSchemes Map"]
    E --> I["Themes Map"]
    E --> J["NewTabMenu"]

    F --> K["Profile Defaults<br/>(profiles.defaults)"]
    F --> L["Profile List<br/>(profiles.list)"]

    K -->|"継承"| L

    L --> M["AppearanceConfig"]
    L --> N["FontConfig"]
    M -->|"参照"| H

    style A fill:#e1f5fe
    style B fill:#fff3e0
    style D fill:#f3e5f5
    style C fill:#e8f5e9
    style K fill:#fff9c4
```

## アプリケーション状態の永続化構造

```mermaid
graph LR
    S["state.json"] --> SA["ApplicationState"]

    SA --> SH["Shared スコープ"]
    SA --> SL["Local スコープ"]

    SH --> SH1["SettingsHash"]
    SH --> SH2["GeneratedProfiles"]
    SH --> SH3["RecentCommands"]
    SH --> SH4["DismissedMessages"]
    SH --> SH5["SSHFolderGenerated"]

    SL --> SL1["PersistedWindowLayouts"]
    SL --> SL2["AllowedCommandlines"]
    SL --> SL3["DismissedBadges"]

    SL1 --> WL["WindowLayout"]
    WL --> WL1["TabLayout"]
    WL --> WL2["InitialPosition"]
    WL --> WL3["InitialSize"]
    WL --> WL4["LaunchMode"]

    style S fill:#e1f5fe
    style SH fill:#e8f5e9
    style SL fill:#fff3e0
```
