# kuingsmile/word-gpt-plus architecture

> Architecture diagram of the GitHub repository kuingsmile/word-gpt-plus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kuingsmile/word-gpt-plus
- Repository: https://github.com/kuingsmile/word-gpt-plus

## Overview

1. **What this repo is**
   - This is a Microsoft Word add-in, not a standalone desktop app.
   - The UI is a Vue single-page app built with TypeScript and Vite, then hosted inside Word’s add-in webview.
   - Its job is to let users chat with AI and let an agent read/write/format the current Word document.

2. **Execution boundary**
   - The app runs in the Word add-in host and depends on the Office/Word environment to access the document.
   - It also connects outward directly to AI providers such as OpenAI-compatible APIs, Azure OpenAI, Gemini, Groq, and local Ollama.
   - That means there are two major external boundaries: the Word document boundary and the model-provider boundary.

3. **UI shell and navigation**
   - `src/main.ts` bootstraps the app into `src/App.vue`.
   - `src/router/index.ts` routes between the main task-pane views: `HomePage.vue`, `SettingsPage.vue`, and `checkPointsPage.vue`.
   - The Home page is the primary chat/agent workspace; Settings configures providers and behavior; the checkpoints page appears to manage saved workflow/document states.

4. **Component layer**
   - Reusable UI is concentrated in `src/components/`.
   - These components implement the add-in’s custom controls and layout blocks: buttons, inputs, messages, setting cards, sections, and selects.
   - The component layer is presentation-focused and sits above the action/state logic in `utils/` and `api/`.

5. **Provider and request layer**
   - `src/api/` holds the abstraction for talking to AI backends.
   - `common.ts`, `types.ts`, `union.ts`, and `checkpoints.ts` suggest a shared request/response model plus provider-specific variations and checkpoint-related operations.
   - This layer is the outbound network boundary for model calls and likely handles provider differences, streaming, and request normalization.

6. **Agent/document-tool layer**
   - The repo’s agent mode is centered around `src/utils/wordTools.ts`, `wordFormatter.ts`, and related helpers.
   - This layer exposes Word-specific capabilities to the AI: reading selection/content, inserting and replacing text, formatting paragraphs, managing tables/bookmarks, and similar document operations.
   - Conceptually, this is the bridge between LLM reasoning and the actual Word document state.

7. **Prompting, settings, and user preferences**
   - `src/utils/settingForm.ts`, `settingPreset.ts`, and `constant.ts` define the shape and defaults of provider settings.
   - `src/utils/enum.ts` and `src/utils/common.ts` support shared app logic and configuration interpretation.
   - Settings are persisted locally in the add-in environment, matching the README’s privacy model: no central backend stores user API keys.

8. **Response handling and messaging**
   - `src/utils/message.ts`, `generalTools.ts`, and the `Message.vue` component indicate a structured chat/message pipeline.
   - The app appears to support streaming AI output, per-message actions like replace/append/copy, and user-visible status/error reporting.
   - This layer is where AI responses are turned into interactive chat UI updates and document actions.

9. **Formatting pipeline**
   - `wordFormatter.ts` is an important architecture piece because AI output is not shown raw; it is transformed into Word-friendly formatting.
   - The add-in supports markdown-style response rendering and conversion into Word styles, so formatting is part of the product’s core behavior, not just a UI concern.
   - That makes the output path: model response → formatter → Word-compatible display/actions.

10. **Internationalization**
   - `src/i18n/` contains English and Simplified Chinese locale files.
   - Localization is built into the UI layer, so language selection affects labels, settings, and prompts across the task pane.
   - This is a pure presentation/config boundary, separate from provider logic.

11. **Static assets and hosting**
   - `public/` contains static files including `PrivacyPage.html` and assets like the logo.
   - The repo includes `release/instant-use/manifest.xml` and `release/self-hosted/manifest.xml`, which show two deployment modes: a hosted “instant use” manifest and a self-hosted manifest.
   - `Dockerfile` and the GitHub workflow indicate the frontend can be packaged into a container for simple deployment.

12. **Word add-in packaging**
   - `index.html`, `vite.config.js`, and the Office add-in manifests define the browser entrypoint and how Word loads the app.
   - `wordgpt.bat` and `async_hook.js` look like support scripts for Windows/add-in startup or environment integration.
   - The overall packaging model is: build the SPA, serve it over HTTP(S), and point Word’s manifest to that URL.

13. **Likely end-to-end data flow**
   - User action in Word → task-pane UI event → settings/model selection → API request to provider → streamed response back to UI.
   - In agent mode, the response may include tool calls that are resolved through Word/document utilities, then fed back into the conversation.
   - Final output can be rendered in the chat UI, inserted into the document, or both.

