# formkit/drag-and-drop architecture

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

- Interactive diagram: https://gitdiagram.com/formkit/drag-and-drop
- Repository: https://github.com/formkit/drag-and-drop

## Overview

##### Project Type and Purpose
- This is a lightweight, framework-agnostic drag and drop library from FormKit that enables data-first sorting and transferring of list items.
- It is designed to work with various front-end frameworks – React, Solid, and Vue – offering dedicated wrappers for each, while keeping a core engine for the basic drag and drop functionality.
- The library includes plugins (e.g., animations, drop-or-swap, insert) that add modular features to the core functionality.
- The repository includes comprehensive documentation (found in the docs directory) and tests (via Playwright and other test directories) to showcase usage scenarios and ensure reliability.

##### Analyzing the File Structure
- Top-Level Structure: The project root includes configuration files, build scripts (e.g., tsup.config.ts, build.ts), and distribution artifacts (dist) that are built from the source code.
- Source Directory (src): Breaks down into core code (src/index.ts) and subdirectories for framework-specific implementations (src/react, src/solid, src/vue) as well as plugins (src/plugins/animations, src/plugins/drop-or-swap, src/plugins/insert).
- Documentation (docs): Contains the documentation website, demo components, examples, and even some server logic. This is essential to communicate usage and integration.
- Tests: Various directories (tests, tests-frameworks, playwright) are dedicated to testing – ensuring that the functionality is validated across different frameworks and under various conditions.

##### Key Components
a. Core Library:
– Drag & Drop Engine: Place this as the central component encapsulating the logic that handles drag events, sorting, transferring, and maintaining state.
– Plugins: Represent each plugin (animations, drop-or-swap, insert) connected to the core engine, shown as extensions or modules that can plug into the main drag and drop functionality.

b. Framework-Specific Wrappers:
– Solid & Vue Wrappers: Similarly, include dedicated components/interfaces for Solid and Vue, indicating that these wrap the core library to seamlessly integrate with respective reactive paradigms.

c. Build & Distribution:
– Build Process: A module showing the TypeScript source transformation into various module formats (CommonJS, ESM) and integration of TypeScript type extraction (as noted in the README). Represent the build script (build.ts) feeding into a “dist” component with subdirectories per framework.

d. Documentation and Testing:
– Documentation Site: Include a component that represents the static docs site built from the docs directory (with examples, components, and server side API for stars, etc.).

##### Relationships and Interactions
- Adapter/wrapper layer: Each framework-specific wrapper (React, Solid, Vue) connects to the core engine demonstrating that they act as “glue” between the library’s functionality and the framework’s paradigms.
- Build process as an intermediary that compiles the src/ directory into optimized dist/ outputs which are then consumed by developers.
- Feedback loops from tests and documentation back to the main codebase, highlighting continuous integration pipelines (e.g., GitHub workflows).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Library Core Subgraph
    subgraph "Library Core"
        CE["Core Drag & Drop Engine"]:::core
        AP["Animations Plugin"]:::plugin
        DPS["Drop-or-Swap Plugin"]:::plugin
        IP["Insert Plugin"]:::plugin
    end

    %% Framework Wrappers Subgraph
    subgraph "Framework Wrappers"
        RW["React Wrapper"]:::wrapper
        SW["Solid Wrapper"]:::wrapper
        VW["Vue Wrapper"]:::wrapper
    end

    %% Build and Distribution Subgraph
    subgraph "Build and Distribution"
        BP["Build Process"]:::build
        DS["Distribution (dist)"]:::build
    end

    %% Auxiliary Components Subgraph
    subgraph "Auxiliary Components"
        DSITE["Documentation Site"]:::docs
        TS["Test Suites"]:::test
        CI["CI/CD Pipelines"]:::ci
    end

    %% Relationships: Core to Plugins
    CE -->|"extends"| AP
    CE -->|"extends"| DPS
    CE -->|"extends"| IP

    %% Relationships: Wrappers use the Core Engine
    RW -->|"wraps"| CE
    SW -->|"wraps"| CE
    VW -->|"wraps"| CE

    %% Relationships: Build Process compiles source from Core and Wrappers
    CE -->|"compiled_by"| BP
    RW -->|"compiled_by"| BP
    SW -->|"compiled_by"| BP
    VW -->|"compiled_by"| BP
    BP -->|"outputs_to"| DS

    %% Relationships: Auxiliary components provide feedback
    DSITE -->|"documents"| CE
    TS -->|"tests"| CE
    CI -->|"validates"| CE

    %% Click Events for Components
    click CE "https://github.com/formkit/drag-and-drop/blob/main/src/index.ts"
    click AP "https://github.com/formkit/drag-and-drop/blob/main/src/plugins/animations/index.ts"
    click DPS "https://github.com/formkit/drag-and-drop/blob/main/src/plugins/drop-or-swap/index.ts"
    click IP "https://github.com/formkit/drag-and-drop/blob/main/src/plugins/insert/index.ts"
    click RW "https://github.com/formkit/drag-and-drop/tree/main/src/react"
    click SW "https://github.com/formkit/drag-and-drop/tree/main/src/solid"
    click VW "https://github.com/formkit/drag-and-drop/tree/main/src/vue"
    click BP "https://github.com/formkit/drag-and-drop/blob/main/build.ts"
    click DSITE "https://github.com/formkit/drag-and-drop/tree/main/docs"
    click TS "https://github.com/formkit/drag-and-drop/tree/main/tests"
    click CI "https://github.com/formkit/drag-and-drop/tree/main/.github/workflows"

    %% Styling
    classDef core fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef plugin fill:#ffdd88,stroke:#555,stroke-width:1px;
    classDef wrapper fill:#88bbff,stroke:#333,stroke-width:1px;
    classDef build fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef docs fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef test fill:#ffab91,stroke:#333,stroke-width:2px;
    classDef ci fill:#b2dfdb,stroke:#333,stroke-width:2px;
```
