# moise7000/pb-runner architecture

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

- Interactive diagram: https://gitdiagram.com/moise7000/pb-runner
- Repository: https://github.com/moise7000/pb-runner

## Overview

##### Project type and purpose
- From the file tree and README: this is a native iOS “endless runner” game (“Lombric Runner”) built in Swift, using Xcode and SpriteKit (SKView/SKScene). Its purpose is to present multiple levels/“scenes,” handle user input, play audio, render pixel-art assets and parallax backgrounds, and manage game state (skins, scores, unlocked content).

##### File structure
- Top-level:
- pb-runner.xcodeproj / .xcworkspace – Xcode project & workspace
- pb-runner/ (app target)
- pb-runnerTests, pb-runnerUITests
- assets/ (teaser video, screenshot images)
- Inside pb-runner/:
- AppDelegate.swift, Info.plist, Main.storyboard – application launch & configuration
- Controllers/ – game-wide controllers (GameManager, AudioManager, BackgroundSelector, ControlSelector)
- Model/ – data models (GameData, PlayerSkinModel, BackgroundSkinModel)
- Scenes/ – SKScene subclasses (MainMenuScene, GameScene, CreditsScene, OptionsScene, GameOverScene, etc.)
- Views/ – Swift UI-like overlay views (OptionsView, UnlockAnimationView, PlayerSkinSelector)
- Helpers/ – utility extensions & background-viewport logic
- Transitions/ – SKTransition helpers (circle, star, utils)
- Assets.xcassets, Songs/ – graphics & audio resources
- Tests – unit & UI tests

##### Extract insights from the README
- It emphasizes pixel-art assets in 16×16, dynamic parallax backgrounds, multiple scenes, and audio themes. No network, backend, or database—pure on-device game.

##### Main components
a. iOS Application Layer
- UIApplication / AppDelegate
- Main.storyboard → instantiates GameViewController
b. Presentation Layer
- GameViewController (hosts SKView)
- SKView → SKScene instances
c. Game Scenes
- MainMenuScene, GameScene, OptionsScene, CreditsScene, GameOverScene
- Each scene handles its own lifecycle (didMove, update, touchesBegan, etc.)
d. Controllers
- GameManager: central game logic (score, level progression, state transitions)
- AudioManager: loads/plays Songs (mainMenuSong, snowTheme, gameOverSong)
- BackgroundSelector: picks & configures parallax backgrounds (via Helpers/ViewportBackground)
- ControlSelector: maps touch input to game actions
e. Models
- GameData: current score, unlocked skins, settings
- PlayerSkinModel & BackgroundSkinModel: data for customization
f. Views / UI Overlays
- OptionsView: UI for settings
- PlayerSkinSelector & UnlockAnimationView: UI for selecting/unlocking skins
g. Asset Store
- Assets.xcassets (pixel art images, parallax layers)
- Songs/ (audio files)
h. Helpers & Transitions
- Helpers: array extensions, background viewport logic
- Transitions: SKTransition factories for scene changes

##### Relationships & interactions
- AppDelegate launches → GameViewController
- GameViewController loads SKView → presents initial MainMenuScene
- Scenes inject or reference Controllers and Models:
- On scene load, they ask BackgroundSelector for configured SKNode hierarchy
- User touches → forwarded by SKScene → ControlSelector → GameManager
- GameManager updates GameData → Scenes read data (e.g., score, skin selection)
- AudioManager subscribes to game state changes to play appropriate tracks
- Scenes or Views use Models to load correct textures from Assets.xcassets
- Transitions invoked by Scenes via TransitionUtils

##### Architectural patterns & principles
- MVC-style separation:
- Model: GameData, SkinModels
- View: SKScene + custom Views
- Controller: GameManager, AudioManager, selectors
- Single Responsibility: each Controller handles one domain (audio, input, background)
- Dependency Injection: Scenes receive references to Controllers and Models on init
- Resource management: Asset catalogs centralized under Assets.xcassets

##### Elements
- App launch → GameViewController → SKView → Scene
- Scene → BackgroundSelector → Helpers → SKNodes
- Scene → ControlSelector → GameManager → Model
- GameManager → AudioManager → Songs
- Blue for app & presentation
- Green for controllers
- Yellow for models
- Orange for assets/resources
- Gray for helpers/transitions

