# rfx14/cartoonwars architecture

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

- Interactive diagram: https://gitdiagram.com/rfx14/cartoonwars
- Repository: https://github.com/rfx14/cartoonwars

## Overview

#### Purpose and Platform
CartoonWars is a native iOS SpriteKit game project. It models a side-based tower/troop battle with animated unit assets, combat, purchasing/upgrades, AI behavior, and game-state coordination. The Xcode target and iOS lifecycle are defined by `CartoonWars.xcodeproj/project.pbxproj`, `CartoonWars/AppDelegate.swift`, and `CartoonWars/SceneDelegate.swift`.

#### Application and Scene Entry
UIKit launches through the storyboard and view-controller layer, then hosts the SpriteKit game view/scene. `CartoonWars/Base.lproj/Main.storyboard` establishes the UI entry; `CartoonWars/GameViewController.swift` loads or configures gameplay; `CartoonWars/GameView.swift` is the SpriteKit-facing rendering/view abstraction. `CartoonWars/GameScene.swift` is the central real-time scene controller, paired with serialized scene content in `CartoonWars/GameScene.sks`.

#### Gameplay Orchestration
`CartoonWars/GameScene.swift` owns the frame-driven game world: it is the likely boundary where player input, SpriteKit nodes, physics callbacks, spawning, and visual game events meet. `CartoonWars/GameState.swift` provides a separate state model for match progression and rules, reducing direct coupling between scene rendering and gameplay status. `CartoonWars/Actions.sks` supplies authored SpriteKit actions used by scene/node behavior.

#### Domain Model: Battle and Economy
Combatants and defensive objectives are represented in `CartoonWars/Models/Troop.swift` and `CartoonWars/Models/Tower.swift`. Attack semantics are separated into `CartoonWars/Models/Attack.swift`, while `CartoonWars/Models/Upgradable.swift` defines the upgrade-oriented capability shared by relevant game entities. Economy and player purchase flow are modeled by `CartoonWars/Models/Shop.swift`; the gameplay/UI-facing contract is likely centralized in `CartoonWars/Models/GameInterface.swift`.

#### AI Decision Layer
Computer-controlled behavior is represented by `CartoonWars/Models/ComputerPlayer.swift` and the behavior-tree implementation in `CartoonWars/BehaviorTree/BehaviorTree.swift`. This forms a decision boundary: the AI selects actions such as troop deployment or upgrades through game-domain interfaces, while `GameScene` executes resulting effects in the SpriteKit world.

#### Rendering, Animation, and Physics
SpriteKit is the material runtime for scene rendering, actions, animation, and collision handling. `CartoonWars/Models/Animation.swift` encapsulates animation behavior; unit sprite atlases provide runtime frames in `CartoonWars/knight.atlas`, `CartoonWars/orc.atlas`, and `CartoonWars/soldier.atlas`. Collision/contact classification is centralized by `CartoonWars/Models/PhysicsCategory.swift`, allowing scene physics events to map into combat/game-rule processing.

#### Assets and External Dependencies
The project appears self-contained: no backend, package manager, or external service configuration is present. Visual resources are bundled in `CartoonWars/Assets.xcassets` and unit atlases, including `CartoonWars/werewolf.atlas`. Build, signing, deployment target, and target membership are controlled by the Xcode project at `CartoonWars.xcodeproj/project.pbxproj`.

