# peterrichards-lr/liferay-fragments architecture

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

- Interactive diagram: https://gitdiagram.com/peterrichards-lr/liferay-fragments
- Repository: https://github.com/peterrichards-lr/liferay-fragments

## Overview

##### Project type and purpose
- This is a monorepo of “Liferay Fragments” – essentially a static-asset library of UI fragments (HTML, CSS, JS, JSON, FreeMarker) for use in Liferay DXP/DXP 7.4+.
- Each top-level folder (e.g., commerce, finance, form-fragments, header-components, etc.) groups a collection of related fragments, each packaged with configuration.json, fragment.json, index.html, index.js, index.css, and sometimes language or template files.

##### File structure
- Top-level directories = fragment categories (commerce, forms, profile, etc.)
- Under each category:
- collection.json – metadata for the fragment collection
- fragments/<fragment-name> – per-fragment folder
– fragment.json – fragment metadata (name, CSS/JS entry points)
– configuration.json or index.json – editor UI settings
– index.html, index.js, index.css – the runtime assets
– optional FreeMarker (.ftl) or properties for localization
- Build/deploy scripts: create-fragment-zips.sh packages each fragment into a ZIP for Liferay import
- .github/workflows/release.yml – CI to build and publish fragment zips
- docs/ – architecture and usage videos, images

##### Extract insights from the README
- The README describes functional groups (Meter Reading, Date Display, Form Populator, Liferay Iframer, Layout Components, Header Components, Profile fragments, Miscellaneous, Commerce)
- Highlights patterns: drop-zones, client-side retry logic, FreeMarker injection, Liferay JS API usage (Liferay.CommerceContext), remote apps via iframes
- Notes dependencies on Liferay portal features (Fragment Editor, Page Editor, FreeMarker engine settings, segmentation, commerce context)

a. Main components
– Developer Monorepo (source code)
– Build Pipeline (create-fragment-zips.sh + CI workflow)
– Fragment Packages (ZIP artifacts)
– Liferay Portal Runtime
- Fragment Renderer Engine
- Fragment Editor / Page Content Editor
- FreeMarker Engine (with staticUtil)
- Liferay APIs (CommerceContext, Segmentation, Remote Apps)
– Browser Client
- HTML/CSS/JS from each fragment
- Interactions with Liferay JS objects (e.g., Liferay.CommerceContext)
– External Services
- Liferay Commerce back-end (for purchased products)
- Third-party JS libraries (PDF export, date handling)

b. Relationships and data flows
1. Developer commits to Monorepo → CI workflow triggers → run create-fragment-zips.sh → produce ZIP artifacts
2. Admin imports ZIPs into Liferay via Fragment Admin UI → portal registers fragment metadata
3. Author drags fragments onto pages in Page Editor → portal resolves fragment.json, configuration.json → injects index.html, index.css, index.js into page
4. At runtime, Browser loads fragment assets → fragment JS may call:
– Liferay JS APIs (navigation, commerce context, segmentation)
– External endpoints (Commerce REST, third-party services)
– DOM manipulation (drop-zones, form fields, back-button logic)
5. Some fragments use FreeMarker on server to inject configuration or context (e.g., CommerceContext Contributor)

c. Architectural patterns & design principles
– Micro-frontend style: each fragment is a self-contained UI module
– Plugin architecture: portal picks up fragment packages at runtime
– Separation of concerns: configuration vs view vs logic in distinct files
– Drop-zone pattern: layout and form fragments expose zones for nested content
– Progressive enhancement: JS only runs in runtime view, not in editors

