# rohanrhu/swipy architecture

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

- Interactive diagram: https://gitdiagram.com/rohanrhu/swipy
- Repository: https://github.com/rohanrhu/swipy

## Overview

##### Project Type and Purpose
- Swipy is a SwiftUI library that integrates with existing applications (or can be directly copied into a project as a single Swipy.swift file) to add swipe actions.
- Its purpose is to wrap SwiftUI views in a gesture-aware container that supports swiping with customizable actions, behaviors, and a central model to track swipe state.

##### Analyzing the File Structure
- The top-level files are Project management files such as Package.swift (for Swift Package Manager) and an Xcode project (Swipy.xcodeproj).
- The core logic lives in the single source file “Swipy/Swipy.swift” where the main SwiftUI components (views and model) are defined.
- Support files like README, LICENSE, CONTRIBUTING, and CODE_OF_CONDUCT are present for project governance, while Media holds relevant images used by the README.

##### Main Components
- Swipy View: The primary component that wraps any content view to capture swipe gestures. It accepts a binding for isSwipingAnItem, a content closure, and an actions closure.
- SwipyAction: The component that encapsulates an individual swipe action (e.g. delete, edit). It uses a closure that receives a SwipyModel for performing actions.
- SwipyModel: The internal state model that is passed into closures. It maintains properties such as swipeOffset, isSwiping, isSwiped, and supports imperative methods like swipe() and unswipe().
- Behaviors:
- SwipySwipeBehavior: Configures the starting and continuing conditions for swipe gestures using predefined methods (.normal, .soft, etc.) or custom decider functions.
- SwipyScrollBehavior: Configures the interaction with scrolling (prevents vertical scroll interference during swiping).
- External Dependencies: SwiftUI as the underlying UI framework; the library is intended to be integrated using Swift Package Manager or manually via copying the file.

##### Examining Interactions Between Components
- The user’s gesture on a swipeable view (wrapped within Swipy) initiates the gesture listening in the SwiftUI environment.
- Swipy captures the swipe gesture and updates the SwipyModel, which holds the current swipe state.
- The actions themselves are closures that may trigger a method on the model (like unswipe() after a deletion action), which then informs the UI to update accordingly.
- The isSwipingAnItem binding serves as a flag that’s also used to control container (e.g., ScrollView) scrolling via SwiftUI’s .scrollDisabled modifier.

##### Final Elements
- Clear labels for each component (e.g., “Swipy – swipeable container”, “SwipyAction – action button view”, “SwipyModel – tracking swipe state”).

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Nodes
    userInteraction["User Interaction (Swipe Gesture)"]:::external
    containerView["Container View (ScrollView)"]:::external
    swiftUIFramework["SwiftUI Framework"]:::external

    %% Swipy Library Container
    subgraph "Swipy Library"
        subgraph "Core Components"
            swipyView["Swipy (View) - swipeable container"]:::swiftui
            swipyAction["SwipyAction - action button view"]:::swiftui
            swipyModel["SwipyModel - tracking swipe state"]:::model
            swipyBehaviors["Swipe & Scroll Behaviors - gesture configuration"]:::behavior
        end
    end

    %% Interactions and Data Flow
    userInteraction -->|"triggers"| swipyView
    containerView -->|"integrates"| swipyView
    swiftUIFramework ---|"supports"| swipyView

    swipyView -->|"updatesState"| swipyModel
    swipyView -->|"revealsActions"| swipyAction
    swipyView -->|"appliesBehavior"| swipyBehaviors
    swipyAction -->|"invokesAction"| swipyModel

    %% Click Events
    click swipyView "https://github.com/rohanrhu/swipy/blob/main/Swipy/Swipy.swift"
    click swipyAction "https://github.com/rohanrhu/swipy/blob/main/Swipy/Swipy.swift"
    click swipyModel "https://github.com/rohanrhu/swipy/blob/main/Swipy/Swipy.swift"
    click swipyBehaviors "https://github.com/rohanrhu/swipy/blob/main/Swipy/Swipy.swift"

    %% Styles
    classDef swiftui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef model fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef behavior fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
