How karandudhbhate-10/support-ai works
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: settings/route.ts Settings API · get/route.ts Settings read · chat/route.ts Chat API · getSession.ts Session
Components 20
App surfaces
Route-based user-facing pages and their client components.
- Home · Landing page route.
src/app/page.tsx - Home UI · Browser-side home experience.
src/components/HomeClient.tsx - Dashboard · Dashboard route.
src/app/dashboard/page.tsx - Dashboard UI · Browser-side dashboard experience.
src/components/DashboardClient.tsx - Learn more · Informational route.
src/app/learn-more/page.tsx - Root layout · Global Next.js app shell.
src/app/layout.tsx
API layer
Next.js route handlers for auth, chat, and settings.
- Login · Starts authentication flow.
src/app/api/auth/login/route.ts - Callback · Handles provider return and session exchange.
src/app/api/auth/callback/route.ts - Logout · Ends the user session.
src/app/api/auth/logout/route.ts - Chat API · Backend for chat interactions.
src/app/api/chat/route.ts - Settings API · Writes application settings.
src/app/api/settings/route.ts - Settings read · Reads application settings.
src/app/api/settings/get/route.ts
Core services
Shared server helpers, persistence, and auth integration.
- Session · Shared session lookup utility.
src/lib/getSession.ts - Scalekit · External auth/provider integration.
src/lib/scalekit.ts - Database · Shared database access layer.
src/lib/db.ts - Settings model · Settings persistence shape and logic.
src/model/settings.model.ts - Proxy · Request-time access control and routing gate.
src/proxy.ts
Embed
External widget and embedded runtime entrypoints.
- Embed page · Embed route for integration use.
src/app/embed/page.tsx - Embed UI · Browser-side embedded experience.
src/components/EmbedClient.tsx - Widget script · Standalone public chat widget entrypoint.
public/chatBot.js
Connections 24
- 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.