From Page Replication to Experience Optimization: Engineering Practices for AI-Assisted Coding
Rebuilding a chat application with AI coding tools is more than matching pixels. This article breaks down a production-grade engineering workflow for AI-assisted page replication: defining deliverables (functional specs, baseline builds, improved builds), splitting work into two rounds with real API integration, controlling conversation state and streaming output, securing API keys, testing across a full scenario matrix, and evaluating quality across five dimensions—so the result is a maintainable engineering asset rather than a demo prototype.
1. The Real Difficulty of Page Replication Isn’t “Looking Like the Original”
Rebuilding a chat application from public code, design materials, or reference pages looks like a straightforward front-end task: reproduce the navigation bar, message list, and input box, then wire up the model API. But once you start implementing, the hard problems usually lie beyond the page itself.
How do you display a waiting state after the user sends a message? If streaming output is interrupted, is the already-received content preserved? If the user switches conversations, can an old request still modify the current page? Where should API keys be stored? Can model output be rendered directly as page markup? These questions determine whether an application is a demo prototype or a maintainable engineering asset.
Therefore, evaluating AI coding capability should shift from “can it generate a page” to “can it complete a full loop from requirements to acceptance.” The evaluation target includes not only the model but also the task execution framework around it: file reading and writing, command execution, context management, task planning, test feedback, and necessary human confirmation.
The same model may exhibit different development behaviors in different execution environments; the same environment paired with different models may produce different implementation paths. The final result cannot be attributed to a single factor.
2. Define Three Types of Deliverables to Avoid Mixing Objectives
A complete page rebuild task should be split into at least three deliverables: a functional specification, a baseline implementation, and an improved implementation. They are interrelated but have different acceptance criteria.
2.1 Functional Specification and System Architecture Diagram
A functional spec is not a visual description of the reference page—it is a contract for product behavior. It should answer:
- What core operations users can perform;
- The inputs, outputs, and preconditions of each operation;
- How normal and exceptional flows are handled;
- Which features are in scope and which are deferred;
- How to judge that a feature is complete.
Take a generic chat web page as an example. Functionality can be divided into conversation management, message interaction, content display, and basic settings. Conversation management includes creating, switching, deleting, and restoring history; message interaction includes input validation, sending, generating state, stop generation, and failure retry; content display includes text formatting, code block rendering, copy actions, and scrolling through long content.
For capabilities not yet implemented, limitations should be clearly noted. For example, if you use browser-local persistence, don’t claim support for multi-device sync; without an account system, don’t describe the local conversation list as cloud history under a user account.
The architecture diagram should show the flow of data and control, not just component names. A common structure can be expressed as:
User actions→ Page components→ Conversation and request state management→ Application server→ Model service API
Meanwhile, conversation state can interact with a persistence module, and the application server can connect to logging, monitoring, and configuration modules.
This separation clarifies the responsibilities of the UI, business state, API adaptation, and operational support, reducing cross-coupling during later modifications.
2.2 Baseline Replication Build
The baseline build should follow the confirmed interaction contract and visual structure, without adding new product logic ad hoc during implementation.
“Replication” here should be limited to rebuilding legally available materials and common interaction patterns—it should not copy protected brand marks, proprietary assets, or unlicensed content by default. If reference materials are incomplete, inferences should be documented in the delivery notes rather than treated as known requirements.
The goal of the baseline is to establish a verifiable foundation: is the layout complete, do the main operations work, is the API actually connected, is there feedback for exceptions? Only with a stable baseline do subsequent optimizations become meaningfully comparable.
2.3 Experience Improvement Build
The improvement build should target specific, identified problems—not simply change colors, add animations, or pile on features.
For example, long conversations may need a clearer way to locate specific sessions; mobile may need adjusted navigation and input areas; generation failures should preserve user input and offer an understandable recovery path; when a user is actively reading history, the page should not be forcibly scrolled back to the bottom by new content.
Every change should state: what the problem is, what the change is, and how it is verified. Only then can you distinguish genuine UX improvements from subjective aesthetic changes.
3. Split the Task into Two Rounds to Observe Engineering Behavior After API Integration
The value of a two-round mechanism is separating “requirements-driven implementation” from “correction after real dependencies are connected.”
In the first round, provide requirements, reference materials, and delivery requirements—but no production keys. Implementation should rely on mock data or a swappable API adapter layer, and clearly mark which parts have not been verified against real services.
A qualified first-round result includes at least:
- A page that can launch and be operated;
- A feature list and architecture notes;
- API integration points and configuration approach;
- Known limitations and items pending verification;
- A test plan covering the main user paths.
In the second round, provide safe test credentials or an accessible test environment, require real API integration, and re-run the relevant tests.
This is where engineering quality gaps appear most clearly. Shallow verification only confirms “a message sent once returns a response”; more thorough verification also checks response parsing, streaming display, cancellation behavior, failure recovery, conversation isolation, and handling of sensitive information.
Therefore, the second round should not be treated as merely filling in a config value—it is a regression pass after a dependency change. Once the API switches from mock to real, every feature that depends on its behavior may be affected.
4. Unified Conditions Matter More Than Unified Prompts
If you want to use multiple AI coding configurations to validate a method—say, six independent task groups—identical prompts alone do not guarantee fairness.
You should also standardize:
The initial project. Each group uses the same directory structure, reference materials, dependency constraints, and task instructions, so no group gets a head start from pre-existing code.
Resource boundaries. Define execution time limits, available permissions, whether external references are allowed, and the scope of human assistance. If a group hits a dependency download failure or network outage, log it separately rather than attributing it to model weakness.
Key delivery method. Test credentials should have consistent permissions, validity periods, and usage limits, injected via secure configuration—not written directly into public prompts or source code.
Acceptance scripts and manual checklists. Screenshots, operation paths, request results, and test reports should be collected under the same rules.
Execution records. Beyond the final page, keep records of key modifications, test runs, issues found, and fix evidence. A page that “looks done” has not necessarily been adequately verified.
Without repeated runs, results only reflect a single task execution and cannot directly establish a stable capability ranking. More reliable conclusions require repeated runs under identical conditions plus analysis of result variance.
5. Key Integration Must Be Designed Together with Security Boundaries
A chat web page typically needs access to an external model service, but keys must not be written into browser code just for integration convenience.
Front-end resources can be inspected, and browser requests can be examined. Placing long-lived credentials in page scripts, build artifacts, or local storage exposes them to anyone who can access the page.
A better approach is for the application server to hold credentials, with the browser calling only the application’s own business APIs. The server handles identity verification, permission checks, request constraints, and external API calls.
A representative flow:
Receive page request→ Verify caller permissions→ Validate message format and length→ Read credentials from secure configuration→ Call the model service→ Forward the necessary response content→ Log sanitized runtime information
You must also prevent the server from becoming an unrestricted public proxy. Even if keys aren’t exposed, allowing unlimited anonymous calls to the business API still creates resource-abuse risk.
After testing, temporary credentials should be revoked or rotated. Logs must never contain full keys, and user input and model output should be handled carefully to keep sensitive content out of debug records.
6. Use an Explicit State Model to Govern Conversation Interaction
Many page problems are not styling bugs but the result of unbounded state management.
A message may go through at least these states: pending, generating, complete, failed, and canceled. Request state and message state can be linked, but should not be collapsed into a single global “loading” flag.
For example, a user sends a request in conversation A, then switches to conversation B. If the request returns, it should update the message in conversation A—not append content to the currently displayed conversation B.
Implementation should establish independent identifiers for conversations, messages, and requests, and verify ownership when handling asynchronous callbacks. The core logic can be expressed in pseudocode:
Start request:Create a request IDSave the owning conversation ID and target message IDSet the target message to "generating"On content chunk received:Check whether the request is still validLocate the target message in its owning conversationAppend content and update the displayOn request completion:Set the target message to "complete"On error:Preserve already-received contentRecord the failure reasonShow an actionable recovery optionOn user stop:Send a cancel signalPrevent subsequent callbacks from modifying the messageMark the message as "canceled"
Canceling a local request does not necessarily mean remote computation stops immediately—the actual effect depends on the service API’s behavior. The UI should therefore accurately represent local state and must not claim, unverified, that all remote processing has stopped.
7. Streaming Output Requires Boundary Handling, Not Just Chunk Concatenation
Streaming reduces time-to-first-content, but increases parsing and display complexity.
Network data chunks don’t necessarily correspond to complete messages—or even to a complete character or event. The implementation must maintain buffers according to the actual protocol and parse only after content is confirmed complete; text decoding must correctly handle characters split across chunks.
Page updates also need pacing. Triggering a full re-render on every tiny fragment can cause noticeable overhead. Short-interval incremental updates can be merged without affecting perceived interactivity.
Auto-scrolling should respect user intent: if the user is still at the bottom, follow new content; if the user has scrolled up to read history, preserve their reading position and provide an entry point back to the latest message.
Formatted content generated by the model must not be trusted by default. Allowed display syntax should be constrained; if page markup generation is required, it must be sanitized so untrusted content is never inserted as executable page fragments.
8. Expand Testing from “Succeeded Once” to a Full Scenario Matrix
Engineering acceptance should cover at least four categories of scenarios.
Happy paths: create a conversation, send a message, receive a reply, switch conversations, restore history. Focus on state consistency, not just whether buttons are clickable.
Input boundaries: empty input, whitespace-only, overly long content, multiline text, and IME composition states. In particular, avoid triggering send while text is still in the input-method composition phase.
API exceptions: expired credentials, insufficient permissions, timeouts, dropped connections, and unexpected response formats. The page should show understandable errors and distinguish retryable from non-retryable failures.
Operation races: rapid repeated sends, deleting a conversation during generation, immediately resending after stopping, and multiple requests returning out of order. These tests expose duplicated messages, state overwrites, and cross-conversation data writes.
Retry also needs care. If you cannot confirm whether the previous request was already processed server-side, automatic retries may cause duplicate calls. For operations with external side effects or resource consumption, design deduplication based on API behavior rather than blindly increasing retry counts.
Every test item should record the steps, expected result, actual result, and fix status. A single “tests passed” summary is not traceable quality evidence.
9. How to Evaluate Final Delivery Quality
Evaluation criteria should extend beyond page appearance to five dimensions:
- Requirements completeness: Does the functional spec cover the main flows, with explicit scope and limitations?
- Implementation correctness: Are core features genuinely usable, is state consistent, are exceptions recoverable?
- Security and robustness: Are credentials isolated, is untrusted content constrained, do APIs have basic access control?
- Maintainability: Are UI, state, APIs, and configuration reasonably separated, and is key logic easy to locate and modify?
- Verification adequacy: Do tests cover real APIs and edge scenarios, is regression run after fixes, and are conclusions backed by evidence?
Different projects can apply different weights, but you should not produce seemingly precise capability scores without unified testing and repeated runs. Severe issues—such as credential leakage or cross-conversation data mixing—are better treated as acceptance blockers rather than offset by good visual polish.
10. From One-Shot Generation to a Repeatable Development Process
The real value of AI-assisted coding lies not in how many files it generates at once, but in whether it reduces the communication and verification cost between requirements and delivery.
A repeatable process should include: defining deliverables, freezing baseline requirements, establishing API boundaries, completing the baseline implementation, integrating real dependencies, running scenario tests, fixing and regressing, and archiving delivery evidence.
The baseline build answers “was it implemented as required,” the improvement build answers “were real experience problems solved,” and the test report answers “why you can believe it works.”
Only when these three support each other does a page rebuild task evolve from a showcase demo into engineering practice. The same principle applies when judging AI coding outcomes: running is just the starting point—being explainable, verifiable, securely maintainable, and continuously improvable is the standard for reliable delivery.
