# rocketchat/apps.quickreplies architecture

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

- Interactive diagram: https://gitdiagram.com/rocketchat/apps.quickreplies
- Repository: https://github.com/rocketchat/apps.quickreplies

## Overview

##### Project type and purpose
- This is a Rocket.Chat “App” (plugin) written in TypeScript that implements a Quick Replies feature for customer-support agents. It plugs into the Rocket.Chat Apps Engine and adds slash-commands, modals, buttons, AI-powered suggestions, and persistent storage of canned responses.

##### File structure
- Root:
- QuickRepliesApp.ts – the entry point (App class registering commands & handlers)
- app.json – metadata for the Rocket.Chat Apps Engine
- src/commands – classes for slash-commands (`/quick`, `/qs`)
- src/handlers – event handlers for button clicks, block actions, view submissions, etc.
- src/config – global settings (language, AI toggles)
- src/definition – TypeScript interfaces for commands, handlers, UI elements, storage adapters
- src/lib – helper implementations (BlockBuilder, ElementBuilder, translation loader)
- src/modal – definitions of modal UIs (create/edit/list quick replies, AI reply modal)
- src/storage – concrete storage adapters wrapping Rocket.Chat persistence APIs (AIStorage, ReplyStorage, userPreferenceStorage, etc.)
- i18n & lib/Translation – JSON/TS files providing localized strings
- package.json, tsconfig.json – build and dependency config

##### Key insights from the README
- The App listens for `/quick` or `/qs` commands
- Agents can create, list, configure, and invoke quick replies
- AI integration is optional (via `/quick ai`)
- Placeholders in replies are replaced at send time
- Deployment is via `rc-apps deploy` to a Rocket.Chat Server

