# aestheticsuraj234/chai-gpt-build architecture

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

- Interactive diagram: https://gitdiagram.com/aestheticsuraj234/chai-gpt-build
- Repository: https://github.com/aestheticsuraj234/chai-gpt-build

## Overview

This is a Next.js conversational AI application. Users start or select a conversation, view its history, compose a message, and receive a streamed assistant response; conversation and message records are persisted in PostgreSQL. The graph also preserves authentication/onboarding and conversation-management capabilities. Several UI and route relationships come from the SOURCE INDEX rather than inspected implementations, so those links are limited to references it explicitly reports.

Main entry points: [`app/api/chat/route.ts`](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/api/chat/route.ts) (Chat streaming API), [`lib/db.ts`](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/lib/db.ts) (Database client), [`features/conversation/components/conversation-view.tsx`](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/conversation-view.tsx) (Conversation view), [`features/auth/action/require-user.ts`](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/auth/action/require-user.ts) (Require user)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App entry points"]
  node_home["Chat home<br/>[page.tsx]"]
  node_chat_route["Conversation route<br/>[page.tsx]"]
  node_auth_route["Sign-in page<br/>[page.tsx]"]
  node_root_layout["Chat layout<br/>[layout.tsx]"]
end

subgraph group_conversation["Conversation experience"]
  node_start_chat["Start conversation<br/>[start-new-chat.ts]"]
  node_shell["Chat shell<br/>[chat-shell.tsx]"]
  node_view["Conversation view"]
  node_sidebar["Conversation sidebar<br/>[app-sidebar.tsx]"]
  node_composer["Message composer<br/>[chat-composer.tsx]"]
  node_messages_view["Message display<br/>[chat-messages.tsx]"]
  node_empty_state["Empty state<br/>[chat-empty.tsx]"]
  node_conversation_hook["Conversation queries"]
  node_query_keys["Query key factory<br/>[query-keys.ts]"]
  node_conversation_actions["Conversation management"]
end

subgraph group_identity["Identity and access"]
  node_require_user["Require user<br/>[require-user.ts]"]
  node_onboard["User onboarding<br/>[onboard.ts]"]
end

subgraph group_runtime["Chat and persistence"]
  node_message_actions["Message management<br/>[messages-action.ts]"]
  node_message_hook["Message queries<br/>[use-messages.ts]"]
  node_chat_api["Chat streaming API<br/>[route.ts]"]
  node_model["Model selection<br/>[model.ts]"]
  node_chat_store["AI message store<br/>[chat-store.ts]"]
  node_db_client["Database client<br/>[db.ts]"]
end

node_user(("User"))
node_clerk{{"Clerk identity"}}
node_postgres[("PostgreSQL")]

node_user -->|"opens"| node_home
node_user -->|"signs in"| node_auth_route
node_user -->|"opens chat"| node_chat_route
node_home -->|"starts chat"| node_start_chat
node_home -.->|"renders within"| node_root_layout
node_root_layout -->|"runs onboarding"| node_onboard
node_root_layout -->|"renders"| node_shell
node_chat_route -->|"loads conversation"| node_conversation_actions
node_chat_route -->|"loads messages"| node_chat_store
node_chat_route -->|"renders"| node_view
node_shell -.->|"renders"| node_sidebar
node_view -->|"queries"| node_conversation_hook
node_view -->|"renders"| node_composer
node_view -->|"renders"| node_messages_view
node_view -->|"renders"| node_empty_state
node_conversation_hook -->|"calls"| node_conversation_actions
node_conversation_hook -->|"uses keys"| node_query_keys
node_sidebar -->|"queries"| node_conversation_hook
node_start_chat -->|"checks identity"| node_require_user
node_start_chat -->|"creates record"| node_db_client
node_conversation_actions -->|"checks identity"| node_require_user
node_conversation_actions -->|"reads and writes"| node_db_client
node_message_hook -->|"calls"| node_message_actions
node_message_hook -->|"uses keys"| node_query_keys
node_message_actions -->|"checks identity"| node_require_user
node_message_actions -->|"reads and writes"| node_db_client
node_onboard -->|"updates user"| node_db_client
node_require_user -->|"authenticates with"| node_clerk
node_chat_api -->|"checks identity"| node_require_user
node_chat_api -->|"checks ownership"| node_db_client
node_chat_api -->|"loads and saves"| node_chat_store
node_chat_api -->|"selects model"| node_model
node_chat_api -->|"streams response"| node_user
node_db_client -->|"connects"| node_postgres
node_chat_store -->|"reads and writes"| node_db_client
node_chat_api -->|"protects route"| node_clerk

