# ant-design/x architecture

> Architecture diagram of the GitHub repository ant-design/x, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ant-design/x
- Repository: https://github.com/ant-design/x

## Overview

##### Main Components
- UI Component Library – At the core are the atomic components (found under directories like components/bubble, components/sender, components/prompts, etc.). These components encapsulate the view layer for various AI chat scenarios.
- Runtime Integration Modules – Modules such as useXAgent, useXChat, XRequest, and XStream provide logic to integrate with external model inference services. They are responsible for handling API requests, streaming responses, and managing conversation data flows.
- Theme and Configuration – There is a dedicated theme layer (in directories like .dumi/theme and components/theme) that manages styling, theming, and customization.
- Documentation & Demo Infrastructure – The .dumi directory and docs folder constitute the documentation site. They show demos, interactive examples, and provide component documentation.
- Testing & Build Infrastructure – Includes directories for tests, scripts, and configuration files (e.g., webpack.config.js, tsconfig.json). These support automated testing and build processes.
- External Integration / API Layer – This layer isn’t a separate service but is integrated via the runtime tools (e.g., XRequest) that connect to external inference services.

##### Architectural Patterns & Technical Stack
- Use of the Atomic Design paradigm for building UI components.
- Separation of concerns: presentation (UI components and theme), business logic (runtime hooks for data flow and API calls), and infrastructure (documentation, testing, and build configurations).
- Clearly label major modules with their technology – for example, “React Components (TypeScript)” for the UI, “API Integration via XRequest (REST/Streaming)” for the runtime layer, etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Component Library
    subgraph "UI Component Library"
        UI1["Bubble (Atomic)"]
        UI2["Sender (Atomic)"]
        UI3["Prompts (Atomic)"]
        UI4["Conversations (Atomic)"]
        UI5["Suggestion (Atomic)"]
        UI6["Thought-Chain (Atomic)"]
    end

    %% Runtime & Integration Modules
    subgraph "Runtime & Integration Modules"
        RT1["useXAgent (Hook)"]
        RT2["useXChat (Hook)"]
        RT3["XRequest (Utility)"]
        RT4["XStream (Utility)"]
    end

    %% Theme & Customization
    subgraph "Theme & Customization"
        TH1["Dumi Theme"]
        TH2["Components Theme"]
    end

    %% Documentation & Demo Infrastructure
    subgraph "Documentation & Demo"
        DOC1["Dumi Site"]
        DOC2["Docs"]
    end

    %% Testing & Build Infrastructure
    subgraph "Testing & Build Infrastructure"
        TB1["Tests"]
        TB2["Scripts"]
        TB3["Webpack.config"]
        TB4["Tsconfig.json"]
        TB5["CI/CD Workflows"]
    end

    %% External Inference Service
    subgraph "External Inference Service"
        EXT1(("OpenAI/Qwen API"))
    end

    %% Connections between UI and Runtime
    UI2 -->|"triggers"| RT1
    UI2 -->|"chat_triggers"| RT2
    RT1 -->|"API_call"| EXT1
    EXT1 -->|"response"| RT1
    RT1 -->|"updates_UI"| UI1
    RT2 -->|"fetches_data"| UI4

    %% Theme influences UI (bi-directional)
    UI1 <-->|"styled_by"| TH1

    %% Documentation displays UI demos
    UI3 -->|"demos"| DOC2
    UI4 -->|"demos"| DOC1

    %% Class styles for color coding
    class UI1,UI2,UI3,UI4,UI5,UI6 ui;
    class RT1,RT2,RT3,RT4 runtime;
    class TH1,TH2 theme;
    class DOC1,DOC2 docs;
    class TB1,TB2,TB3,TB4,TB5 test;
    class EXT1 external;

    %% Click Events for UI Component Library
    click UI1 "https://github.com/ant-design/x/tree/main/components/bubble"
    click UI2 "https://github.com/ant-design/x/tree/main/components/sender"
    click UI3 "https://github.com/ant-design/x/tree/main/components/prompts"
    click UI4 "https://github.com/ant-design/x/tree/main/components/conversations"
    click UI5 "https://github.com/ant-design/x/tree/main/components/suggestion"
    click UI6 "https://github.com/ant-design/x/tree/main/components/thought-chain"

    %% Click Events for Runtime Integration Modules
    click RT1 "https://github.com/ant-design/x/tree/main/components/use-x-agent"
    click RT2 "https://github.com/ant-design/x/tree/main/components/use-x-chat"
    click RT3 "https://github.com/ant-design/x/tree/main/components/x-request"
    click RT4 "https://github.com/ant-design/x/tree/main/components/x-stream"

    %% Click Events for Theme and Configuration
    click TH1 "https://github.com/ant-design/x/tree/main/.dumi/theme"
    click TH2 "https://github.com/ant-design/x/tree/main/components/theme"

    %% Click Events for Documentation & Demo Infrastructure
    click DOC1 "https://github.com/ant-design/x/blob/main/.dumi"
    click DOC2 "https://github.com/ant-design/x/tree/main/docs"

    %% Click Events for Testing & Build Infrastructure
    click TB1 "https://github.com/ant-design/x/tree/main/tests"
    click TB2 "https://github.com/ant-design/x/tree/main/scripts"
    click TB3 "https://github.com/ant-design/x/blob/main/webpack.config.js"
    click TB4 "https://github.com/ant-design/x/blob/main/tsconfig.json"
    click TB5 "https://github.com/ant-design/x/tree/main/.github/workflows"

    %% Style Definitions
    classDef ui fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef runtime fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef theme fill:#f4a460,stroke:#000,stroke-width:1px;
    classDef docs fill:#fffacd,stroke:#000,stroke-width:1px;
    classDef test fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef external fill:#87ceeb,stroke:#000,stroke-width:1px;
```
