AI-Generated Frontend Applications: Common Problems and Engineering Practices
AI coding tools can generate frontend prototypes quickly, but interaction workflows, UI consistency, and code structure still need careful review. Using a React 18 e-commerce prototype, this article explains how to combine staged generation with targeted edits, validate design and responsive behavior, separate data access from presentation, and apply reusable prompts and acceptance checks.
Scope and Example Boundaries
This article uses an e-commerce frontend prototype with four pages: user registration, a dashboard, an order list, and a coupon wallet. The assumed stack is React 18, TypeScript, Vite, and Tailwind CSS.
The discussion focuses on three areas: interaction workflows, UI quality, and code structure. Backend implementation, payment integration, and security auditing are outside its scope.
This is not a comparative ranking of specific tools. The problems and practices described here apply broadly to AI coding tools, and the same checklist can be used to evaluate the tools you already use.
1. Three Interaction Modes and When to Use Them
AI coding tools commonly support three interaction patterns. The main difference is when a person reviews and intervenes in the generation process.
| Mode | How it works | Best suited to | Recovery when something goes wrong |
|---|---|---|---|
| Fully automatic | Generates an entire project from one request | One-off demo pages | Errors tend to surface together and are difficult to isolate; restarting may be necessary |
| Builder | Generates modules incrementally, with confirmation after each step | Moderately complex business applications | Return to the last approved module |
| Craft | Makes targeted changes to individual files or components | Local improvements to existing code | Small change scope keeps rollback costs low |
For the e-commerce prototype, start with Builder mode to generate the page scaffolding, then use Craft mode to refine each page. Commit each completed module to Git after it passes review. If a later change fails, you can return to the most recent accepted version instead of debugging everything from scratch.
2. Common UI Problems and How to Check Them
Colors and Design Tokens
AI-generated interfaces often use colors inconsistently. The same semantic role may have different color values across pages. Define design tokens first, then require the tool to reference those tokens rather than write color values directly.
:root {--color-brand: #1d4ed8;--color-brand-hover: #1e40af;--color-text-primary: #0f172a;--color-text-on-brand: #ffffff;--color-danger: #dc2626;--color-disabled: #94a3b8;}
Invisible button text often results from conflicting style overrides. For example, a global rule may set text to white while another rule changes the component background to white. Using paired foreground and background tokens within components helps prevent these conflicts.
Acceptance criteria:
- Body text must have a contrast ratio of at least 4.5:1 against its background to meet WCAG AA requirements for normal text.
- Button text colors must reference paired tokens such as
--color-text-on-brand, rather than hard-coded colors. - Disabled states must use dedicated tokens rather than relying only on opacity.
Responsive Layouts
Distorted sign-in forms and unusable mobile layouts often indicate that the generated code lacks appropriate media queries or flexible layouts. Review the application at these four viewport widths.
| Viewport width | Typical device | What to check |
|---|---|---|
| 375px | Small smartphone | The sign-in form fits the screen, and inputs do not overflow |
| 768px | Tablet in portrait orientation | The order table becomes cards or supports horizontal scrolling |
| 1024px | Small laptop | The dashboard sidebar is expanded without squeezing the main content |
| 1440px | Desktop | The content area has a maximum width rather than stretching indefinitely |
In Tailwind CSS, a form container can be constrained as follows:
<div class="mx-auto w-full max-w-sm px-4 md:max-w-md lg:max-w-lg"><!-- Sign-in form content --></div>
Use device emulation in the browser’s developer tools to check every page at all four widths. Apart from intentional scrolling within the order table, pages should not display unexpected horizontal scrollbars.
Realistic Business Data
Tools often fill interfaces with placeholders such as “Product name” and “Order number.” This makes pages look unfinished and does not reveal how layouts behave with realistic content lengths.
Mock data should meet these requirements:
- Include at least five records in each list.
- Display monetary amounts with two decimal places.
- Cover four order statuses: pending payment, shipped, completed, and canceled.
- Provide empty and loading states for every list.
3. Code Structure and Data Coupling
A Common Problem
Generated components often contain their data directly:
function OrderList() {const orders = [{ id: "A1001", amount: 299, status: "Pending payment" },];return <ul>{orders.map(o => <li key={o.id}>{o.id}</li>)}</ul>;}
With this structure, connecting a real API requires changing the component itself. Data sources, request logic, and presentation become intertwined, making the page harder to test and reuse.
Recommended Directory Structure
src/api/ # Backend communication; request code onlyclient.ts # Shared request wrapper, auth headers, and error-code handlingorders.ts # Order-related API functionsmocks/ # Mock data for development onlyorders.mock.tsfeatures/orders/OrderList.tsx # Presentation onlyuseOrders.ts # Data fetching and state managementcomponents/ # Shared buttons, tables, and empty-state components
Page components should neither call fetch directly nor import mock data. Instead, they should obtain data through a hook.
API Service Layer Example
Keep API types and request functions in the api directory:
// src/api/orders.tsimport { http } from "./client";export interface Order {id: string;amount: number;status: "Pending payment" | "Shipped" | "Completed" | "Canceled";createdAt: string;}export function fetchOrders(): Promise<Order[]> {return http.get<Order[]>("/orders");}
The hook selects its data source using an environment variable and manages loading and error states:
// src/features/orders/useOrders.tsimport { useEffect, useState } from "react";import { fetchOrders, type Order } from "@/api/orders";import { mockOrders } from "@/mocks/orders.mock";const useMock = import.meta.env.VITE_USE_MOCK === "true";export function useOrders() {const [orders, setOrders] = useState<Order[]>([]);const [error, setError] = useState<string | null>(null);const [loading, setLoading] = useState(true);useEffect(() => {const source = useMock ? Promise.resolve(mockOrders) : fetchOrders();source.then(setOrders).catch(() => setError("Unable to load orders. Please try again later.")).finally(() => setLoading(false));}, []);return { orders, error, loading };}
Switching data sources requires changing only VITE_USE_MOCK; component code stays the same. During acceptance testing, set this variable to false while the API is unavailable and verify that the page displays an error message rather than a blank screen.
Shared authentication and error-code handling belong in client.ts. For example, an expired token can trigger a centralized redirect to the sign-in page. Individual pages should not repeat this logic.
For cloud-service integration, add the relevant frontend functions to the api layer. For example, an avatar upload can use an uploadAvatar function, with the backend returning the image URL. Asynchronous order notifications are handled by a backend message queue; the frontend retrieves results through polling or server push rather than connecting directly to the queue.
4. A Reusable Prompt Template
The following template combines design constraints, engineering constraints, and delivery requirements. Asking for the directory structure before code generation creates a review checkpoint for the Builder workflow.
Generate an e-commerce frontend application using React 18, TypeScript,Vite, and Tailwind CSS.Design constraints:1. Reference color design tokens through CSS variables only.Do not hard-code color values in components.2. Maintain a text-to-background contrast ratio of at least 4.5:1.3. Make all pages usable at viewport widths of 375px, 768px, 1024px,and 1440px, without unexpected horizontal scrolling.Engineering constraints:1. Put all API request code in src/api.Page components must not call fetch directly.2. Put mock data in src/mocks and switch data sources usingthe VITE_USE_MOCK environment variable.3. Every list page must handle loading, empty, and request-failure states.Delivery requirements:1. Output the directory structure first and wait for my confirmationbefore generating code.2. Deliver each page separately and list the files changed.3. Provide complete code. Do not omit sections or replace them withphrases such as "the rest is the same as above."
5. Post-Generation Acceptance Checklist
Review the generated application item by item. The following table summarizes common errors, verification methods, and corrective actions.
| Common error | How to check | Corrective action |
|---|---|---|
| Errors on the first run | Run npm run build, then npm run dev, and confirm that both complete or start without errors |
Give the tool the complete error output and ask it to fix only that error |
| Invisible text or poor color contrast | Check the text-to-background contrast of every button | Use paired foreground and background token variables |
| Broken mobile layouts | Review every page at the four specified viewport widths | Constrain container widths and convert wide tables into cards |
| Mock data scattered throughout components | Search component files for array literals containing mock records | Move mock data into src/mocks and access it through the data hook |