d. Key technologies & frameworks
– Liferay DXP Fragment Framework
– FreeMarker (server-side templating)
– HTML, CSS, Vanilla JS for fragment logic
– CI/CD: GitHub Actions, shell scripts
– ZIP packaging for fragment distribution

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Layer
    subgraph "Source Code" 
        direction TB
        Monorepo["Developer Monorepo (source code)"]:::source
        Docs["Documentation (architecture & usage)"]:::source
    end

    %% Build Layer
    subgraph "Build & CI/CD" 
        direction TB
        Script["Build Pipeline Script<br/>(fragment zipping)"]:::build
        CI["CI/CD Workflow<br/>(GitHub Actions)"]:::build
        Artifacts["ZIP Artifacts"]:::artifact
    end

    %% Portal Layer
    subgraph "Liferay Portal Runtime" 
        direction TB
        Renderer["Fragment Renderer Engine"]:::portal
        Editor["Fragment Editor / Page Editor"]:::portal
        FreeMarker["FreeMarker Engine"]:::portal
        APIs["Liferay JS APIs<br/>(CommerceContext, Segmentation)"]:::portal
    end

    %% Client Layer
    subgraph "Browser Client" 
        direction TB
        Browser["Browser<br/>(HTML/CSS/JS)"]:::client
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        Commerce["Liferay Commerce Back-end"]:::external
        ThirdParty["Third-party JS Libraries"]:::external
    end

    %% Fragment Categories
    subgraph "Fragment Categories (× N)" 
        direction TB
        CommerceFrags["Commerce Fragments"]:::fragment
        FormPop["Form Populator Fragment"]:::fragment
        DateDisplay["Date Display Fragments"]:::fragment
        HeaderComps["Header Components"]:::fragment
        LayoutComps["Layout Components"]:::fragment
        MeterReading["Meter Reading Fragments"]:::fragment
        ProfileFrags["Profile Fragments"]:::fragment
        RemoteApp["Remote App (iframe) Fragment"]:::fragment
        FormFrags["Form Fragments Collection"]:::fragment
        ResponsiveMenus["Responsive Menus (FreeMarker)"]:::fragment
        MiscFrags["Miscellaneous Utility Fragments"]:::fragment
        ObjectsFrags["Objects Fragments"]:::fragment
        PopFormFields["Populated Form Fields"]:::fragment
        PulseFrags["Pulse Fragments"]:::fragment
        WidgetMods["Widget Modifiers"]:::fragment
        Collections["Global Collection Metadata"]:::fragment
    end

    %% Connections
    Monorepo -->|commits trigger| CI
    Monorepo -->|contains| Script
    Monorepo -->|contains| Docs
    CI -->|runs| Script
    Script -->|produces| Artifacts
    Artifacts -->|import ZIPs| Renderer
    Renderer -->|registers metadata| Editor
    Editor -->|injects assets| Browser
    FreeMarker -->|renders templates| Browser
    Renderer -->|uses| FreeMarker
    Renderer -->|uses| APIs
    Browser -->|loads assets| APIs
    Browser -->|calls| Commerce
    Browser -->|calls| ThirdParty

    %% Fragment injection
    Collections --> CommerceFrags
    Collections --> FormPop
    Collections --> DateDisplay
    Collections --> HeaderComps
    Collections --> LayoutComps
    Collections --> MeterReading
    Collections --> ProfileFrags
    Collections --> RemoteApp
    Collections --> FormFrags
    Collections --> ResponsiveMenus
    Collections --> MiscFrags
    Collections --> ObjectsFrags
    Collections --> PopFormFields
    Collections --> PulseFrags
    Collections --> WidgetMods

    %% Click Events
    click Monorepo "https://github.com/peterrichards-lr/liferay-fragments/tree/main//"
    click Script "https://github.com/peterrichards-lr/liferay-fragments/blob/main/create-fragment-zips.sh"
    click CI "https://github.com/peterrichards-lr/liferay-fragments/blob/main/.github/workflows/release.yml"
    click Docs "https://github.com/peterrichards-lr/liferay-fragments/tree/main/docs/"
    click CommerceFrags "https://github.com/peterrichards-lr/liferay-fragments/tree/main/commerce/fragments/"
    click FormPop "https://github.com/peterrichards-lr/liferay-fragments/tree/main/forms/fragments/form-populator/"
    click DateDisplay "https://github.com/peterrichards-lr/liferay-fragments/tree/main/date-display/fragments/"
    click HeaderComps "https://github.com/peterrichards-lr/liferay-fragments/tree/main/header-components/fragments/"
    click LayoutComps "https://github.com/peterrichards-lr/liferay-fragments/tree/main/layout-components/fragments/"
    click MeterReading "https://github.com/peterrichards-lr/liferay-fragments/tree/main/meter-reading/fragments/"
    click ProfileFrags "https://github.com/peterrichards-lr/liferay-fragments/tree/main/profile/fragments/"
    click RemoteApp "https://github.com/peterrichards-lr/liferay-fragments/tree/main/remote-app-utilities/liferay-iframer/"
    click FormFrags "https://github.com/peterrichards-lr/liferay-fragments/tree/main/form-fragments/fragments/"
    click ResponsiveMenus "https://github.com/peterrichards-lr/liferay-fragments/tree/main/responsive-menus/fragments/"
    click MiscFrags "https://github.com/peterrichards-lr/liferay-fragments/tree/main/misc/fragments/"
    click ObjectsFrags "https://github.com/peterrichards-lr/liferay-fragments/tree/main/objects/fragments/"
    click PopFormFields "https://github.com/peterrichards-lr/liferay-fragments/tree/main/populated-form-fields/fragments/"
    click PulseFrags "https://github.com/peterrichards-lr/liferay-fragments/tree/main/pulse/fragments/"
    click WidgetMods "https://github.com/peterrichards-lr/liferay-fragments/tree/main/widget-modifiers/fragments/"
    click Collections "https://github.com/peterrichards-lr/liferay-fragments/blob/main/* /collection.json"

    %% Styles
    classDef source fill:#D0E8FF,stroke:#2B6CB0,color:#2B6CB0;
    classDef build fill:#FFE8B5,stroke:#D69E2E,color:#D69E2E;
    classDef artifact fill:#F0FFF4,stroke:#2F855A,color:#2F855A;
    classDef portal fill:#E6FFFA,stroke:#319795,color:#319795;
    classDef client fill:#EBF4FF,stroke:#2B6CB0,color:#2B6CB0;
    classDef external fill:#F0F0F0,stroke:#A0AEC0,color:#4A5568;
    classDef fragment fill:#FFF5F5,stroke:#C53030,color:#C53030;
```
