Replicating a Chat Web UI from Product Docs: A Spec-Driven Engineering Guide

    This article explains how to turn a chat product's public behavior into an executable specification, then build a faithful replica and an improved version of a chat web page. It covers writing functional documentation and structure diagrams, layering the implementation, defining acceptance boundaries for streaming, sharing, attachments and voice, comparing AI coding tools fairly, and keeping keys, logs and quotas within safe engineering limits.

    From “Looks Like the Real Thing” to a Verifiable Chat UI

    Many teams want to ship a chat web page quickly: a session list on the left, a message stream in the middle, an input area at the bottom, plus deep-thinking modes, file attachments, and voice capabilities. Public documentation usually only describes API shapes. What’s genuinely hard is translating product behavior into an executable specification, then making the implementation align with that specification.

    If you just say “make it exactly like the original,” AI coding tools will produce an interface that looks complete but cannot be accepted or verified.

    A safer approach is to split the work into three deliverables:

    1. A product functional specification and structure diagram.
    2. A replica page that reproduces the live product’s behavior.
    3. An improved version built on top of the replica.

    These three artifacts have different responsibilities and must not be conflated into a single prompt judged only by a final screenshot.

    Write the Product Down Before Replicating It

    The functional specification should cover what users can observe, not a pile of API nouns. Organize it around the conversation lifecycle:

    • Entry and identity: login state, guest limitations, quota prompts, unexpected logout handling.
    • Session management: create, rename, delete, search history, pin.
    • Message stream: user messages, assistant messages, streaming output, interrupting generation, regenerate, copy.
    • Input area: multi-line text, quick send, attachments, references, character or quota hints.
    • Enhanced capabilities: retrieval-augmented answers, file parsing, and voice synthesis/recognition entry points and failure states.
    • Sharing and multi-device: share-link permissions, input area position on mobile, narrow-screen layout.

    The structure diagram can be a single-level function tree: page regions as roots, capabilities as branches, states as leaves. Every leaf should state its trigger, success result, failure prompt, and whether it requires login. Without this, “fidelity” becomes a matter of subjective feeling.

    The document must explicitly mark acceptance boundaries. For example: share links must be verified in a different browser or an incognito window; on mobile, check whether the input box is obscured by the keyboard; after a stream is interrupted, check whether already-output text is preserved. These details often matter more than brand colors in determining whether a replica “feels right.”

    Replication Phase: Align Behavior, Not Brand Skin

    The goal of replication is behavioral alignment: information architecture, control positions, empty states, loading states, error states, and key dimensions. Visual details can be observed from the public page, but never write third-party names, domains, or proprietary model identifiers into code or copy.

    A layered implementation is recommended:

    1. View layer: only layout and state display.
    2. Session state layer: manages the message list, the generating flag, and the current session ID.
    3. Gateway layer: wraps conversation, file, and voice calls, with unified timeout, retry, and error-code mapping.

    Streaming consumption can stay minimal and avoid hardcoding vendor-specific fields:

    1. onChunk(chunk):
    2. append to current assistant message
    3. scroll if user is near bottom
    4. onDone:
    5. mark message complete
    6. persist conversation
    7. onError(code):
    8. show retry, keep partial text

    Quotas, per-message length limits, and daily request counts should be configurable policies surfaced in the UI in advance, rather than obscure error messages after the API fails. The point of an open or public capability is to let integrators validate it within their own quotas and product rhythm—not to assume unlimited upstream calls.

    Improved Version: Only Add Capabilities That Close the Loop

    Don’t pile features onto the improved version. Prioritize gaps exposed during replication:

    • Stop generation mid-stream; after stopping, support resume-from-breakpoint or regenerate.
    • For long answers, add outline navigation and code-block copy buttons.
    • Show upload parsing progress and failure reasons for attachments.
    • Route voice input and text input through the same send pipeline to avoid two separate states.
    • On mobile, fix the input area within the safe area; design its height separately from the desktop information density.

    Retrieval, files, and voice must all have fallbacks: when a capability is unavailable, the main conversation path must still support sending plain text. If an improvement breaks the main path, it isn’t an improvement.

    Using One Task Set to Compare Different Tools

    To compare multiple models and coding environments, the prompts, materials, number of rounds, and acceptance criteria must be identical. In the first round, provide only the requirements: produce the functional spec, structure diagram, replica page, and improved page, and allow browsing the logged-in reference page and API documentation. In the second round, provide the keys or environment variables needed for calls, then observe whether the tool stops at a smoke test (“it connects, so it works”) or follows the main path hunting for defects.

    Record four categories of results rather than a single overall score:

    Observation Passing behavior
    Documentation Functions, states, and acceptance steps are complete; the structure diagram matches page regions
    Fidelity Desktop and mobile key regions, sizes, and empty states are close to the reference page
    Depth After receiving keys, tests sharing, interruption, overlong input, and error codes
    Improvements Changes are explainable and do not break the replicated main path

    A common divergence: one environment proactively writes “share links must be verified in another browser” in its spec and aligns the mobile input box’s position and dimensions; another environment only sends a single shortest-possible request in round two to confirm connectivity. This isn’t model-parameter mysticism—it’s different default tool strategies: some bias toward finishing quickly, others keep exploring boundaries. Keeping the same prompt and materials lets you attribute differences to strategy rather than to “a slip this time.”

    Engineering Boundaries That Must Hold

    Keys belong only in server-side or local environment variables—never in repositories, frontend bundles, or screenshots. Sanitize logs; avoid persisting user text and voice content long-term. Restrict file uploads by type and size, and make parsing failures retryable. Set timeouts and concurrency limits on conversation APIs so a single page can’t drain a shared quota.

    Evaluation conclusions should describe process, not exaggerated performance numbers. Without a consistent sample size, network conditions, and acceptance checklist, do not claim one approach “comprehensively leads.” Instead, say: under the same prompt and acceptance checklist, which group’s documentation was more complete, whose mobile layout was closer, and which group found more defects in round two.

    Rollout Order

    First freeze a one-page functional specification and a structure diagram. Then build the replica. Only then open the improvement branch. Each round should add only observable acceptance items: streaming, stop, retry, attachments, voice, sharing, narrow screens. Check off passing items; return failing items to the document and revise the state description. The AI coding tool is an accelerator—the product specification is what determines whether the replica holds up.