# rational-kunal/p2p-rock-paper-scissor architecture

> Architecture diagram of the GitHub repository rational-kunal/p2p-rock-paper-scissor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rational-kunal/p2p-rock-paper-scissor
- Repository: https://github.com/rational-kunal/p2p-rock-paper-scissor

## Overview

##### Main Components

A. Client Layer (iOS Devices)
- Host Device
- Peer Device(s)

B. Application Layer
- View Layer
- Game Logic Layer
- Network Layer

##### Detailed Component Breakdown

A. View Layer (UI Components):
- StartMenuView
- GameView
- Main.storyboard
- LaunchScreen.storyboard

B. Model Layer:
- GameState
- Hand
- SessionState

C. Service Layer:
- GameSessionService (Core networking component)

D. Controller Layer:
- ViewController
- SceneDelegate
- AppDelegate

- [Device 1] <-----> [Multipeer Connectivity] <-----> [Device 2]

##### For each device, create a layered architecture
- UI Layer
- ↕
- Controller Layer
- ↕
- Service Layer
- ↕
- Model Layer

##### Component Relationships

- Views → ViewController (user actions)
- ViewController → GameSessionService (game logic)
- GameSessionService → Models (state updates)
- GameSessionService ←→ Multipeer Connectivity (P2P communication)

##### Specific flows

a. Game Session Establishment:
- StartMenuView → ViewController → GameSessionService → Multipeer Connectivity

b. Game State Updates:
- GameView → ViewController → GameSessionService → Models

c. P2P Communication:
- Device 1 GameSessionService ←→ Multipeer Connectivity ←→ Device 2 GameSessionService

##### Important Details to Highlight

- Multipeer Connectivity framework integration
- Real-time game state synchronization
- Session management flow
- Player move handling
- Result calculation and distribution

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Device1[iOS Device 1]
        subgraph ViewLayer1[View Layer]
            SMV1[StartMenuView]:::view
            GV1[GameView]:::view
            MS1[Main.storyboard]:::view
            LS1[LaunchScreen.storyboard]:::view
        end

        subgraph ControllerLayer1[Controller Layer]
            VC1[ViewController]:::controller
            SD1[SceneDelegate]:::controller
            AD1[AppDelegate]:::controller
        end

        subgraph ServiceLayer1[Service Layer]
            GSS1[GameSessionService]:::service
        end

        subgraph ModelLayer1[Model Layer]
            GS1[GameState]:::model
            H1[Hand]:::model
            SS1[SessionState]:::model
        end
    end

    subgraph Device2[iOS Device 2]
        subgraph ViewLayer2[View Layer]
            SMV2[StartMenuView]:::view
            GV2[GameView]:::view
            MS2[Main.storyboard]:::view
            LS2[LaunchScreen.storyboard]:::view
        end

        subgraph ControllerLayer2[Controller Layer]
            VC2[ViewController]:::controller
            SD2[SceneDelegate]:::controller
            AD2[AppDelegate]:::controller
        end

        subgraph ServiceLayer2[Service Layer]
            GSS2[GameSessionService]:::service
        end

        subgraph ModelLayer2[Model Layer]
            GS2[GameState]:::model
            H2[Hand]:::model
            SS2[SessionState]:::model
        end
    end

    MCF[Multipeer Connectivity Framework]:::framework

    %% Relationships Device 1
    SMV1 & GV1 --> VC1
    VC1 --> GSS1
    GSS1 --> GS1 & H1 & SS1
    GSS1 -.->|P2P Communication| MCF

    %% Relationships Device 2
    SMV2 & GV2 --> VC2
    VC2 --> GSS2
    GSS2 --> GS2 & H2 & SS2
    GSS2 -.->|P2P Communication| MCF

    %% Click events for component mapping
    click SMV1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Views/StartMenuView.swift"
    click SMV2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Views/StartMenuView.swift"
    click GV1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Views/GameView.swift"
    click GV2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Views/GameView.swift"
    click MS1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Base.lproj/Main.storyboard"
    click MS2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Base.lproj/Main.storyboard"
    click LS1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Base.lproj/LaunchScreen.storyboard"
    click LS2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Base.lproj/LaunchScreen.storyboard"
    click GS1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Models/GameState.swift"
    click GS2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Models/GameState.swift"
    click H1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Models/Hand.swift"
    click H2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Models/Hand.swift"
    click SS1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Models/SessionState.swift"
    click SS2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Models/SessionState.swift"
    click GSS1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Services/GameSessionService.swift"
    click GSS2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/Services/GameSessionService.swift"
    click VC1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/ViewController.swift"
    click VC2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/ViewController.swift"
    click SD1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/SceneDelegate.swift"
    click SD2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/SceneDelegate.swift"
    click AD1 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/AppDelegate.swift"
    click AD2 "https://github.com/rational-kunal/P2P-Rock-Paper-Scissor/blob/main/Rock Paper Scissor/AppDelegate.swift"

    %% Styling
    classDef view fill:#3498db,stroke:#2980b9,color:white
    classDef controller fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef model fill:#e67e22,stroke:#d35400,color:white
    classDef framework fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        L1[View Component]:::view
        L2[Controller Component]:::controller
        L3[Service Component]:::service
        L4[Model Component]:::model
        L5[Framework Component]:::framework
    end
```
