# shadcn-ui/chatbot-template architecture

> Architecture diagram of the GitHub repository shadcn-ui/chatbot-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shadcn-ui/chatbot-template
- Repository: https://github.com/shadcn-ui/chatbot-template

## Overview

This Next.js chatbot template takes a user prompt through the chat UI to a streaming AI Gateway response, then renders text, reasoning, citations, and tool states. Distinct branches support GitHub repository lookup, provider-native web search, and a human-in-the-loop questionnaire whose answer resumes the conversation. The graph includes the model allowlist and the principal message-part renderers. Evidence is limited to the supplied excerpts, source index, and README; some UI-to-route wiring and unsampled tool internals are documented rather than inspected.

Main entry points: [`components/chat-message.tsx`](https://github.com/shadcn-ui/chatbot-template/blob/main/components/chat-message.tsx) (Message dispatch), [`components/chat.tsx`](https://github.com/shadcn-ui/chatbot-template/blob/main/components/chat.tsx) (Conversation state), [`app/api/chat/route.ts`](https://github.com/shadcn-ui/chatbot-template/blob/main/app/api/chat/route.ts) (Streaming chat route), [`tools/index.ts`](https://github.com/shadcn-ui/chatbot-template/blob/main/tools/index.ts) (Tool registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Chat experience"]
  node_page["Chat page<br/>[page.tsx]"]
  node_chat["Conversation state<br/>[chat.tsx]"]
  node_prompt["Prompt and model form<br/>[prompt-form.tsx]"]
  node_questioncard["Pending question UI<br/>[question-card.tsx]"]
end

subgraph group_server["Chat orchestration"]
  node_models["Model allowlist<br/>[models.ts]"]
  node_api["Streaming chat route<br/>[route.ts]"]
end

subgraph group_tools["Tool capabilities"]
  node_toolregistry["Tool registry<br/>[index.ts]"]
  node_githubtool["GitHub lookup tool<br/>[github_repo.ts]"]
  node_searchtool["Web search tool<br/>[web_search.ts]"]
  node_asktool["Question tool<br/>[ask_user.ts]"]
end

subgraph group_rendering["Message rendering"]
  node_message["Message dispatch<br/>[chat-message.tsx]"]
  node_textpart["Markdown text part<br/>[text-part.tsx]"]
  node_githubpart["GitHub result part"]
  node_searchpart["Search status part"]
  node_askpart["Question answer part<br/>[ask-user-part.tsx]"]
  node_reasoningpart["Reasoning part<br/>[reasoning-part.tsx]"]
  node_sourcespart["Citation drawer<br/>[sources-part.tsx]"]
  node_scroller["Message scroller"]
  node_questionnaire["Questionnaire controls<br/>[questionnaire.tsx]"]
end

node_user(("Chat user"))
node_gateway{{"Vercel AI Gateway"}}
node_github{{"GitHub service"}}
node_providersearch{{"Provider search"}}

node_user -->|"opens"| node_page
node_page -->|"renders"| node_chat
node_chat -->|"renders"| node_prompt
node_prompt -->|"submits prompt"| node_chat
node_chat -->|"streams with"| node_api
node_api -->|"validates model"| node_models
node_api -->|"selects tools"| node_toolregistry
node_api -->|"generates response"| node_gateway
node_toolregistry -->|"registers"| node_githubtool
node_toolregistry -->|"registers"| node_asktool
node_toolregistry -->|"selects"| node_searchtool
node_githubtool -.->|"looks up repository"| node_github
node_searchtool -->|"uses native search"| node_providersearch
node_chat -->|"renders messages"| node_message
node_message -->|"delegates text"| node_textpart
node_message -->|"delegates tool part"| node_githubpart
node_message -->|"delegates tool part"| node_searchpart
node_message -->|"delegates tool part"| node_askpart
node_message -->|"delegates reasoning"| node_reasoningpart
node_message -->|"renders citations"| node_sourcespart
node_chat -->|"displays conversation"| node_scroller
node_chat -->|"shows pending question"| node_questioncard
node_questioncard -->|"renders controls"| node_questionnaire
node_questioncard -->|"submits tool answer"| node_chat
node_textpart -->|"returns rendered text"| node_message

click node_page "https://github.com/shadcn-ui/chatbot-template/blob/main/app/page.tsx"
click node_chat "https://github.com/shadcn-ui/chatbot-template/blob/main/components/chat.tsx"
click node_prompt "https://github.com/shadcn-ui/chatbot-template/blob/main/components/prompt-form.tsx"
click node_models "https://github.com/shadcn-ui/chatbot-template/blob/main/lib/models.ts"
click node_api "https://github.com/shadcn-ui/chatbot-template/blob/main/app/api/chat/route.ts"
click node_toolregistry "https://github.com/shadcn-ui/chatbot-template/blob/main/tools/index.ts"
click node_githubtool "https://github.com/shadcn-ui/chatbot-template/blob/main/tools/github_repo.ts"
click node_searchtool "https://github.com/shadcn-ui/chatbot-template/blob/main/tools/web_search.ts"
click node_asktool "https://github.com/shadcn-ui/chatbot-template/blob/main/tools/ask_user.ts"
click node_questioncard "https://github.com/shadcn-ui/chatbot-template/blob/main/components/question-card.tsx"
click node_message "https://github.com/shadcn-ui/chatbot-template/blob/main/components/chat-message.tsx"
click node_textpart "https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/text-part.tsx"
click node_githubpart "https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/github-repo-part.tsx"
click node_searchpart "https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/web-search-part.tsx"
click node_askpart "https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/ask-user-part.tsx"
click node_reasoningpart "https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/reasoning-part.tsx"
click node_sourcespart "https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/sources-part.tsx"
click node_scroller "https://github.com/shadcn-ui/chatbot-template/blob/main/components/ui/message-scroller.tsx"
click node_questionnaire "https://github.com/shadcn-ui/chatbot-template/blob/main/components/ui/questionnaire.tsx"

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_page,node_chat,node_prompt,node_questioncard,node_user toneBlue
class node_models,node_api toneAmber
class node_toolregistry,node_githubtool,node_searchtool,node_asktool toneMint
class node_message,node_textpart,node_githubpart,node_searchpart,node_askpart,node_reasoningpart,node_sourcespart,node_scroller,node_questionnaire toneRose
class node_gateway,node_github,node_providersearch toneIndigo
```

## Components

### Chat experience

- [Chat page](https://github.com/shadcn-ui/chatbot-template/blob/main/app/page.tsx): `app/page.tsx`
- [Conversation state](https://github.com/shadcn-ui/chatbot-template/blob/main/components/chat.tsx): `components/chat.tsx`
- [Prompt and model form](https://github.com/shadcn-ui/chatbot-template/blob/main/components/prompt-form.tsx): `components/prompt-form.tsx`
- [Pending question UI](https://github.com/shadcn-ui/chatbot-template/blob/main/components/question-card.tsx): `components/question-card.tsx`

### Chat orchestration

- [Model allowlist](https://github.com/shadcn-ui/chatbot-template/blob/main/lib/models.ts): `lib/models.ts`
- [Streaming chat route](https://github.com/shadcn-ui/chatbot-template/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`

### Tool capabilities

- [Tool registry](https://github.com/shadcn-ui/chatbot-template/blob/main/tools/index.ts): `tools/index.ts`
- [GitHub lookup tool](https://github.com/shadcn-ui/chatbot-template/blob/main/tools/github_repo.ts): `tools/github_repo.ts`
- [Web search tool](https://github.com/shadcn-ui/chatbot-template/blob/main/tools/web_search.ts): `tools/web_search.ts`
- [Question tool](https://github.com/shadcn-ui/chatbot-template/blob/main/tools/ask_user.ts): `tools/ask_user.ts`

### Message rendering

- [Message dispatch](https://github.com/shadcn-ui/chatbot-template/blob/main/components/chat-message.tsx): `components/chat-message.tsx`
- [Markdown text part](https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/text-part.tsx): `components/parts/text-part.tsx`
- [GitHub result part](https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/github-repo-part.tsx): `components/parts/github-repo-part.tsx`
- [Search status part](https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/web-search-part.tsx): `components/parts/web-search-part.tsx`
- [Question answer part](https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/ask-user-part.tsx): `components/parts/ask-user-part.tsx`
- [Reasoning part](https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/reasoning-part.tsx): `components/parts/reasoning-part.tsx`
- [Citation drawer](https://github.com/shadcn-ui/chatbot-template/blob/main/components/parts/sources-part.tsx): `components/parts/sources-part.tsx`
- [Message scroller](https://github.com/shadcn-ui/chatbot-template/blob/main/components/ui/message-scroller.tsx): `components/ui/message-scroller.tsx`
- [Questionnaire controls](https://github.com/shadcn-ui/chatbot-template/blob/main/components/ui/questionnaire.tsx): `components/ui/questionnaire.tsx`

### Other components

- **Chat user**
- **Vercel AI Gateway**
- **GitHub service**
- **Provider search**

## Connections

- Chat user → Chat page: opens (evidence: `README.md`)
- Chat page → Conversation state: renders (evidence: `app/page.tsx`)
- Conversation state → Prompt and model form: renders (evidence: `components/chat.tsx`)
- Prompt and model form → Conversation state: submits prompt (evidence: `components/chat.tsx`)
- Conversation state → Streaming chat route: streams with (evidence: `README.md`)
- Streaming chat route → Model allowlist: validates model (evidence: `app/api/chat/route.ts`)
- Streaming chat route → Tool registry: selects tools (evidence: `app/api/chat/route.ts`)
- Streaming chat route → Vercel AI Gateway: generates response (evidence: `README.md`)
- Tool registry → GitHub lookup tool: registers (evidence: `tools/index.ts`)
- Tool registry → Question tool: registers (evidence: `tools/index.ts`)
- Tool registry → Web search tool: selects (evidence: `tools/index.ts`)
- GitHub lookup tool → GitHub service: looks up repository (evidence: `README.md`)
- Web search tool → Provider search: uses native search (evidence: `README.md`)
- Conversation state → Message dispatch: renders messages (evidence: `components/chat.tsx`)
- Message dispatch → Markdown text part: delegates text (evidence: `components/chat-message.tsx`)
- Message dispatch → GitHub result part: delegates tool part (evidence: `components/chat-message.tsx`)
- Message dispatch → Search status part: delegates tool part (evidence: `components/chat-message.tsx`)
- Message dispatch → Question answer part: delegates tool part (evidence: `components/chat-message.tsx`)
- Message dispatch → Reasoning part: delegates reasoning (evidence: `components/chat-message.tsx`)
- Message dispatch → Citation drawer: renders citations (evidence: `components/chat-message.tsx`)
- Conversation state → Message scroller: displays conversation (evidence: `components/chat.tsx`)
- Conversation state → Pending question UI: shows pending question (evidence: `components/chat.tsx`)
- Pending question UI → Questionnaire controls: renders controls (evidence: `components/question-card.tsx`)
- Pending question UI → Conversation state: submits tool answer (evidence: `components/chat.tsx`)
- Markdown text part → Message dispatch: returns rendered text (evidence: `components/chat-message.tsx`)
