# theniks/strategypattern architecture

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

- Interactive diagram: https://gitdiagram.com/theniks/strategypattern
- Repository: https://github.com/theniks/strategypattern

## Overview

##### Project type and purpose
- This is an iOS demo app (UIKit + Storyboards) that illustrates the Strategy Pattern in Swift/POP (Protocol-Oriented Programming).
- Its purpose: allow the user to pick a payment method at runtime (Credit Card, Apple Pay, PayPal), then process the payment via a common interface without conditional checks.

a. UI Layer
- Main.storyboard & LaunchScreen
- PaymentViewController / PaymentViewControllerOptimize
- SceneDelegate / AppDelegate
b. Domain Layer (Strategy Pattern)
- PaymentMethodProtocol (the “Strategy” interface)
- Concrete strategy implementations (e.g. CreditCardPayment, ApplePayPayment, PayPalPayment) in PaymentMethod.swift
- PaymentContext (or the controller that holds a reference to PaymentMethodProtocol)
c. System Frameworks
- UIKit
d. External Service
- Payment Gateway API (e.g. calls out to a backend or Apple Pay framework)

##### Relationships and data-flow
- User taps “Pay” in the UI → PaymentViewController invokes PaymentContext.processPayment()
- PaymentContext holds a PaymentMethodProtocol reference → calls concreteStrategy.processPayment(amount)
- ConcreteStrategy calls out to external payment API or Apple Pay framework → returns success/failure → back to PaymentContext → notifies UI layer
- SceneDelegate/AppDelegate handle app lifecycle but do not contain business logic

##### Architectural patterns and design principles
- Strategy Pattern: define a family of interchangeable algorithms (Payment methods) that conform to the same protocol.
- Protocol-Oriented Programming: no inheritance, only protocols and struct/class implementations.
- Single Responsibility: each PaymentMethod class handles exactly one payment type.
- Dependency Injection: ViewController or Context is injected with a concrete strategy at runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        MS["Main.storyboard"]:::ui
        LS["LaunchScreen.storyboard"]:::ui
        PVC["PaymentViewController"]:::ui
        PVO["PaymentViewControllerOptimize"]:::ui
        SD["SceneDelegate"]:::ui
        AD["AppDelegate"]:::ui
    end

    %% Domain / Strategy Layer
    subgraph "Domain / Strategy Layer"
        direction TB
        PMProto["PaymentMethodProtocol"]:::domain
        PCC["CreditCardPayment"]:::domain
        PAP["ApplePayPayment"]:::domain
        PPP["PayPalPayment"]:::domain
        PCtx["PaymentContext"]:::domain
    end

    %% System Frameworks
    subgraph "Frameworks & Assets"
        direction TB
        UIK["UIKit"]:::framework
        APF["ApplePay Framework"]:::framework
        AI["AppIcon"]:::asset
        AC["AccentColor"]:::asset
    end

    %% External Services
    subgraph "External Services"
        direction TB
        PAPI["Payment Gateway API"]:::external
    end

    %% Relationships
    PVC -->|"user taps Pay"| PCtx
    PVO -->|"user taps Pay"| PCtx
    PCtx -->|"holds reference"| PMProto
    PCtx -->|"processPayment(amount)"| PCC
    PCtx -->|"processPayment(amount)"| PAP
    PCtx -->|"processPayment(amount)"| PPP
    PCC -->|"calls API"| PAPI
    PAP -->|"invokes"| APF
    PPP -->|"calls API"| PAPI
    PAPI -->|"returns result"| PCtx
    APF -->|"returns result"| PCtx
    PCtx -->|"result(success/failure)"| PVC

    %% Click Events
    click MS "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/Base.lproj/Main.storyboard"
    click LS "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/Base.lproj/LaunchScreen.storyboard"
    click PVC "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/PaymentViewController.swift"
    click PVO "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/PaymentViewControllerOptimize.swift"
    click SD "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/SceneDelegate.swift"
    click AD "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/AppDelegate.swift"
    click PMProto "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/PaymentMethod.swift"
    click PCC "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/PaymentMethod.swift"
    click PAP "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/PaymentMethod.swift"
    click PPP "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/PaymentMethod.swift"
    click AI "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/Assets.xcassets/AppIcon.appiconset"
    click AC "https://github.com/theniks/strategypattern/blob/main/PaymentApp/PaymentApp/Assets.xcassets/AccentColor.colorset"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085;
    classDef domain fill:#d4edda,stroke:#155724,color:#155724;
    classDef framework fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef asset fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
