A comprehensive ticket management system with role-based access control, real-time updates, and analytics.
- Submit support tickets with subject, description, and priority
- View all personal tickets in a dashboard
- Track ticket status (New, Open, Pending, On Hold, Solved, Closed)
- Reply to tickets and view conversation history
- Dark/Light theme toggle
- View all tickets across the system
- Filter tickets by status (New, Open, Pending, On Hold, Solved)
- Assign tickets to themselves
- Reply to tickets (public and internal notes)
- Update ticket status and priority
- Automatic session tracking (login time, duration, reply counts)
- Dashboard with ticket statistics
- Complete agent performance analytics dashboard
- Track agent sessions (login/logout times, duration, activity)
- View agent metrics (total replies, tickets assigned, solve rate)
- Monitor system-wide statistics
- Create and manage custom ticket forms
- Full access to all agent features
- Ticket numbering starting from 0
- Activity log for each ticket (who responded, when)
- File attachments support
- Custom ticket forms
- Role-based permissions (User, Agent, Admin)
- RESTful API architecture
- Dark and Light theme support
- Node.js with Express
- TypeScript
- PostgreSQL database
- Prisma ORM
- Clerk authentication
- React with TypeScript
- Vite build tool
- TailwindCSS for styling
- React Router for navigation
- React Query for data fetching
- Clerk React SDK
Before you begin, ensure you have:
- Node.js 18+ installed
- PostgreSQL 14+ installed and running
- A Clerk account (free tier available at https://clerk.com)
# Install root dependencies
npm install
# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm install
cd ..- Go to https://clerk.com and create a free account
- Create a new application in Clerk dashboard
- Get your Publishable Key and Secret Key from the API Keys section
- In Clerk dashboard, go to "User & Authentication" > "Metadata"
- Add a public metadata field called "role" (this will store USER, AGENT, or ADMIN)
cd backend
cp .env.example .envEdit backend/.env:
DATABASE_URL="postgresql://postgres:yourpassword@localhost:5432/ticket_system?schema=public"
PORT=3001
NODE_ENV=development
CLERK_PUBLISHABLE_KEY=pk_test_your_key_here
CLERK_SECRET_KEY=sk_test_your_key_here
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=10485760
FRONTEND_URL=http://localhost:5173
cd ../frontend
cp .env.example .envEdit frontend/.env:
VITE_CLERK_PUBLISHABLE_KEY=pk_test_your_key_here
VITE_API_URL=http://localhost:3001/api
cd backend
# Generate Prisma client
npm run db:generate
# Run database migrations
npm run db:migrate
# Optional: Open Prisma Studio to view/manage data
npm run db:studioOpen two terminal windows:
Terminal 1 (Backend):
cd backend
npm run devTerminal 2 (Frontend):
cd frontend
npm run devThe application will be available at:
- Frontend: http://localhost:5173
- Backend: http://localhost:3001
Since this is a new installation, you'll need to manually set user roles in Clerk:
- Sign up a user through the application
- Go to Clerk Dashboard > Users
- Click on the user
- Scroll to "Public metadata"
- Add:
{"role": "ADMIN"}for admin,{"role": "AGENT"}for agent, or{"role": "USER"}for regular user - Save changes
- Users: Stores user accounts with roles (USER, AGENT, ADMIN)
- Tickets: Main ticket entity with status, priority, assignments
- Comments: Ticket replies and internal notes
- Attachments: File uploads linked to tickets
- Forms: Custom ticket submission forms (created by admin)
- Categories: Ticket categorization
- TicketActivity: Activity log for each ticket
- AgentSession: Agent login/logout tracking with metrics
- NEW: Freshly created ticket
- OPEN: Agent is working on it
- PENDING: Waiting for customer response
- ON_HOLD: Temporarily paused
- SOLVED: Issue resolved
- CLOSED: Ticket archived
- LOW
- NORMAL
- HIGH
- URGENT
GET /api/tickets- Get all tickets (filtered by user role)GET /api/tickets/:id- Get single ticket with commentsPOST /api/tickets- Create new ticketPATCH /api/tickets/:id- Update ticket (status, priority, assignment)GET /api/tickets/stats/overview- Get ticket statistics
POST /api/comments- Add reply to ticketGET /api/comments/ticket/:ticketId- Get all comments for a ticket
POST /api/attachments/upload- Upload fileGET /api/attachments/:id/download- Download file
GET /api/forms- Get all active formsGET /api/forms/:id- Get single formPOST /api/forms- Create new formPATCH /api/forms/:id- Update formDELETE /api/forms/:id- Delete form
GET /api/analytics/agents- Get agent performance metricsGET /api/analytics/system- Get system-wide statisticsGET /api/analytics/agents/:agentId/sessions- Get agent session history
POST /api/sessions/start- Start agent sessionPOST /api/sessions/end/:sessionId- End agent sessionGET /api/sessions/current- Get current active session
The application supports dark and light themes:
- Toggle button in the header (sun/moon icon)
- Preference saved to localStorage
- Persists across sessions
- Applies to all pages and components
# Backend tests (when implemented)
cd backend
npm test
# Frontend tests (when implemented)
cd frontend
npm test# Build backend
cd backend
npm run build
npm start
# Build frontend
cd frontend
npm run build
npm run previewticket-system/
├── backend/
│ ├── src/
│ │ ├── routes/ # API route handlers
│ │ ├── middleware/ # Auth and validation middleware
│ │ ├── lib/ # Utilities (Prisma client)
│ │ └── server.ts # Express app entry point
│ ├── prisma/
│ │ └── schema.prisma # Database schema
│ ├── package.json
│ └── tsconfig.json
├── frontend/
│ ├── src/
│ │ ├── pages/ # Route components
│ │ ├── components/ # Reusable UI components
│ │ ├── contexts/ # React contexts (Theme)
│ │ ├── lib/ # API client utilities
│ │ ├── App.tsx # Main app component
│ │ ├── main.tsx # Entry point
│ │ └── index.css # Global styles
│ ├── package.json
│ └── vite.config.ts
└── package.json # Root package.json
- All routes are protected with Clerk authentication
- Role-based access control enforced on both frontend and backend
- Users can only view their own tickets
- Agents/Admins can view all tickets
- Internal notes only visible to agents and admins
- File uploads have size limits and type validation
- SQL injection protection via Prisma ORM
- XSS protection via input sanitization
After basic setup, consider adding:
- Email notifications for ticket updates
- Real-time updates using WebSockets
- Advanced search and filtering
- Custom SLA rules and escalation
- Knowledge base integration
- Multi-language support
- Export tickets to CSV/PDF
MIT