# インフラ構成図

## システム全体構成図

```mermaid
flowchart TB
    subgraph Internet["インターネット"]
        User[("ユーザー")]
        Admin[("管理者")]
    end

    subgraph CDN["CDN / リバースプロキシ層（オプション）"]
        Varnish["Varnish / Fastly"]
    end

    subgraph WebTier["Webサーバー層"]
        LB["ロードバランサー"]
        subgraph WebServers["Webサーバー"]
            Web1["Caddy/Nginx #1"]
            Web2["Caddy/Nginx #2"]
        end
    end

    subgraph AppTier["アプリケーション層"]
        subgraph AppServers["APサーバー"]
            App1["PHP-FPM #1<br/>Shopware 6"]
            App2["PHP-FPM #2<br/>Shopware 6"]
        end
        subgraph Workers["ワーカー"]
            Worker1["Message Consumer #1"]
            Worker2["Message Consumer #2"]
        end
    end

    subgraph DataTier["データ層"]
        subgraph Database["データベース"]
            DB_Master[("MariaDB<br/>Master")]
            DB_Slave[("MariaDB<br/>Slave")]
        end
        subgraph Search["検索エンジン"]
            OS1["OpenSearch #1"]
            OS2["OpenSearch #2"]
            OS3["OpenSearch #3"]
        end
        subgraph Cache["キャッシュ"]
            Valkey["Valkey<br/>(Redis互換)"]
        end
    end

    subgraph External["外部サービス"]
        SMTP["SMTP Server"]
        S3["S3 / GCS<br/>ストレージ"]
        Store["Shopware Store"]
    end

    User --> CDN
    Admin --> CDN
    CDN --> LB
    LB --> Web1
    LB --> Web2
    Web1 --> App1
    Web1 --> App2
    Web2 --> App1
    Web2 --> App2

    App1 --> DB_Master
    App1 --> OS1
    App1 --> Valkey
    App2 --> DB_Master
    App2 --> OS2
    App2 --> Valkey

    Worker1 --> DB_Master
    Worker2 --> DB_Master

    DB_Master --> DB_Slave
    OS1 <--> OS2
    OS2 <--> OS3

    App1 --> SMTP
    App2 --> SMTP
    App1 --> S3
    App2 --> S3
    App1 --> Store
    App2 --> Store
```

## 開発環境構成図（Docker Compose）

```mermaid
flowchart TB
    subgraph Docker["Docker Compose環境"]
        subgraph Services["サービス"]
            Web["web<br/>ghcr.io/shopware/docker-dev:php8.4-node24-caddy<br/>:8000, :5173, :9998, :9999"]
            DB["database<br/>mariadb:latest<br/>:3306"]
            Adminer["adminer<br/>:9080"]
            Valkey["valkey<br/>valkey/valkey:alpine"]
            Mailer["mailer<br/>axllent/mailpit<br/>:8025"]
            OpenSearch["opensearch<br/>opensearchproject/opensearch:2<br/>:9200"]
        end

        subgraph Volumes["永続化ボリューム"]
            DBData[("db-data")]
            AppCode[(".:/var/www/html")]
        end
    end

    Developer[("開発者")] --> |"localhost:8000"| Web
    Developer --> |"localhost:9080"| Adminer
    Developer --> |"localhost:8025"| Mailer
    Developer --> |"localhost:3306"| DB

    Web --> |"DATABASE_URL"| DB
    Web --> |"OPENSEARCH_URL"| OpenSearch
    Web --> |"MAILER_DSN"| Mailer
    Web --> Valkey
    Adminer --> DB

    DB --> DBData
    Web --> AppCode
```

## ネットワークフロー図

```mermaid
flowchart LR
    subgraph Public["パブリックゾーン"]
        Internet(("インターネット"))
    end

    subgraph DMZ["DMZ"]
        LB["ロードバランサー<br/>:443 (HTTPS)"]
        CDN["CDN"]
    end

    subgraph AppZone["アプリケーションゾーン"]
        Web["Webサーバー<br/>:80, :443"]
        App["APサーバー<br/>PHP-FPM :9000"]
    end

    subgraph DataZone["データゾーン"]
        DB[("MariaDB<br/>:3306")]
        OS["OpenSearch<br/>:9200"]
        Cache["Valkey<br/>:6379"]
    end

    Internet --> |"HTTPS"| LB
    LB --> |"HTTP/HTTPS"| CDN
    CDN --> |"HTTP"| Web
    Web --> |"FastCGI"| App
    App --> |"MySQL Protocol"| DB
    App --> |"HTTP"| OS
    App --> |"RESP Protocol"| Cache
```

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

```mermaid
flowchart TB
    subgraph Frontend["フロントエンド"]
        Storefront["Storefront<br/>(Twig + JS)"]
        Administration["Administration<br/>(Vue.js)"]
    end

    subgraph Backend["バックエンド"]
        Core["Shopware Core<br/>(Symfony)"]
        Framework["Framework Bundle"]
        System["System Bundle"]
        Content["Content Bundle"]
        Checkout["Checkout Bundle"]
        Elasticsearch["Elasticsearch Bundle"]
    end

    subgraph Infrastructure["インフラストラクチャ"]
        PHP["PHP 8.2-8.5"]
        Symfony["Symfony 7.4"]
        Doctrine["Doctrine DBAL"]
        Monolog["Monolog"]
        Messenger["Symfony Messenger"]
    end

    subgraph DataStores["データストア"]
        MariaDB[("MariaDB")]
        OpenSearch[("OpenSearch")]
        Valkey[("Valkey")]
        Filesystem[("Filesystem<br/>/ S3 / GCS")]
    end

    Storefront --> Core
    Administration --> Core
    Core --> Framework
    Core --> System
    Core --> Content
    Core --> Checkout
    Core --> Elasticsearch

    Framework --> PHP
    Framework --> Symfony
    Framework --> Doctrine
    Framework --> Monolog
    Framework --> Messenger

    Doctrine --> MariaDB
    Elasticsearch --> OpenSearch
    Messenger --> MariaDB
    Messenger --> Valkey
    Content --> Filesystem
```

