# インフラ構成図

## 全体構成図

```mermaid
graph TB
    subgraph "Developer Workstation"
        VSCode[VS Code]
        DevContainer[Dev Container Extension]
    end

    subgraph "Local Docker Environment"
        DC[Docker Compose]
        subgraph "Docker Network"
            DB1[dbatools1<br/>SQL Server<br/>Port: 1401]
            DB2[dbatools2<br/>SQL Server<br/>Port: 1402]
            DB3[dbatools3<br/>SQL Server<br/>Port: 1403]
        end
        VOL[Workspace Volume<br/>/workspace]
    end

    subgraph "External Services"
        GH[GitHub<br/>Repository]
        PSG[PowerShell Gallery<br/>Module Distribution]
        DH[Docker Hub<br/>Images]
        CC[Codecov<br/>Coverage Report]
    end

    subgraph "CI/CD - AppVeyor"
        AV[AppVeyor Builder]
        subgraph "AppVeyor Matrix"
            AVM1[SINGLE<br/>SQL 2022]
            AVM2[MULTI<br/>SQL 2022 + 2017]
            AVM3[COPY<br/>SQL 2017 + 2022]
            AVM4[HADR<br/>SQL 2022]
            AVM5[RESTART<br/>SQL 2022]
            AVM6[2008R2<br/>Legacy Test]
        end
    end

    subgraph "CI/CD - GitHub Actions"
        GHA[GitHub Actions]
        subgraph "Platform Matrix"
            LINUX[Linux Runner<br/>ubuntu-latest]
            WIN[Windows Runner<br/>windows-latest]
            MAC[macOS Runner<br/>macos-latest]
        end
        subgraph "Docker Containers"
            MSSQL1[mssql1<br/>Port: 1433]
            MSSQL2[mssql2<br/>Port: 14333]
        end
    end

    VSCode --> DevContainer
    DevContainer --> DC
    DC --> DB1
    DC --> DB2
    DC --> DB3
    DC --> VOL
    DB2 -.->|depends_on| DB1
    DB3 -.->|depends_on| DB1

    GH --> AV
    GH --> GHA
    AV --> AVM1
    AV --> AVM2
    AV --> AVM3
    AV --> AVM4
    AV --> AVM5
    AV --> AVM6
    GHA --> LINUX
    GHA --> WIN
    GHA --> MAC
    LINUX --> MSSQL1
    LINUX --> MSSQL2
    AV --> CC
    GHA --> CC
    PSG -.->|install modules| DC
    PSG -.->|install modules| GHA
    DH -.->|pull images| DC
    DH -.->|pull images| LINUX
```

## ローカル開発環境構成図

```mermaid
graph LR
    subgraph "Host Machine"
        subgraph "VS Code"
            EXT1[PowerShell Extension]
            EXT2[SQL Server Extension]
            EXT3[GitHub PR Extension]
        end

        subgraph "Docker Desktop"
            subgraph "Dev Container"
                PS7[PowerShell 7]
                PY3[Python 3]
                GIT[Git]
                PESTER[Pester 4.4.3]
                PSA[PSScriptAnalyzer 1.18.2]

                subgraph "dbatools1 Container"
                    SQL1[SQL Server Engine]
                    AGENT1[SQL Agent]
                end

                subgraph "dbatools2 Container"
                    SQL2[SQL Server Engine]
                    AGENT2[SQL Agent]
                end

                subgraph "dbatools3 Container"
                    SQL3[SQL Server Engine]
                    AGENT3[SQL Agent]
                end
            end
        end
    end

    EXT1 --> PS7
    EXT2 --> SQL1
    PS7 --> PESTER
    PS7 --> PSA
    PS7 --> SQL1
    PS7 --> SQL2
    PS7 --> SQL3
```

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

