How peterrichards-lr/liferay-fragments works
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