# karandudhbhate-10/support-ai architecture

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

- Interactive diagram: https://gitdiagram.com/karandudhbhate-10/support-ai
- Repository: https://github.com/karandudhbhate-10/support-ai

## Overview

1. This repository is a single Next.js full-stack application using the App Router. It combines UI pages, server route handlers, and shared library code in one codebase.

2. The main user-facing surfaces are route-based pages under `src/app`: a landing/home page (`/`), a dashboard (`/dashboard`), an embed page (`/embed`), and a “learn more” page. These are the top-level navigation and presentation layer.

3. The app is split between server-rendered route handlers and client components. The `src/components/*Client.tsx` files likely hold browser-side interactivity for the home, dashboard, and embed experiences, while the `src/app/*/page.tsx` files wire those components into routes.

4. Authentication is handled through a dedicated auth subsystem under `src/app/api/auth/*`. There are explicit login, callback, and logout routes, which strongly suggests an external identity provider/OAuth-style flow rather than local username/password auth.

5. The `src/lib/scalekit.ts` file indicates Scalekit is the authentication provider or session/auth SDK used by the app. The callback route likely exchanges the provider response for an application session, and `src/lib/getSession.ts` is the shared server-side helper used to read the current user session in pages and APIs.

6. Persistent application data appears to center on settings. The `src/app/api/settings/route.ts` and `src/app/api/settings/get/route.ts` handlers, together with `src/model/settings.model.ts`, form the settings data path. This suggests the dashboard configures per-user or per-tenant behavior that is stored and retrieved through these endpoints.

7. Chat is a distinct backend capability exposed through `src/app/api/chat/route.ts`. Given the presence of `public/chatBot.js` and the `/embed` route, the likely architecture is that an embeddable widget or script sends chat requests to this API, which then serves as the runtime backend for conversational interactions.

8. The embed subsystem is important as an integration boundary. `src/app/embed/page.tsx` plus `public/chatBot.js` imply the project provides a drop-in client/embed experience that can be consumed outside the main dashboard, probably using the same auth/session and settings data model.

9. Data access and server-side integration live in `src/lib/db.ts` and the model layer. That separation suggests route handlers call into shared DB utilities, while `settings.model.ts` defines the shape or access logic for persisted settings.

10. `src/proxy.ts` is likely a request gatekeeper used by Next.js to protect routes or redirect unauthenticated traffic. Architecturally, that means access control happens before page rendering for sensitive routes like the dashboard and settings endpoints.

11. The app has the usual Next.js support files (`layout.tsx`, `globals.css`, `next.config.ts`, `eslint.config.mjs`, `postcss.config.mjs`, `tsconfig.json`), so the runtime is a standard TypeScript Next.js deployment with serverless-style route handlers rather than a separate backend service.

12. In diagram terms, the main flow is: browser or embed script hits the Next.js UI, UI calls route handlers for auth/chat/settings, route handlers use session helpers and DB/model code, and auth is delegated through Scalekit. The key boundaries are UI vs API, authenticated vs unauthenticated routes, and dashboard/admin configuration vs embeddable chat runtime.

