AI Coding Assistants: Building an E-Commerce Frontend from Scratch

    Learn how to use an AI coding assistant to deliver a maintainable e-commerce frontend, from defining scope and choosing an execution mode to structuring the codebase and validating the purchase flow. This practical guide covers data boundaries, accessibility, failure states, security precautions, and a staged delivery process that keeps generated code reviewable and reversible.

    AI coding assistants can now contribute to frontend development from initial page structure to complete interactive flows. But success is not measured by whether the first generated version looks finished. It depends on whether the code runs reliably locally, whether a team can maintain it, and whether subsequent changes avoid compounding technical debt.

    Using a component-based e-commerce frontend as an example, this article explains how to make an assistant a source of auditable productivity rather than an uncontrolled stream of generated code.

    1. Define the Deliverables Before Generating Code

    An e-commerce storefront may contain many pages, but its core is a verifiable user journey. Define the minimum deliverable as an explicit checklist rather than a vague request to “build a shopping site”:

    • Product details: Title, price, variants, stock status, and descriptions with images.
    • Checkout: Address, delivery options, discounts, order totals, and submission.
    • Payment result: Success, failure, and processing states.
    • Login and registration: Validation, error messages, and submission-in-progress states.
    • Account area: Overview, orders, coupons or account balances, and account settings.

    Then add nonfunctional requirements: usable desktop and narrow-screen layouts, sufficient text-to-background contrast, separation of styling and logic, decoupled API data and views, and no secrets or real user data committed to the repository.

    Specific constraints make it harder for the assistant to substitute placeholder images, empty directories, or a storefront that looks functional but cannot complete a purchase.

    A useful task description includes inputs, outputs, and acceptance criteria. For example:

    Implement a checkout page using function components. Inputs are cart items, address details, and discount information; the output is an order draft ready for submission. Calculate all totals in one place. Show clear messages for an empty cart, a missing address, and insufficient stock. Do not hard-code sample products in component files.

    This is less likely to require rework than “build an attractive purchase page.”

    2. Treat Assistant Modes as Risk Levels

    Common assistant capabilities fall into roughly three categories. Product names vary, but the engineering implications are similar.

    Conversational completion

    This works well for changing a function, adding validation, or explaining an error. Its limited change scope makes it suitable for repositories that already have a working structure.

    Task-based generation

    This can generate multiple pages from a checklist in one pass. Its strengths are speed and broad coverage of the user journey. Its risks include shallow architecture, mock data embedded directly in views, narrow-screen-only styling, and login forms that stretch awkwardly on wider screens.

    After generation, immediately run the build, check the routes, and click through the entire purchase flow. Screenshots are not sufficient evidence of completion.

    Planning and decomposition

    For complex tasks, this mode first proposes directories, state boundaries, and page responsibilities, then implements them incrementally. It may respond more slowly, but it can reduce structural mistakes such as same-name nested directories, routes pointing to nonexistent pages, and multiple agents overwriting one another’s files.

    When agents work in parallel, assign a single owner to each file and specify the merge order. Otherwise, a later write can undo an earlier fix.

    The selection rule is straightforward:

    • For a new project, plan before generating.
    • For an existing project, prefer small, focused changes.
    • If the project does not run locally, stop adding pages and fix build or runtime errors first.

    Automated sequences of edits can reduce manual work, but every step must be reversible. Do not enable highly autonomous operation without version control.

    3. Use a Minimal, Maintainable Architecture

    Assistants often generate flat projects with every page placed in one directory. Such a project may run, yet quickly become difficult to change. A more reliable minimum structure separates code by reasons for change rather than simply collecting page files:

    • app: Routing, layouts, and global error boundaries.
    • pages: Page composition only, without pricing formulas or request details.
    • features: Self-contained login, cart, checkout, orders, account assets, and settings functionality.
    • entities: Types and pure functions for products, users, and orders.
    • shared: Buttons, form controls, price formatting, and the request client.
    • mocks: Sample data enabled only in development and isolated from production builds.

    State management does not need to be heavyweight from the start. The main cross-page state is the current user, cart, and checkout draft. Lightweight context or a state library can handle these, while page-specific form state stays local.

    Empty hook files and empty context directories should count as unfinished work, not “architecture reserved for later.” Empty abstractions can mislead maintainers into thinking the boundaries have already been designed.

    Route all data access through one client module. Read the base URL from environment variables, and handle timeouts, error codes, and redirects for unauthenticated users in one place. Do not hard-code domains in components or log tokens to the console.

    Export sample data from a separate module, and have pages consume it through the same types used for API data. Moving from mocks to a real API should then require changes at the client boundary rather than changes to every button handler.

    Prices, shipping charges, and discounts must be calculated by pure functions with input and output examples. Views should only display formatted results. If pricing logic is scattered across three pages, a later request to “fix the styling” can easily produce inconsistent amounts due.

    4. Validate a User Journey, Not Just the Appearance

    After generation, check the project in the following order. Stop and resolve any failure before continuing.

    1. Install dependencies and start the development server. Record the first compilation error and ask the assistant to fix only that error, rather than letting it rewrite half the project.
    2. Open every route. Check for blank screens and duplicated nested layouts.
    3. Complete the purchase journey. Add a product from its detail page to the cart, proceed through checkout and submission, inspect the result page, and open the order list. Verify quantities and totals throughout.
    4. Exercise form edge cases. Test empty values, excessively long text, incorrect passwords, and repeated submissions. Validation messages should appear beside the relevant fields, not only in the console.
    5. Check narrow and wide viewports. Look for button text that blends into its background, distorted forms, and undersized click targets.
    6. Search the repository for placeholders. Inspect placeholder images, hard-coded product arrays, and outdated comments. Temporary images are acceptable only when they use a shared media placeholder component with a clearly identified replacement point.
    7. Check accessibility. Review contrast, focus order, and image alternative text. Responsive widths alone do not make an interface accessible.

    A uniform primary color matters less than meaningful state colors. Success, warning, danger, and disabled states should not depend on barely distinguishable pale shades.

    White text on a very light background is a common generation defect. Use design tokens that pair foreground and background colors rather than hard-coding colors on individual buttons.

    5. Use Explicit Constraints to Prevent Structural Errors

    The following examples are reusable internal implementation constraints, not interfaces from a particular product.

    1. type Money = { currency: "CNY"; cents: number };
    2. type CartLine = {
    3. skuId: string;
    4. title: string;
    5. unitPrice: Money;
    6. qty: number;
    7. };
    8. export function lineAmount(line: CartLine): Money {
    9. if (line.qty <= 0) throw new Error("Quantity must be greater than 0");
    10. return { currency: "CNY", cents: line.unitPrice.cents * line.qty };
    11. }
    1. export function Field({
    2. label, error, children,
    3. }: {
    4. label: string;
    5. error?: string;
    6. children: React.ReactNode;
    7. }) {
    8. const id = React.useId();
    9. return (
    10. <div>
    11. <label htmlFor={id}>{label}</label>
    12. {React.cloneElement(children as React.ReactElement, {
    13. id,
    14. "aria-invalid": Boolean(error),
    15. })}
    16. {error ? <p role="alert">{error}</p> : null}
    17. </div>
    18. );
    19. }

    Keeping constraints like these in repository documentation is more effective than repeatedly correcting the assistant in conversation.

    Limit each iteration to one feature directory. At the end of the iteration, require a list of changed files and manual verification steps. If the assistant starts creating same-name nested directories, stop it immediately and instruct it to modify the existing paths.

    6. Balance Quality, Speed, and Cost

    Fast generation means a shorter wait, not necessarily less rework. Track four measures together:

    • Time to the first runnable version.
    • Number of manual repair rounds.
    • Number of defects in the user journey.
    • Number of files that must change when a field is updated later.

    The assistant saves time only when both the initial delivery effort and the downstream maintenance burden remain low.

    A free or rate-limited service is not automatically unusable. Nor does a desire for faster delivery justify merging unreviewed code. Network access in the team’s development environment is only an initial requirement. Separately assess model reliability, whether repository-wide context handling causes confusion, and whether logs upload source code.

    For account, order, and account-asset pages, default to least privilege: local sample accounts, synthetic data, and unnecessary telemetry disabled. Never provide production tokens to an assistant.

    Focus code review on three areas:

    1. Separation of styling and behavior. Moving style strings to the bottom of the same file is not meaningful separation.
    2. Business-oriented types. Types should express domain concepts rather than relying on any throughout.
    3. Complete failure paths. Handle failed requests, repeated clicks, expired sessions, and stock changes.

    An implementation that generates only the success page is not a complete shopping flow.

    7. Deliver in Reversible Stages

    On the first day, deliver only working routes, design tokens, data types, and one mock purchase journey.

    On the second day, add validation, error states, and narrow-screen support.

    On the third day, move mock data out of components, connect the frontend to the team’s test API, and add empty states for orders and account assets.

    Create a version-control checkpoint at the end of each day so the work can be rolled back.

    Assistants are useful for accelerating boilerplate, forms, and repetitive pages. They should not decide pricing rules, permission models, or release criteria for the team.

    Put acceptance criteria into each task, and keep human ownership of pure functions and data boundaries. That is how generated code moves from looking finished to being ready for delivery.