AI-Assisted E-commerce Frontend Development: Practices for Multi-Page Consistency
This article explores how to leverage AI-assisted programming tools to build a multi-page e-commerce frontend. It covers task decomposition for defining page dependencies, four dimensions of consistency evaluation, and six metrics for assessing generated results. Additionally, it provides engineering practices for defining design tokens, isolating mock data, and handling form validation rules, along with common pitfalls and a comprehensive delivery checklist.
1. Background: The Role of AI-Assisted Programming in E-commerce Frontends
AI-assisted programming tools can generate project skeletons, page code, and basic interactions based on natural language requirements. For multi-page projects like e-commerce sites, the value of these tools lies primarily in shortening the time from requirement to a runnable prototype. However, generation speed does not equate to delivery quality. Whether the styles across pages are consistent, whether data structures match, and whether the project directory conforms to engineering standards determine the subsequent maintenance costs.
Therefore, when evaluating such tools, one cannot only look at single-generation results but also needs to check their performance on a complete project. This article uses a ten-page e-commerce frontend project as an example to illustrate how to organize requirements, design validation steps, and determine whether the generated results are ready for the next phase.
2. Task Decomposition: Defining the Page List and Dependencies
A complete e-commerce site typically includes the following three types of pages:
- Browsing and Transaction Flow: Home page (product list), Product detail page, Checkout page, Purchase success page.
- Account System: Login page, Registration page.
- User Center: Dashboard, Orders page, Coupons/Wallet page, Settings page.
These pages are not independent of each other. The product list depends on the product data structure, the detail and checkout pages share product specifications, the purchase success page needs to read order information, and the sub-pages of the user center depend on the login state. Before submitting generation requirements, you should first draw a transition and data dependency diagram between pages. Once dependencies are clear, you can determine which modules need to be prioritized for generation and which need manual confirmation.
3. Four Dimensions of Consistency
The overall consistency of the site is usually checked from the following four aspects:
- Visual consistency: Colors, font sizes, spacing, border radius, and button styles should be uniformly defined and not hardcoded in each page.
- Navigation consistency: The position, text, and active state of the top navigation, bottom navigation, and breadcrumbs should maintain the same rules across different pages.
- Data consistency: The name, price, and stock fields of the same product in the list, detail, and orders should come from the same data source.
- Interaction consistency: The presentation of loading states, empty states, error messages, and form validation information should be unified.
During the check, you can verify these four dimensions page by page and record inconsistent locations. After identifying issues, prioritize modifying shared configurations or common components rather than patching them page by page.
4. Evaluation Dimensions
To determine whether the generated results are qualified, you can refer to the following six dimensions:
- Completeness: Do all pages exist, can routes be accessed, and is the transition between pages a closed loop?
- Runnability: Can it be started directly after dependency installation, and are there blocking errors in the console?
- Consistency: Check according to the four dimensions in Section 3.
- Maintainability: Is the directory structure clear, are styles, logic, and data separated, and are there duplicate directories or identical nested names?
- Usability: Is mobile adaptation normal, can forms be validated, and does the contrast between button text and background meet readability requirements?
- Modification cost: Without rewriting the overall structure, how many rounds of dialogue and manual adjustments are needed to modify a requirement?
Each dimension should be given a conclusion of pass, partial pass, or fail, with specific locations attached. Such records can be compared horizontally across multiple generations.
5. Engineering Practices: Define Constraints First, Then Generate Pages
To reduce late-stage rework, it is recommended to fix three types of basic content before generating pages: design tokens, data models, and service interfaces.
5.1 Unified Design Tokens
Centralize colors, spacing, and breakpoints in a configuration file. Pages should only reference variables, not write color values directly.
// src/config/theme.jsexport const theme = {colors: {primary: '#1E6FD9',textOnPrimary: '#FFFFFF',surface: '#FFFFFF',textMain: '#1F2329',},spacing: { sm: 8, md: 16, lg: 24 },breakpoints: { mobile: 576, tablet: 992 },};
The foreground and background colors of buttons should be defined in pairs. This prevents white text on a white background, as contrast issues can be detected in the unified configuration.
5.2 Mock Data Isolation from Pages
Mock data should not be scattered in page components. It is recommended to place the data in an independent directory, and pages should only obtain data through the service layer. When connecting to the real backend later, you only need to replace the service layer implementation without altering the page code.
// src/data/products.js: Mock data is maintained only hereexport const products = [{ id: 'p001', name: 'Sample Product A', price: 199, stock: 20, image: '/assets/placeholder-1.png' },{ id: 'p002', name: 'Sample Product B', price: 89, stock: 0, image: '/assets/placeholder-2.png' },];// src/services/productService.js: Pages only depend on this interfaceimport { products } from '../data/products';export async function fetchProducts() {return products;}export async function fetchProductById(id) {return products.find((item) => item.id === id) ?? null;}
Image paths should also be centrally configured. In the production environment, images can be stored in object storage or a static asset service, and the base address can be injected through configuration to avoid hardcoding domains in the code.
5.3 Form Validation Rules
Registration and login pages are where validation logic is most concentrated. Validation rules should be independent pure functions for easy isolated testing.
// src/utils/validators.jsexport function validateRegisterForm(values) {const errors = {};if (!/^1\d{10}$/.test(values.phone)) {errors.phone = 'Invalid phone number format';}if (values.password.length < 8) {errors.password = 'Password must be at least 8 characters';}if (values.password !== values.confirmPassword) {errors.confirmPassword = 'The passwords entered do not match';}return errors;}
The validation function returns an error object, and the page renders prompts based on the object. This approach also makes it easy to check whether the prompt text on the registration and login pages is unified.
6. Common Issues and Solutions
When generating projects in practice, the following issues are common:
- Excessive placeholder images: Define the image directory and naming rules during the generation phase, and require each product to correspond to at least one replaceable image.
- Oversimplified detail information: Specify in the requirements that the detail page must include fields such as specifications, parameters, stock status, delivery instructions, and review summaries.
- Insufficient mobile adaptation: Require the layout to be designed based on mobile width first, and then incrementally add tablet and desktop styles. Login and registration pages often deform due to numerous form fields and require separate checks.
- Chaotic directory structure: Specify the directory tree in the prompt, such as the locations of pages, components, services, data, and styles, and verify them one by one after generation.
- Code error loop fixing: Only fix one issue at a time after each fix, and rerun the validation. If three consecutive fixes are ineffective, return to the requirement or structure level for re-evaluation instead of continuously stacking patches.
- Empty directories and unimplemented modules: After generation, check whether each directory has actual content. For directories with only frameworks and no implementations, delete or complete them.
7. Delivery Checklist
Before the project enters the next phase, it is recommended to complete the following checks:
- All ten pages are accessible via routes, and the core transition paths can be fully traversed.
- The startup command executes successfully, with no blocking errors in the console.
- Colors, font sizes, and spacing all come from the unified configuration, with no isolated color values.
- Mock data only exists in the data directory, and there is no hardcoded product information in the page code.
- Form validation on registration, login, and checkout pages covers required fields, formats, and consistency rules.
- Under common mobile widths, navigation, lists, and forms can be operated normally.
- The directory structure is consistent with the agreement, with no duplicate or identically named nested directories.
- The contrast between text and background for each button meets readability requirements.
After completing the checks, the project can enter the API integration and business testing phase. These checks demonstrate that the generated results possess basic completeness and maintainability, but they cannot replace subsequent security reviews, performance testing, and business acceptance.
