# dhairya-code/ai-customer-support-ticketing-system architecture

> Architecture diagram of the GitHub repository dhairya-code/ai-customer-support-ticketing-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhairya-code/ai-customer-support-ticketing-system
- Repository: https://github.com/dhairya-code/ai-customer-support-ticketing-system

## Overview

ResolveAI is an AI-first customer-support application. Customers authenticate, ask questions in chat, receive knowledge-base answers or Gemini responses, and can be escalated into persistent tickets. Customers then track and reply to their tickets; staff authenticate separately, triage the queue, manage ticket status and metadata, and send public replies or internal notes. The graph preserves these documented capabilities; some subsystem links rely on README descriptions because their implementation files were not sampled.

Main entry points: [`src/app/api/chat/route.ts`](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/api/chat/route.ts) (Chat endpoint), [`src/lib/tickets.ts`](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/tickets.ts) (Ticket and customer thread service), [`src/lib/staff-tickets.ts`](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/staff-tickets.ts) (Triage and staff thread service), [`src/db/index.ts`](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/db/index.ts) (Database client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and access"]
  node_customer_auth["Customer sign-in<br/>[login-form.tsx]"]
  node_staff_auth["Staff sign-in"]
  node_auth_service["Auth service<br/>[auth.ts]"]
  node_session_access["Session and role guards<br/>[session.ts]"]
end

subgraph group_customer["Customer support"]
  node_chat_ui["AI support chat<br/>[customer-chat.tsx]"]
  node_chat_api["Chat endpoint<br/>[route.ts]"]
  node_chat_validation["Chat validation<br/>[chat.ts]"]
  node_knowledge["Knowledge base<br/>[knowledge-base.ts]"]
  node_gemini["Gemini assistant<br/>[gemini.ts]"]
  node_ticket_service["Ticket and customer thread service<br/>[tickets.ts]"]
  node_customer_tickets["Customer ticket pages<br/>[page.tsx]"]
  node_ticket_actions["Customer reply actions<br/>[actions.ts]"]
end

subgraph group_staff["Staff operations"]
  node_staff_queue["Staff queue and metrics<br/>[page.tsx]"]
  node_staff_detail["Staff ticket detail<br/>[page.tsx]"]
  node_staff_actions["Staff ticket actions<br/>[actions.ts]"]
  node_staff_ticket_service["Triage and staff thread service<br/>[staff-tickets.ts]"]
end

subgraph group_platform["Data and integrations"]
  node_email_service["Ticket email notifications<br/>[email.ts]"]
  node_db_client["Database client<br/>[index.ts]"]
  node_support_data[("Users tickets messages<br/>[schema.ts]")]
end

node_customer_actor(("Customer"))
node_staff_actor(("Support staff"))
node_neon[("Neon PostgreSQL")]
node_gemini_service["Google Gemini"]
node_resend["Resend email"]

node_customer_actor -->|"signs in"| node_customer_auth
node_customer_auth -->|"authenticates"| node_auth_service
node_staff_actor -->|"signs in"| node_staff_auth
node_staff_auth -->|"authenticates"| node_auth_service
node_staff_auth -->|"checks staff role"| node_session_access
node_customer_actor -->|"asks question"| node_chat_ui
node_chat_ui -->|"sends chat"| node_chat_api
node_chat_api -->|"checks session"| node_session_access
node_chat_api -->|"validates input"| node_chat_validation
node_chat_api -->|"consults"| node_knowledge
node_chat_api -->|"requests response"| node_gemini
node_gemini -->|"calls model"| node_gemini_service
node_chat_api -->|"creates escalation ticket"| node_ticket_service
node_ticket_service -->|"writes ticket and transcript"| node_support_data
node_chat_api -->|"sends escalation notices"| node_email_service
node_email_service -.->|"sends email"| node_resend
node_customer_actor -->|"tracks ticket"| node_customer_tickets
node_customer_tickets -->|"requires customer"| node_session_access
node_customer_tickets -->|"loads thread"| node_ticket_service
node_customer_tickets -->|"submits reply"| node_ticket_actions
node_ticket_actions -.->|"adds reply"| node_ticket_service
node_staff_actor -->|"triages queue"| node_staff_queue
node_staff_queue -->|"requires staff"| node_session_access
node_staff_queue -->|"loads queue metrics"| node_staff_ticket_service
node_staff_actor -->|"manages ticket"| node_staff_detail
node_staff_detail -->|"requires staff"| node_session_access
node_staff_detail -->|"loads ticket thread"| node_staff_ticket_service
node_staff_detail -->|"submits changes"| node_staff_actions
node_staff_actions -.->|"updates ticket"| node_staff_ticket_service
node_staff_ticket_service -->|"reads and writes"| node_support_data
node_staff_actions -.->|"notifies on reply"| node_email_service
node_email_service -->|"reads recipient"| node_support_data
node_db_client -->|"connects"| node_neon
node_ticket_service -->|"queries"| node_db_client
node_staff_ticket_service -->|"queries"| node_db_client
node_auth_service -->|"persists auth data"| node_db_client
node_db_client -->|"uses schema"| node_support_data

click node_customer_auth "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/components/auth/login-form.tsx"
click node_staff_auth "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/components/auth/staff-login-form.tsx"
click node_auth_service "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/auth.ts"
click node_session_access "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/session.ts"
click node_chat_ui "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/components/chat/customer-chat.tsx"
click node_chat_api "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/api/chat/route.ts"
click node_chat_validation "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/chat.ts"
click node_knowledge "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/knowledge-base.ts"
click node_gemini "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/gemini.ts"
click node_ticket_service "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/tickets.ts"
click node_customer_tickets "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/(customer)/tickets/%5Bid%5D/page.tsx"
click node_ticket_actions "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/(customer)/tickets/%5Bid%5D/actions.ts"
click node_staff_queue "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/admin/page.tsx"
click node_staff_detail "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/admin/tickets/%5Bid%5D/page.tsx"
click node_staff_actions "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/admin/tickets/%5Bid%5D/actions.ts"
click node_staff_ticket_service "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/staff-tickets.ts"
click node_email_service "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/email.ts"
click node_db_client "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/db/index.ts"
click node_support_data "https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/db/schema.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_customer_auth,node_staff_auth,node_auth_service,node_session_access toneBlue
class node_chat_ui,node_chat_api,node_chat_validation,node_knowledge,node_gemini,node_ticket_service,node_customer_tickets,node_ticket_actions,node_neon toneAmber
class node_staff_queue,node_staff_detail,node_staff_actions,node_staff_ticket_service toneMint
class node_email_service,node_db_client,node_support_data toneRose
class node_customer_actor,node_staff_actor,node_gemini_service,node_resend toneIndigo
```

## Components

### Identity and access

- [Customer sign-in](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/components/auth/login-form.tsx): `src/components/auth/login-form.tsx`
- [Staff sign-in](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/components/auth/staff-login-form.tsx): `src/components/auth/staff-login-form.tsx`
- [Auth service](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Session and role guards](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/session.ts): `src/lib/session.ts`

### Customer support

- [AI support chat](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/components/chat/customer-chat.tsx): `src/components/chat/customer-chat.tsx`
- [Chat endpoint](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [Chat validation](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/chat.ts): `src/lib/chat.ts`
- [Knowledge base](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/knowledge-base.ts): `src/lib/knowledge-base.ts`
- [Gemini assistant](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/gemini.ts): `src/lib/gemini.ts`
- [Ticket and customer thread service](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/tickets.ts): `src/lib/tickets.ts`
- [Customer ticket pages](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/(customer)/tickets/%5Bid%5D/page.tsx): `src/app/(customer)/tickets/[id]/page.tsx`
- [Customer reply actions](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/(customer)/tickets/%5Bid%5D/actions.ts): `src/app/(customer)/tickets/[id]/actions.ts`

### Staff operations

- [Staff queue and metrics](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/admin/page.tsx): `src/app/admin/page.tsx`
- [Staff ticket detail](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/admin/tickets/%5Bid%5D/page.tsx): `src/app/admin/tickets/[id]/page.tsx`
- [Staff ticket actions](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/app/admin/tickets/%5Bid%5D/actions.ts): `src/app/admin/tickets/[id]/actions.ts`
- [Triage and staff thread service](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/staff-tickets.ts): `src/lib/staff-tickets.ts`

### Data and integrations

- [Ticket email notifications](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/lib/email.ts): `src/lib/email.ts`
- [Database client](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/db/index.ts): `src/db/index.ts`
- [Users tickets messages](https://github.com/dhairya-code/ai-customer-support-ticketing-system/blob/main/src/db/schema.ts): `src/db/schema.ts`

### Other components

- **Customer**
- **Support staff**
- **Neon PostgreSQL**
- **Google Gemini**
- **Resend email**

## Connections

- Customer → Customer sign-in: signs in (evidence: `README.md`)
- Customer sign-in → Auth service: authenticates (evidence: `src/components/auth/login-form.tsx`)
- Support staff → Staff sign-in: signs in (evidence: `README.md`)
- Staff sign-in → Auth service: authenticates (evidence: `src/components/auth/staff-login-form.tsx`)
- Staff sign-in → Session and role guards: checks staff role (evidence: `src/app/admin/login/page.tsx`)
- Customer → AI support chat: asks question (evidence: `README.md`)
- AI support chat → Chat endpoint: sends chat (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Session and role guards: checks session (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Chat validation: validates input (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Knowledge base: consults (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Gemini assistant: requests response (evidence: `src/app/api/chat/route.ts`)
- Gemini assistant → Google Gemini: calls model (evidence: `README.md`)
- Chat endpoint → Ticket and customer thread service: creates escalation ticket (evidence: `README.md`)
- Ticket and customer thread service → Users tickets messages: writes ticket and transcript (evidence: `src/lib/tickets.ts`)
- Chat endpoint → Ticket email notifications: sends escalation notices (evidence: `src/app/api/chat/route.ts`)
- Ticket email notifications → Resend email: sends email (evidence: `README.md`)
- Customer → Customer ticket pages: tracks ticket (evidence: `README.md`)
- Customer ticket pages → Session and role guards: requires customer (evidence: `src/app/(customer)/tickets/[id]/page.tsx`)
- Customer ticket pages → Ticket and customer thread service: loads thread (evidence: `src/app/(customer)/tickets/[id]/page.tsx`)
- Customer ticket pages → Customer reply actions: submits reply (evidence: `src/app/(customer)/tickets/[id]/page.tsx`)
- Customer reply actions → Ticket and customer thread service: adds reply
- Support staff → Staff queue and metrics: triages queue (evidence: `README.md`)
- Staff queue and metrics → Session and role guards: requires staff (evidence: `src/app/admin/page.tsx`)
- Staff queue and metrics → Triage and staff thread service: loads queue metrics (evidence: `src/app/admin/page.tsx`)
- Support staff → Staff ticket detail: manages ticket (evidence: `README.md`)
- Staff ticket detail → Session and role guards: requires staff (evidence: `src/app/admin/tickets/[id]/page.tsx`)
- Staff ticket detail → Triage and staff thread service: loads ticket thread (evidence: `src/app/admin/tickets/[id]/page.tsx`)
- Staff ticket detail → Staff ticket actions: submits changes (evidence: `src/app/admin/tickets/[id]/page.tsx`)
- Staff ticket actions → Triage and staff thread service: updates ticket
- Triage and staff thread service → Users tickets messages: reads and writes (evidence: `src/lib/staff-tickets.ts`)
- Staff ticket actions → Ticket email notifications: notifies on reply
- Ticket email notifications → Users tickets messages: reads recipient (evidence: `src/lib/email.ts`)
- Database client → Neon PostgreSQL: connects (evidence: `src/db/index.ts`)
- Ticket and customer thread service → Database client: queries (evidence: `src/lib/tickets.ts`)
- Triage and staff thread service → Database client: queries (evidence: `src/lib/staff-tickets.ts`)
- Auth service → Database client: persists auth data (evidence: `src/lib/auth.ts`)
- Database client → Users tickets messages: uses schema (evidence: `src/db/index.ts`)
