# paypal/paypal-ios architecture

> Architecture diagram of the GitHub repository paypal/paypal-ios, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/paypal/paypal-ios
- Repository: https://github.com/paypal/paypal-ios

## Overview

##### Project type and purpose
- This is an open-source PayPal iOS SDK, written in Swift, designed to be consumed by iOS apps via CocoaPods or SwiftPM.
- It provides modular libraries for card payments, PayPal web checkout, vaulting, payment buttons, fraud protection (Magnes), and core networking/analytics.

##### File structure
- Top-level “Sources” directory contains five independently versioned modules:
– CorePayments: networking clients, HTTP/GraphQL wrappers, analytics
– CardPayments: card-specific API clients, models, error handling
– PayPalWebPayments: web checkout client, request/response models
– FraudProtection: Magnes SDK integration & device data collector
– PaymentButtons: UI components (UIKit/SwiftUI) for PayPal/Venmo buttons
- “Demo” and “SampleApps” show consumer iOS apps that import the SDK modules, providing view models, SwiftUI/UIKit views, and example flows.
- “Frameworks/XCFrameworks” holds third-party risk/Magnes framework.
- CI/CD manifests in .github/workflows (build, tests, lint, release).
- UnitTests folder mirrors each module with XCTest coverage.

##### README for additional insights
- Confirms multi-package structure, iOS 14+ target, Swift 5.9+, supports UIKit & SwiftUI.
- Highlights authentication via client ID, external PayPal REST/GraphQL services, and analytics pipeline.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Demo and Sample Applications
    subgraph "Consumer iOS Apps" 
        direction TB
        DemoApp["Demo App"]:::app
        SPMApp["SPM Test App"]:::app
    end

    %% PayPal iOS SDK Modules
    subgraph "PayPal iOS SDK" 
        direction TB
        CorePayments["CorePayments"]:::sdk
        CardPayments["CardPayments"]:::sdk
        PayPalWebPayments["PayPalWebPayments"]:::sdk
        FraudProtection["FraudProtection"]:::sdk
        PaymentButtons["PaymentButtons"]:::sdk
    end

    %% External Services
    subgraph "External Services"
        direction TB
        RESTAPI["PayPal REST API"]:::external
        GraphQLAPI["PayPal GraphQL API"]:::external
        MagnesService["Magnes Fraud Service"]:::external
        AnalyticsAPI["Lighthouse/FPTI Analytics"]:::external
    end

    %% CI/CD Pipelines
    subgraph "CI/CD (GitHub Actions)"
        direction TB
        Build["Build"]:::cicd
        Tests["Tests"]:::cicd
        Lint["Lint"]:::cicd
        Release["Release"]:::cicd
    end

    %% Unit Tests
    subgraph "Unit Tests" 
        direction TB
        CoreTests["PaymentsCoreTests"]:::test
        CardTests["CardPaymentsTests"]:::test
        WebTests["PayPalWebPaymentsTests"]:::test
        FraudTests["FraudProtectionTests"]:::test
        ButtonTests["PaymentButtonsTests"]:::test
        SharedTests["TestShared"]:::test
    end

    %% Dependencies and Flows
    DemoApp -->|"imports via SPM/CocoaPods"| CorePayments
    DemoApp -->|"imports via SPM/CocoaPods"| CardPayments
    DemoApp -->|"imports via SPM/CocoaPods"| PayPalWebPayments
    DemoApp -->|"imports via SPM/CocoaPods"| FraudProtection
    DemoApp -->|"imports via SPM/CocoaPods"| PaymentButtons

    SPMApp -->|"imports via SPM/CocoaPods"| CorePayments
    SPMApp -->|"imports via SPM/CocoaPods"| CardPayments
    SPMApp -->|"imports via SPM/CocoaPods"| PayPalWebPayments
    SPMApp -->|"imports via SPM/CocoaPods"| FraudProtection
    SPMApp -->|"imports via SPM/CocoaPods"| PaymentButtons

    CardPayments -->|"uses NetworkingClient"| CorePayments
    PayPalWebPayments -->|"uses NetworkingClient"| CorePayments
    PaymentButtons -->|"view models → CorePayments"| CorePayments
    FraudProtection -->|"device data → AnalyticsService"| CorePayments

    CorePayments -->|"REST"| RESTAPI
    CorePayments -->|"GraphQL"| GraphQLAPI
    CorePayments -->|"sends analytics"| AnalyticsAPI

    FraudProtection -->|"SDK calls"| MagnesService

    %% CI/CD flows
    Build --> Tests
    Tests --> Lint
    Lint --> Release

    %% Tests invoke modules
    CoreTests --> CorePayments
    CardTests --> CardPayments
    WebTests --> PayPalWebPayments
    FraudTests --> FraudProtection
    ButtonTests --> PaymentButtons
    SharedTests --> CorePayments
    SharedTests --> CardPayments
    SharedTests --> PayPalWebPayments
    SharedTests --> FraudProtection
    SharedTests --> PaymentButtons

    %% Click Events
    click CorePayments "https://github.com/paypal/paypal-ios/tree/main/Sources/CorePayments"
    click CardPayments "https://github.com/paypal/paypal-ios/tree/main/Sources/CardPayments"
    click PayPalWebPayments "https://github.com/paypal/paypal-ios/tree/main/Sources/PayPalWebPayments"
    click FraudProtection "https://github.com/paypal/paypal-ios/tree/main/Sources/FraudProtection"
    click PaymentButtons "https://github.com/paypal/paypal-ios/tree/main/Sources/PaymentButtons"
    click DemoApp "https://github.com/paypal/paypal-ios/tree/main/Demo/Demo"
    click DemoApp "https://github.com/paypal/paypal-ios/blob/main/Demo/Demo.xcodeproj"
    click SPMApp "https://github.com/paypal/paypal-ios/tree/main/SampleApps/SPMTest/SPMTest"
    click SPMApp "https://github.com/paypal/paypal-ios/blob/main/SampleApps/SPMTest/SPMTest.xcodeproj"
    click MagnesService "https://github.com/paypal/paypal-ios/blob/main/Frameworks/XCFrameworks/PPRiskMagnes.xcframework"
    click Build "https://github.com/paypal/paypal-ios/blob/main/.github/workflows/build.yml"
    click Tests "https://github.com/paypal/paypal-ios/blob/main/.github/workflows/tests.yml"
    click Lint "https://github.com/paypal/paypal-ios/blob/main/.github/workflows/swiftlint.yml"
    click Release "https://github.com/paypal/paypal-ios/blob/main/.github/workflows/release.yml"
    click PackageSwift "https://github.com/paypal/paypal-ios/blob/main/Package.swift"
    click CocoaPodSpec "https://github.com/paypal/paypal-ios/blob/main/PayPal.podspec"
    click Lint "https://github.com/paypal/paypal-ios/blob/main/.swiftlint.yml"
    click Lint "https://github.com/paypal/paypal-ios/blob/main/scripts/swiftlint.sh"
    click CoreTests "https://github.com/paypal/paypal-ios/tree/main/UnitTests/PaymentsCoreTests"
    click CardTests "https://github.com/paypal/paypal-ios/tree/main/UnitTests/CardPaymentsTests"
    click WebTests "https://github.com/paypal/paypal-ios/tree/main/UnitTests/PayPalWebPaymentsTests"
    click FraudTests "https://github.com/paypal/paypal-ios/tree/main/UnitTests/FraudProtectionTests"
    click ButtonTests "https://github.com/paypal/paypal-ios/tree/main/UnitTests/PaymentButtonsTests"
    click SharedTests "https://github.com/paypal/paypal-ios/tree/main/UnitTests/TestShared"

    %% Styles
    classDef sdk fill:#D6E4FF,stroke:#1F4E79,stroke-width:1px
    classDef app fill:#DFF6DD,stroke:#2E7D32,stroke-width:1px
    classDef external fill:#FFF4E5,stroke:#E65100,stroke-width:1px
    classDef cicd fill:#ECEFF1,stroke:#455A64,stroke-width:1px
    classDef test fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
```
