Template developers: Template Structure
Understand how the ecommerce boilerplate under web-builder/apps/templates/ecommerce-boilerplate is organized so you can update UIs without touching core plumbing.
Architecture at a glance
- Location: Clone the template into
web-builder/apps/templates/ecommerce-boilerplate. - App Router-first: Routes live in
app/with a shared layout inapp/layout.tsxthat wraps pages withApolloWrapperandClientLayout. - Composable sections: Page JSON defines
pageItems; React components inapp/_components/sections/render each section type. - Data-aware: GraphQL operations in
graphql/and helper hooks inlib/fetch CMS/client-portal data; static JSON indata/backs local mocks. - Shared UI: Shadcn UI primitives live in
components/ui; reusable widgets (loaders, alerts, forms) live incomponents/common. - UI-only scope: Do not add/remove sections or change core wiring. Limit changes to UI (markup/styles/states) inside existing files.
Top-level folders
app/: All routes and page shells. Notable entries:_components/: Layout chrome (Header,Footer,ClientLayout) and all section components under_components/sections/.page.tsx: Home page that mapspageItemsto section components viarenderSections.- Route folders like
about/,contact/,products/,profile/that render CMS-backed pages withusePage.
components/: Reusable UI.ui/: Shadcn primitives (buttons, inputs, dialog, sheet, etc.).common/: Shared widgets (loaders, dynamic forms, empty states, template alerts).
data/: Local config and mock content.configs.json: Template metadata (title, description), appearance tokens, menus, integrations.pages/*.json: Page-level content (index.json,about.json,contact.json, etc.) used in build/local modes.
graphql/: Domain-specific operations grouped by feature (auth/,clientportal/,cms/,ecommerce/,order/,payment/,products/) plus aggregatequeries.ts/mutations.ts.lib/: Cross-cutting utilities.apollo-wrapper.tsxandclient.ts: Apollo Client setup.- Contexts (
AuthContext,CartContext) and hooks (useClientPortal,usePage,fetchCms,fetchCpConfig,fetchTours). renderSections.tsx: Helper to render a section list from a component map.
types/: Shared TypeScript contracts (types/sections.tsdefines the baseSectionshape).public/: Static assets (images, icons, favicons).
Page composition flow
- Home (
app/page.tsx): ImportspageDatafromdata/pages/index.json, builds aSectionComponentMap, and callsrenderSectionsto output the page. WhenBUILD_MODE=true, it swaps toapp/page.client.tsxto let the builder inject live data via query params. - Other routes: Pages like
about/page.tsxandcontact/page.tsxcallusePage(pageName)to fetch CMS content withGET_CMS_PAGE, passing theclient-portal-idheader from route params. Sections are rendered by switching onsection.type. - Layout:
app/layout.tsxwraps everything inApolloWrapperandClientLayout, ensuring GraphQL and layout chrome are available to every page.
Sections
- Location:
app/_components/sections/. Each file exports a React component that accepts{ section: Section }. - Registry (read-only):
app/page.tsxmapssection.typeto components for build/local;lib/usePage.tsxdoes the same for CMS. Do not add or remove mappings—only adjust UI inside existing section files. - Behavior: Sections are responsible for their own data needs (e.g., product listings, CMS posts) and should support sensible defaults so mocked JSON can render without live APIs.
Config and data sources
- Template config:
data/configs.jsonstores meta tags, theme tokens, menus, and integration placeholders. Keep IDs and secrets out of this file; use environment variables instead. - Page mocks:
data/pages/*.jsonsupplytitle,description, andpageItemsfor local development and build previews. Use these to validate layout and theming without hitting the CMS. - Environment flags:
BUILD_MODE=truetoggles builder-driven rendering; absence falls back to local JSON-driven rendering for the home page.
Shared UI and utilities
- UI primitives live in
components/ui(generated viacomponents.jsonshadcn config). - Cross-template widgets live in
components/common(loaders, dynamic forms, empty states). - Utility helpers like
lib/utils.tshandle class merging and small helpers reused across sections.
GraphQL layer
- Operations are organized by domain inside
graphql/, with aggregated exports ingraphql/queries.tsandgraphql/mutations.ts. lib/apollo-wrapper.tsxprovides the provider setup;lib/client.tsconfigures the Apollo client instance.- Hooks and fetchers in
lib/(e.g.,usePage,fetchCms,fetchCpConfig) standardize how sections and pages request CMS/client-portal data, keeping rendering logic composable and data-aware.
Development Guide
Rules and workflow for UI-only changes, repo setup, and what you are allowed to edit.
Template Layout
Understand the global layout (header, footer, theme) for the ecommerce boilerplate so you can adjust UI without touching core logic.