Rebuilding a Complex AI Chat Application in Vue 3: Architecture and Practice
This article walks through rebuilding a full-featured AI chat application in Vue 3, moving beyond a single input box to a real architecture. It covers modeling messages as a tree, fine-grained state subscriptions for streaming performance, a unified pipeline for multimodal input, lessons from adopting advanced toolkits, plugin-style registries for tool calling and instruction management, and a versioned archive format for bidirectional migration. Readers will learn how the right data structures and boundaries reduced production source code by roughly 27% while adding new capabilities.
1. Why a Complex AI Chat App Needs More Than One Input Box
When many teams build an AI chat feature, the first version is often just an input box plus a single streaming text API call. That is enough for a demo, but problems surface quickly in real usage: how to organize multi-turn context, how to separate reasoning from the final answer, how to keep old messages after a regeneration, how to fold file uploads and voice input into the same message flow, and how to migrate and archive conversation history.
When one cloud vendor open-sourced its official web client, it did not ship a toy demo. It delivered a complete browser-only application that connects directly to the API: streaming chat, deep thinking, web search, think-while-searching, web page reading, multimodal file uploads, voice input, streaming text-to-speech, a full message branch tree, and ZIP-based history archive import/export, all inside a single frontend project. The original implementation was built on React 18 and Zustand, with more than eighteen thousand lines of production source code alone.
For developers on the Vue stack, the real question is not whether the syntax can be translated. It is whether the same or even more capability can be carried with less code while fully preserving the protocol and interactions. The answer is yes, but it requires a serious refactor rather than a line-by-line port.
2. Model the Domain First, Then Talk About Components and Code Size
The first step in rebuilding this kind of application is to break the interface into domain models, not into components. Start by defining four entities:
- Session: holds the title, creation time, and archive status;
- Message: distinguishes user messages, reasoning segments, body segments, and tool-call segments;
- Branch: each user message can derive multiple child nodes, forming a tree;
- Attachment: files, images, and audio are unified as resources with a type and lifecycle.
A sample type definition looks like this:
type NodeId = string;interface MessageNode {id: NodeId;parentId: NodeId | null;role: 'user' | 'assistant' | 'system';reasoning?: string; // deep thinking streamcontent: string; // body streamcitations?: Citation[]; // search citationsattachments?: Attachment[];children: NodeId[]; // core of the branch tree}
Once messages are modeled as a tree instead of a linear array, “regenerate,” “switch to a previous version,” and “compare different answers” collapse from three features into one operation: moving the current pointer. This is the first source of reduced code size. When the data structure is right, boilerplate logic disappears on its own.
3. State Management Trade-offs: Fine-Grained Subscription Beats a Global Object
The performance bottleneck in a complex chat app is usually not the network but rendering. Streaming output can trigger dozens of updates per second. If the entire conversation tree is placed in one deeply reactive object and subscribed to as a whole, it causes large-scale re-renders.
A more reliable approach is to layer it:
- Keep the session list lightweight, storing metadata only;
- Store the active session’s message tree in a flat Map, linking nodes by id;
- Let each message node subscribe independently, updating only when it changes;
- Buffer streaming deltas and commit them in batches, merged per animation frame.
const nodes = reactive(new Map<NodeId, MessageNode>());const activeId = ref<NodeId | null>(null);function appendDelta(id: NodeId, chunk: string) {const node = nodes.get(id);if (node) node.content += chunk; // only subscribers of this node are notified}
This combination of flattening plus fine-grained subscription keeps the code simple while avoiding the cost of recursive rendering, and makes branch switching almost free.
4. Streaming and Multimodal Input: Unify Heterogeneous Inputs into One Pipeline
The real difficulty in a complex app is merging heterogeneous inputs. If text, images, audio, and follow-up file uploads each get their own logic, the code size will inevitably balloon. A workable approach is to define a unified message assembly pipeline:
- Input stage: all inputs are first converted into attachment descriptions; text is just one of them;
- Transport stage: everything is wrapped into a request body with type markers, and stream parsing dispatches by event type;
- Render stage: segment types map to different renderers, with reasoning segments collapsed, body segments rendered as Markdown, and citation segments made clickable.
The voice flow works the same way: recognition results are written back into the input box as text, and the read-aloud request is an independent streaming audio channel that runs in parallel with the text stream without blocking it. The key is “one shared state, multiple consumers,” rather than maintaining a separate conversation copy for voice.
5. Lessons Learned: Code Grew After Adopting an Advanced Toolkit
A counterintuitive phenomenon appeared during the third architecture iteration: after introducing an advanced runtime toolkit to reduce hand-written code, the total size went up instead of down. There were three reasons: the adapter layer re-wrapped existing capabilities; the toolkit’s generic abstractions covered scenarios that were never used; and debugging plus type declarations also counted toward the source.
The conclusion after review: a toolkit pays off only when it replaces cross-cutting concerns (render scheduling, stream buffering, lifecycle management). If it merely expresses the same business branches in a different style, the return is negative. After unifying the counting to the same formatting standard, production source code was compressed from more than eighteen thousand lines to about thirteen thousand lines, a net reduction of roughly five thousand lines, or about 27%, and that was after adding tool-calling and instruction-management capabilities.
6. Extending Capabilities: How Tool Calling and Instruction Management Land
On top of the rebuilt baseline, two high-frequency needs can be extended:
- Tool connection and invocation: describe a tool’s name, input schema, and authentication method via configuration. The frontend only initiates the call and renders the result card, without hard-coding any specific service;
- Instruction management: support three import sources, local Markdown files, folder directories, and remote repositories. After parsing front matter, they are registered as reusable instructions and can be referenced on demand within a session.
The engineering recommendation is to make both a “plugin-style registry,” where adding a capability only adds one registration entry without changing the main flow. This is the key constraint for controlling code size.
7. Compatibility and Migration: The Archive Format Must Be Readable Both Ways
If a history archive can only be imported by the version that exported it, migration costs for users are extremely high. The practical approach is to treat the archive as a stable contract: write the version number explicitly into the manifest inside the package, store node structure and attachment references separately, and perform version detection and field fallback on import. Only then can seamless bidirectional import and export work across different implementation versions.
If server-side persistence is involved, it can be handled by general cloud capabilities, for example object storage for archive packages, a logging service for call traces, and monitoring and alerting to track streaming failure rates, while the frontend keeps only the necessary local cache and index.
8. Conclusion
Rebuilding a full-featured complex AI chat application in Vue 3 is not mainly about migrating syntax. It comes down to three things: modeling messages as a tree, making state subscriptions fine-grained, and unifying heterogeneous inputs into one pipeline. Do these three, and code size drops naturally, while extending tool and instruction capabilities will not spiral out of control. Keeping the archive format and protocol stable is what gives the implementation room for long-term evolution and interoperability.
