Rebuilding an AI Chat Web App with an AI Agent: A Practical Development Guide

    A practical workflow for using an AI agent to recreate an authorized AI chat web application. Learn how to define deliverables, document features and architecture, connect a real model API securely, and verify the implementation with repeatable tests and clear acceptance criteria.

    Audience and Prerequisites

    This guide is for developers with frontend experience and technical leads. Before starting, confirm three prerequisites:

    • You have written authorization to recreate the target product.
    • You have API access to the target model.
    • Your team has selected its technology stack and versions.

    The recommended environment is Node.js 20 or later, React 18 with Vite, Zustand for state management, and Vitest and Playwright for testing. Other frameworks are also suitable. Use your team’s actual versions and record them in the test log.

    The workflow is not tied to a particular model. When switching models or agent frameworks, the main changes are the API endpoint and request format; the overall process remains the same.

    Compliance Boundaries

    Any pages and documentation the agent accesses in the first round must meet these requirements:

    • Pages are either authorized for access or publicly accessible.
    • API documentation is official and publicly available.
    • Access complies with the target website’s robots.txt rules and terms of service.

    The agent must not collect private data, bypass login requirements or paywalls, or reuse the target product’s trademarks, icons, or other assets in a published release. Before work begins, the project lead must verify the authorization and document its scope in the project description.

    1. Define Deliverables and Acceptance Criteria First

    “Looks similar” and “works well” are not measurable completion criteria. Before starting, turn each deliverable into a checklist with explicit evidence of completion.

    Deliverable 1: Functional Specification and Architecture Diagram

    • Cover all five modules: conversation management, message flow, streaming responses, context memory, and model parameters. Missing any module is a failure.
    • Specify each module’s inputs, outputs, and upstream and downstream dependencies.
    • Show the relationships between modules in a single diagram.

    Required evidence: A functional specification file and an architecture diagram file, with their paths recorded in the project README.

    Deliverable 2: Recreated Web App

    • The page opens locally after running npm install and npm run dev.
    • Sending messages, receiving replies, and switching conversations all work.
    • Loading, error, and empty states are visible.
    • At viewport widths of 375px and 1440px, the layout has no overflow or overlapping text.

    Required evidence: Two screenshots documenting the checklist results, plus the output from npm test.

    Deliverable 3: Improved Web App

    • Document at least one user-experience improvement, including its goal and scope of impact.
    • Pass the same test cases used for the recreated version.
    • Make the differences between the original recreation and the improved version traceable in version history.

    Required evidence: An improvement document and results from running the same test suite against both versions.

    Pass/fail rule: A deliverable is complete only when every item in its checklist passes. If any item fails, record the reason and rework it. Do not use “mostly passed” as a completion status.

    Avoid using “pixel-perfect reproduction” as an acceptance criterion. It is difficult to assess consistently and can consume excessive time on visual details. A more practical approach is to check the layout at 375px and 1440px and retain evidence through screenshot comparisons or automated scripts.

    Test Log Template

    Record the following fields for every test run. Consistent fields make results comparable across teams.

    Field What to Record
    Model name and version The model and version actually called
    Agent framework and version For example, FrameworkName v1.2.0
    Interaction rounds The number of agent–user interaction rounds during the test
    Available tools and permissions Readable files, executable commands, and accessible URLs
    Completion time for each deliverable Recorded to the nearest minute
    Number of human interventions Include the reason for every intervention

    2. Round One: Generate the Functional Specification and Architecture Diagram

    The first round helps the agent understand the product and plan the implementation. Do not write application code during this round.

    Before using the template below, replace three variables: the target page URL, the API documentation URL, and the intended technology stack.

    Round-One Prompt Template

    You are a senior product manager and frontend architect. Visit the following two URLs, using only authorized pages and public API documentation.

    Target page: {target page URL}
    API documentation: {API documentation URL}
    Intended technology stack: {intended technology stack}

    Complete these tasks in order:

    1. Inspect the page and list all core features you observe. Group them into modules such as conversation management, message flow, streaming responses, context memory, and model parameters.
    2. Read the API documentation and summarize the request parameters, response formats, and error codes for chat completion and streaming interfaces.
    3. Produce a functional specification, a module architecture diagram, and technology recommendations. Include the frontend framework, state management approach, and styling approach.
    4. List any information that cannot be verified from the page or documentation separately and mark it as requiring confirmation. Do not guess.

    Do not write application code in this round.

    The key is to let the agent inspect the actual page and documentation. With only a written description, it may guess the interface structure. Direct access provides concrete information about the layout and documented API response formats.

    At the end of round one, a human reviewer must verify three things:

    1. All required modules are covered.
    2. API fields match the documentation.
    3. The project lead has resolved the items marked as requiring confirmation.

    Proceed to round two only after all three checks pass.

    3. Round Two: Connect the Real API and Run Integration Tests

    Begin round two once the initial implementation is available based on the first round’s outputs. The goal is to connect frontend requests to the real API while retaining a mock-data switch for easy fallback.

    Preparation

    1. Create .env.local in the project root and add:
      1. API_KEY=your_api_key
      2. USE_MOCK=false
    2. Confirm that .gitignore includes .env.local and .env*.local.
    3. Run git status and verify that .env.local does not appear among the files to be committed.
    4. Before integration testing, create a branch that preserves the current state, such as before-real-api, so you can roll back.

    Round-Two Prompt Template

    API access has been enabled. Read the key only from the server-side environment variable API_KEY. Follow these requirements strictly:

    1. Never place the key in frontend code, configuration files, or logs, and never commit it to the repository.
    2. The frontend must call only this project’s server-side endpoint, using the actual project path—for example, /api/chat. The server must attach the key and forward requests to the model API.
    3. Retain the USE_MOCK environment-variable switch: use mock data when it is true and call the real API when it is false.
    4. Implement incremental output for streaming responses and handle the end-of-stream marker correctly.
    5. Complete integration checks in the following order and report the result of each:
      • a. Pass npm run lint.
      • b. Pass npm test.
      • c. Pass npm run test:e2e, covering message sending, reply reception, and conversation switching.
      • d. Call the server-side endpoint with curl -N and confirm that output arrives incrementally.
    6. If any step fails, identify and explain the cause first. Do not delete or skip test cases.