AI-Assisted Chat Web App Rebuild: From Page Replication to Verified Software Delivery
This article turns a chat-page rebuild task into a repeatable engineering workflow. It covers turning observable behavior into traceable requirements, drawing architecture diagrams that describe data flow and responsibility boundaries, splitting work into a mock-first round and a credential-based integration round, handling conversation state and streaming responses correctly, and defining a unified acceptance protocol with regression checks so that improvements are backed by evidence rather than decoration.
1. From Rebuilding a Page to Delivering Software
Asking an AI coding system to build a similar application from an existing chat web page looks like a UI task. In practice it spans product understanding, interaction modeling, service integration, state management, and quality verification.
The original practice set three deliverables: a product requirements document with a structure diagram, a web app that follows the reference experience, and a revised web app improved based on development findings. Abstracted, these become a general engineering method: understand the product first, establish a baseline implementation, then make evidence-based improvements.
One boundary must be stated clearly: rebuilding a page is not reproducing the underlying model, training process, or server-side system of the original service. Even if the layout, conversation controls, and reply display closely match the reference, only the front-end experience and some business flows have been reimplemented. The scope here is building a chat application with AI coding assistance, not copying model capability.
So acceptance cannot stop at “does the page look similar.” It has to answer:
- Are the product requirements complete and traceable?
- Do the core interactions form a closed loop?
- Do real service calls complete reliably?
- Does the app remain usable under error conditions?
- Do the improvements deliver clear value instead of adding decoration?
2. Define Scope First, Then Write the Functional Document
1. Convert observable behavior into explicit requirements
A reference page shows product behavior, not necessarily the complete business rules. Before development, record observed behavior, assumptions that still need verification, and capabilities that will not be implemented as separate items.
A chat page typically has a conversation list, a message area, an input area, and some settings entry points. That does not justify assuming every application supports attachments, web retrieval, or a particular reasoning mode. Only confirmed behavior enters the baseline requirements; unconfirmed features belong on a to-verify list.
For each requirement, record:
| Item | What to specify |
|---|---|
| User goal | What task the user wants to complete |
| Trigger | How a click, input, or keyboard action starts the flow |
| Preconditions | Whether a valid conversation, login state, or service credential is required |
| State changes | How the UI and data are updated |
| Error handling | How failures are reported, recovered from, or retried |
| Acceptance criteria | What observable result proves the feature works |
This is more effective than writing “supports sending messages.” Sending a message involves input validation, request state, reply reception, failure feedback, and duplicate-submission control at minimum. Missing any one of them can produce defects in real use.
2. Draw the line between baseline and improved versions
The baseline should implement the confirmed interaction flows and should not absorb large amounts of unverified new functionality. The improved version should address specific problems and stay comparable to the baseline.
For example, the baseline can implement creating a conversation, switching conversations, sending text, displaying replies, and basic error messages. The improved version can strengthen long-reply reading, keyboard accessibility, failure recovery, and mobile layout.
Both should share the necessary business logic so that implementing them separately does not produce inconsistent interface behavior. Differences are best confined to interaction strategy, information organization, and the presentation layer rather than a purposeless rewrite.
3. A Structure Diagram Must Describe Data Flow and Responsibility Boundaries
A useful structure diagram does not only draw page regions; it shows the full path a message takes from input to return.
User input↓Page interaction layer↓Conversation and request state management↓Application backend↓Model service interface↓Response handling and message persistence↓Incremental page rendering
Each layer should carry a clear responsibility.
The page interaction layer handles input, display, and operation feedback, and must not hold server-side secrets directly. Conversation state management owns the current conversation, the message list, and request state. The application backend owns credential storage, request validation, access control, and any necessary call limits. The model service adapter layer handles the actual API contract so that service differences do not leak into page components.
Conversation data can use a generic structure:
Conversationidtitlecreated_atupdated_atmessagesMessageidconversation_idrolecontentstatuscreated_at
These are internal application data designs, not field names from any external service. Map them to the real API documentation during implementation, and do not assume every service uses the same protocol.
If the first version relies only on browser local storage, state the limits explicitly: nothing syncs across devices, clearing browser data can lose records, and multi-user isolation cannot depend on local storage. When long-term retention or cross-device access is needed, introduce server-side persistence and identity verification.
4. The Two-Round Task Is About Controlled Integration, Not Pasting in a Key
The original practice used two rounds of input: requirements first, calling credentials second. Abstractly, this separates application construction from real service integration.
1. Round one produces a verifiable application skeleton
Without credentials, most engineering work can still be completed:
- Requirements document and page structure;
- Core components and conversation state;
- Mock responses and loading feedback;
- API adapter layer;
- Configuration notes and a test checklist;
- Display and recovery paths for common errors.
Mock responses should cover normal replies, empty responses, request failures, and long-content display, and must be clearly labeled as mocks. A successful run on mock data proves only that parts of the page logic work; it does not prove that real service integration is done.
2. Round two verifies the real interface
Once credentials are available, verification goes beyond “does it return some text.” It also covers authentication, request format, response parsing, connection interruption, and multi-turn conversation.
Credentials should be injected through controlled server-side configuration, never written into page source files, browser-readable build artifacts, public logs, or version history. If a credential has been exposed in an untrusted location, revoke and reissue it promptly; deleting the code alone does not remove the risk.
Real calls should cover at least these paths:
- A single-turn request completes;
- Multi-turn conversation carries the required context;
- Invalid credentials produce an understandable message;
- When the service is unavailable, the page does not stay in a loading state indefinitely;
- After the user cancels, the UI and the actual request behavior stay consistent;
- When switching conversations, returned content is not written to the wrong place.
The last two are the most commonly missed. Restoring a button state does not necessarily mean the request was terminated, and a change of current conversation does not mean an async response will be attributed correctly. Requests therefore need an explicit conversation identifier and independent lifecycle management.
5. The Hard Parts of a Chat App Are State and Streaming
1. Replace scattered flags with explicit state
Simple apps often use a single “is loading” flag, but a real conversation flow includes sending, receiving, completing, failing, and canceling. Define clear transitions:
Idle → Request sent → Receiving reply → Complete↘ Failed↘ Canceled
Each state should specify which actions are allowed. Whether sending again is permitted while a request is in flight, whether received content is kept after cancellation, and whether a retry can follow a failure directly should all be decided by product rules.
If multiple conversations may run concurrently, request state must be managed per conversation or per request. Otherwise, one conversation finishing can wrongly clear another conversation’s loading state.
2. Handle incremental responses correctly
If the real API supports incremental output, the front end can render content progressively before the full reply is generated. The actual protocol governs this; a single network read is not a complete message.
Network transport chunks and application message boundaries are different things. Parsing logic usually needs a buffer that keeps incomplete data for the next read and determines event boundaries and termination conditions according to the API contract.
Character decoding, abrupt interruptions, and partial-content retention also need consideration. For long replies, the page should not trigger an expensive update for every tiny fragment; batching increments over a short window balances smooth display against rendering cost.
3. Treat scrolling as product logic
More aggressive auto-scroll is not better. If the user is reading earlier content, forcing a jump to the bottom on every reply update breaks the reading experience.
A more reasonable rule: follow automatically when the user is near the bottom; stop following when the user scrolls up, and offer an entry point back to the latest content. The input area, the reply area, and the mobile keyboard also need protection against occlusion and layout jumping.
6. Unified Acceptance Matters More Than Comparing Generation Speed
The original practice noted that different execution systems may adopt different testing strategies after credentials are provided: some verify only the simplest path, others keep checking and fixing problems. This does not prove one system is generally stronger, since results are also affected by tool permissions, context, runtime environment, and prompting.
The more reliable approach is to write testing requirements into a unified acceptance protocol instead of letting the coding system decide when to stop.
| Acceptance dimension | What to check |
|---|---|
| Documentation completeness | Requirements, boundaries, structure, and acceptance criteria are all present |
| Core functionality | Create, switch, send, and receive form a closed loop |
| State correctness | Consistency under concurrency, cancellation, and failure |
| Integration reliability | Real requests and responses are handled correctly |
| Security | Credential isolation, input validation, and log redaction are in place |
| Usability | Long text, small screens, and keyboard operation work |
| Maintainability | Module boundaries, configuration notes, and tests are clear |
Each acceptance item should retain evidence such as test steps, observed results, and known limitations. “Tests passed” cannot substitute for actual inspection records, and nothing may be claimed as verified when it was not executed.
For reproducibility, fix the task description, initial code, tool permissions, and acceptance scope. If extra fix rounds are allowed, record their count and content so results obtained under different conditions are not compared directly.
7. Improvements Need Problem Evidence and Regression Verification
The improved version should close the loop of problem → measure → verification.
For example, if long replies are hard to read, add sensible paragraph hierarchy, a content-copy entry point, and scroll control. If failure causes are unclear, distinguish configuration errors, network errors, and service-returned errors, with matching recovery advice. If operations are easy to trigger by mistake, improve send-state feedback rather than simply adding confirmation dialogs.
Message rendering also needs security boundaries. Content from users or the model is not trusted by default. If rich text is supported, restrict executable content and dangerous links so uncontrolled content cannot enter the page execution environment.
The server side needs basic protection too: input length limits, call-rate control, timeout handling, and appropriate resource limits. Logs should prioritize the state, duration, and error category needed to locate problems; they should not store full conversations by default and must never record secrets. For sensitive business scenarios, define retention periods, access permissions, and deletion mechanisms.
After all improvements, rerun the baseline functional tests. An experience optimization that breaks conversation switching, message attribution, or request cancellation is not a valid improvement.
8. Build a Delivery Loop That Supports Continuous Iteration
AI coding can speed up building pages and application skeletons, but engineering responsibility does not disappear. A complete delivery includes at least the requirements document, structure description, runnable code, configuration guide, test records, and known limitations.
Recommended order:
- Confirm observable requirements and implementation boundaries;
- Build the structure diagram and data model;
- Complete baseline interactions with mock responses;
- Integrate the real service securely;
- Verify normal, error, and concurrent paths;
- Implement improvements based on problem evidence;
- Run regression tests and assemble the delivery materials.
The point of this method is not to make a generation system draw a page faster, but to keep requirements, implementation, and verification aligned with each other. Only when a chat-page rebuild moves from visual similarity to correct behavior, reliable calls, controlled security, and reproducible results does it become a software delivery with real engineering value.
