# インフラ構成図

## 全体システム構成図

```mermaid
graph TB
    subgraph "End Users"
        iOS["iOS Device<br/>(iPhone/iPad)"]
    end

    subgraph "Wikipedia iOS App"
        App["Wikipedia App<br/>(Swift/Obj-C)"]
        WMF["WMF Framework"]
        WMFData["WMFData"]
        WMFComponents["WMFComponents"]
        Widgets["Widgets Extension"]
        Notifications["Notification Extension"]
        Stickers["Stickers Extension"]
    end

    subgraph "Local Storage"
        CoreData["Core Data<br/>(Offline Articles)"]
        Cache["URLCache<br/>(Image/Article Cache)"]
        UserDefaults["UserDefaults<br/>(Settings)"]
    end

    subgraph "Wikimedia Foundation APIs"
        subgraph "MediaWiki API"
            MW["MediaWiki API<br/>({lang}.wikipedia.org/w/api.php)"]
        end
        subgraph "RESTBase Services"
            PCS["Page Content Service<br/>(/api/rest_v1)"]
            Feeds["Wikifeeds<br/>(Feed Content)"]
            Metrics["Metrics API<br/>(wikimedia.org)"]
        end
        subgraph "Other Wikimedia Services"
            Wikidata["Wikidata API<br/>(wikidata.org)"]
            Commons["Commons API<br/>(commons.wikimedia.org)"]
            Upload["Upload Service<br/>(upload.wikimedia.org)"]
        end
    end

    subgraph "Third Party Services"
        hCaptcha["hCaptcha"]
        Adyen["Adyen<br/>(Apple Pay)"]
    end

    iOS --> App
    App --> WMF
    App --> WMFData
    App --> WMFComponents
    App --> Widgets
    App --> Notifications
    App --> Stickers

    WMF --> CoreData
    WMF --> Cache
    App --> UserDefaults

    WMF --> |HTTPS| MW
    WMF --> |HTTPS| PCS
    WMF --> |HTTPS| Feeds
    WMF --> |HTTPS| Metrics
    WMF --> |HTTPS| Wikidata
    WMF --> |HTTPS| Commons
    WMF --> |HTTPS| Upload

    App --> |SDK| hCaptcha
    App --> |Apple Pay| Adyen
```

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

```mermaid
graph LR
    subgraph "Development"
        Dev["Developer"]
        LocalEnv["Local Environment<br/>(Xcode 16+)"]
    end

    subgraph "Version Control"
        GitHub["GitHub Repository<br/>(wikimedia/wikipedia-ios)"]
        Main["main branch"]
        TWN["twn branch"]
        Feature["Feature branches"]
    end

    subgraph "GitHub Actions"
        UnitTests["Run Unit Tests<br/>(PR Trigger)"]
        Localization["Import Localizations<br/>(twn push)"]
        TagBeta["Tag Latest Beta<br/>(Daily 10:00 UTC)"]
        UpdateVersion["Update App Version<br/>(Manual)"]
    end

    subgraph "Xcode Cloud"
        NightlyBuild["Nightly Build<br/>(latest_beta tag)"]
        WeeklyStaging["Weekly Staging Build<br/>(Sunday)"]
        Experimental["Experimental Build<br/>(Manual)"]
    end

    subgraph "Distribution"
        TestFlight["TestFlight"]
        AppStore["App Store"]
    end

    subgraph "External Services"
        TranslateWiki["TranslateWiki.net"]
        Phabricator["Phabricator"]
    end

    Dev --> LocalEnv
    LocalEnv --> GitHub
    GitHub --> Main
    GitHub --> TWN
    GitHub --> Feature

    Feature --> |PR| UnitTests
    TWN --> |push| Localization
    Main --> TagBeta

    TranslateWiki --> TWN

    TagBeta --> |tag change| NightlyBuild
    NightlyBuild --> TestFlight
    WeeklyStaging --> TestFlight
    Experimental --> TestFlight

    TestFlight --> AppStore

    GitHub --> Phabricator
```

## 環境構成図

