# yuigod/vue-doc-qa-chat architecture

> Architecture diagram of the GitHub repository yuigod/vue-doc-qa-chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuigod/vue-doc-qa-chat
- Repository: https://github.com/yuigod/vue-doc-qa-chat

## Overview

##### Project type and purpose
- This is a Vue3 + TypeScript + Vite + ElementPlus web-front-end module for a local knowledge-base Q&A application.
- It communicates with a Python FastAPI server (“py-doc-qa-deepseek-server”) that in turn uses LangChain + DeepSeek R1 for embedding and LLM inference, and stores documents, sessions, and vectors.

##### File structure
- Top-level:
- public/ – static assets & preview videos
- src/ – application code
- api/, http/, utils/ – service-layer abstractions & HTTP client wrappers
- components/, layout/, views/ – UI building blocks and pages
- router/, stores/ – navigation & state (Pinia)
- Patterns & frameworks:
- Composition-API Vue components (App.vue, *.vue under components & views)
- Centralized HTTP module that integrates Axios + Fetch with interceptors & cancellation
- API folder separated by domain (chat, chatSession, documents)
- Pinia stores for global state (app.ts)
- Vite build & dev config, multiple tsconfig files, linting & formatting configs

##### README insights
- Describes the main features: document upload & management, RAG-style chat with streaming responses, chat history management
- References the FastAPI backend and its endpoints
- Mentions markdown rendering via markdown-it and custom styling

