# efremidze/magnetic architecture

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

- Interactive diagram: https://gitdiagram.com/efremidze/magnetic
- Repository: https://github.com/efremidze/magnetic

## Overview

##### Project Type and Purpose
- Magnetic is an **open-source iOS UI component library** (bubble picker) built in Swift.
- It ships as a Swift Package, CocoaPod, or Carthage framework.
- It provides an `SKScene` subclass (`Magnetic`) and supporting views/nodes to display interactive “bubbles.”

##### A: Distribution & Build
- **Package Managers**
– CocoaPods (Magnetic.podspec)
– Carthage (Cartfile support)
– SwiftPM (Package.swift)
- **CI/CD**
– GitHub Actions (/.github/workflows/ci.yml)
– Travis CI (.travis.yml)
- **Documentation Generation**
– Jazzy (docs/**) produces HTML/Jazzy docsets.

##### B: Runtime Framework (Magnetic)

- MagneticView.swift (UIView subclass wrapping SKView)
- Magnetic.swift (SKScene subclass)
- Node.swift (SKShapeNode subclass)
- SKMultilineLabelNode.swift
- MagneticView+SwiftUI.swift (SwiftUI wrapper)
- MagneticView+Accessibility.swift
- MagneticDelegate protocol

– from MagneticView → presents → Magnetic (SKScene)
– Magnetic → manages → Node instances

Also annotate:
– **Delegate Pattern**: Magnetic → MagneticDelegate → Application
– **Animation Hooks**: Node.selectedAnimation(), deselectedAnimation(), removedAnimation()

##### Data Flow & Component Interaction
1. App code calls `magnetic.addChild(node)`
2. Magnetic positions nodes inside SKScene
3. User taps Node → SKScene dispatches touch → Node triggers animation
4. Node state change → MagneticDelegate callbacks → App

##### Architectural Patterns & Principles
- **MVC-ish**:
– ViewController → View (MagneticView) → Model/View (Magnetic + Node)
- **Delegate Pattern** for event callbacks
- **Composition** of SpriteKit nodes for UI
- **Extension points** via subclassing Node
- **Modular packaging**: clear separation between Sources, Example, Docs

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "A: Distribution & Build"
        Podspec["CocoaPods\n(Magnetic.podspec)"]:::build
        SPMPkg["SwiftPM\n(Package.swift)"]:::build
        Carthage["Carthage\n(Cartfile)"]:::build
        GHAct["GitHub Actions\n(.github/workflows/ci.yml)"]:::build
        Travis["Travis CI\n(.travis.yml)"]:::build
        DocsGen["Jazzy Docs\n(docs/)"]:::build
    end

    Podspec -->|"package"| GHAct
    SPMPkg -->|"package"| GHAct
    Carthage -->|"package"| GHAct
    GHAct -->|"build artifacts"| DocsGen
    Travis -->|"build artifacts"| DocsGen

    subgraph "B: Magnetic Framework\n(Runtime Core)"
        MV["MagneticView.swift\n(UIView wrapper)"]:::core
        MScene["Magnetic.swift\n(SKScene)"]:::core
        Node["Node.swift\n(SKShapeNode)"]:::core
        LabelNode["SKMultilineLabelNode.swift"]:::core
        ColorExt["SKAction+Color.swift"]:::core
        SwiftUIExt["MagneticView+SwiftUI.swift"]:::core
        AccExt["MagneticView+Accessibility.swift"]:::core
        Delegate["MagneticDelegate\n(protocol)"]:::core
    end

    MV -->|"presents"| MScene
    MScene -->|"manages"| Node
    Node -->|"uses"| LabelNode
    Node -->|"uses"| ColorExt
    MScene -->|"delegate→"| Delegate

    subgraph "C: Consumer App\n(Example App)"
        VC["ViewController.swift"]:::consumer
        Info["Info.plist"]:::consumer
        Assets["Assets.xcassets"]:::consumer
        MainSB["Main.storyboard"]:::consumer
        LaunchSB["LaunchScreen.storyboard"]:::consumer
        User["User Interaction\n(taps)"]:::consumer
    end

    VC -->|"instantiates"| MV
    VC -->|"configures\nmagnetic"| MScene
    User -->|"touches"| MScene
    MScene -->|"didSelect(node)"| VC
    MainSB --> VC
    LaunchSB --> VC
    Assets -.-> Info

    classDef build fill:#F8B195,stroke:#F08A5D,color:#000
    classDef core fill:#C8E6C9,stroke:#66BB6A,color:#000
    classDef consumer fill:#B3E5FC,stroke:#29B6F6,color:#000

    click Podspec "https://github.com/efremidze/magnetic/blob/master/Magnetic.podspec"
    click SPMPkg "https://github.com/efremidze/magnetic/blob/master/Package.swift"
    click GHAct "https://github.com/efremidze/magnetic/blob/master/.github/workflows/ci.yml"
    click Travis "https://github.com/efremidze/magnetic/blob/master/.travis.yml"
    click DocsGen "https://github.com/efremidze/magnetic/tree/master/docs/"
    click MScene "https://github.com/efremidze/magnetic/blob/master/Sources/Magnetic.swift"
    click MV "https://github.com/efremidze/magnetic/blob/master/Sources/MagneticView.swift"
    click Node "https://github.com/efremidze/magnetic/blob/master/Sources/Node.swift"
    click LabelNode "https://github.com/efremidze/magnetic/blob/master/Sources/SKMultilineLabelNode.swift"
    click ColorExt "https://github.com/efremidze/magnetic/blob/master/Sources/SKAction+Color.swift"
    click SwiftUIExt "https://github.com/efremidze/magnetic/blob/master/Sources/MagneticView+SwiftUI.swift"
    click AccExt "https://github.com/efremidze/magnetic/blob/master/Sources/MagneticView+Accessibility.swift"
    click Delegate "https://github.com/efremidze/magnetic/blob/master/docs/Protocols/MagneticDelegate.html"
    click VC "https://github.com/efremidze/magnetic/blob/master/Example/ViewController.swift"
    click Info "https://github.com/efremidze/magnetic/blob/master/Example/Info.plist"
    click Assets "https://github.com/efremidze/magnetic/tree/master/Example/Assets.xcassets/"
    click MainSB "https://github.com/efremidze/magnetic/blob/master/Example/Base.lproj/Main.storyboard"
    click LaunchSB "https://github.com/efremidze/magnetic/blob/master/Example/Base.lproj/LaunchScreen.storyboard"
```
