# material-motion/material-motion-swift architecture

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

- Interactive diagram: https://gitdiagram.com/material-motion/material-motion-swift
- Repository: https://github.com/material-motion/material-motion-swift

## Overview

##### Main Components

a. Core Runtime Layer
- MotionRuntime (Central coordinator)
- ReactiveProperty system
- Interaction base system

b. Interaction Layer
- Pre-built interactions (Draggable, Scalable, Rotatable, etc.)
- Custom interaction support
- Transition system

c. Operators Layer
- Foundation operators
- Gesture operators
- Mathematical operators
- Utility operators

d. Systems Layer
- Core Animation integration
- Gesture recognition system
- ScrollView integration
- Timeline system

**┌─────────────────────────────────────────────────────────────┐**
- Client Application                      │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Motion Runtime Layer                     │
- ┌─────────────┐    ┌──────────────┐    ┌───────────────┐  │
- MotionRuntime│←→ │ReactiveSystem│←→ │InteractionBase │  │
- ┘    └──────────────┘    └───────────────┘  │
- ┬─────────────────┬────────────────────┬─────────┘
- ↓                 ↓                    ↓
**┌──────────────────┐ ┌───────────────┐  ┌─────────────────┐**
- Interactions    │ │   Operators   │  │     Systems     │
- ┌──────────────┐│ │ ┌───────────┐ │  │ ┌─────────────┐ │
- Draggable   ││ │ │Foundation │ │  │ │CoreAnimation│ │
- Scalable    ││ │ │ Gestures  │ │  │ │  Gestures   │ │
- Rotatable   ││ │ │   Math    │ │  │ │ ScrollView  │ │
- Springs     ││ │ │  Utility  │ │  │ │  Timeline   │ │
- ┘│ │ └───────────┘ │  │ └─────────────┘ │
- ┘ └───────────────┘  └─────────────────┘

##### Implementation Details to Note
- The runtime acts as the central coordinator
- All interactions are built on top of reactive properties
- Operators provide transformation and manipulation capabilities
- System integration handles platform-specific features

##### Key Design Patterns to Highlight
- Observer pattern (Reactive system)
- Builder pattern (Interaction construction)
- Strategy pattern (Different animation systems)
- Facade pattern (Runtime API)

Remember to emphasize the reactive nature of the system and how it integrates with iOS's native animation and gesture systems. This is crucial for understanding how the library provides its core functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application"]
        App[Client App]:::client
    end

    subgraph Runtime["Motion Runtime Layer"]
        MR["MotionRuntime"]:::runtime
        RS["ReactiveProperty System"]:::runtime
        IB["Interaction Base"]:::runtime
    end

    subgraph Interactions["Interaction Layer"]
        direction TB
        DR["Draggable"]:::interaction
        SC["Scalable"]:::interaction
        RO["Rotatable"]:::interaction
        SP["Spring"]:::interaction
        TO["Tossable"]:::interaction
    end

    subgraph Operators["Operators Layer"]
        direction TB
        FO["Foundation Operators"]:::operator
        GO["Gesture Operators"]:::operator
        MO["Mathematical Operators"]:::operator
        UO["Utility Operators"]:::operator
    end

    subgraph Systems["Systems Layer"]
        direction TB
        CA["Core Animation Integration"]:::system
        GR["Gesture Recognition"]:::system
        SV["ScrollView Integration"]:::system
        TS["Timeline System"]:::system
    end

    subgraph Reactive["Reactive Types"]
        RT["Core Reactive Types"]:::reactive
        UI["UI Integration"]:::reactive
    end

    subgraph Transition["Transition System"]
        TC["Transition Controller"]:::transition
        TR["Core Transition"]:::transition
    end

    %% Relationships
    App --> MR
    MR <--> RS
    MR <--> IB
    
    MR --> DR
    MR --> SC
    MR --> RO
    MR --> SP
    MR --> TO
    
    RS --> FO
    RS --> GO
    RS --> MO
    RS --> UO
    
    IB --> CA
    IB --> GR
    IB --> SV
    IB --> TS
    
    RS --> RT
    RT --> UI
    
    IB --> TC
    TC --> TR

    %% Styles
    classDef client fill:#E5E5E5,stroke:#333
    classDef runtime fill:#B3E0FF,stroke:#333
    classDef interaction fill:#90EE90,stroke:#333
    classDef operator fill:#FFB366,stroke:#333
    classDef system fill:#DDA0DD,stroke:#333
    classDef reactive fill:#FFD700,stroke:#333
    classDef transition fill:#87CEEB,stroke:#333

    %% Click Events
    click MR "https://github.com/material-motion/material-motion-swift/blob/develop/src/MotionRuntime.swift"
    click RS "https://github.com/material-motion/material-motion-swift/blob/develop/src/ReactiveProperty.swift"
    click IB "https://github.com/material-motion/material-motion-swift/blob/develop/src/Interaction.swift"
    click DR "https://github.com/material-motion/material-motion-swift/blob/develop/src/interactions/Draggable.swift"
    click SC "https://github.com/material-motion/material-motion-swift/blob/develop/src/interactions/Scalable.swift"
    click RO "https://github.com/material-motion/material-motion-swift/blob/develop/src/interactions/Rotatable.swift"
    click SP "https://github.com/material-motion/material-motion-swift/blob/develop/src/interactions/Spring.swift"
    click TO "https://github.com/material-motion/material-motion-swift/blob/develop/src/interactions/Tossable.swift"
    click FO "https://github.com/material-motion/material-motion-swift/tree/develop/src/operators/foundation"
    click GO "https://github.com/material-motion/material-motion-swift/tree/develop/src/operators/gestures"
    click MO "https://github.com/material-motion/material-motion-swift/blob/develop/src/operators/distanceFrom.swift"
    click UO "https://github.com/material-motion/material-motion-swift/blob/develop/src/operators/merge.swift"
    click CA "https://github.com/material-motion/material-motion-swift/blob/develop/src/systems/coreAnimationTweenToStream.swift"
    click GR "https://github.com/material-motion/material-motion-swift/blob/develop/src/systems/gestureToStream.swift"
    click SV "https://github.com/material-motion/material-motion-swift/blob/develop/src/systems/scrollViewToStream.swift"
    click TS "https://github.com/material-motion/material-motion-swift/blob/develop/src/timeline/Timeline.swift"
    click RT "https://github.com/material-motion/material-motion-swift/blob/develop/src/reactivetypes/MotionObservable.swift"
    click UI "https://github.com/material-motion/material-motion-swift/blob/develop/src/reactivetypes/Reactive+UIView.swift"
    click TC "https://github.com/material-motion/material-motion-swift/blob/develop/src/transitions/TransitionController.swift"
    click TR "https://github.com/material-motion/material-motion-swift/blob/develop/src/transitions/Transition.swift"
```