Main entry points: [`CartoonWars/GameScene.swift`](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameScene.swift) (Game Scene), [`CartoonWars/Models/Troop.swift`](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Troop.swift) (Troops and Towers), [`CartoonWars/Models/ComputerPlayer.swift`](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/ComputerPlayer.swift) (Computer Player), [`CartoonWars/Base.lproj/Main.storyboard`](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Base.lproj/Main.storyboard) (Main Storyboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ios["iOS Entry"]
  node_project["Xcode Target<br/>build target<br/>[project.pbxproj]"]
  node_storyboard["Main Storyboard<br/>UIKit entry<br/>[Main.storyboard]"]
  node_app_delegate["App Delegate<br/>iOS lifecycle<br/>[AppDelegate.swift]"]
  node_scene_delegate["Scene Delegate<br/>scene lifecycle"]
  node_view_controller["Game View Controller<br/>UIKit controller"]
end

subgraph group_gameplay["Gameplay Runtime"]
  node_game_view["Game View<br/>SpriteKit view<br/>[GameView.swift]"]
  node_game_scene{{"Game Scene<br/>real-time controller<br/>[GameScene.swift]"}}
  node_game_state["Game State<br/>match state<br/>[GameState.swift]"]
  node_scene_content["Scene Content<br/>SpriteKit scene<br/>[GameScene.sks]"]
  node_actions["Authored Actions<br/>SpriteKit actions<br/>[Actions.sks]"]
  node_physics["Physics Categories<br/>collision rules"]
end

subgraph group_domain["Battle Domain"]
  node_battle_models["Troops and Towers<br/>combat entities<br/>[Troop.swift]"]
  node_attack["Attack Model<br/>combat semantics<br/>[Attack.swift]"]
  node_shop["Shop and Upgrades<br/>economy<br/>[Shop.swift]"]
  node_game_interface["Game Interface<br/>gameplay contract"]
end

subgraph group_ai["AI"]
  node_computer_player["Computer Player<br/>AI player"]
  node_behavior_tree["Behavior Tree<br/>AI decisions<br/>[BehaviorTree.swift]"]
end

subgraph group_assets["SpriteKit Assets"]
  node_animation["Animation<br/>[Animation.swift]"]
  node_unit_atlases["Unit Sprite Atlases<br/>animation frames<br/>[knight.atlas]"]
  node_asset_catalog["Asset Catalog<br/>bundled resources<br/>[Assets.xcassets]"]
end

node_project -->|"builds"| node_app_delegate
node_app_delegate -->|"launches"| node_scene_delegate
node_scene_delegate -->|"uses"| node_storyboard
node_storyboard -->|"instantiates"| node_view_controller
node_view_controller -->|"hosts"| node_game_view
node_game_view -->|"presents"| node_game_scene
node_scene_content -->|"defines"| node_game_scene
node_game_scene -->|"updates"| node_game_state
node_game_scene -->|"spawns and controls"| node_battle_models
node_game_scene -->|"resolves"| node_attack
node_game_scene -->|"processes purchases"| node_shop
node_game_scene -->|"uses"| node_game_interface
node_game_scene -->|"handles contacts with"| node_physics
node_game_scene -->|"runs"| node_actions
node_battle_models -->|"use"| node_attack
node_battle_models -->|"animate through"| node_animation
node_animation -->|"loads frames from"| node_unit_atlases
node_game_scene -->|"renders resources from"| node_asset_catalog
node_computer_player -->|"evaluates"| node_behavior_tree
node_behavior_tree -->|"chooses actions through"| node_game_interface
node_computer_player -.->|"deploys via"| node_game_scene

click node_project "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars.xcodeproj/project.pbxproj"
click node_storyboard "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Base.lproj/Main.storyboard"
click node_app_delegate "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/AppDelegate.swift"
click node_scene_delegate "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/SceneDelegate.swift"
click node_view_controller "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameViewController.swift"
click node_game_view "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameView.swift"
click node_game_scene "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameScene.swift"
click node_game_state "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameState.swift"
click node_scene_content "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameScene.sks"
click node_actions "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Actions.sks"
click node_battle_models "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Troop.swift"
click node_attack "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Attack.swift"
click node_shop "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Shop.swift"
click node_game_interface "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/GameInterface.swift"
click node_computer_player "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/ComputerPlayer.swift"
click node_behavior_tree "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/BehaviorTree/BehaviorTree.swift"
click node_animation "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Animation.swift"
click node_physics "https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/PhysicsCategory.swift"
click node_unit_atlases "https://github.com/rfx14/cartoonwars/tree/main/CartoonWars/knight.atlas"
click node_asset_catalog "https://github.com/rfx14/cartoonwars/tree/main/CartoonWars/Assets.xcassets"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_project,node_storyboard,node_app_delegate,node_scene_delegate,node_view_controller toneBlue
class node_game_view,node_game_scene,node_game_state,node_scene_content,node_actions,node_physics toneAmber
class node_battle_models,node_attack,node_shop,node_game_interface toneMint
class node_computer_player,node_behavior_tree toneRose
class node_animation,node_unit_atlases,node_asset_catalog toneIndigo
```

## Components

### iOS Entry

- [Xcode Target](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars.xcodeproj/project.pbxproj): build target · Defines app lifecycle, signing, and deployment. · `CartoonWars.xcodeproj/project.pbxproj`
- [Main Storyboard](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Base.lproj/Main.storyboard): UIKit entry · `CartoonWars/Base.lproj/Main.storyboard`
- [App Delegate](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/AppDelegate.swift): iOS lifecycle · `CartoonWars/AppDelegate.swift`
- [Scene Delegate](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/SceneDelegate.swift): scene lifecycle · `CartoonWars/SceneDelegate.swift`
- [Game View Controller](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameViewController.swift): UIKit controller · Loads and configures the SpriteKit gameplay view. · `CartoonWars/GameViewController.swift`

### Gameplay Runtime

- [Game View](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameView.swift): SpriteKit view · `CartoonWars/GameView.swift`
- [Game Scene](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameScene.swift): real-time controller · Coordinates input, spawning, physics, and visual game events. · `CartoonWars/GameScene.swift`
- [Game State](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameState.swift): match state · Holds progression and gameplay rules state. · `CartoonWars/GameState.swift`
- [Scene Content](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/GameScene.sks): SpriteKit scene · `CartoonWars/GameScene.sks`
- [Authored Actions](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Actions.sks): SpriteKit actions · `CartoonWars/Actions.sks`
- [Physics Categories](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/PhysicsCategory.swift): collision rules · Classifies contacts for combat processing. · `CartoonWars/Models/PhysicsCategory.swift`

### Battle Domain

- [Troops and Towers](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Troop.swift): combat entities · Combatants and defensive objectives. · `CartoonWars/Models/Troop.swift`
- [Attack Model](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Attack.swift): combat semantics · `CartoonWars/Models/Attack.swift`
- [Shop and Upgrades](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Shop.swift): economy · Models purchasing and upgrade flow. · `CartoonWars/Models/Shop.swift`
- [Game Interface](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/GameInterface.swift): gameplay contract · UI-facing domain contract. · `CartoonWars/Models/GameInterface.swift`

### AI

- [Computer Player](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/ComputerPlayer.swift): AI player · `CartoonWars/Models/ComputerPlayer.swift`
- [Behavior Tree](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/BehaviorTree/BehaviorTree.swift): AI decisions · Selects deployments and upgrades. · `CartoonWars/BehaviorTree/BehaviorTree.swift`

### SpriteKit Assets

- [Animation](https://github.com/rfx14/cartoonwars/blob/main/CartoonWars/Models/Animation.swift): animation behavior · `CartoonWars/Models/Animation.swift`
- [Unit Sprite Atlases](https://github.com/rfx14/cartoonwars/tree/main/CartoonWars/knight.atlas): animation frames · Knight, orc, soldier, and werewolf frames. · `CartoonWars/knight.atlas`
- [Asset Catalog](https://github.com/rfx14/cartoonwars/tree/main/CartoonWars/Assets.xcassets): bundled resources · `CartoonWars/Assets.xcassets`

## Connections

- Xcode Target → App Delegate: builds
- App Delegate → Scene Delegate: launches
- Scene Delegate → Main Storyboard: uses
- Main Storyboard → Game View Controller: instantiates
- Game View Controller → Game View: hosts
- Game View → Game Scene: presents
- Scene Content → Game Scene: defines
- Game Scene → Game State: updates
- Game Scene → Troops and Towers: spawns and controls
- Game Scene → Attack Model: resolves
- Game Scene → Shop and Upgrades: processes purchases
- Game Scene → Game Interface: uses
- Game Scene → Physics Categories: handles contacts with
- Game Scene → Authored Actions: runs
- Troops and Towers → Attack Model: use
- Troops and Towers → Animation: animate through
- Animation → Unit Sprite Atlases: loads frames from
- Game Scene → Asset Catalog: renders resources from
- Computer Player → Behavior Tree: evaluates
- Behavior Tree → Game Interface: chooses actions through
- Computer Player → Game Scene: deploys via