14. **How to draw the architecture**
   - Draw a central “Word GPT Plus Add-in UI” box containing pages/components/router.
   - Connect it to a “Local settings/store” boundary for API keys, prompts, and preferences.
   - Connect it outward to “AI Providers” and inward to “Word document APIs / Office host.”
   - Place the agent/tool layer between the LLM and Word to show that document actions are mediated, not direct from the UI alone.

Main entry points: [`src/pages/HomePage.vue`](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/HomePage.vue) (Home), [`src/router/index.ts`](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/router/index.ts) (Router), [`src/api/common.ts`](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/common.ts) (API Core), [`src/pages/SettingsPage.vue`](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/SettingsPage.vue) (Settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Add-in UI"]
  node_entry(("Main<br/>bootstrap<br/>[main.ts]"))
  node_app["App Shell<br/>[App.vue]"]
  node_router["Router<br/>navigation<br/>[index.ts]"]
  node_home["Home<br/>chat workspace<br/>[HomePage.vue]"]
  node_settings["Settings<br/>preferences<br/>[SettingsPage.vue]"]
  node_checkpoints["Checkpoints<br/>workflow states"]
  node_components["UI Controls<br/>components"]
  node_i18n["Locales<br/>localization<br/>[index.ts]"]
end

subgraph group_agent["Agent & Docs"]
  node_messages["Chat State<br/>conversation state<br/>[message.ts]"]
  node_wordtools[("Word Tools<br/>document tools<br/>[wordTools.ts]")]
  node_formatter["Formatter<br/>render transform<br/>[wordFormatter.ts]"]
  node_generaltools["Tools Core<br/>agent helpers<br/>[generalTools.ts]"]
  node_settingsform["Settings Model<br/>config schema<br/>[settingForm.ts]"]
end

subgraph group_providers["AI Providers"]
  node_apicommon[("API Core<br/>provider core<br/>[common.ts]")]
  node_apitypes["API Types<br/>contracts<br/>[types.ts]"]
  node_apiunion[("Provider Union<br/>provider adapters<br/>[union.ts]")]
  node_apicheckpoints["Checkpoint API<br/>checkpoint ops<br/>[checkpoints.ts]"]
end

subgraph group_platform["Packaging"]
  node_manifest["Packaging<br/>[index.html]"]
end

node_wordhost[("Word Host<br/>external host")]
node_providersext[("Model Providers<br/>external services")]
node_storage[("Local Store<br/>local persistence")]

node_entry -->|"mounts"| node_app
node_app -->|"uses"| node_router
node_router -->|"routes"| node_home
node_router -->|"routes"| node_settings
node_router -->|"routes"| node_checkpoints
node_home -->|"renders"| node_components
node_settings -->|"renders"| node_components
node_checkpoints -->|"renders"| node_components
node_home -->|"manages"| node_messages
node_home -->|"tools"| node_wordtools
node_home -->|"formats"| node_formatter
node_messages -->|"requests"| node_apicommon
node_apicommon -->|"contracts"| node_apitypes
node_apicommon -->|"adapts"| node_apiunion
node_apicommon -.->|"calls"| node_providersext
node_settings -->|"configures"| node_settingsform
node_settingsform -->|"persists"| node_storage
node_wordtools -.->|"reads/writes"| node_wordhost
node_formatter -.->|"renders to"| node_wordhost
node_generaltools -->|"supports"| node_wordtools
node_i18n -->|"localizes"| node_home
node_i18n -->|"localizes"| node_settings
node_manifest -.->|"loads in"| node_wordhost
node_manifest -.->|"starts"| node_entry
node_apicheckpoints -->|"supports"| node_checkpoints

click node_entry "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/main.ts"
click node_app "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/App.vue"
click node_router "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/router/index.ts"
click node_home "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/HomePage.vue"
click node_settings "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/SettingsPage.vue"
click node_checkpoints "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/checkPointsPage.vue"
click node_components "https://github.com/kuingsmile/word-gpt-plus/tree/master/src/components"
click node_i18n "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/i18n/index.ts"
click node_messages "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/message.ts"
click node_wordtools "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/wordTools.ts"
click node_formatter "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/wordFormatter.ts"
click node_generaltools "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/generalTools.ts"
click node_settingsform "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/settingForm.ts"
click node_apicommon "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/common.ts"
click node_apitypes "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/types.ts"
click node_apiunion "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/union.ts"
click node_apicheckpoints "https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/checkpoints.ts"
click node_manifest "https://github.com/kuingsmile/word-gpt-plus/blob/master/index.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_app,node_router,node_home,node_settings,node_checkpoints,node_components,node_i18n toneBlue
class node_messages,node_wordtools,node_formatter,node_generaltools,node_settingsform toneAmber
class node_apicommon,node_apitypes,node_apiunion,node_apicheckpoints toneMint
class node_manifest toneRose
class node_wordhost,node_providersext,node_storage toneNeutral
```

## Components

### Add-in UI

Vue task-pane shell, pages, and reusable presentation components.

- [Main](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/main.ts): bootstrap · Bootstraps the Vue app into the add-in shell. · `src/main.ts`
- [App Shell](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/App.vue): shell · Top-level SPA container for the task pane. · `src/App.vue`
- [Router](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/router/index.ts): navigation · Routes between home, settings, and checkpoints views. · `src/router/index.ts`
- [Home](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/HomePage.vue): chat workspace · Primary chat and agent workspace. · `src/pages/HomePage.vue`
- [Settings](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/SettingsPage.vue): preferences · Provider and behavior configuration view. · `src/pages/SettingsPage.vue`
- [Checkpoints](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/pages/checkPointsPage.vue): workflow states · Saved document or workflow state management. · `src/pages/checkPointsPage.vue`
- [UI Controls](https://github.com/kuingsmile/word-gpt-plus/tree/master/src/components): components · Reusable buttons, inputs, cards, selects, and message blocks. · `src/components`
- [Locales](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/i18n/index.ts): localization · Language strings and translation setup. · `src/i18n/index.ts`

### Agent & Docs

Word-specific tools, formatting, and chat/message handling.

- [Chat State](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/message.ts): conversation state · Structured message handling and UI message flow. · `src/utils/message.ts`
- [Word Tools](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/wordTools.ts): document tools · Reads, writes, and edits Word document content. · `src/utils/wordTools.ts`
- [Formatter](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/wordFormatter.ts): render transform · Converts model output into Word-friendly formatting. · `src/utils/wordFormatter.ts`
- [Tools Core](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/generalTools.ts): agent helpers · Shared agent utilities and action helpers. · `src/utils/generalTools.ts`
- [Settings Model](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/utils/settingForm.ts): config schema · Provider settings shape, defaults, and presets. · `src/utils/settingForm.ts`

### AI Providers

Outbound request layer and provider abstractions.

- [API Core](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/common.ts): provider core · Shared request/response behavior and provider normalization. · `src/api/common.ts`
- [API Types](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/types.ts): contracts · Common provider and message type definitions. · `src/api/types.ts`
- [Provider Union](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/union.ts): provider adapters · Provider-specific request variations and dispatch. · `src/api/union.ts`
- [Checkpoint API](https://github.com/kuingsmile/word-gpt-plus/blob/master/src/api/checkpoints.ts): checkpoint ops · Checkpoint-related request or persistence operations. · `src/api/checkpoints.ts`

### Packaging

Word add-in entrypoints, manifests, and deployment assets.

- [Packaging](https://github.com/kuingsmile/word-gpt-plus/blob/master/index.html): add-in packaging · Build and Word add-in loading entrypoints and manifests. · `index.html`

### Other components

- **Word Host**: external host · Microsoft Word task-pane and document runtime boundary.
- **Model Providers**: external services · OpenAI-compatible, Azure OpenAI, Gemini, Groq, and Ollama endpoints.
- **Local Store**: local persistence · In-host storage for settings, keys, and preferences.

## Connections

- Main → App Shell: mounts · Initial app bootstrap into the SPA shell.
- App Shell → Router: uses · Application shell delegates page selection to the router.
- Router → Home: routes · Primary workspace view.
- Router → Settings: routes · Configuration view.
- Router → Checkpoints: routes · Saved state view.
- Home → UI Controls: renders · Uses shared controls and message UI.
- Settings → UI Controls: renders · Uses settings cards, inputs, and selects.
- Checkpoints → UI Controls: renders · Uses shared UI controls.
- Home → Chat State: manages · Conversation state and streaming updates.
- Home → Word Tools: tools · Agent actions are mediated through document tools.
- Home → Formatter: formats · Converts AI output into Word-friendly display/actions.
- Chat State → API Core: requests · Chat interactions flow into provider calls.
- API Core → API Types: contracts · Shared request/response schema.
- API Core → Provider Union: adapts · Provider-specific behavior and routing.
- API Core → Model Providers: calls · Outbound network boundary to model endpoints.
- Settings → Settings Model: configures · Settings page edits provider and behavior defaults.
- Settings Model → Local Store: persists · API keys and preferences are stored locally in-host.
- Word Tools → Word Host: reads/writes · Document boundary through the Office/Word runtime.
- Formatter → Word Host: renders to · Produces Word-compatible formatting and document output.
- Tools Core → Word Tools: supports · Shared document/agent helpers.
- Locales → Home: localizes · Language selection affects task-pane UI.
- Locales → Settings: localizes · Settings labels and descriptions.
- Packaging → Word Host: loads in · Word add-in packaging and task-pane entry boundary.
- Packaging → Main: starts · Build output points to the SPA entrypoint.
- Checkpoint API → Checkpoints: supports · Checkpoint state operations used by the checkpoints page.