##### Detailed capturing of essential elements
- One-to-many relationship: GameViewController can present multiple Scene types
- That Models are singletons or passed by reference

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application & Presentation Layer
    AppDelegate["UIApplication / AppDelegate"]:::app
    MainSB["Main.storyboard"]:::app
    GameVC["GameViewController"]:::app
    SKView["SKView"]:::app

    %% Scenes
    subgraph Scenes
        direction TB
        MainMenuScene["MainMenuScene\ndidMove(), update(), touchesBegan()"]:::scene
        GameScene["GameScene\ndidMove(), update(), touchesBegan()"]:::scene
        OptionsScene["OptionsScene\ndidMove(), update(), touchesBegan()"]:::scene
        CreditsScene["CreditsScene\ndidMove(), update(), touchesBegan()"]:::scene
        GameOverScene["GameOverScene\ndidMove(), update(), touchesBegan()"]:::scene
    end

    %% Controllers
    GameManager["GameManager"]:::controller
    AudioManager["AudioManager"]:::controller
    BackgroundSelector["BackgroundSelector"]:::controller
    ControlSelector["ControlSelector"]:::controller

    %% Models
    GameData["GameData"]:::model
    PlayerSkinModel["PlayerSkinModel"]:::model
    BackgroundSkinModel["BackgroundSkinModel"]:::model

    %% Views / UI Overlays
    OptionsView["OptionsView"]:::app
    PlayerSkinSelector["PlayerSkinSelector"]:::app
    UnlockAnimationView["UnlockAnimationView"]:::app

    %% Assets / Resources
    AssetsCatalog["Assets.xcassets"]:::asset
    Songs["Songs/"]:::asset

    %% Helpers & Transitions
    ArrayExt["ArrayExtension"]:::helper
    ViewportBackground["ViewportBackground"]:::helper
    TransitionUtils["TransitionUtils"]:::helper
    TransitionCircle["TransitionCircle"]:::helper
    TransitionStar["TransitionStar"]:::helper

    %% Relationships
    AppDelegate -->|"launch"| MainSB
    MainSB -->|"instantiates"| GameVC
    GameVC -->|"hosts"| SKView
    SKView -->|"presents initial"| MainMenuScene
    SKView -->|"can present"| GameScene
    SKView -->|"can present"| OptionsScene
    SKView -->|"can present"| CreditsScene
    SKView -->|"can present"| GameOverScene

    MainMenuScene -->|"requestBackground()"| BackgroundSelector
    GameScene -->|"requestBackground()"| BackgroundSelector
    OptionsScene -->|"requestBackground()"| BackgroundSelector
    CreditsScene -->|"requestBackground()"| BackgroundSelector
    GameOverScene -->|"requestBackground()"| BackgroundSelector

    BackgroundSelector -->|"uses logic"| ViewportBackground
    BackgroundSelector -->|"uses utils"| ArrayExt

    MainMenuScene -->|"userInput()"| ControlSelector
    GameScene -->|"userInput()"| ControlSelector
    OptionsScene -->|"userInput()"| ControlSelector
    CreditsScene -->|"userInput()"| ControlSelector
    GameOverScene -->|"userInput()"| ControlSelector

    ControlSelector -->|"invokeAction()"| GameManager
    GameManager -->|"updateScore(), updateState()"| GameData
    MainMenuScene -->|"readSettings()"| GameData
    GameScene -->|"readScore(), readSkins()"| GameData
    OptionsScene -->|"readSettings()"| GameData
    GameOverScene -->|"readScore()"| GameData

    GameManager -->|"stateChanged()"| AudioManager
    AudioManager -->|"playTrack()"| Songs

    MainMenuScene -->|"loadTextures()"| AssetsCatalog
    GameScene -->|"loadTextures()"| AssetsCatalog
    OptionsScene -->|"loadTextures()"| AssetsCatalog
    CreditsScene -->|"loadTextures()"| AssetsCatalog
    GameOverScene -->|"loadTextures()"| AssetsCatalog

    MainMenuScene -->|"showOverlay()"| OptionsView
    MainMenuScene -->|"showOverlay()"| PlayerSkinSelector
    MainMenuScene -->|"showOverlay()"| UnlockAnimationView

    Scenes -.->|"transition()"| TransitionUtils
    TransitionUtils -->|"factory()"| TransitionCircle
    TransitionUtils -->|"factory()"| TransitionStar

    %% Click Events
    click AppDelegate "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/AppDelegate.swift"
    click MainSB "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Base.lproj/Main.storyboard"
    click GameVC "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Controllers/GameViewController.swift"
    click MainMenuScene "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Scenes/MainMenuScene.swift"
    click GameScene "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Scenes/GameScene.swift"
    click OptionsScene "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Scenes/OptionsScene.swift"
    click CreditsScene "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Scenes/CreditsScene.swift"
    click GameOverScene "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Scenes/GameOverScene.swift"
    click GameManager "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Controllers/GameManager.swift"
    click AudioManager "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Controllers/AudioManager.swift"
    click BackgroundSelector "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Controllers/BackgroundSelector.swift"
    click ControlSelector "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Controllers/ControlSelector.swift"
    click GameData "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Model/GameData.swift"
    click PlayerSkinModel "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Model/PlayerSkinModel.swift"
    click BackgroundSkinModel "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Model/BackgroundSkinModel.swift"
    click OptionsView "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Views/OptionsView.swift"
    click PlayerSkinSelector "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Skins/PlayerSkinSelector.swift"
    click UnlockAnimationView "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Skins/UnlockAnimationView.swift"
    click AssetsCatalog "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Assets.xcassets"
    click Songs "https://github.com/moise7000/pb-runner/tree/main/pb-runner/pb-runner/Songs/"
    click ArrayExt "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Helpers/ArrayExtension.swift"
    click ViewportBackground "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Helpers/ViewportBackground.swift"
    click TransitionUtils "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Transitions/TransitionUtils.swift"
    click TransitionCircle "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Transitions/TransitionCircle.swift"
    click TransitionStar "https://github.com/moise7000/pb-runner/blob/main/pb-runner/pb-runner/Transitions/TransitionStar.swift"

    %% Styles
    classDef app fill:#D0E6FF,stroke:#004A99,color:#000;
    classDef scene fill:#E6F0FF,stroke:#2A52BE,color:#000;
    classDef controller fill:#DFF2D8,stroke:#2E7D32,color:#000;
    classDef model fill:#FFF4CC,stroke:#F9A825,color:#000;
    classDef asset fill:#FFE0B2,stroke:#E65100,color:#000;
    classDef helper fill:#F0F0F0,stroke:#616161,color:#000;
```
