Skip to content

Commit e4827e3

Browse files
authored
@W-18737391 Add development guidelines and page creation rules for generated project
2 parents ff0cc39 + ae0fe8d commit e4827e3

File tree

15 files changed

+351
-126
lines changed

15 files changed

+351
-126
lines changed

.cursor/rules/storefront-development/component-generation-requirements.mdc

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/pwa-kit-create-app/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v3.12.0-dev.0
2+
- Add development guidelines and create page Cursor rules for generated project [2786](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2786)
3+
14
## v3.11.0-dev.0 (May 23, 2025)
25
- Fix exiting before `program.json` content can be flushed [#2699](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2699)
36
- Add `program.json` + Support for Agent-Friendly CLI Input via stdio [#2662](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2662)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
description: Salesforce Commerce Composable Storefront Development Guidelines
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Commerce Composable Storefront Development Guidelines
8+
9+
## Overview
10+
Guidelines for Salesforce Commerce Composable Storefront development using PWA Kit, Retail React App, and Chakra UI.
11+
12+
## Core Principles
13+
- Analyze requirements and existing codebase thoroughly
14+
- Use existing components and hooks when possible
15+
- Plan before implementing
16+
- Test comprehensively with Jest
17+
18+
## PWA Kit Essentials
19+
20+
### Architecture
21+
- Server-side rendering (SSR) for initial loads
22+
- Client-side rendering (CSR) for interactions
23+
- Isomorphic code (works on server and client)
24+
- Proxy requests via `/mobify/proxy/<PROXY_PATH>`
25+
26+
### Special Components
27+
- Components starting with `_` are special PWA Kit components
28+
- `_app-config`: Top-level app configuration
29+
- `_app`: Persistent layout (header, footer, sidebar)
30+
- `_error`: 404 and error pages
31+
32+
## Development Rules
33+
- Use kebab-case for file names (except special components with `_`)
34+
- Use Chakra UI and existing components
35+
- Create modular, reusable components
36+
- Use React Hooks for state management
37+
- Access data via commerce-sdk-react hooks
38+
- Ensure mobile-friendly and accessible components
39+
- Maintain consistent code formatting using project standards
40+
- Write comprehensive test coverage
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
description: Page Creation Rule - automatically apply when user asks to create new page, add page, make page, build page, generate page
3+
globs:
4+
alwaysApply: false
5+
---
6+
USE WHEN create a new page, add a new page, make a new page, build a new page, generate a new page, create page, add page, make page, build page, generate page
7+
8+
**Mandatory**
9+
- DO ask user to clarify page name and page route before proceed
10+
- ONLY Create a bare minimum page component
11+
- Do NOT include other project components or hooks unless specifically requested
12+
- Do NOT add extra styling, layout, or features unless explicitly asked
13+
14+
## Implementation Steps
15+
1. Create simple component in `app/pages/[page-name]/index.jsx`
16+
2. Add route to `app/routes.jsx`

packages/pwa-storefront-mcp/src/utils/pwa-developer-guideline-tool.js

Lines changed: 30 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,103 +6,40 @@
66
*/
77
import {EmptyJsonSchema} from './utils'
88

9-
const guidelinesText = `# Salesforce Commerce Composable Storefront Development Guidelines
9+
const guidelinesText = `# Commerce Composable Storefront Development Guidelines
1010
1111
## 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.
1313
1414
## 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
10643
`
10744

10845
export default {

packages/pwa-storefront-mcp/src/utils/pwa-developer-guideline-tool.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('PWA Development Guidelines', () => {
2727
{
2828
type: 'text',
2929
text: expect.stringContaining(
30-
'Salesforce Commerce Composable Storefront Development Guidelines'
30+
'Commerce Composable Storefront Development Guidelines'
3131
)
3232
}
3333
]
@@ -41,9 +41,8 @@ describe('PWA Development Guidelines', () => {
4141
const requiredSections = [
4242
'Overview',
4343
'Core Principles',
44-
'Technical Stack',
45-
'PWK Kit Architecture',
46-
'Quality Standards'
44+
'PWA Kit Essentials',
45+
'Development Rules'
4746
]
4847

4948
requiredSections.forEach((section) => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: Check and verify accessibility on local project
3+
globs:
4+
alwaysApply: false
5+
---
6+
To check accessibility of a project, use the accessibility rules defined in ./cursor-accessibility-mdc/ directory.
7+
Run an automated scan for the entire codebase within the project and check for any violations.
8+
Show the scanned results in summary and detailed violations if any.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: When accessibility is checked. Check if Buttons must have a discernible name using text or aria attributes
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-button-name
8+
9+
Buttons must have a discernible name using text or aria attributes
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<button(?![^>]*\b(aria-label|aria-labelledby|title|name)=)
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<button></button>
22+
// ✅ Good
23+
<button>Submit</button>
24+
// ✅ Good
25+
<button aria-label="Close dialog"><XIcon /></button>
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: When accessibility is checked. Check if heading levels should increase sequentially for semantic structure
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-heading-order
8+
9+
Heading levels should increase sequentially for semantic structure
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<h([3-6])>
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<h1>Main Title</h1>
22+
<h4>Subsection</h4>
23+
// ✅ Good
24+
<h1>Main Title</h1>
25+
<h2>Subsection</h2>
26+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
description: When accessibility is checked. Ensure all <img> tags include descriptive alt attributes
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-image-alt
8+
9+
Ensure all <img> tags include descriptive alt attributes
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<img(?![^>]*\balt=)
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<img src="photo.jpg" />
22+
// ✅ Good
23+
<img src="photo.jpg" alt="Company logo" />
24+
```

0 commit comments

Comments
 (0)