# adobe/aem-react-editable-components architecture

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

- Interactive diagram: https://gitdiagram.com/adobe/aem-react-editable-components
- Repository: https://github.com/adobe/aem-react-editable-components

## Overview

##### Project type and purpose
- It’s an NPM-distributed React library, not a standalone application.
- Purpose: supply editable React components and an integration layer that hooks into the AEM SPA Editor and AEM SPA Page Model Manager.

##### Main components
A. Consumer React SPA (the host application)
B. @adobe/aem-react-editable-components library, broken down into:
1. API Layer
– fetchModel.ts
2. Core Integration
– ComponentMapping.tsx
– EditableComponent.tsx
3. React UI Components
– Page.tsx (entry point)
– Container.tsx
– ResponsiveGrid.tsx
– Placeholder.tsx
– AllowedComponentsContainer.tsx
4. Hooks & Utilities
– useEditor.ts
– Utils.ts
– constants & types
C. External Services
– AEM SPA Page Model Manager (remote JSON model provider)
– AEM SPA Editor (authoring environment)

##### Relationships & data-flow
1. At app startup the Consumer SPA invokes fetchModel → AEM Page Model Manager
2. fetchModel returns a JSON “page model”
3. Core ComponentMapping maps model component names to React UI Components
4. Page component recursively renders the tree via EditableComponent wrappers
5. useEditor hook and EditableComponent register edit events with the AEM SPA Editor window APIs
6. User actions in the browser (drag, drop, edit) emit events back to AEM SPA Editor

##### Architectural patterns & principles
- Plugin-style component mapping for extensibility (ComponentMapping)
- Separation of concerns:
– API layer (fetchModel)
– Rendering layer (Page, Container, etc.)
– Integration layer (EditableComponent, useEditor)
- Hook pattern for lifecycle integration with external editor
- Strongly-typed contract via Typescript types in src/types

##### Special notes for this open-source tool
- Extensibility boundary at ComponentMapping (users can register custom components).
- Dependency on the AEM SPA Page Model Manager (consumer must include it).
- That the library is a middleware between a React SPA and AEM services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer App
    subgraph "Consumer React SPA" 
        direction TB
        SPA["Browser / Consumer SPA"]:::consumer
    end

    %% Library Modules
    subgraph "@adobe/aem-react-editable-components"
        direction TB

        subgraph "API Layer"
            fetchModel["fetchModel.ts"]:::api
        end

        subgraph "Core Integration"
            ComponentMapping["ComponentMapping.tsx"]:::core
            EditableComponent["EditableComponent.tsx"]:::core
        end

        subgraph "UI Components"
            Page["Page.tsx"]:::ui
            Container["Container.tsx"]:::ui
            ResponsiveGrid["ResponsiveGrid.tsx"]:::ui
            Placeholder["Placeholder.tsx"]:::ui
            AllowedComponentsContainer["AllowedComponentsContainer.tsx"]:::ui
        end

        subgraph "Hooks & Utilities"
            useEditor["useEditor.ts"]:::hook
            Utils["Utils.ts"]:::util
            Constants["constants"]:::util
            TypesFile["types.ts"]:::util
        end
    end

    %% External Services
    AEMModelManager[(AEM SPA Page Model Manager)]:::external
    AEMEditor[(AEM SPA Editor)]:::external

    %% Data Flow
    SPA -->|"GET model"| fetchModel
    fetchModel -->|"GET model"| AEMModelManager
    AEMModelManager -->|"JSON model"| fetchModel
    fetchModel -->|"return model"| ComponentMapping
    ComponentMapping -->|"map & render"| Page
    Page -->|"recursive render"| EditableComponent
    EditableComponent -->|"register edit"| useEditor
    useEditor -->|"emit edit event"| AEMEditor

    %% Click Events
    click fetchModel "https://github.com/adobe/aem-react-editable-components/blob/master/src/api/fetchModel.ts"
    click ComponentMapping "https://github.com/adobe/aem-react-editable-components/blob/master/src/core/ComponentMapping.tsx"
    click EditableComponent "https://github.com/adobe/aem-react-editable-components/blob/master/src/core/EditableComponent.tsx"
    click Page "https://github.com/adobe/aem-react-editable-components/blob/master/src/components/Page.tsx"
    click Container "https://github.com/adobe/aem-react-editable-components/blob/master/src/components/Container.tsx"
    click ResponsiveGrid "https://github.com/adobe/aem-react-editable-components/blob/master/src/components/ResponsiveGrid.tsx"
    click Placeholder "https://github.com/adobe/aem-react-editable-components/blob/master/src/components/Placeholder.tsx"
    click AllowedComponentsContainer "https://github.com/adobe/aem-react-editable-components/blob/master/src/components/AllowedComponentsContainer.tsx"
    click useEditor "https://github.com/adobe/aem-react-editable-components/blob/master/src/hooks/useEditor.ts"
    click Utils "https://github.com/adobe/aem-react-editable-components/blob/master/src/utils/Utils.ts"
    click Constants "https://github.com/adobe/aem-react-editable-components/tree/master/src/constants/"
    click TypesFile "https://github.com/adobe/aem-react-editable-components/blob/master/src/types.ts"

    %% Styles
    classDef api fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef core fill:#FFF3E0,stroke:#E65100,color:#E65100;
    classDef ui fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef hook fill:#FFF8E1,stroke:#FF8F00,color:#FF8F00;
    classDef util fill:#ECEFF1,stroke:#546E7A,color:#546E7A;
    classDef consumer fill:#E3F2FD,stroke:#1565C0,color:#1565C0;
    classDef external fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A;
```