click node_home "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(root)/page.tsx"
click node_chat_route "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(root)/c/%5Bid%5D/page.tsx"
click node_auth_route "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(auth)/sign-in/%5B%5B...sign-in%5D%5D/page.tsx"
click node_root_layout "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(root)/layout.tsx"
click node_start_chat "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/home/actions/start-new-chat.ts"
click node_shell "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-shell.tsx"
click node_view "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/conversation-view.tsx"
click node_sidebar "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/app-sidebar.tsx"
click node_composer "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-composer.tsx"
click node_messages_view "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-messages.tsx"
click node_empty_state "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-empty.tsx"
click node_conversation_hook "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/hooks/use-conversation.ts"
click node_query_keys "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/utils/query-keys.ts"
click node_conversation_actions "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/actions/conversation-actions.ts"
click node_message_actions "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/messages/actions/messages-action.ts"
click node_message_hook "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/messages/hooks/use-messages.ts"
click node_require_user "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/auth/action/require-user.ts"
click node_onboard "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/auth/action/onboard.ts"
click node_chat_api "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/api/chat/route.ts"
click node_model "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/ai/utils/model.ts"
click node_chat_store "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/ai/actions/chat-store.ts"
click node_db_client "https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/lib/db.ts"

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_home,node_chat_route,node_auth_route,node_root_layout,node_user toneBlue
class node_start_chat,node_shell,node_view,node_sidebar,node_composer,node_messages_view,node_empty_state,node_conversation_hook,node_query_keys,node_conversation_actions,node_postgres toneAmber
class node_require_user,node_onboard toneMint
class node_message_actions,node_message_hook,node_chat_api,node_model,node_chat_store,node_db_client toneRose
class node_clerk toneIndigo
```

## Components

### App entry points

- [Chat home](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(root)/page.tsx): `app/(root)/page.tsx`
- [Conversation route](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(root)/c/%5Bid%5D/page.tsx): `app/(root)/c/[id]/page.tsx`
- [Sign-in page](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(auth)/sign-in/%5B%5B...sign-in%5D%5D/page.tsx): `app/(auth)/sign-in/[[...sign-in]]/page.tsx`
- [Chat layout](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/(root)/layout.tsx): `app/(root)/layout.tsx`

### Conversation experience

- [Start conversation](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/home/actions/start-new-chat.ts): `features/home/actions/start-new-chat.ts`
- [Chat shell](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-shell.tsx): `features/conversation/components/chat-shell.tsx`
- [Conversation view](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/conversation-view.tsx): `features/conversation/components/conversation-view.tsx`
- [Conversation sidebar](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/app-sidebar.tsx): `features/conversation/components/app-sidebar.tsx`
- [Message composer](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-composer.tsx): `features/conversation/components/chat-composer.tsx`
- [Message display](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-messages.tsx): `features/conversation/components/chat-messages.tsx`
- [Empty state](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/components/chat-empty.tsx): `features/conversation/components/chat-empty.tsx`
- [Conversation queries](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/hooks/use-conversation.ts): `features/conversation/hooks/use-conversation.ts`
- [Query key factory](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/utils/query-keys.ts): `features/conversation/utils/query-keys.ts`
- [Conversation management](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/conversation/actions/conversation-actions.ts): `features/conversation/actions/conversation-actions.ts`

### Identity and access

- [Require user](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/auth/action/require-user.ts): `features/auth/action/require-user.ts`
- [User onboarding](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/auth/action/onboard.ts): `features/auth/action/onboard.ts`

### Chat and persistence

- [Message management](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/messages/actions/messages-action.ts): `features/messages/actions/messages-action.ts`
- [Message queries](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/messages/hooks/use-messages.ts): `features/messages/hooks/use-messages.ts`
- [Chat streaming API](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Model selection](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/ai/utils/model.ts): `features/ai/utils/model.ts`
- [AI message store](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/features/ai/actions/chat-store.ts): `features/ai/actions/chat-store.ts`
- [Database client](https://github.com/aestheticsuraj234/chai-gpt-build/blob/master/lib/db.ts): `lib/db.ts`

### Other components

- **User**
- **Clerk identity**
- **PostgreSQL**

## Connections

- User → Chat home: opens (evidence: `app/(root)/page.tsx`)
- User → Sign-in page: signs in (evidence: `app/(auth)/sign-in/[[...sign-in]]/page.tsx`)
- User → Conversation route: opens chat (evidence: `app/(root)/c/[id]/page.tsx`)
- Chat home → Start conversation: starts chat (evidence: `app/(root)/page.tsx`)
- Chat home → Chat layout: renders within
- Chat layout → User onboarding: runs onboarding (evidence: `app/(root)/layout.tsx`)
- Chat layout → Chat shell: renders (evidence: `app/(root)/layout.tsx`)
- Conversation route → Conversation management: loads conversation (evidence: `app/(root)/c/[id]/page.tsx`)
- Conversation route → AI message store: loads messages (evidence: `app/(root)/c/[id]/page.tsx`)
- Conversation route → Conversation view: renders (evidence: `app/(root)/c/[id]/page.tsx`)
- Chat shell → Conversation sidebar: renders
- Conversation view → Conversation queries: queries (evidence: `features/conversation/components/conversation-view.tsx`)
- Conversation view → Message composer: renders (evidence: `features/conversation/components/conversation-view.tsx`)
- Conversation view → Message display: renders (evidence: `features/conversation/components/conversation-view.tsx`)
- Conversation view → Empty state: renders (evidence: `features/conversation/components/conversation-view.tsx`)
- Conversation queries → Conversation management: calls (evidence: `features/conversation/hooks/use-conversation.ts`)
- Conversation queries → Query key factory: uses keys (evidence: `features/conversation/hooks/use-conversation.ts`)
- Conversation sidebar → Conversation queries: queries (evidence: `features/conversation/components/app-sidebar.tsx`)
- Start conversation → Require user: checks identity (evidence: `features/home/actions/start-new-chat.ts`)
- Start conversation → Database client: creates record (evidence: `features/home/actions/start-new-chat.ts`)
- Conversation management → Require user: checks identity (evidence: `features/conversation/actions/conversation-actions.ts`)
- Conversation management → Database client: reads and writes (evidence: `features/conversation/actions/conversation-actions.ts`)
- Message queries → Message management: calls (evidence: `features/messages/hooks/use-messages.ts`)
- Message queries → Query key factory: uses keys (evidence: `features/messages/hooks/use-messages.ts`)
- Message management → Require user: checks identity (evidence: `features/messages/actions/messages-action.ts`)
- Message management → Database client: reads and writes (evidence: `features/messages/actions/messages-action.ts`)
- User onboarding → Database client: updates user (evidence: `features/auth/action/onboard.ts`)
- Require user → Clerk identity: authenticates with (evidence: `features/auth/action/require-user.ts`)
- Chat streaming API → Require user: checks identity (evidence: `app/api/chat/route.ts`)
- Chat streaming API → Database client: checks ownership (evidence: `app/api/chat/route.ts`)
- Chat streaming API → AI message store: loads and saves (evidence: `app/api/chat/route.ts`)
- Chat streaming API → Model selection: selects model (evidence: `app/api/chat/route.ts`)
- Chat streaming API → User: streams response (evidence: `app/api/chat/route.ts`)
- Database client → PostgreSQL: connects (evidence: `lib/db.ts`)
- AI message store → Database client: reads and writes (evidence: `features/ai/actions/chat-store.ts`)
- Chat streaming API → Clerk identity: protects route (evidence: `app/api/chat/route.ts`)
