Engineering Practices for AI-Assisted Development of an E-Commerce Frontend

    This article explains how to use AI-assisted coding tools to build a complete, multi-page e-commerce frontend with production-level engineering quality. It covers task decomposition for a ten-page storefront, three dimensions of consistency (routing, data models, and visual design tokens), a six-point checklist for evaluating generated code, a staged generation-and-verification workflow with a data layer abstraction example, common pitfalls and fixes, and practical recommendations for team adoption.

    1. Background: From Single-Page Prototypes to Full Sites

    AI-assisted coding tools can now generate frontend project skeletons from natural language descriptions. For a page with only a few components, the output usually runs right away. The real test comes with a complete site. A ten-page e-commerce project involves routing, authentication state, shopping cart, orders, and wallet modules, and the generation tool must maintain structural uniformity, coherent interactions, and maintainable code across all of them.

    In practice, teams typically encounter three categories of problems:

    1. The generated project starts, but certain page routes are broken or throw errors.
    2. Page styling is inconsistent—for example, mobile layouts mixed with desktop layouts, or button colors clashing with backgrounds.
    3. The directory structure is messy: duplicate folder names appear, or directories like hooks and context are reserved but left empty.

    These issues show that the standard for evaluating AI-generated code cannot be limited to “does the page render.” Overall engineering quality matters just as much.

    2. Task Decomposition: A Ten-Page E-Commerce Site

    When requesting a complete site, break the requirements into a clear page list and business boundaries first. A typical page breakdown looks like this:

    Module Page Suggested Route
    Product browsing Home (product list) /
    Product browsing Product detail /products/:id
    Transaction Checkout /checkout
    Transaction Checkout success /checkout/success
    Account Login /login
    Account Register /register
    User center Dashboard /account/dashboard
    User center Order list /account/orders
    User center Wallet and coupons /account/wallet
    User center Account settings /account/settings

    After decomposition, each page needs clearly defined input data, output behavior, and shared components it depends on. Without this step, the generation tool will often use different names for the same concept—for example, the product ID might be id on the list page but productId on the detail page—which eventually breaks navigation parameters.

    3. Three Dimensions of Completeness and Consistency

    3.1 Route Consistency

    Routing is the first check of site completeness. Define the route table in one place so a single source manages all page paths, avoiding hard-coded navigation URLs scattered across pages.

    1. // routes.js: centrally declare all page paths
    2. export const ROUTES = {
    3. home: '/',
    4. productDetail: (id) => `/products/${id}`,
    5. checkout: '/checkout',
    6. checkoutSuccess: '/checkout/success',
    7. login: '/login',
    8. register: '/register',
    9. dashboard: '/account/dashboard',
    10. orders: '/account/orders',
    11. wallet: '/account/wallet',
    12. settings: '/account/settings',
    13. };

    During acceptance, iterate through the route table and visit each path, confirming that every page renders correctly with no console errors. This step is quick, yet it exposes most navigation problems early.

    3.2 Data Model Consistency

    The same product should use the same field definitions across the list, detail, cart, and order pages. If each page defines its own data structure, missing fields or type mismatches will surface during later maintenance. Establish unified models for core entities and verify their references after code generation.

    3.3 Visual Design Consistency

    Visual issues are often overlooked, but they directly affect delivery quality. Define base design tokens early in the project—primary color, secondary colors, font sizes, spacing, and breakpoints—then have all components reference these variables. This prevents problems like button text matching its background color or broken mobile layouts.

    1. /* tokens.css: unified design variables */
    2. :root {
    3. --color-primary: #1677ff;
    4. --color-text-on-primary: #ffffff;
    5. --space-2: 8px;
    6. --space-4: 16px;
    7. --breakpoint-mobile: 768px;
    8. }

    4. Six Dimensions for Evaluating Generated Results

    Teams can use the following checklist to evaluate AI-generated projects. Each item should receive a clear pass/fail verdict, with specific issues recorded.

    1. Runnability: Do dependency installation, startup, and build succeed on the first try? The number of errors and fix iterations is an important metric.
    2. Structural soundness: Does the directory layout follow common layering conventions? Are there duplicate names or empty directories?
    3. Data-view decoupling: Is mock data separated from page components? Data hard-coded inside components forces heavy rework when connecting to real APIs later.
    4. Form validation: Do registration, login, and checkout forms enforce required fields, formats, and length limits, with error messages mapped to the correct fields?
    5. Responsive layout: Are pages usable at common screen widths, with key buttons clickable and text readable?
    6. Maintainability: Are styles separated from logic, and is shared logic extracted into reusable modules?

    For evaluation, fix a single requirements document and compare results across multiple generation runs. A single run is heavily influenced by randomness; only repeated comparison reflects a tool’s stability.

    5.1 Write the Spec Before Generating Code

    Before submitting a generation request, prepare a specification covering the page list, route table, data models, interaction rules, and visual standards. The more complete the spec, the closer the output matches expectations. The spec also serves as the basis for later acceptance.

    5.2 Staged Generation and Verification

    Generating all pages in one shot is not recommended. A safer approach splits the work into four stages:

    1. Generate the project skeleton and routes; confirm all pages are reachable.
    2. Generate the data layer and shared components; confirm mock data is stored independently.
    3. Generate pages one at a time, running a build and basic checks after each page is completed.
    4. Apply visual standards uniformly and check style consistency across pages.

    Staged generation makes problems easier to locate. If an error appears in stage three, you can roll back directly to the last passing version instead of debugging blindly across the whole project.

    5.3 Data Layer Abstraction Example

    Data access should go through a unified interface; page components should not read mock data files directly. When connecting to real services later, you only need to swap the data layer implementation.

    1. // repositories/productRepository.js
    2. import mockProducts from '../mock/products.json';
    3. const USE_MOCK = import.meta.env.VITE_USE_MOCK !== 'false';
    4. export async function listProducts({ page = 1, pageSize = 20 } = {}) {
    5. if (USE_MOCK) {
    6. const start = (page - 1) * pageSize;
    7. return mockProducts.slice(start, start + pageSize);
    8. }
    9. // Production: replace with the real API call
    10. const res = await fetch(`/api/products?page=${page}&pageSize=${pageSize}`);
    11. if (!res.ok) throw new Error('Failed to load product list');
    12. return res.json();
    13. }

    The page layer only calls listProducts and doesn’t care where the data comes from. This pattern also simplifies unit testing, since tests can inject mock data directly.

    6. Common Problems and How to Handle Them

    Problem 1: Messy directory structure. Generation tools sometimes create duplicate directories inside existing ones. State directory conventions explicitly in your prompts, and run a directory-check script after each generation round. If duplicate nesting appears, roll back immediately.

    Problem 2: Stuck in a fix loop. If the tool modifies the same code repeatedly without resolving the error, stop automatic fixes. Inspect the error stack manually, identify the root cause, and then give a precise instruction.

    Problem 3: Too many placeholder images. Placeholders keep the layout correct, but they can’t validate image loading, lazy loading, or size adaptation. Specify image size standards and fallback strategies in the spec, and check how the UI behaves when images fail to load during acceptance.

    Problem 4: Inconsistent styling. Use the design tokens described above, and enforce restrictions on hard-coded color values with style-checking tools. Buttons with insufficient contrast can be caught by automated accessibility checkers.

    Problem 5: Sparse detail pages. Generated output often covers only the most basic fields. List the information items each page must display in the spec—such as product specifications, stock status, review summaries, and shipping details—and verify them item by item.

    7. Recommendations for Team Adoption

    AI-assisted coding is well suited for scaffolding, repetitive page generation, and first-draft styling. Humans should still own architecture decisions, business rule confirmation, and final quality control. Teams are advised to establish the following practices:

    • Keep the specification document and acceptance checklist for every generated project as a traceable record.
    • Wire builds, type checks, linting, and basic end-to-end tests into the CI pipeline so every generation result is verified automatically.
    • Conduct a manual review of generated code, focusing on security-sensitive logic such as validation and escaping of form inputs and how authentication state is stored.
    • Log the error types and fix time for each generation run, gradually building the team’s own prompt templates and problem knowledge base.

    With these practices, AI-generated code can progress from “it runs” to “it can be maintained over time,” and teams gain a clearer sense of which parts of the work can be delegated to tools and which must remain under human control.