# mby444/ticketing-system architecture

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

- Interactive diagram: https://gitdiagram.com/mby444/ticketing-system
- Repository: https://github.com/mby444/ticketing-system

## Overview

This is a Next.js support-ticket application: users register or sign in, create and follow tickets, add attachments and comments, while staff triage, assign, update, and filter tickets. Ticket actions are the central server-side workflow boundary; authentication/authorization and persistence support those operations, and asynchronous jobs deliver ticket emails. Source excerpts show the dashboard, ticket-detail, auth, and email-worker flows. Other links below rely on SOURCE INDEX references; unsampled implementation details and wiring are not inferred.

Main entry points: [`actions/ticket.actions.ts`](https://github.com/mby444/ticketing-system/blob/main/actions/ticket.actions.ts) (Ticket actions), [`app/dashboard/page.tsx`](https://github.com/mby444/ticketing-system/blob/main/app/dashboard/page.tsx) (Staff dashboard), [`lib/authorization.ts`](https://github.com/mby444/ticketing-system/blob/main/lib/authorization.ts) (Access guards), [`actions/auth.actions.ts`](https://github.com/mby444/ticketing-system/blob/main/actions/auth.actions.ts) (Auth actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and access"]
  node_authui["Sign-in forms<br/>[login-form.tsx]"]
  node_registerui["Registration form<br/>[register-form.tsx]"]
  node_authactions["Auth actions<br/>[auth.actions.ts]"]
  node_authlib["Token and cookies<br/>[auth.ts]"]
  node_access["Access guards<br/>[authorization.ts]"]
  node_currentuser["Current user<br/>[current-user.ts]"]
  node_roles["Role definitions<br/>[roles.ts]"]
end

subgraph group_tickets["Ticket workflow"]
  node_ticketsui["Ticket list<br/>[page.tsx]"]
  node_newticket["Ticket creation form<br/>[ticket-form.tsx]"]
  node_detail["Ticket details<br/>[page.tsx]"]
  node_ticketactions["Ticket actions<br/>[ticket.actions.ts]"]
  node_comments["Comments<br/>[comment-thread.tsx]"]
  node_database[("Application database<br/>[prisma.ts]")]
  node_priority["Priority rules<br/>[priority.ts]"]
end

subgraph group_staff["Staff triage"]
  node_dashboard["Staff dashboard<br/>[page.tsx]"]
  node_tickettable["Ticket table<br/>[TicketTable.tsx]"]
  node_filters["Dashboard filters"]
  node_sorting["Dashboard sorting<br/>[dashboard-sort.ts]"]
end

subgraph group_messaging["Attachments and email"]
  node_upload["Attachment storage<br/>[cloudinary.ts]"]
  node_queueclient["Email job publisher<br/>[qstash.ts]"]
  node_worker["Email job worker<br/>[route.ts]"]
  node_emailservice["Email dispatch<br/>[email.ts]"]
  node_templates["Email templates"]
end

node_visitor(("User"))
node_queue["QStash"]

node_visitor -->|"signs in"| node_authui
node_visitor -->|"registers"| node_registerui
node_authui -->|"submits credentials"| node_authactions
node_registerui -->|"submits registration"| node_authactions
node_authactions -->|"reads and creates users"| node_database
node_authactions -->|"signs session token"| node_authlib
node_access -->|"resolves session"| node_currentuser
node_currentuser -->|"verifies cookie token"| node_authlib
node_access -->|"checks roles"| node_roles
node_visitor -->|"views tickets"| node_ticketsui
node_ticketsui -->|"requires user"| node_access
node_ticketsui -->|"fetches tickets"| node_ticketactions
node_visitor -->|"creates ticket"| node_newticket
node_newticket -->|"submits ticket"| node_ticketactions
node_detail -->|"loads ticket"| node_ticketactions
node_detail -->|"requires user"| node_access
node_detail -->|"renders conversation"| node_comments
node_ticketactions -->|"reads and updates records"| node_database
node_ticketactions -->|"checks identity"| node_currentuser
node_ticketactions -->|"uploads attachments"| node_upload
node_ticketactions -->|"publishes email jobs"| node_queueclient
node_ticketactions -->|"uses priority rules"| node_priority
node_dashboard -->|"requires staff role"| node_access
node_dashboard -->|"loads tickets and agents"| node_ticketactions
node_dashboard -->|"filters ticket set"| node_filters
node_dashboard -->|"sorts ticket set"| node_sorting
node_dashboard -->|"renders results"| node_tickettable
node_tickettable -->|"builds sort links"| node_sorting
node_tickettable -->|"submits inline changes"| node_ticketactions
node_queueclient -->|"enqueues jobs"| node_queue
node_queue -.->|"delivers job"| node_worker
node_worker -->|"dispatches email"| node_emailservice
node_emailservice -.->|"renders messages"| node_templates

click node_authui "https://github.com/mby444/ticketing-system/blob/main/app/(auth)/login/login-form.tsx"
click node_registerui "https://github.com/mby444/ticketing-system/blob/main/app/(auth)/register/register-form.tsx"
click node_authactions "https://github.com/mby444/ticketing-system/blob/main/actions/auth.actions.ts"
click node_authlib "https://github.com/mby444/ticketing-system/blob/main/lib/auth.ts"
click node_access "https://github.com/mby444/ticketing-system/blob/main/lib/authorization.ts"
click node_currentuser "https://github.com/mby444/ticketing-system/blob/main/lib/current-user.ts"
click node_ticketsui "https://github.com/mby444/ticketing-system/blob/main/app/tickets/page.tsx"
click node_newticket "https://github.com/mby444/ticketing-system/blob/main/app/tickets/new/ticket-form.tsx"
click node_detail "https://github.com/mby444/ticketing-system/blob/main/app/tickets/%5Bid%5D/page.tsx"
click node_ticketactions "https://github.com/mby444/ticketing-system/blob/main/actions/ticket.actions.ts"
click node_comments "https://github.com/mby444/ticketing-system/blob/main/app/tickets/%5Bid%5D/comment-thread.tsx"
click node_dashboard "https://github.com/mby444/ticketing-system/blob/main/app/dashboard/page.tsx"
click node_tickettable "https://github.com/mby444/ticketing-system/blob/main/components/dashboard/TicketTable.tsx"
click node_filters "https://github.com/mby444/ticketing-system/blob/main/lib/dashboard-filters.ts"
click node_sorting "https://github.com/mby444/ticketing-system/blob/main/lib/dashboard-sort.ts"
click node_database "https://github.com/mby444/ticketing-system/blob/main/lib/prisma.ts"
click node_upload "https://github.com/mby444/ticketing-system/blob/main/lib/cloudinary.ts"
click node_queueclient "https://github.com/mby444/ticketing-system/blob/main/lib/qstash.ts"
click node_worker "https://github.com/mby444/ticketing-system/blob/main/app/api/jobs/send-email/route.ts"
click node_emailservice "https://github.com/mby444/ticketing-system/blob/main/lib/email.ts"
click node_templates "https://github.com/mby444/ticketing-system/tree/main/emails"
click node_priority "https://github.com/mby444/ticketing-system/blob/main/lib/priority.ts"
click node_roles "https://github.com/mby444/ticketing-system/blob/main/lib/roles.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_authui,node_registerui,node_authactions,node_authlib,node_access,node_currentuser,node_roles,node_visitor toneBlue
class node_ticketsui,node_newticket,node_detail,node_ticketactions,node_comments,node_database,node_priority toneAmber
class node_dashboard,node_tickettable,node_filters,node_sorting toneMint
class node_upload,node_queueclient,node_worker,node_emailservice,node_templates toneRose
class node_queue toneIndigo
```

## Components

### Identity and access

- [Sign-in forms](https://github.com/mby444/ticketing-system/blob/main/app/(auth)/login/login-form.tsx): `app/(auth)/login/login-form.tsx`
- [Registration form](https://github.com/mby444/ticketing-system/blob/main/app/(auth)/register/register-form.tsx): `app/(auth)/register/register-form.tsx`
- [Auth actions](https://github.com/mby444/ticketing-system/blob/main/actions/auth.actions.ts): `actions/auth.actions.ts`
- [Token and cookies](https://github.com/mby444/ticketing-system/blob/main/lib/auth.ts): `lib/auth.ts`
- [Access guards](https://github.com/mby444/ticketing-system/blob/main/lib/authorization.ts): `lib/authorization.ts`
- [Current user](https://github.com/mby444/ticketing-system/blob/main/lib/current-user.ts): `lib/current-user.ts`
- [Role definitions](https://github.com/mby444/ticketing-system/blob/main/lib/roles.ts): `lib/roles.ts`

### Ticket workflow

- [Ticket list](https://github.com/mby444/ticketing-system/blob/main/app/tickets/page.tsx): `app/tickets/page.tsx`
- [Ticket creation form](https://github.com/mby444/ticketing-system/blob/main/app/tickets/new/ticket-form.tsx): `app/tickets/new/ticket-form.tsx`
- [Ticket details](https://github.com/mby444/ticketing-system/blob/main/app/tickets/%5Bid%5D/page.tsx): `app/tickets/[id]/page.tsx`
- [Ticket actions](https://github.com/mby444/ticketing-system/blob/main/actions/ticket.actions.ts): `actions/ticket.actions.ts`
- [Comments](https://github.com/mby444/ticketing-system/blob/main/app/tickets/%5Bid%5D/comment-thread.tsx): `app/tickets/[id]/comment-thread.tsx`
- [Application database](https://github.com/mby444/ticketing-system/blob/main/lib/prisma.ts): `lib/prisma.ts`
- [Priority rules](https://github.com/mby444/ticketing-system/blob/main/lib/priority.ts): `lib/priority.ts`

### Staff triage

- [Staff dashboard](https://github.com/mby444/ticketing-system/blob/main/app/dashboard/page.tsx): `app/dashboard/page.tsx`
- [Ticket table](https://github.com/mby444/ticketing-system/blob/main/components/dashboard/TicketTable.tsx): `components/dashboard/TicketTable.tsx`
- [Dashboard filters](https://github.com/mby444/ticketing-system/blob/main/lib/dashboard-filters.ts): `lib/dashboard-filters.ts`
- [Dashboard sorting](https://github.com/mby444/ticketing-system/blob/main/lib/dashboard-sort.ts): `lib/dashboard-sort.ts`

### Attachments and email

- [Attachment storage](https://github.com/mby444/ticketing-system/blob/main/lib/cloudinary.ts): `lib/cloudinary.ts`
- [Email job publisher](https://github.com/mby444/ticketing-system/blob/main/lib/qstash.ts): `lib/qstash.ts`
- [Email job worker](https://github.com/mby444/ticketing-system/blob/main/app/api/jobs/send-email/route.ts): `app/api/jobs/send-email/route.ts`
- [Email dispatch](https://github.com/mby444/ticketing-system/blob/main/lib/email.ts): `lib/email.ts`
- [Email templates](https://github.com/mby444/ticketing-system/tree/main/emails): `emails`

### Other components

- **User**
- **QStash**

## Connections

- User → Sign-in forms: signs in (evidence: `app/(auth)/login/login-form.tsx`)
- User → Registration form: registers (evidence: `app/(auth)/register/register-form.tsx`)
- Sign-in forms → Auth actions: submits credentials (evidence: `app/(auth)/login/login-form.tsx`)
- Registration form → Auth actions: submits registration (evidence: `app/(auth)/register/register-form.tsx`)
- Auth actions → Application database: reads and creates users (evidence: `actions/auth.actions.ts`)
- Auth actions → Token and cookies: signs session token (evidence: `actions/auth.actions.ts`)
- Access guards → Current user: resolves session (evidence: `lib/authorization.ts`)
- Current user → Token and cookies: verifies cookie token (evidence: `lib/current-user.ts`)
- Access guards → Role definitions: checks roles (evidence: `lib/authorization.ts`)
- User → Ticket list: views tickets (evidence: `app/tickets/page.tsx`)
- Ticket list → Access guards: requires user (evidence: `app/tickets/page.tsx`)
- Ticket list → Ticket actions: fetches tickets (evidence: `app/tickets/page.tsx`)
- User → Ticket creation form: creates ticket (evidence: `app/tickets/new/ticket-form.tsx`)
- Ticket creation form → Ticket actions: submits ticket (evidence: `app/tickets/new/ticket-form.tsx`)
- Ticket details → Ticket actions: loads ticket (evidence: `app/tickets/[id]/page.tsx`)
- Ticket details → Access guards: requires user (evidence: `app/tickets/[id]/page.tsx`)
- Ticket details → Comments: renders conversation (evidence: `app/tickets/[id]/page.tsx`)
- Ticket actions → Application database: reads and updates records (evidence: `actions/ticket.actions.ts`)
- Ticket actions → Current user: checks identity (evidence: `actions/ticket.actions.ts`)
- Ticket actions → Attachment storage: uploads attachments (evidence: `actions/ticket.actions.ts`)
- Ticket actions → Email job publisher: publishes email jobs (evidence: `actions/ticket.actions.ts`)
- Ticket actions → Priority rules: uses priority rules (evidence: `actions/ticket.actions.ts`)
- Staff dashboard → Access guards: requires staff role (evidence: `app/dashboard/page.tsx`)
- Staff dashboard → Ticket actions: loads tickets and agents (evidence: `app/dashboard/page.tsx`)
- Staff dashboard → Dashboard filters: filters ticket set (evidence: `app/dashboard/page.tsx`)
- Staff dashboard → Dashboard sorting: sorts ticket set (evidence: `app/dashboard/page.tsx`)
- Staff dashboard → Ticket table: renders results (evidence: `app/dashboard/page.tsx`)
- Ticket table → Dashboard sorting: builds sort links (evidence: `components/dashboard/TicketTable.tsx`)
- Ticket table → Ticket actions: submits inline changes (evidence: `components/dashboard/TicketTable.tsx`)
- Email job publisher → QStash: enqueues jobs (evidence: `lib/qstash.ts`)
- QStash → Email job worker: delivers job
- Email job worker → Email dispatch: dispatches email (evidence: `app/api/jobs/send-email/route.ts`)
- Email dispatch → Email templates: renders messages
