# measuredco/puck architecture

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

- Interactive diagram: https://gitdiagram.com/measuredco/puck
- Repository: https://github.com/measuredco/puck

## Overview

##### Main Components Identification

The system consists of several key architectural components:

a) Core Editor Components:
- Puck Editor UI
- Component Rendering System
- Drag & Drop System
- Field Management System
- Plugin System

b) Integration Layer:
- Framework Adapters (Next.js, Remix)
- Data Management
- API Layer

**┌─────────────────────────────────────────────────────────────┐**
- Puck Editor System                      │

- ┌─────────────┐    ┌──────────────┐    ┌──────────────┐   │
- Editor    │    │   Preview    │    │    Render    │   │
- Interface │    │    Panel     │    │    Engine    │   │
- ┘    └──────────────┘    └──────────────┘   │

- ▼                 ▼                   ▼            │
- ┌─────────────────────────────────────────────────────┐   │
- Core Components                     │   │
- ┌──────────┐  ┌─────────┐  ┌────────────────┐     │   │
- DragDrop │  │ Fields  │  │ ComponentList  │     │   │
- ┘  └─────────┘  └────────────────┘     │   │
- ┘   │

- ┌─────────────────────────────────────────────────────┐   │
- Plugin System                       │   │
- ┌──────────────┐  ┌───────────────┐  ┌─────────┐  │   │
- EmotionCache │  │ HeadingAnalyzer│  │ Custom  │  │   │
- ┘  └───────────────┘  └─────────┘  │   │
- ┘   │

- ┌─────────────────────────────────────────────────────┐   │
- Framework Integration                  │   │
- ┌──────────┐  ┌─────────┐  ┌────────────────┐     │   │
- Next.js │  │  Remix  │  │ Custom Adapter │     │   │
- ┘  └─────────┘  └────────────────┘     │   │
- ┘   │
- ┘

##### Key Relationships to Highlight

- Bidirectional data flow between Editor Interface and Preview Panel
- Plugin system integration points
- Demonstrate framework adapter connections
- Component rendering pipeline

##### Important Implementation Details

- Configuration system
- Data persistence flow
- Component registry
- Document the drag-and-drop system

##### Specific Technical Elements

- The modular architecture allowing for custom components
- The plugin system's extensibility
- The framework-agnostic core with framework-specific adapters
- The separation between editor and render modes

- How components interact
- Where to extend functionality
- How data flows through the system
- Integration points for different frameworks
- Plugin architecture and extension points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph PuckEditor["Puck Editor System"]
        UI["Editor Interface"]:::editor
        Preview["Preview Panel"]:::preview
        Render["Render Engine"]:::render

        subgraph CoreComponents["Core Components"]
            DnD["Drag & Drop System"]:::core
            Fields["Field Management"]:::core
            CompList["Component Registry"]:::core
        end

        subgraph PluginSystem["Plugin System"]
            EmotionCache["Emotion Cache"]:::plugin
            HeadingAnalyzer["Heading Analyzer"]:::plugin
            ContentfulField["Contentful Field"]:::plugin
        end

        subgraph DataManagement["Data Management"]
            Reducer["State Reducer"]:::data
            DataResolver["Data Resolver"]:::data
            PropTransform["Props Transformer"]:::data
        end

        subgraph FrameworkIntegration["Framework Integration"]
            NextJS["Next.js Adapter"]:::framework
            Remix["Remix Adapter"]:::framework
        end

        UI --> Preview
        Preview --> Render
        UI --> CoreComponents
        CoreComponents --> PluginSystem
        CoreComponents --> DataManagement
        DataManagement --> FrameworkIntegration
    end

    %% Component Relationships
    UI --> DnD
    UI --> Fields
    UI --> CompList
    Preview --> Render
    DnD --> DataManagement
    Fields --> DataManagement

    %% Click Events
    click UI "https://github.com/measuredco/puck/blob/main/packages/core/components/Puck/index.tsx"
    click Render "https://github.com/measuredco/puck/blob/main/packages/core/components/Render/index.tsx"
    click DnD "https://github.com/measuredco/puck/tree/main/packages/core/lib/dnd"
    click Fields "https://github.com/measuredco/puck/tree/main/packages/core/components/Fields"
    click CompList "https://github.com/measuredco/puck/blob/main/packages/core/components/ComponentList/index.tsx"
    click EmotionCache "https://github.com/measuredco/puck/tree/main/packages/plugin-emotion-cache"
    click HeadingAnalyzer "https://github.com/measuredco/puck/tree/main/packages/plugin-heading-analyzer"
    click ContentfulField "https://github.com/measuredco/puck/tree/main/packages/field-contentful"
    click NextJS "https://github.com/measuredco/puck/tree/main/recipes/next"
    click Remix "https://github.com/measuredco/puck/tree/main/recipes/remix"
    click Reducer "https://github.com/measuredco/puck/tree/main/packages/core/reducer"
    click DataResolver "https://github.com/measuredco/puck/blob/main/packages/core/lib/resolve-all-data.ts"
    click PropTransform "https://github.com/measuredco/puck/blob/main/packages/core/lib/transform-props.ts"
    click Preview "https://github.com/measuredco/puck/tree/main/packages/core/components/Preview"

    %% Styles
    classDef editor fill:#2196F3,color:white
    classDef preview fill:#4CAF50,color:white
    classDef render fill:#9C27B0,color:white
    classDef core fill:#3F51B5,color:white
    classDef plugin fill:#FF9800,color:white
    classDef data fill:#795548,color:white
    classDef framework fill:#607D8B,color:white

    %% Legend
    subgraph Legend
        L1["Editor Components"]:::editor
        L2["Preview System"]:::preview
        L3["Render System"]:::render
        L4["Core Components"]:::core
        L5["Plugins"]:::plugin
        L6["Data Management"]:::data
        L7["Framework Integration"]:::framework
    end
```
