AI-Assisted Development of Conversational Web Apps: From Requirements to Optimization

    Conversational web apps are one of the most direct ways to expose large language model capabilities. This article examines the practical process of building such an app with AI coding tools: defining deliverables, mapping product features, prompting in focused rounds, replicating a reference UI, implementing streaming output, and testing edge cases. It also covers security, compliance, and experience optimization, with the goal of turning a one-off prototype into a maintainable engineering practice.

    Introduction

    Conversational web apps are one of the most direct ways to expose large language model capabilities. A user asks a question, the page streams the response in real time, and the interface also handles history, model switching, and regeneration. This type of UI has a clear structure and a narrow interaction model, which makes it a useful sample for observing the full path from requirements to delivery.

    In the past, building such a page required a product manager to write requirements, a designer to produce mockups, a front-end engineer to reproduce the visual details, and a back-end developer to wire up APIs. AI coding tools can now absorb much of that execution work. But as the tools become more capable, human judgment is still needed to define the problem boundary, acceptance criteria, and quality floor.

    This article discusses the process from an engineering perspective. It stays at a generic technical level and does not evaluate any specific product. The features, APIs, and UI elements mentioned are common forms in conversational applications; actual implementation should follow the official documentation of the service you use.

    1. Define the Deliverables First

    Many projects fail because the goal is vague. “Build a chat page like some website” sounds clear, but it contains many unstated assumptions: Does the user need to log in? Where is history stored? Is mobile support required? How rich is the reply formatting?

    A useful approach is to split the task into three types of deliverables.

    1. Product functionality document: describes which features the page has, how each is triggered, what the inputs and outputs are, and what happens in error states.
    2. Replica version: matches the reference page closely in visuals and interaction, used to verify whether the requirement is understood correctly.
    3. Optimized version: improves the replica using general interaction experience, such as reducing steps, improving accessibility, and adding export or search capabilities.

    These three deliverables are progressive. The replica is a baseline for validating understanding. Optimization can only be credible after a reliable replica exists. If the replica is inaccurate, optimization has no solid foundation.

    2. Product Features and Structure

    A typical conversational web page can be broken down into five functional areas.

    • Session management: create, switch, rename, delete, and pin sessions.
    • Input and sending: multiline input, send on Enter, file attachment, stop generation, and sending-state feedback.
    • Reply display: streaming output, Markdown rendering, code highlighting and copy, collapsible reasoning trace, and regeneration.
    • Settings and account: login state, model selection, theme, language, and API key configuration.
    • Auxiliary capabilities: sharing sessions, exporting records, keyboard shortcuts, error prompts, and retry.

    The structure can be shown as a tree for quick review:

    1. Conversational App
    2. ├── Session Sidebar
    3. │ ├── New Session
    4. │ ├── History Session List (search, rename, delete)
    5. │ └── User Info and Settings Entry
    6. ├── Main Conversation Area
    7. │ ├── Message List (user messages / assistant messages)
    8. │ ├── Streaming Output and Stop Button
    9. │ └── Message Actions (copy, regenerate, feedback)
    10. ├── Input Area
    11. │ ├── Multiline Text Box
    12. │ ├── Attachments and Feature Toggles
    13. │ └── Send Button and Character Counter
    14. └── Settings Panel
    15. ├── Model and Parameters
    16. ├── Theme and Language
    17. └── Keys and Data Management

    Every item in the functional document should state three things: where the entry point is, what success looks like, and what failure looks like. The third point is often overlooked, but it determines whether users can recover when the network fails or quota is exhausted.

    3. Prompt Design: Iterate in Rounds, One Problem at a Time

    When using AI coding tools, prompt organization directly affects output quality. A reliable approach is to work in two rounds.

    Round 1 should only describe the requirement: page structure, feature list, visual requirements, and delivery format. Do not ask the tool to connect to a real service yet. The goal is to get a runnable page and supporting documentation. This confirms whether the structure is reasonable and reduces rework.

    Round 2 should add integration details after the page is running, and require verification. Integration details may include service endpoint, model name, and access credentials. This round focuses on integration and testing. Ask the tool to produce test cases covering normal conversation, network interruption, credential errors, very long input, and empty input.

    The prompt should also include explicit constraints, such as “do not write credentials into front-end source code” and “do not invent API fields; follow the documentation.” The more specific the constraints, the less likely the tool will drift.

    The difference between rounds is also important. Some tools only perform a minimal smoke test in Round 2, confirming that the page can send a request. Other tools actively construct abnormal scenarios, find style misalignment, incorrect scroll position, duplicate sends, and then fix them. Evaluation should look at test records, not just whether the final page looks usable.

    4. UI Replication Method

    The goal of replication is to make users feel that the structure and interaction are consistent with the reference, not to copy every pixel. These are practical checkpoints.

    4.1 Layout Structure

    First determine the relative relationships of major regions: Is the sidebar width fixed? Is the main conversation area centered? Is the input area fixed at the bottom? On mobile, the sidebar usually collapses into a drawer and the input area takes the full width. Breakpoints should be recorded explicitly, for example using 768 pixels as the divide between desktop and mobile.

    4.2 Dimensions and Spacing

    Measure dimensions from the reference page instead of estimating them. A common method is to inspect element width, height, padding, and font size in browser developer tools, then record them in a design token table. Design tokens include basic variables such as colors, font sizes, border radius, shadows, and spacing. Code should reference these tokens so that theme adjustments can be made in one place.

    4.3 Fonts and Colors

    For interfaces that include CJK text, the font stack should prioritize system sans-serif fonts, and code blocks should use a monospace font. Color variables should be separated into light and dark themes, and readability contrast should be checked. Text-to-background contrast should be at least 4.5:1.

    4.4 Comparison and Acceptance

    After replication, place the replica and reference page side by side and verify item by item. Screenshots at the same viewport size can be compared with a diff tool to identify inconsistent regions. Pay attention to input box height, message bubble spacing, code block scrolling, and whether the mobile page jumps when the soft keyboard opens.

    5. Core Implementation Details

    5.1 Streaming Output

    Streaming output is central to the conversational experience. The server returns content in chunks, and the front-end appends each chunk to the message area. Common approaches include Server-Sent Events or chunked transfer encoding, where the front-end reads the response body and parses each line.

    The following example only shows the parsing logic. API fields should follow the documentation of the service you use:

    1. async function readStream(response, onToken) {
    2. const reader = response.body.getReader();
    3. const decoder = new TextDecoder();
    4. let buffer = '';
    5. while (true) {
    6. const { value, done } = await reader.read();
    7. if (done) break;
    8. buffer += decoder.decode(value, { stream: true });
    9. const lines = buffer.split('\n');
    10. buffer = lines.pop(); // Keep the incomplete line in the buffer
    11. for (const line of lines) {
    12. if (!line.startsWith('data: ')) continue;
    13. const payload = line.slice(6).trim();
    14. if (payload === '[DONE]') return;
    15. const delta = JSON.parse(payload).choices?.[0]?.delta?.content ?? '';
    16. onToken(delta);
    17. }
    18. }
    19. }

    Three points matter here. First, use streaming mode when decoding so that multi-byte characters are not truncated. Second, keep the incomplete line in the buffer, otherwise data can be lost. Third, support cancellation at any time using AbortController, and show a clear “stopped” state in the UI.

    5.2 Markdown and Code Blocks

    Assistant replies often contain headings, lists, tables, and code. Use a mature Markdown parsing library and sanitize the output to prevent malicious content from injecting scripts. Code blocks should include a language label, a copy button, and horizontal scrolling.

    There is another detail in streaming Markdown rendering: an unclosed code fence can cause all subsequent content to be displayed as code. One way to handle this is to count fences before rendering and temporarily close an unclosed fence, or wait until the stream ends and render the full result.

    5.3 Sessions and History

    Session data includes session ID, title, creation time, message list, and model parameters. Local browser storage can be used, but it has limited capacity and clearing browser data will lose the records. For cross-device synchronization, sessions should be stored server-side and support time sorting and keyword search.

    Context length is another common problem. As messages accumulate, each request carries more content, which increases latency and cost. Common strategies include keeping only the most recent turns, summarizing earlier messages, or letting the user choose whether to include history. The policy should be visible in settings so users do not assume the model remembers everything.

    5.4 Stop and Regenerate

    Stopping generation requires two actions: abort the network request and preserve the content already produced. Regeneration should issue a new request based on the same user message, and the previous reply should be retained as a historical version for comparison.

    6. Testing and Acceptance

    After connecting a real service, testing should cover the following scenarios.

    Scenario Acceptance Criteria
    Normal conversation The first token arrives and the stream stays continuous; UI state returns to normal after completion.
    Network interruption A clear error is shown; already generated content is preserved; retry is supported.
    Credential error The error message is clear, credentials are not exposed, and other functions continue to work.
    Very long input The front-end provides a character or length hint; server errors have readable text.
    Rapid consecutive sends Duplicate submission is disabled or requests are queued in order.
    Mobile The input box stays visible when the soft keyboard opens; sidebar opens and closes correctly.
    Accessibility Keyboard navigation works; icon buttons have accessible names; color contrast meets the required standard.

    Testing should not rely only on manual clicks. Core parsing logic can be covered by unit tests using simulated chunk data. UI flows can be covered by end-to-end test scripts that run after every change as a regression check.

    7. Experience Optimization Directions

    Once the replica meets the baseline, optimization can focus on real usage pain points. The following directions are widely used in general conversational products.

    • Session search: support full-text search by title and content, with keyword highlighting.
    • Message export: support export as plain text or Markdown, keeping language information in code blocks.
    • Keyboard shortcuts: provide quick actions for new session, switching sessions, and focusing the input box, and show the full shortcut list in settings.
    • Input experience: support Shift+Enter for new lines, auto-growing input height, and image preview when pasting images.
    • Error recovery: failed messages remain in the input box so users can modify and resend them.
    • Accessibility: set live-region attributes on dynamic content areas so screen readers can announce new replies.

    Optimization needs evidence. Each change should correspond to a specific problem and be verified in testing. For example, if users often accidentally delete a session, add a confirmation step or move deletion into a trash area. If the mobile input area covers text, adjust how viewport height is calculated.

    8. Engineering and Security Recommendations

    Conversational applications handle credentials and user data, so security must be considered early.

    1. Credentials should not be written into front-end code. Any script running in a browser can be inspected, so placing access credentials directly in a page will expose them. A recommended approach is to proxy requests through a back-end service, with the front-end communicating only with that service.
    2. Credentials should be injected through environment variables or a secret management service, not committed to the code repository or printed to logs.
    3. User input and model output in logs should be redacted and given a retention period.
    4. Request frequency should be rate-limited to avoid abnormal loops exhausting quota.
    5. User input should be validated for length, and server-returned content should be sanitized before rendering.

    A back-end proxy can also handle timeout, retry, and error-code mapping uniformly, so the front-end only needs to manage UI states. This layering makes it easier to switch or integrate multiple services later without changing interface code.

    9. Compliance and Boundaries

    When replicating a reference page, copyright and trademark issues should be considered. Page structure, interaction patterns, and common components are generally acceptable as common practice, but directly copying icons, brand marks, copy, and assets may infringe on others’ rights. It is safer to use the replica for learning and internal prototypes, and to replace all brand elements and redesign the visual style before public release.

    Any application that connects to third-party services should also follow that service’s terms of use, including call frequency, data retention, and content moderation requirements. Read the relevant documentation before development and confirm the permitted scope of use.

    10. Conclusion

    Using AI tools to build a conversational web app becomes practical when the task is decomposed clearly and acceptance criteria are defined in advance. Round-based prompting reduces rework. Measurement and comparison keep the replica faithful. Core implementation work should focus heavily on streaming output, session management, and abnormal recovery. Testing should cover boundary conditions that occur in real usage.

    Tools accelerate execution, but judgment still comes from the developer. Clear deliverables, explicit constraints, and defined acceptance methods make tool output stable and reliable. Following this process lets a team turn a one-off prototype into an engineering practice that can be iterated on sustainably.