Building Complex AI Chat Applications in Vue 3: Engineering Lessons and Architecture Evolution

    This article breaks down why a production AI chat interface is far more complex than a single input box and a streaming API call. Using an open-source chat web project as a reference, it explains the core challenges: rich semantic content blocks instead of plain text, message branching trees instead of linear arrays, structured citations for "think-and-search" flows, and decoupled multimodal and voice side channels. It then walks through three rounds of architecture evolution, showing how consolidating messages, content blocks, citations, and task queues into unified primitives reduced production source code from roughly 18,000 lines to about 13,000 lines, and closes with reusable engineering conclusions for lowering implementation and maintenance costs.

    1. Why a “Chat Page” Is Far More Complex Than It Looks

    When teams estimate the effort for an AI chat application, they often reduce it to “one input box plus one streaming API call.” In real projects, that estimate almost always spirals out of control. Most of the complexity in a mature chat product lives below the surface, not in the message rendering layer: protocol semantics, state consistency, traceable history structures, failure handling and retries, and side channels such as multimodal input and voice.

    As a reference point, an open-source chat web example project has a production codebase on the order of 18,000 lines, excluding static assets like icons. That number alone shows that the real engineering cost comes from edge cases and state management, not from the UI skeleton.

    1.1 Not a Plain Text Stream, but Rich Semantic Content Blocks

    The mainstream approach is no longer “return a block of plain text.” Instead, it uses an extended interface compatible with a general message protocol: a single reply may interleave reasoning, body paragraphs, tool-call intents, citation sources, and verifiable signature fragments. If the frontend treats this as plain text and simply concatenates it, three problems appear immediately: reasoning content gets displayed as body text, citations cannot be located, and missing signatures make the content untrustworthy.

    The content layer must therefore be modeled as a “sequence of blocks,” not a single string:

    1. // Minimal modeling sketch for content blocks
    2. message.content = [
    3. { type: 'thinking', text: '...', signature: '...' },
    4. { type: 'text', text: '...' },
    5. { type: 'tool_use', name: 'search', input: { q: '...' } },
    6. { type: 'citation', ref: 3 }
    7. ]

    1.2 A Message Branch Tree, Not a Linear Array

    Once you support “regenerate” and “answer in a different direction,” the conversation structure inevitably turns from an array into a tree. Each node needs a stable identifier, a parent pointer, a set of children, and an active path. If you keep using array indices for positioning, a single branch shifts everything globally.

    The more robust engineering approach is to give nodes immutable identifiers, store the active path separately, and project a linear view from that path at render time.

    1. const tree = { rootId: 'n0', nodes: { n0: { id:'n0', parent:null, children:['n1'] } } }
    2. const activePath = ['n0', 'n1', 'n3'] // Only the path determines the currently visible conversation

    1.3 Retrieval Citations and “Think-and-Search”

    Web access does not mean a single request; it means multi-round orchestration of “reason, retrieve, reason again.” The frontend must be able to express intermediate states, display citation numbers, and jump to the source when a number is clicked in the body text. This requires citations to be structured data, not bare numbers the model happens to generate.

    1.4 Multimodal and Voice Side Channels

    File uploads involve chunking, type validation, retrying failed chunks, and temporary credentials. The voice pipeline involves capture, encoding, streaming recognition, and queue scheduling for reading aloud while generating. The more loosely coupled these two channels are with the main conversation, the lower the long-term maintenance cost.

    2. Three Rounds of Architecture Evolution: From “It Runs” to “It’s Controllable”

    Round 1: Direct Connection and Minimum Viability

    Start with the simplest structure to get streaming rendering working and validate protocol parsing. This stage has the fewest problems, but branching and citations are nearly impossible to extend.

    This is the most counterintuitive pitfall: after introducing a more feature-complete runtime suite, the code volume went up instead of down. The reason is that the adapter layer, style overrides, and concept mapping all existed at the same time, which meant maintaining two mental models. The conclusion is clear: a suite must provide state primitives that are isomorphic to the business domain; otherwise the reuse gains are eaten by adaptation costs.

    Round 3: Unified Primitives and Consistent Conventions

    Consolidate the message tree, content blocks, citations, and task queue into unified primitives, and unify formatting and static-check conventions before counting again. The final production source code was compressed to around 13,000 lines, a net reduction of about 5,000 lines, close to a 30% drop, while the newly added capabilities were still included.

    3. Reusable Engineering Conclusions

    1. Define the protocol and state model first, then write components; the UI is the cheapest part.
    2. Branch trees, citations, and task queues must be independent primitives; do not stuff them into the message object.
    3. Connect side capabilities (voice, upload, tool calls) to the main flow through events and queues.
    4. Unify formatting conventions before measuring code volume; otherwise any “less code” conclusion does not hold.
    5. Use a versioned archive structure for history, with bidirectional compatibility checks retained, to avoid broken links on upgrade.

    With this approach, a team can significantly reduce the implementation and maintenance cost of a complex chat application without sacrificing feature completeness, and leave clear boundaries for later extensions such as tool calls and instruction management.