|
6 | 6 | */ |
7 | 7 | import {EmptyJsonSchema} from './utils' |
8 | 8 |
|
9 | | -const guidelinesText = `# Salesforce Commerce Composable Storefront Development Guidelines |
| 9 | +const guidelinesText = `# Commerce Composable Storefront Development Guidelines |
10 | 10 |
|
11 | 11 | ## Overview |
12 | | -This document offers guidelines in the development of Salesforce Commerce Composable Storefront applications using PWA Kit. The AI should possess a comprehensive understanding of the PWA Kit architecture, sample Retail React App, Chakra UI, and standard React application practices. |
| 12 | +Guidelines for Salesforce Commerce Composable Storefront development using PWA Kit, Retail React App, and Chakra UI. |
13 | 13 |
|
14 | 14 | ## Core Principles |
15 | | -
|
16 | | -### Project Understanding |
17 | | -- Thoroughly analyze requests and the existing project for successful implementation. |
18 | | -- Promptly clarify ambiguous requirements. |
19 | | -
|
20 | | -### Development Workflow |
21 | | -- **Analyze Requirements** - Clearly define the objectives and functionalities required. |
22 | | -- **Review Existing Code** - Examine the current codebase to identify similar solutions and potentially reusable components. |
23 | | -- **Understand Existing Hooks and Utilities** - Familiarize with hooks and utility functions available within the project, including those from commerce-sdk-react and template-retail-react-app modules. |
24 | | -- **Plan Implementation** - Design component structure before coding. |
25 | | -- **Implement Incrementally** - Develop and test the service in small, manageable steps. |
26 | | -- **Test Thoroughly** - Ensure comprehensive testing, including the use of Jest. |
27 | | -
|
28 | | -## Technical Stack |
29 | | -
|
30 | | -### Core Technologies |
31 | | -- **React** - UI components and SPA architecture |
32 | | -- **Express** - Server-side rendering and backend |
33 | | -- **@salesforce/commerce-sdk-react** - Commerce Cloud API integration (hooks) |
34 | | -- **PWA Kit** - SSR, routing, config, Salesforce integration |
35 | | -- **Chakra UI V2** - UI components and theming |
36 | | -- **Emotion** - CSS-in-JS styling |
37 | | -- **React Router** - Routing |
38 | | -- **React Intl** - Localization |
39 | | -- **React Query** - Data fetching/caching |
40 | | -- **Webpack** - Bundling |
41 | | -- **React Testing Library, Jest** - Testing libraries |
42 | | -- **react-helmet, framer-motion, etc.** - Utilities, animation, head management |
43 | | -- **ESLint/Prettier** - Code formatting and linting |
44 | | -
|
45 | | -## PWK Kit Architecture |
46 | | -
|
47 | | -### Configuration Files |
48 | | -- PWA Kit apps are customized using configuration files for API access, URL formatting, and server-side rendering. |
49 | | -- These files support JavaScript, YAML, and JSON formats, with default.js being the standard. |
50 | | -- Configuration values are serialized for isomorphic rendering, so secrets must not be included. |
51 | | -- Environment-specific configuration files can replace or complement default.js. |
52 | | -- File precedence is .js > .yml > .yaml > .json if base names are the same. |
53 | | -
|
54 | | -### Proxy Requests |
55 | | -- Managed Runtime's proxy feature routes API requests through the storefront domain to avoid CORS issues and improve performance. |
56 | | -- Local proxy configurations are set in config/default.js, while Managed Runtime deployments use Runtime Admin or the Managed Runtime API. |
57 | | -- Requests use the /mobify/proxy/<PROXY_PATH> pattern. |
58 | | -- Proxied requests and responses are modified for transparent operation. |
59 | | -- Proxied requests are uncached by default but can be cached using a caching path prefix. |
60 | | -
|
61 | | -### Rendering |
62 | | -- PWA Kit uses server-side rendering (SSR) for fast initial page loads, leveraging CDN caching. |
63 | | -- After the first load, client-side rendering (CSR) takes over for fluid user interactions. |
64 | | -- Application code must be isomorphic, functioning in both server and client environments, often with conditional logic. |
65 | | -- Props from API requests are serialized into the page source during SSR for client-side hydration. |
66 | | -- A correlation ID is provided on each page for tracking requests across PWA Kit and other systems. |
67 | | -
|
68 | | -### Routing |
69 | | -- PWA Kit uses Express.js and React Router for handling requests and rendering components. |
70 | | -- Routes are defined in app/routes.jsx as an array of objects with 'path' and 'component' properties. |
71 | | -- You can use both withReactQuery and withLegacyGetProps at the same time. |
72 | | -- getProps and shouldGetProps were removed from the default template of pages of the Retail React App, but aren't deprecated. Long-term support for these methods remains. |
73 | | -
|
74 | | -### PWA Kit Special Components |
75 | | -- Customize your storefront by overriding default special components that start with an underscore (_), such as app/components/_app-config/index.jsx. |
76 | | -- app/components/_app-config: The top-level component for app-wide configurations like theme providers and state management. |
77 | | -- app/components/_app: The child of _app-config. Use it for layout and UI that persist throughout your React app, such as the header, footer, and sidebar. |
78 | | -- app/components/_error: Renders when a page or its data isn't found, or when an error occurs, returning a 404 status. |
79 | | -
|
80 | | -### State Management |
81 | | -- PWA Kit applications support various state management approaches, including simple prop-passing or React's Context API. |
82 | | -- The React Context API can be used with useReducer and useContext for shared global state. |
83 | | -- The AppConfig special component is the primary place to initialize a state management system. |
84 | | -- When integrating libraries like Redux, AppConfig methods such as restore, freeze, extraGetPropsArgs, and render are utilized. |
85 | | -
|
86 | | -### PWA Kit Extensibility |
87 | | -- In PWA Kit v3, you can extend a base template (@salesforce/retail-react-app) by replacing specific files using a local "overrides directory." |
88 | | -- Extensibility is configured in package.json with the base template (ccExtensibility.extends) and your overrides directory (ccExtensibility.overridesDir). |
89 | | -- To override a file, recreate its exact path and filename in your overrides directory. |
90 | | -
|
91 | | -### PWA Kit Storefront Development |
92 | | -- Start development with Retail React App sample codebase and tooling. |
93 | | -- Use included npm scripts for automating development tasks like build, test, and lint. |
94 | | -- Access Shopper data through the commerce-sdk-react hooks to fetch, cache, and mutate utilizing Salesforce Commerce API (SLAS) and OCAPI. |
95 | | -- Use Chakra UI and existing components when available. |
96 | | -- Create simple, functional, modular, reusable components. |
97 | | -- Use the React Helmet library to modify the HTML tags in Document, such as <head>. |
98 | | -- Use kebab-case for file names. Only start with an underscore (_) if they are special components. |
99 | | -- Use React Hooks (e.g., useState, useEffect, useContext, useMemo, useCallback) for state management and side effects. |
100 | | -
|
101 | | -## Quality Standards |
102 | | -- Maintain consistent code formatting using project standards. |
103 | | -- Write comprehensive test coverage. |
104 | | -- Ensure components are accessible and mobile-friendly. |
105 | | -- Follow security best practices for all code. |
| 15 | +- Analyze requirements and existing codebase thoroughly |
| 16 | +- Use existing components and hooks when possible |
| 17 | +- Plan before implementing |
| 18 | +- Test comprehensively with Jest |
| 19 | +
|
| 20 | +## PWA Kit Essentials |
| 21 | +
|
| 22 | +### Architecture |
| 23 | +- Server-side rendering (SSR) for initial loads |
| 24 | +- Client-side rendering (CSR) for interactions |
| 25 | +- Isomorphic code (works on server and client) |
| 26 | +- Proxy requests via \`/mobify/proxy/<PROXY_PATH>\` |
| 27 | +
|
| 28 | +### Special Components |
| 29 | +- Components starting with \`_\` are special PWA Kit components |
| 30 | +- \`_app-config\`: Top-level app configuration |
| 31 | +- \`_app\`: Persistent layout (header, footer, sidebar) |
| 32 | +- \`_error\`: 404 and error pages |
| 33 | +
|
| 34 | +## Development Rules |
| 35 | +- Use kebab-case for file names (except special components with \`_\`) |
| 36 | +- Use Chakra UI and existing components |
| 37 | +- Create modular, reusable components |
| 38 | +- Use React Hooks for state management |
| 39 | +- Access data via commerce-sdk-react hooks |
| 40 | +- Ensure mobile-friendly and accessible components |
| 41 | +- Maintain consistent code formatting using project standards |
| 42 | +- Write comprehensive test coverage |
106 | 43 | ` |
107 | 44 |
|
108 | 45 | export default { |
|
0 commit comments