```mermaid
flowchart TB
    subgraph "Source Control"
        COMMIT[Git Commit/Push]
        PR[Pull Request]
    end

    subgraph "AppVeyor Pipeline"
        direction TB
        AVB[Build Script]
        AVP[appveyor.prep.ps1<br/>Environment Setup]
        AVS[appveyor.sqlserver.ps1<br/>SQL Server Setup]
        AVT[appveyor.pester.ps1<br/>Test Execution]
        AVF[appveyor.post.ps1<br/>Finalization]

        AVB --> AVP --> AVS --> AVT --> AVF
    end

    subgraph "GitHub Actions Pipeline"
        direction TB
        GHC[Checkout]
        GHL[Install dbatools.library]
        GHD[Setup Docker Images]
        GHT[Run Tests]

        GHC --> GHL --> GHD --> GHT
    end

    subgraph "Test Environments"
        direction LR
        TE1[SQL 2022]
        TE2[SQL 2017]
        TE3[SQL 2008 R2]
        TE4[LocalDB]
    end

    subgraph "Artifacts"
        COV[Coverage Report]
        LOG[Test Logs]
    end

    COMMIT --> AVB
    COMMIT --> GHC
    PR --> AVB
    PR --> GHC

    AVT --> TE1
    AVT --> TE2
    AVT --> TE3
    GHT --> TE1
    GHT --> TE4

    AVF --> COV
    AVF --> LOG
    GHT --> COV
    GHT --> LOG
```

## ネットワーク構成図

```mermaid
graph TB
    subgraph "Local Environment"
        HOST[Host Machine<br/>localhost]

        subgraph "Docker Network - bridge"
            DC1[dbatools1<br/>Internal: 1433<br/>External: 1401]
            DC2[dbatools2<br/>Internal: 1433<br/>External: 1402]
            DC3[dbatools3<br/>Internal: 1433<br/>External: 1403]
        end
    end

    subgraph "GitHub Actions Environment"
        RUNNER[GitHub Runner]

        subgraph "Docker Network - localnet"
            GC1[mssql1<br/>Internal: 1433<br/>External: 1433]
            GC2[mssql2<br/>Internal: 1433<br/>External: 14333]
        end

        subgraph "Shared Volume"
            SV[/shared]
        end
    end

    HOST -->|Port 1401| DC1
    HOST -->|Port 1402| DC2
    HOST -->|Port 1403| DC3

    RUNNER -->|Port 1433| GC1
    RUNNER -->|Port 14333| GC2
    GC1 --> SV
    GC2 --> SV
    GC1 <-->|hostname: mssql1<br/>mssql2| GC2
```

## テストマトリックス構成図

```mermaid
graph LR
    subgraph "AppVeyor Matrix"
        direction TB
        S1[SINGLE 1/3<br/>SQL 2022]
        S2[SINGLE 2/3<br/>SQL 2022]
        S3[SINGLE 3/3<br/>SQL 2022]
        M[MULTI<br/>SQL 2022 + 2017]
        C[COPY<br/>SQL 2017 + 2022]
        H[HADR<br/>SQL 2022]
        R[RESTART<br/>SQL 2022]
        D[default]
        L1[2008R2 1/2<br/>VS 2015]
        L2[2008R2 2/2<br/>VS 2015]
    end

    subgraph "GitHub Actions Matrix"
        direction TB
        GL[Linux<br/>ubuntu-latest]
        GW[Windows<br/>windows-latest]
        GM[macOS<br/>macos-latest]
    end

    subgraph "Test Types"
        T1[Unit Tests]
        T2[Integration Tests]
        T3[Cross-Platform Tests]
    end

    S1 --> T1
    S2 --> T1
    S3 --> T1
    M --> T2
    C --> T2
    H --> T2
    R --> T2
    L1 --> T2
    L2 --> T2
    GL --> T3
    GW --> T3
    GM --> T3
```

## 依存関係図

```mermaid
graph TB
    subgraph "PowerShell Modules"
        DBATOOLS[dbatools<br/>v2.7.24]
        DBLIB[dbatools.library<br/>v2025.12.28]
        PESTER[Pester<br/>v4.4.3]
        PSA[PSScriptAnalyzer<br/>v1.18.2]
    end

    subgraph "Runtime"
        PS7[PowerShell 7.x]
        PS5[PowerShell 5.1<br/>Windows Only]
        NET[.NET Runtime]
    end

    subgraph "Database"
        SMO[SQL Server SMO]
        SQLCLIENT[Microsoft.Data.SqlClient]
    end

    subgraph "Tools"
        SQLPKG[SqlPackage]
        GIT[Git]
    end

    DBATOOLS --> DBLIB
    DBATOOLS --> PS7
    DBATOOLS --> PS5
    DBLIB --> SMO
    DBLIB --> SQLCLIENT
    SMO --> NET
    SQLCLIENT --> NET
    PESTER --> PS7
    PSA --> PS7
    DBATOOLS -.->|optional| SQLPKG
```
