Engineering Practice Guide for Recreating Chat Applications
This guide explains how to recreate a chat web app as three related deliverables: an acceptance-ready capability document, a strictly aligned clone, and a restrained improvement build. It covers domain models, streaming state machines, evaluation cases, quotas, and maintainability so the result is usable, not just screenshot-similar.
Chat-style pages look like an input box plus a message list. In practice, a recreation also hits product definition, interaction states, streaming protocols, multimodal entry points, quota policy, and acceptance criteria. Screenshot-level similarity often yields a demo that cannot be used long term. Adding features too early removes the baseline needed to judge fidelity. A more stable approach is three deliverables that share one domain model but different goals: a capability and structure document that answers what the original product has; a strictly aligned clone that answers whether the critical paths can be completed the same way; and an experience-based improvement that answers what can be added without breaking those paths.
Write capabilities as an acceptance-ready structure
Build a capability list before generating UI. Organize it by user-visible tasks, not by API fields. A typical chat site covers:
- Session: create, switch, rename, delete, pin, search history, and whether unsent drafts persist.
- Messages: user, assistant, system, error, and interrupted messages; states include queued, generating, complete, failed, and stopped.
- Input: multiline text, paste, shortcut send, stop generation, regenerate, and edit-then-resend.
- Context: whether history is included, how the window is truncated, and whether overflow is shown to the user or dropped silently.
- Attachments: file pick, type and size checks, parse progress, and how cited snippets appear in answers.
- Retrieval: whether external material is added before answering, whether citations expand, and whether failure falls back to a plain model answer.
- Voice: read-aloud and dictation as independent capabilities, decoupled from text chat so voice failures do not break the main path.
- Account and quota: login, remaining usage, per-request length, concurrency limits, and recoverable messages after rate limiting.
Use a two-layer structure. The upper layer is user tasks: ask, follow up, ask with files, search history, share or export. The lower layer is supporting capabilities: session storage, message rendering, stream receive, attachment parsing, retrieval orchestration, voice, quotas, and audit. Arrows express dependency only, not a vendor implementation, so swapping models, gateways, or storage does not move product boundaries.
For each feature, document trigger, preconditions, success, failure, and what must not happen. “Stop generation” is not hiding a button: after click, local append stops immediately, the server aborts or ignores later chunks, the message is marked stopped, the input becomes editable again, and generated text is kept. Without those acceptance sentences, the same button becomes different products.
Keep aligned clone and improved clone separate
The first implementation is behavior alignment, not visual invention. Lock the scope in advance: information architecture, primary color and density, input placement, bubble alignment, loading and empty states, whether mobile input sticks to the bottom, whether scroll follows the latest message, and whether long answers are copyable. Pixel-perfect match is not always useful, but key sizes, layering, and state transitions must be reviewable. Mobile distorts easily: desktop input sits mid-lower, while a narrow screen is often pushed by the keyboard or covered by bottom navigation. Call out breakpoints, for example fixing the input to the visible bottom on narrow screens and sharing one slot for send and stop so layout does not jump.
Only the second implementation may improve, and each change must answer a concrete problem such as history that is hard to find, errors that cannot be recovered, long text that is hard to scan, or citations that cannot be traced. Reasonable enhancements include in-session search, answer outlines, one-click code copy, retry with the original payload, independent attachment parse status, collapsible sources, and editing the next draft while generation runs. More buttons are not an optimization. Every extra entry must name the main path it serves and whether the system stays complete when it is turned off.
Share components, isolate with feature flags. The clone defaults experimental features off; the improved build turns them on. Comparison then does not treat extra features as clone defects, and demos do not break the baseline.
Two rounds of work expose strategy differences
Use two constrained rounds rather than stuffing requirements and keys into one prompt. Round one gives only the goal, reference scope, and deliverables: product notes, structure diagram, aligned implementation, improved implementation. Do not provide credentials. The executor should finish information architecture, state machines, page skeleton, and local fake data streams. Round two provides limited credentials and requires real chat plus tests.
Three reasons: without credentials, reviewable interaction can still ship, proving design is not bound to one call; credentials are secrets and belong in environment variables or short-lived tokens, not the repo, screenshots, or logs; round two shows strategy. Some implementations send one “hello” and claim done; others cover empty input, oversized input, consecutive follow-ups, mid-stream stop, reconnect after drop, attachment failure, quota exhaustion, and session restore after refresh.
Do not judge only whether the final page looks good. Record which probes round two ran. A fixed set:
- First question succeeds, message order is correct, focus returns to the input.
- Stop during streaming; existing text is kept and no more text is appended.
- Follow-up in the same session carries history; a new session does not mix history.
- After refresh the session remains; in-flight generation has a definite outcome.
- Limit, timeout, and auth failures show understandable messages and never leak credentials.
- If attachments or retrieval fail, text chat still works.
- On a narrow screen the input is visible, focusable, and not covered by fixed chrome.
Shallow smoke only proves the path is wired. Deep regression finds state-machine bugs: late chunks written after stop, history concatenated twice on retry, error copy that exposes internal addresses. Record strategy in an evaluation column for probe depth, not as a vague claim that one implementation is smarter.
Frontend state matters more than API shape
The core of a chat page is a small state machine, not a request helper. The input needs at least idle, ready-to-send, sending, and generating. While generating, only stop is allowed, not another send of the same turn; after stop, return to ready-to-send. Index the message list by session id plus message id. Streaming chunks update only the target message so the whole list is not redrawn and scroll does not jitter.
On the stream, append incrementally and handle three failures: connection drop, explicit server error, and user stop. Interrupt and stop both need terminal states so the UI does not stay on “generating” forever. If the protocol pushes chunks, tolerate empty chunks and out-of-order arrival; use sequence or accumulated text, and do not assume every chunk has business meaning.
Control flow, not a platform API:
onSend(text):draft = text.trim()if draft is empty or state != ready: returnappend user messageappend assistant placeholderstate = generatingstream = startChat(sessionId, draft)for each chunk in stream:if state != generating: breakappend chunk to placeholderif userStopped: mark stoppedelse if stream failed: mark failed and keep retryelse: mark donestate = ready
Persist session lists and message bodies in the browser first, then move to the server. Wherever they live, define retention, export, and delete. If share links copy context, document expiry and visibility, and accept in another browser or private window so the current login is not mistaken for a guest view.
Quotas, security, and maintainability
Once chat is open, limits almost always appear: daily counts, input length, concurrency, attachment size. Do not make limits a sudden failure. Pre-check locally before send; if too long, prompt to truncate or split. On rate limit, show when retry is allowed and keep the user’s original text. The server remains the final authority; client checks only improve experience.
Do not ship keys to a public page. The browser talks to your own backend; the backend holds credentials, authenticates, records usage, and audits. Redact logs; do not store full prompts or file bodies without a clear compliance basis and retention policy. Validate upload type and size first, store parse results apart from originals, and cite only needed snippets in answers.
Split “model call,” “retrieval,” “voice,” and “render” into modules. If the model is down, history still shows. If retrieval times out, fall back to an answer without citations. If read-aloud fails, copy still works. That degradation is worth more than another flashy entry.
How to judge whether a recreation is good enough
Score on a five-point scale and watch the weakest dimension, not the average: coverage, state correctness, visual and responsive quality, recoverable errors, test depth, and whether improvements stay restrained. The aligned clone is judged mainly on the first four. The improved build is judged on the last two only if the first four do not drop. If the main path is less stable after “improvements,” the improvements do not count.
Ship the document, aligned implementation, and improved implementation together. The document states in-scope and out-of-scope. The clone locks the behavior baseline. The improved build records why each addition exists and how to turn it off. Recreation then becomes an engineering practice that can be reviewed, have its model layer replaced, and keep iterating—not a one-off page generation.