##### Elements
- External services: “Rocket.Chat Database”, “External AI Service”
- “/quick, /qs events →” to Commands
- “Modal opens ←” from UI-Kit to user
- “Persist & Retrieve →” from Handlers to Storage → Database
- “AI generate →” from Handler to External AI Service → back
- Green for Rocket.Chat core
- Blue for App internal modules
- Orange for external services

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Rocket.Chat Core
    RCServer["Rocket.Chat Server<br>(Apps Engine)"]:::core

    %% Quick Replies App Boundary
    subgraph "QuickReplies App"
        direction TB
        AppEntry["QuickRepliesApp.ts"]:::appmodule
        AppMetadata["app.json"]:::appmodule

        subgraph "Command Module"
            direction TB
            QuickCommand["QuickCommand"]:::appmodule
            QsCommand["QsCommand"]:::appmodule
            CommandUtility["CommandUtility"]:::appmodule
        end

        subgraph "Handler Module"
            direction TB
            HandlerBase["Handler"]:::appmodule
            AIHandler["AIHandler"]:::appmodule
            ExecuteActionButtonHandler["ExecuteActionButtonHandler"]:::appmodule
            ExecuteBlockActionHandler["ExecuteBlockActionHandler"]:::appmodule
            ExecuteViewClosedHandler["ExecuteViewClosedHandler"]:::appmodule
            ExecuteViewSubmitHandler["ExecuteViewSubmitHandler"]:::appmodule
        end

        subgraph "UI-Kit Module"
            direction TB
            BlockBuilder["BlockBuilder"]:::appmodule
            ElementBuilder["ElementBuilder"]:::appmodule
            subgraph "Modals"
                direction TB
                AIreplyModal["AIreplyModal"]:::appmodule
                UserPreferenceModal["UserPreferenceModal"]:::appmodule
                DropDownComponent["DropDownComponent"]:::appmodule
                InputElementComponent["inputElementComponent"]:::appmodule
                ConfirmDeleteModal["confirmDeleteModal"]:::appmodule
                CreateModal["createModal"]:::appmodule
                EditModal["editModal"]:::appmodule
                ListContextualBar["listContextualBar"]:::appmodule
                SendModal["sendModal"]:::appmodule
            end
        end

        subgraph "Storage Adapters"
            direction TB
            AIStorage["AIStorage"]:::appmodule
            ReceiverStorage["ReceiverStorage"]:::appmodule
            ReplyStorage["ReplyStorage"]:::appmodule
            RoomInteraction["RoomInteraction"]:::appmodule
            UserPreferenceStorage["userPreferenceStorage"]:::appmodule
        end

        subgraph "Config & i18n"
            direction TB
            Settings["settings.ts"]:::appmodule
            TranslationLoader["translation.ts"]:::appmodule
            I18nFiles["i18n JSONs"]:::appmodule
        end

        subgraph "Definitions"
            direction TB
            Definitions["src/definition"]:::appmodule
            IAIstorage["IAIstorage.ts"]:::appmodule
        end
    end

    %% External Services
    RCDatabase[(Rocket.Chat Database)]:::external
    AIService[(External AI Service)]:::external

    %% Interactions
    RCServer -->|"/quick, /qs events"| QuickCommand
    RCServer -->|"/quick, /qs events"| QsCommand

    QuickCommand -->|calls| HandlerBase
    QsCommand -->|calls| HandlerBase

    HandlerBase -->|use| BlockBuilder
    HandlerBase -->|use| ElementBuilder
    HandlerBase -->|open modal| AIreplyModal
    HandlerBase -->|open modal| UserPreferenceModal

    HandlerBase -->|persist & retrieve| AIStorage
    HandlerBase -->|persist & retrieve| ReceiverStorage
    HandlerBase -->|persist & retrieve| ReplyStorage
    HandlerBase -->|persist & retrieve| RoomInteraction
    HandlerBase -->|persist & retrieve| UserPreferenceStorage

    AIStorage -->|internal SDK calls| RCDatabase
    ReceiverStorage -->|internal SDK calls| RCDatabase
    ReplyStorage -->|internal SDK calls| RCDatabase
    RoomInteraction -->|internal SDK calls| RCDatabase
    UserPreferenceStorage -->|internal SDK calls| RCDatabase

    HandlerBase -->|AI generate| AIService
    AIService -->|response| HandlerBase

    BlockBuilder -->|renders UI| RCServer
    ElementBuilder -->|renders UI| RCServer

    %% Click Events
    click AppEntry "https://github.com/rocketchat/apps.quickreplies/blob/main/QuickRepliesApp.ts"
    click AppMetadata "https://github.com/rocketchat/apps.quickreplies/blob/main/app.json"
    click QuickCommand "https://github.com/rocketchat/apps.quickreplies/blob/main/src/commands/QuickCommand.ts"
    click QsCommand "https://github.com/rocketchat/apps.quickreplies/blob/main/src/commands/QsCommand.ts"
    click CommandUtility "https://github.com/rocketchat/apps.quickreplies/blob/main/src/commands/CommandUtility.ts"
    click AIHandler "https://github.com/rocketchat/apps.quickreplies/blob/main/src/handlers/AIHandler.ts"
    click ExecuteActionButtonHandler "https://github.com/rocketchat/apps.quickreplies/blob/main/src/handlers/ExecuteActionButtonHandler.ts"
    click ExecuteBlockActionHandler "https://github.com/rocketchat/apps.quickreplies/blob/main/src/handlers/ExecuteBlockActionHandler.ts"
    click ExecuteViewClosedHandler "https://github.com/rocketchat/apps.quickreplies/blob/main/src/handlers/ExecuteViewClosedHandler.ts"
    click ExecuteViewSubmitHandler "https://github.com/rocketchat/apps.quickreplies/blob/main/src/handlers/ExecuteViewSubmitHandler.ts"
    click HandlerBase "https://github.com/rocketchat/apps.quickreplies/blob/main/src/handlers/Handler.ts"
    click BlockBuilder "https://github.com/rocketchat/apps.quickreplies/blob/main/src/lib/BlockBuilder.ts"
    click ElementBuilder "https://github.com/rocketchat/apps.quickreplies/blob/main/src/lib/ElementBuilder.ts"
    click AIreplyModal "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/AIreplyModal.ts"
    click UserPreferenceModal "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/UserPreferenceModal.ts"
    click DropDownComponent "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/common/DropDownComponent.ts"
    click InputElementComponent "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/common/inputElementComponent.ts"
    click ConfirmDeleteModal "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/confirmDeleteModal.ts"
    click CreateModal "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/createModal.ts"
    click EditModal "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/editModal.ts"
    click ListContextualBar "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/listContextualBar.ts"
    click SendModal "https://github.com/rocketchat/apps.quickreplies/blob/main/src/modal/sendModal.ts"
    click AIStorage "https://github.com/rocketchat/apps.quickreplies/blob/main/src/storage/AIStorage.ts"
    click ReceiverStorage "https://github.com/rocketchat/apps.quickreplies/blob/main/src/storage/ReceiverStorage.ts"
    click ReplyStorage "https://github.com/rocketchat/apps.quickreplies/blob/main/src/storage/ReplyStorage.ts"
    click RoomInteraction "https://github.com/rocketchat/apps.quickreplies/blob/main/src/storage/RoomInteraction.ts"
    click UserPreferenceStorage "https://github.com/rocketchat/apps.quickreplies/blob/main/src/storage/userPreferenceStorage.ts"
    click Settings "https://github.com/rocketchat/apps.quickreplies/blob/main/src/config/settings.ts"
    click TranslationLoader "https://github.com/rocketchat/apps.quickreplies/blob/main/src/lib/Translation/translation.ts"

    %% Styles
    classDef core fill:#e7f7e6,stroke:#333,stroke-width:1px
    classDef appmodule fill:#daf1fc,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px
```
