Rebuilding a Complex AI Chat Application in Vue 3: A Practical Guide
This article shares a practical Vue 3 rebuild of a complex AI chat application and abstracts it into a reusable frontend architecture. It breaks down the real complexity beyond the input box: a rich semantic content-block protocol, a message branching tree, thinking and search orchestration, multimodal file uploads, voice input and streaming playback, and cross-version archive compatibility. It also documents three architecture iterations, a counterintuitive pitfall with heavy component suites, and a four-layer structure that reduced production code by roughly a quarter while adding extensibility through tool connections and instruction management. The goal is to show how clear layering can cut code volume and increase capability at the same time.
Introduction: The Complexity of an AI Chat App Is Not in the Input Box
Many developers assume that building an AI chat page is just rendering a message list and consuming a text stream. But once you break down a fully featured open-source web chat application, you find that about ninety percent of the complexity sits below the surface: a rich semantic content-block protocol, a message branching tree, search citations, file re-uploads, the voice pipeline, history archiving with import and export, and extensible tools and instruction management. Using a complete Vue 3 rebuild of a complex AI chat application as the thread, this article abstracts a general technical approach and discusses how to achieve the same or even more complete capabilities with less code.
Note that this article is not built around any specific third-party product. All implementations are based on common frontend engineering practices and publicly available protocol specifications.
1. The Real Challenge: Six Engineering Problems Beyond the Chat Box
1. It Is Not a Plain Text Stream, but a Rich Semantic Content-Block Protocol
Mature chat applications generally adopt an extended interface compatible with mainstream message protocols. The returned content is not a single string but a composition of multiple semantic blocks: plain text blocks, thinking-process blocks, tool-call blocks, citation-source blocks, file blocks, and more. The frontend must implement an incremental parser that dispatches rendering logic by block type as streaming chunks arrive.
A schematic structure looks like this:
// Pseudocode: incremental rendering dispatched by block typefunction appendChunk(state, chunk) {const block = state.blocks.at(-1)if (chunk.type === 'text_delta') block.text += chunk.deltaelse if (chunk.type === 'thinking_delta') block.thinking += chunk.deltaelse if (chunk.type === 'tool_use') state.blocks.push({ type: 'tool', ...chunk })else if (chunk.type === 'citation') block.citations.push(chunk.source)}
The key point is that blocks may arrive interleaved. Thinking blocks and body text blocks need to be collapsed and displayed independently, tool-call blocks need to carry structured inputs and returns, and citation blocks need to establish anchor mappings with body text fragments.
2. A Message Branching Tree, Not a Linear Array
Regenerating a response, switching between answers from different models, or editing a historical question all turn a conversation from a linear list into a tree. Each node contains a parent pointer, a set of children, content blocks, and metadata. Rendering requires walking back along the currently active path, and switching branches should only recompute the affected subtree.
// Node structure sketch{ id, parentId, children: [], blocks: [], model, createdAt }
The engineering recommendation is to place the tree structure in a reactive state container and use derived computed properties to output the “current path,” avoiding recursive traversal in the template that causes repeated rendering.
3. Timing Orchestration for Deep Thinking and Search While Thinking
The thinking process and web retrieval often proceed in parallel: the model first produces an initial intent, the frontend triggers retrieval, the retrieval results are fed back as supplementary context, and generation then continues. The frontend needs to maintain a cancellable async task queue that handles timeouts, retry on failure, and mid-process user interruption.
4. Multimodal File Upload and Re-upload
File uploads involve chunking, progress, type validation, and re-upload on failure. When referencing files in the conversation context, you need to store a file identifier rather than a local path, so the file can still be correctly restored after switching branches or reloading a session.
5. Voice Input and Streaming Read-Aloud
The voice pipeline includes capture, encoding, incremental recognition, and playback queue management. Streaming read-aloud must handle sentence-boundary splitting, playback interruption and recovery, and voice switching, typically implemented with a queue plus a state machine.
6. Cross-Version Compatibility of History Archives
Archive packages generally use a common compression format to encapsulate the conversation tree and configuration. To achieve bidirectional interoperability with other implementations, you must strictly align field naming, version numbers, and default-value filling strategies, and ignore unknown fields with forward compatibility.
2. Architecture Evolution: Three Iterations and One Counterintuitive Pitfall
Round One: Components Wired Directly, Fast to Get Running
Interface calls, state, and rendering were written directly in the page component. The advantage is speed; the downside is scattered state, with the branching tree and streaming blocks coupled together, making later extension difficult.
Round Two: Introducing an Advanced Suite, but the Code Grew Instead
A counterintuitive pitfall: after introducing a powerful advanced component suite, adapting to its data contract and slot system required writing a large amount of adapter and style-override code, so the total did not shrink but grew. The lesson is that advanced suites are good for rapid validation, but long-term maintenance should converge to lightweight composables plus a small set of base components.
Round Three: Layered Convergence, Net Code Reduction
The final structure is divided into four layers:
- Protocol layer: stream parsing, block dispatch, and error normalization;
- Domain state layer: conversation tree, branch switching, and citation mapping;
- Orchestration layer: scheduling and cancellation of retrieval, file, and voice tasks;
- View layer: pure presentation components plus composable bindings.
After unifying the formatting standard, the production source code was reduced by roughly a quarter compared with the initial rebuild version, while new extensibility was added. This shows that the key to complexity governance is not writing fewer features, but isolating the parts that change easily.
3. Extensibility: Tool Connections and Instruction Management
Two types of extensions are added at the bottom-left entry:
- Tool connections: declare tool names, input schemas, and invocation endpoints in a configuration-driven way. The frontend is only responsible for initiating calls and rendering result blocks, without hardcoding specific logic;
- Instruction management: support importing instruction sets from local text files, directories, or public code repositories, parsing them into reusable prompt templates, and mounting them by scenario.
On security, the following are mandatory: tool calls require explicit user confirmation, sensitive configuration is stored locally and displayed with masking, and imported content is subject to size and format limits.
4. An Actionable Engineering Checklist
- Maintain the message tree with immutable updates; switching branches recomputes only the affected path;
- Decouple stream parsing from the view, so protocol changes touch only one layer;
- Make all async tasks support cancellation and timeouts;
- Add version negotiation and unknown-field ignoring to archive import;
- Unify formatting and static-check standards, and measure refactoring gains with objective metrics;
- Prefer abstracting complex interactions with composables, avoiding being locked into a single suite’s contract.
Conclusion
The value of rebuilding a complex AI chat application lies not in stacking features, but in turning protocol parsing, state modeling, async orchestration, and compatibility strategies into a replaceable layered structure. When the layers are clear, code reduction and feature enhancement can happen at the same time.