## メッセージキュー構成図

```mermaid
flowchart LR
    subgraph Producers["プロデューサー"]
        HTTP["HTTPリクエスト"]
        CLI["CLIコマンド"]
        Scheduler["スケジューラー"]
    end

    subgraph MessageBus["Symfony Messenger"]
        Bus["messenger.bus.default"]
        MW["QueuedTimeMiddleware"]
    end

    subgraph Transports["トランスポート"]
        Async["async<br/>(doctrine://default)"]
        LowPriority["low_priority<br/>(doctrine://default)"]
        Failed["failed<br/>(doctrine://default)"]
    end

    subgraph Consumers["コンシューマー"]
        Worker1["Worker #1"]
        Worker2["Worker #2"]
    end

    subgraph Storage["ストレージ"]
        DB[("MariaDB<br/>messenger_messages")]
    end

    HTTP --> Bus
    CLI --> Bus
    Scheduler --> Bus
    Bus --> MW
    MW --> Async
    MW --> LowPriority

    Async --> DB
    LowPriority --> DB
    Failed --> DB

    Worker1 --> Async
    Worker1 --> LowPriority
    Worker2 --> Async
    Worker2 --> LowPriority

    Worker1 -.-> |"失敗時"| Failed
    Worker2 -.-> |"失敗時"| Failed
```

## キャッシュアーキテクチャ図

```mermaid
flowchart TB
    subgraph Request["リクエスト処理"]
        Client["クライアント"]
        HTTPCache["HTTPキャッシュ<br/>(Varnish/Fastly)"]
        App["Shopwareアプリケーション"]
    end

    subgraph CacheLayers["キャッシュレイヤー"]
        subgraph AppCache["アプリケーションキャッシュ"]
            ObjectCache["cache.object<br/>(172800秒)"]
            HTTPCacheApp["cache.http<br/>(172800秒)"]
            TagsCache["cache.tags"]
            RateLimiter["cache.rate_limiter"]
        end

        subgraph Backend["キャッシュバックエンド"]
            Filesystem["Filesystem<br/>(デフォルト)"]
            ValkeyBackend["Valkey<br/>(オプション)"]
        end
    end

    subgraph Invalidation["キャッシュ無効化"]
        BAN["BAN/PURGE"]
        TagInvalidation["タグベース無効化"]
    end

    Client --> HTTPCache
    HTTPCache --> |"MISS"| App
    App --> ObjectCache
    App --> HTTPCacheApp
    ObjectCache --> TagsCache
    HTTPCacheApp --> TagsCache

    ObjectCache --> Filesystem
    ObjectCache -.-> ValkeyBackend
    HTTPCacheApp --> Filesystem

    App --> BAN
    BAN --> HTTPCache
    App --> TagInvalidation
    TagInvalidation --> TagsCache
```

## 高可用性構成図

```mermaid
flowchart TB
    subgraph AZ1["アベイラビリティゾーン A"]
        Web1["Web #1"]
        App1["App #1"]
        DB_Master[("DB Master")]
        OS1["OpenSearch #1"]
    end

    subgraph AZ2["アベイラビリティゾーン B"]
        Web2["Web #2"]
        App2["App #2"]
        DB_Slave[("DB Slave")]
        OS2["OpenSearch #2"]
    end

    subgraph Shared["共有サービス"]
        LB["ロードバランサー"]
        Valkey["Valkey Cluster"]
    end

    LB --> Web1
    LB --> Web2
    Web1 --> App1
    Web2 --> App2

    App1 --> DB_Master
    App2 --> DB_Master
    DB_Master --> |"レプリケーション"| DB_Slave

    App1 --> OS1
    App1 --> OS2
    App2 --> OS1
    App2 --> OS2
    OS1 <--> |"クラスター同期"| OS2

    App1 --> Valkey
    App2 --> Valkey

    DB_Slave -.-> |"フェイルオーバー"| DB_Master
```

## デプロイメントフロー図

```mermaid
flowchart LR
    subgraph Development["開発環境"]
        Dev["開発者"]
        LocalDocker["Docker Compose"]
    end

    subgraph CI["CI/CD"]
        Git["Git Repository"]
        Pipeline["CI Pipeline"]
        Build["ビルド"]
        Test["テスト"]
    end

    subgraph Staging["ステージング環境"]
        StageBlue["Blue環境"]
        StageGreen["Green環境"]
    end

    subgraph Production["本番環境"]
        ProdBlue["Blue環境"]
        ProdGreen["Green環境"]
        Active(("アクティブ"))
    end

    Dev --> |"push"| Git
    Dev --> LocalDocker
    Git --> Pipeline
    Pipeline --> Build
    Build --> Test
    Test --> |"deploy"| StageBlue
    StageBlue --> |"切り替え"| StageGreen

    StageGreen --> |"promote"| ProdBlue
    ProdBlue --> |"Blue-Green"| ProdGreen
    Active --> ProdBlue
    Active -.-> |"切り替え"| ProdGreen
```