```mermaid
graph TB
    subgraph "Development Environments"
        subgraph "Production Scheme"
            ProdApp["Wikipedia Scheme"]
            ProdAPI["Production APIs<br/>(*.wikipedia.org)"]
        end

        subgraph "Staging Scheme"
            StagingApp["Staging Scheme"]
            BetaCluster["Beta Cluster<br/>(*.beta.wmcloud.org)"]
            AppsLabs["Apps Labs<br/>(mobileapps.wmflabs.org)"]
        end

        subgraph "Local Scheme"
            LocalApp["Local PCS & Announcements"]
            LocalPCS["Local mobileapps<br/>(localhost)"]
            LocalWikifeeds["Local wikifeeds<br/>(localhost)"]
        end

        subgraph "Experimental Scheme"
            ExpApp["Experimental Scheme"]
            ExpAPI["Configurable<br/>(default: Production)"]
        end
    end

    ProdApp --> ProdAPI
    StagingApp --> BetaCluster
    StagingApp --> AppsLabs
    LocalApp --> LocalPCS
    LocalApp --> LocalWikifeeds
    ExpApp --> ExpAPI
```

## ネットワーク構成図

```mermaid
graph TB
    subgraph "iOS App"
        URLSession["URLSession<br/>(HTTPS)"]
        CookieStore["HTTPCookieStorage<br/>(CentralAuth)"]
        Fetcher["Fetcher Layer"]
        Session["Session Manager"]
    end

    subgraph "API Endpoints"
        MediaWikiAPI["MediaWiki API<br/>POST/GET"]
        RESTBaseAPI["RESTBase API<br/>GET"]
        WikidataAPI["Wikidata API<br/>GET/POST"]
        CommonsAPI["Commons API<br/>GET/POST"]
    end

    subgraph "Authentication"
        CentralAuth["CentralAuth<br/>Cookie-based SSO"]
        OAuth["OAuth 2.0<br/>(Optional)"]
    end

    Fetcher --> Session
    Session --> URLSession
    URLSession --> CookieStore
    CookieStore --> CentralAuth

    URLSession --> |TLS 1.2+| MediaWikiAPI
    URLSession --> |TLS 1.2+| RESTBaseAPI
    URLSession --> |TLS 1.2+| WikidataAPI
    URLSession --> |TLS 1.2+| CommonsAPI

    CentralAuth --> MediaWikiAPI
    OAuth --> MediaWikiAPI
```

## アプリモジュール構成図

```mermaid
graph TB
    subgraph "Main Application"
        Wikipedia["Wikipedia<br/>(Main Target)"]
    end

    subgraph "Frameworks"
        WMF["WMF Framework<br/>(Shared Logic)"]
        WMFData["WMFData<br/>(Swift Package)"]
        WMFComponents["WMFComponents<br/>(Swift Package)"]
    end

    subgraph "Extensions"
        ContinueReading["ContinueReadingWidget"]
        WidgetsExt["Widgets Extension"]
        NotificationExt["NotificationServiceExtension"]
        StickersExt["Wikipedia Stickers"]
    end

    subgraph "Test Targets"
        UnitTests["WikipediaUnitTests"]
        UITests["WikipediaUITests"]
    end

    Wikipedia --> WMF
    Wikipedia --> WMFData
    Wikipedia --> WMFComponents

    ContinueReading --> WMF
    WidgetsExt --> WMF
    NotificationExt --> WMF

    UnitTests --> Wikipedia
    UnitTests --> WMF
    UITests --> Wikipedia
```

## バックグラウンド処理構成図

```mermaid
graph LR
    subgraph "Background Task Scheduler"
        BGTaskScheduler["BGTaskScheduler"]
    end

    subgraph "Registered Tasks"
        AppRefresh["org.wikimedia.wikipedia.appRefresh<br/>(App Refresh)"]
        DBHousekeeper["org.wikimedia.wikipedia.databaseHousekeeper<br/>(Database Maintenance)"]
    end

    subgraph "Background Modes"
        Fetch["background fetch"]
        Processing["background processing"]
    end

    subgraph "Data Operations"
        SyncData["Sync Reading Lists"]
        CacheCleanup["Cache Cleanup"]
        ExpireContent["Expire Old Content"]
    end

    BGTaskScheduler --> AppRefresh
    BGTaskScheduler --> DBHousekeeper

    AppRefresh --> Fetch
    DBHousekeeper --> Processing

    AppRefresh --> SyncData
    DBHousekeeper --> CacheCleanup
    DBHousekeeper --> ExpireContent
```
