Building a Complete E-commerce Frontend with AI: Consistency and Runnability in Practice

    AI coding tools are increasingly capable of generating an entire runnable frontend project from a requirements description, not just completing single functions or files. This article uses a ten-page e-commerce frontend as an example to examine the three key quality criteria for whole-site generation—completeness, consistency, and runnability—along with common pitfalls and practical solutions, including route verification, design tokens, and a clean build pipeline.

    From Snippet Generation to Whole-Site Generation

    The capability boundaries of AI coding tools keep expanding. In the past, they mainly handled function completion, single-file edits, and error explanations. Now they are increasingly used to generate a runnable frontend project directly from a requirements description. Developers only need to write out a page list and business goals, and the tool can output route configuration, page components, style files, and mock data.

    This approach is valuable for prototype validation and teaching demos, but the evaluation criteria differ from single-file tasks. Whether a single function is correct can be judged by running it once; whole-site generation must satisfy three categories of requirements simultaneously.

    • Completeness: Every page listed in the requirements exists, is accessible, and has a clear entry point.
    • Consistency: Navigation, visual conventions, data structures, and interaction feedback remain uniform across the site.
    • Runnability: Dependency installation, build, and startup succeed in one pass in a clean environment.

    The rest of this article uses a ten-page e-commerce frontend as an example to break down common problems and countermeasures around these three points. The scenario covers the product list, product detail, checkout confirmation, checkout success, login, and register pages, plus the user center’s overview, orders, wallet and coupons, and account settings.

    Completeness: Page List and Route Verification

    The most common defect in generated results is “enough pages, but broken links.” A tool may generate ten page files yet fail to register several of them in the route table; or the pages exist, but neither the navbar nor in-page buttons link to them.

    A structured check right after generation is recommended. Break the requirements into a checklist where each page corresponds to a route entry:

    1. // Route checklist example: every page must have a path, a name, and an access level
    2. const routes = [
    3. { path: "/", name: "Product List", auth: false },
    4. { path: "/products/:id", name: "Product Detail", auth: false },
    5. { path: "/checkout/:productId", name: "Checkout Confirmation", auth: true },
    6. { path: "/checkout/success/:orderId", name: "Checkout Success", auth: true },
    7. { path: "/login", name: "Login", auth: false },
    8. { path: "/register", name: "Register", auth: false },
    9. { path: "/account", name: "Account Overview", auth: true },
    10. { path: "/account/orders", name: "Orders", auth: true },
    11. { path: "/account/wallet", name: "Wallet & Coupons", auth: true },
    12. { path: "/account/settings", name: "Settings", auth: true },
    13. ];

    The verification should cover three things: whether routes are registered, whether navigation parameters between pages are complete, and whether unauthenticated users visiting protected pages are redirected to the login page. Take the purchase flow as an example: the checkout success page depends on an order ID. If the checkout confirmation page fails to pass the order ID via a route parameter or global state, the success page can only render blank. Problems like this cannot be spotted in static screenshots—you must actually click through the user journey.

    Consistency: Unified Design Tokens and Shared Components

    Consistency problems typically show up as buttons with different colors across pages, inputs with inconsistent border radii and border widths, and erratic spacing. The root cause is that style values are scattered across individual components, and each generation pass may make fresh decisions about colors and sizes.

    The solution is to define visual variables centrally, so that all pages reference variables instead of hard-coding color values:

    1. // Design tokens: the single source of truth for site-wide visual variables
    2. export const theme = {
    3. color: {
    4. primary: "#2F6FEB",
    5. text: "#1F2329",
    6. textOnPrimary: "#FFFFFF",
    7. border: "#D9D9D9",
    8. background: "#F5F6F7",
    9. },
    10. radius: { sm: 4, md: 8 },
    11. spacing: { xs: 4, sm: 8, md: 16, lg: 24 },
    12. };

    After defining tokens, check contrast as well. The contrast between button text and button background must meet accessibility requirements—for example, WCAG 2.1 AA requires a contrast ratio of at least 4.5:1 for normal text. White text on a white background, or light gray text on a light gray background, makes text unreadable, and such issues are not rare in generated output.

    Components of the same type should also have exactly one implementation. Buttons, inputs, cards, and form fields should each be encapsulated as shared components; pages only compose them and never duplicate styles. When the site-wide button style needs adjustment, you change it in one place.

    Runnability: Dependencies, Build, and Closing the Error Loop

    “It runs” is the minimum requirement, yet it is often where the most failures occur. Typical issues include dependency version conflicts, case-mismatched import paths, and module resolution failures caused by a file and a directory sharing the same name.