1) Browser / Frontend SPA
– Vue3 App: router, components, views
– Pinia store
– HTTP Client module (Axios + Fetch wrappers)
– Markdown-it renderer & styling
2) Backend API Server (FastAPI)
– Endpoints: /chat, /session/*, /documents/*, /vector-all
3) Data Storage
– Document File Storage (filesystem or blob store)
– Database (sessions, document metadata, vector flags)
– Vector store (could be part of DB or external vector DB)
4) AI Model & Inference
– LangChain orchestration
– DeepSeek R1 model served via Ollama or other inference service
– User → Browser: interact with UI, triggers API calls
– Browser → HTTP Client → FastAPI server
– FastAPI → DB: CRUD sessions & documents
– FastAPI → File Store: save/read uploaded docs
– FastAPI → Vector Store / LangChain: embedding / vector-based retrieval
– FastAPI → LLM service: streaming chat completions
– FastAPI → Browser: JSON or NDJSON (stream) responses
– Browser: render text, streaming updates, markdown rendering
c. Architectural patterns & design principles:
– Separation of concerns: UI vs. service layer vs. data layer
– Domain-driven API structure (api/chat, api/session, api/documents)
– HTTP abstraction: unified Axios + Fetch with interceptors & cancellation
– State management with Pinia for cross-view state (chat history, docs list)
d. Technologies & frameworks to annotate:
– Vue3 Composition API, Vite, ElementPlus
– Pinia (stores)
– Axios & Fetch wrappers
– Markdown-it + custom plugins/styles
– FastAPI, LangChain, DeepSeek R1, Ollama
– Database (e.g., SQLite/Postgres) and file system or object storage
– Optional vector DB (e.g., Pinecone, Chroma)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB

        subgraph "UI Components"
            direction TB
            EntryPoint["main.ts"]:::service
            App["App.vue"]:::ui
            Layout["LayoutClassic.vue"]:::ui
            Header["LayoutHeader.vue"]:::ui
            Aside["LayoutAside.vue"]:::ui
            Footer["LayoutFooter.vue"]:::ui
            ChatView["ChatView.vue"]:::ui
            AssistantMsg["AssistantChat.vue"]:::ui
            HumanMsg["HumanChat.vue"]:::ui
            History["ChatHistory.vue"]:::ui
            DocsView["DocumentsView.vue"]:::ui
            WriteForm["WriteForm.vue"]:::ui
            BaseDialog["BaseDialog.vue"]:::ui
            ChatLoading["ChatLoading.vue"]:::ui
            Icons["Icon Components"]:::ui
        end

        subgraph "State & Routing"
            direction TB
            Router["router/index.ts"]:::service
            Store["app.ts (Pinia Store)"]:::store
        end

        subgraph "Service Layer"
            direction TB
            HTTPClient["http/index.ts"]:::service
            AxiosConfig["axios/config.ts"]:::service
            FetchConfig["fetch/config.ts"]:::service
            Helpers["abortController.ts<br/>checkStatus.ts<br/>httpError.ts"]:::service
            ChatAPI["api/chat/index.ts"]:::service
            SessionAPI["api/chatSession/index.ts"]:::service
            DocsAPI["api/documents/index.ts"]:::service
        end

        subgraph "Utilities & Styles"
            direction TB
            Markdown["markdownit/index.ts"]:::util
            CodeCopy["codeCopyPlugins.ts"]:::util
            Highlight["hljsConfig.ts"]:::util
            Styles["mdmdt-light.scss"]:::util
            CommonUtil["common.ts"]:::util
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        subgraph "API Controllers" 
            direction TB
            ChatCtrl["/chat"]:::service
            SessionCtrl["/session/*"]:::service
            DocsCtrl["/documents/*"]:::service
            VectorAllCtrl["/vector-all"]:::service
        end

        subgraph "Business Logic & Services"
            direction TB
            FastAPIServer["FastAPI Server"]:::service
            LangChain["LangChain Orchestration"]:::external
            DeepSeek["DeepSeek R1 Model"]:::external
            InferenceSvc["Ollama Inference"]:::external
        end

        subgraph "Data & AI Layers"
            direction TB
            FileStore["Document File Storage"]:::data
            Database["Database (Metadata & Sessions)"]:::data
            VectorStore["Vector Store"]:::data
        end
    end

    %% Connections
    User["User"]:::external -->|interacts| App
    App -->|calls| Router
    App -->|uses| Store
    App -->|renders| Markdown
    App -->|triggers| HTTPClient
    HTTPClient -->|wraps| AxiosConfig
    HTTPClient -->|wraps| FetchConfig
    HTTPClient -->|calls| ChatAPI
    HTTPClient -->|calls| SessionAPI
    HTTPClient -->|calls| DocsAPI

    ChatAPI -->|HTTP| ChatCtrl
    SessionAPI -->|HTTP| SessionCtrl
    DocsAPI -->|HTTP| DocsCtrl

    ChatCtrl -->|business| FastAPIServer
    SessionCtrl -->|business| FastAPIServer
    DocsCtrl -->|business| FastAPIServer
    VectorAllCtrl -->|business| FastAPIServer

    FastAPIServer -->|CRUD| Database
    FastAPIServer -->|FS Read/Write| FileStore
    FastAPIServer -->|vector ops| VectorStore
    FastAPIServer -->|orchestrates| LangChain
    LangChain -->|model| DeepSeek
    DeepSeek -->|inference| InferenceSvc
    FastAPIServer -->|stream| ChatCtrl

    ChatCtrl -->|stream| HTTPClient
    HTTPClient -->|stream| App
    App -->|render stream| AssistantMsg
    App -->|render| HumanMsg
    App -->|update| History

    DocsCtrl -->|respond| HTTPClient
    HTTPClient -->|render| DocsView
    DocsView -->|navigate| WriteForm

    %% Click Events
    click EntryPoint "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/main.ts"
    click App "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/App.vue"
    click Router "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/router/index.ts"
    click Store "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/stores/app.ts"
    click HTTPClient "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/http/index.ts"
    click AxiosConfig "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/http/axios/config.ts"
    click FetchConfig "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/http/fetch/config.ts"
    click ChatAPI "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/api/chat/index.ts"
    click SessionAPI "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/api/chatSession/index.ts"
    click DocsAPI "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/api/documents/index.ts"
    click Markdown "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/utils/markdownit/index.ts"
    click CodeCopy "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/utils/markdownit/codeCopyPlugins.ts"
    click Highlight "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/utils/markdownit/hljsConfig.ts"
    click Styles "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/styles/markdown/mdmdt-light.scss"
    click Layout "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/layout/LayoutClassic.vue"
    click Header "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/layout/components/base/LayoutHeader.vue"
    click Aside "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/layout/components/base/LayoutAside.vue"
    click Footer "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/layout/components/base/LayoutFooter.vue"
    click ChatView "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/views/chat/index.vue"
    click AssistantMsg "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/views/chat/components/AssistantChat.vue"
    click HumanMsg "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/views/chat/components/HumanChat.vue"
    click History "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/views/chat/components/ChatHistory.vue"
    click DocsView "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/views/documents/index.vue"
    click WriteForm "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/views/documents/writeForm.vue"
    click BaseDialog "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Dialog/BaseDialog/index.vue"
    click ChatLoading "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Loading/ChatLoading/index.vue"
    click Icons "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Icon/SendIcon.vue"
    click Icons "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Icon/StopIcon.vue"
    click Icons "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Icon/HumanIcon.vue"
    click Icons "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Icon/AssistantIcon.vue"
    click Icons "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/components/Icon/ErrorIcon.vue"
    click CommonUtil "https://github.com/yuigod/vue-doc-qa-chat/blob/main/src/utils/common.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0370A8,color:#000
    classDef service fill:#DFF7D9,stroke:#2E7D32,color:#000
    classDef store fill:#FFEFD5,stroke:#B8860B,color:#000
    classDef util fill:#FFF4E5,stroke:#CC7A00,color:#000
    classDef data fill:#FFE4C4,stroke:#D2691E,color:#000
    classDef external fill:#E8D0FF,stroke:#6A1B9A,color:#000
```