Main entry points: [`src/app/api/settings/route.ts`](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/settings/route.ts) (Settings API), [`src/app/api/settings/get/route.ts`](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/settings/get/route.ts) (Settings read), [`src/app/api/chat/route.ts`](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/chat/route.ts) (Chat API), [`src/lib/getSession.ts`](https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/getSession.ts) (Session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["App surfaces"]
  node_node_home_page["Home<br/>route page<br/>[page.tsx]"]
  node_node_home_client["Home UI<br/>client component<br/>[HomeClient.tsx]"]
  node_node_dashboard_page["Dashboard<br/>route page<br/>[page.tsx]"]
  node_node_dashboard_client["Dashboard UI<br/>client component"]
  node_node_learn_more_page["Learn more<br/>route page<br/>[page.tsx]"]
  node_node_layout["Root layout<br/>app shell<br/>[layout.tsx]"]
end

subgraph group_group_api["API layer"]
  node_node_auth_login["Login<br/>api route<br/>[route.ts]"]
  node_node_auth_callback["Callback<br/>api route<br/>[route.ts]"]
  node_node_auth_logout["Logout<br/>api route<br/>[route.ts]"]
  node_node_chat_api["Chat API<br/>api route<br/>[route.ts]"]
  node_node_settings_api["Settings API<br/>api route<br/>[route.ts]"]
  node_node_settings_get["Settings read<br/>api route<br/>[route.ts]"]
end

subgraph group_group_core["Core services"]
  node_node_session["Session<br/>server helper<br/>[getSession.ts]"]
  node_node_scalekit["Scalekit<br/>auth sdk<br/>[scalekit.ts]"]
  node_node_db[("Database<br/>db helper<br/>[db.ts]")]
  node_node_settings_model["Settings model<br/>data model<br/>[settings.model.ts]"]
  node_node_proxy{{"Proxy<br/>request guard<br/>[proxy.ts]"}}
end

subgraph group_group_integration["Embed"]
  node_node_embed_page["Embed page<br/>route page<br/>[page.tsx]"]
  node_node_embed_client["Embed UI<br/>client component<br/>[EmbedClient.tsx]"]
  node_node_chatbot_script["Widget script<br/>embed script<br/>[chatBot.js]"]
end

node_node_layout -->|"renders"| node_node_home_page
node_node_home_page -->|"uses"| node_node_home_client
node_node_dashboard_page -->|"uses"| node_node_dashboard_client
node_node_embed_page -->|"uses"| node_node_embed_client
node_node_chatbot_script -->|"calls"| node_node_chat_api
node_node_proxy -->|"protects"| node_node_dashboard_page
node_node_proxy -->|"protects"| node_node_settings_api
node_node_proxy -->|"protects"| node_node_chat_api
node_node_auth_login -->|"starts"| node_node_scalekit
node_node_auth_callback -->|"exchanges"| node_node_scalekit
node_node_auth_logout -->|"clears"| node_node_session
node_node_dashboard_page -->|"reads"| node_node_session
node_node_chat_api -->|"reads"| node_node_session
node_node_settings_api -->|"reads"| node_node_session
node_node_settings_get -->|"reads"| node_node_session
node_node_settings_api -->|"writes"| node_node_db
node_node_settings_get -->|"reads"| node_node_db
node_node_settings_api -->|"uses"| node_node_settings_model
node_node_settings_get -->|"uses"| node_node_settings_model
node_node_chat_api -.->|"uses"| node_node_db
node_node_home_client -.->|"consumes"| node_node_settings_api
node_node_dashboard_client -.->|"consumes"| node_node_settings_get
node_node_embed_client -->|"consumes"| node_node_chat_api
node_node_embed_client -.->|"consumes"| node_node_settings_get

click node_node_home_page "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/page.tsx"
click node_node_home_client "https://github.com/karandudhbhate-10/support-ai/blob/main/src/components/HomeClient.tsx"
click node_node_dashboard_page "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/dashboard/page.tsx"
click node_node_dashboard_client "https://github.com/karandudhbhate-10/support-ai/blob/main/src/components/DashboardClient.tsx"
click node_node_learn_more_page "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/learn-more/page.tsx"
click node_node_embed_page "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/embed/page.tsx"
click node_node_embed_client "https://github.com/karandudhbhate-10/support-ai/blob/main/src/components/EmbedClient.tsx"
click node_node_chatbot_script "https://github.com/karandudhbhate-10/support-ai/blob/main/public/chatBot.js"
click node_node_auth_login "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/auth/login/route.ts"
click node_node_auth_callback "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/auth/callback/route.ts"
click node_node_auth_logout "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/auth/logout/route.ts"
click node_node_chat_api "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/chat/route.ts"
click node_node_settings_api "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/settings/route.ts"
click node_node_settings_get "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/settings/get/route.ts"
click node_node_session "https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/getSession.ts"
click node_node_scalekit "https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/scalekit.ts"
click node_node_db "https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/db.ts"
click node_node_settings_model "https://github.com/karandudhbhate-10/support-ai/blob/main/src/model/settings.model.ts"
click node_node_proxy "https://github.com/karandudhbhate-10/support-ai/blob/main/src/proxy.ts"
click node_node_layout "https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/layout.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_node_home_page,node_node_home_client,node_node_dashboard_page,node_node_dashboard_client,node_node_learn_more_page,node_node_layout toneBlue
class node_node_auth_login,node_node_auth_callback,node_node_auth_logout,node_node_chat_api,node_node_settings_api,node_node_settings_get toneAmber
class node_node_session,node_node_scalekit,node_node_db,node_node_settings_model,node_node_proxy toneMint
class node_node_embed_page,node_node_embed_client,node_node_chatbot_script toneRose
```

## Components

### App surfaces

Route-based user-facing pages and their client components.

- [Home](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/page.tsx): route page · Landing page route. · `src/app/page.tsx`
- [Home UI](https://github.com/karandudhbhate-10/support-ai/blob/main/src/components/HomeClient.tsx): client component · Browser-side home experience. · `src/components/HomeClient.tsx`
- [Dashboard](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/dashboard/page.tsx): route page · Dashboard route. · `src/app/dashboard/page.tsx`
- [Dashboard UI](https://github.com/karandudhbhate-10/support-ai/blob/main/src/components/DashboardClient.tsx): client component · Browser-side dashboard experience. · `src/components/DashboardClient.tsx`
- [Learn more](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/learn-more/page.tsx): route page · Informational route. · `src/app/learn-more/page.tsx`
- [Root layout](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/layout.tsx): app shell · Global Next.js app shell. · `src/app/layout.tsx`

### API layer

Next.js route handlers for auth, chat, and settings.

- [Login](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/auth/login/route.ts): api route · Starts authentication flow. · `src/app/api/auth/login/route.ts`
- [Callback](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/auth/callback/route.ts): api route · Handles provider return and session exchange. · `src/app/api/auth/callback/route.ts`
- [Logout](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/auth/logout/route.ts): api route · Ends the user session. · `src/app/api/auth/logout/route.ts`
- [Chat API](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/chat/route.ts): api route · Backend for chat interactions. · `src/app/api/chat/route.ts`
- [Settings API](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/settings/route.ts): api route · Writes application settings. · `src/app/api/settings/route.ts`
- [Settings read](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/api/settings/get/route.ts): api route · Reads application settings. · `src/app/api/settings/get/route.ts`

### Core services

Shared server helpers, persistence, and auth integration.

- [Session](https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/getSession.ts): server helper · Shared session lookup utility. · `src/lib/getSession.ts`
- [Scalekit](https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/scalekit.ts): auth sdk · External auth/provider integration. · `src/lib/scalekit.ts`
- [Database](https://github.com/karandudhbhate-10/support-ai/blob/main/src/lib/db.ts): db helper · Shared database access layer. · `src/lib/db.ts`
- [Settings model](https://github.com/karandudhbhate-10/support-ai/blob/main/src/model/settings.model.ts): data model · Settings persistence shape and logic. · `src/model/settings.model.ts`
- [Proxy](https://github.com/karandudhbhate-10/support-ai/blob/main/src/proxy.ts): request guard · Request-time access control and routing gate. · `src/proxy.ts`

### Embed

External widget and embedded runtime entrypoints.

- [Embed page](https://github.com/karandudhbhate-10/support-ai/blob/main/src/app/embed/page.tsx): route page · Embed route for integration use. · `src/app/embed/page.tsx`
- [Embed UI](https://github.com/karandudhbhate-10/support-ai/blob/main/src/components/EmbedClient.tsx): client component · Browser-side embedded experience. · `src/components/EmbedClient.tsx`
- [Widget script](https://github.com/karandudhbhate-10/support-ai/blob/main/public/chatBot.js): embed script · Standalone public chat widget entrypoint. · `public/chatBot.js`

## Connections

- Root layout → Home: renders · Global shell wraps routed pages.
- Home → Home UI: uses · Home route mounts interactive client UI.
- Dashboard → Dashboard UI: uses · Dashboard route mounts interactive client UI.
- Embed page → Embed UI: uses · Embed route mounts interactive client UI.
- Widget script → Chat API: calls · Widget script sends conversational requests.
- Proxy → Dashboard: protects · Guards authenticated dashboard access.
- Proxy → Settings API: protects · Guards settings endpoints.
- Proxy → Chat API: protects · Can gate sensitive backend routes.
- Login → Scalekit: starts · Delegates login to external auth provider.
- Callback → Scalekit: exchanges · Consumes provider callback and session data.
- Logout → Session: clears · Uses session context to end access.
- Dashboard → Session: reads · Dashboard checks current user session.
- Chat API → Session: reads · Chat runtime uses session context when available.
- Settings API → Session: reads · Settings writes are session-aware.
- Settings read → Session: reads · Settings reads are session-aware.
- Settings API → Database: writes · Persists settings through shared DB access.
- Settings read → Database: reads · Loads settings through shared DB access.
- Settings API → Settings model: uses · Settings route relies on model logic.
- Settings read → Settings model: uses · Settings read route relies on model logic.
- Chat API → Database: uses · Chat backend likely depends on persistent/shared data.
- Home UI → Settings API: consumes · UI may fetch or update settings-driven state.
- Dashboard UI → Settings read: consumes · Dashboard UI reads settings.
- Embed UI → Chat API: consumes · Embed UI sends chat requests.
- Embed UI → Settings read: consumes · Embed UI reads configuration.
