ambarish0221/DTQ
SmartQueue — AI Helpdesk Workload Optimizer
A production-grade distributed task queue built on Go, Redis, Python, and React, with an integrated AI layer that classifies support tickets, forecasts workload, and provides a real-time streaming assistant for resolving them.
What It Does
Support teams face unpredictable ticket volume. SmartQueue addresses this with three capabilities:
- Ticket classification — incoming support requests are automatically categorised, prioritised (P1–P4), assigned an SLA deadline, and routed to the correct team tier using a large language model.
- Queue health and recommendations — the system monitors queue state and generates actionable recommendations (escalate, batch, defer, reassign) when workload patterns indicate risk.
- AI worker assistant — agents can open a chat with an AI assistant that has access to the ticket context and a knowledge base of IT runbooks, with responses streamed token-by-token.
Technical Stack
Go 1.22, Gin, Python 3.12, FastAPI, Redis 7, React 18, Vite, nginx, Docker Compose, Groq (LLaMA 3.3 70B), Kubernetes, Helm, Terraform (EKS), ArgoCD, Prometheus
Architecture
Browser
|
| HTTP / SSE
v
React Frontend (nginx :3001)
|--- /api/v1/* ---> Go API Server (:8080)
|--- /api/ai/* ---> Python AI Service (:8000)
|
+---------------+---------------+
| | |
Classifier Recommender Bot (SSE)
(LLaMA 3.3) (LLaMA 3.3) (LLaMA 3.3)
| | |
+----------> Groq API <---------+
|
In-memory BM25
(IT runbook search)
Go API Server <----> Redis <----> Go Worker Pool (2 replicas x 5 goroutines)Key Features
Distributed Task Queue
- Priority scheduling — jobs sorted by priority (P1–P4) then FIFO within the same level
- Automatic retries — configurable max retries per job; exhausted jobs move to dead-letter
- Dead-letter queue — failed jobs preserved with error context; retryable via API
- Stale job recovery — background sweeper rescues jobs stuck in processing for more than 5 minutes
- Horizontal scaling — worker replicas and pool size independently configurable
AI Capabilities
- Zero-shot ticket classification — category, priority, tier, SLA hours, effort estimate, tags
- Workload recommendation engine — analyses queue state and generates up to 4 prioritised actions
- Streaming assistant — LLaMA 3.3 70B responses stream token-by-token via Server-Sent Events
- Knowledge base retrieval — in-memory BM25 search across 10 pre-loaded IT runbooks
- Session memory — Redis-backed conversation history per bot session
- Rate limiting — 30 requests per minute per client
- Prompt injection detection — regex-based guardrails applied before every LLM call
- SLA tracking — breach risk scoring (ok / warning / at_risk / breached) computed in real time
- Keyword fallback — classification and recommendations continue working if the LLM is unavailable
- Demo simulator — generates up to 50 realistic classified tickets to demonstrate queue flood behaviour
Project Structure
.
├── cmd/
│ ├── api/main.go # API server entry point
│ └── worker/main.go # Worker pool entry point; registers all job handlers
├── internal/
│ ├── api/
│ │ ├── handler.go # HTTP handlers (submit, get, list, dead-letter, retry, stats)
│ │ └── router.go # Gin route registration
│ ├── queue/
│ │ ├── job.go # Job model, status constants, priority levels
│ │ ├── queue.go # Queue interface
│ │ └── redis_queue.go # Redis implementation (sorted set + hash + list)
│ └── worker/
│ ├── worker.go # Single worker goroutine
│ └── pool.go # Pool manager and stale-job sweeper
├── rag/
│ ├── main.py # FastAPI app; all /api/ai/* endpoints
│ ├── classifier.py # Ticket classification via Groq with keyword fallback
│ ├── recommender.py # Workload analysis and recommendations with rule-based fallback
│ ├── bot.py # Streaming AI assistant with BM25 runbook context injection
│ ├── knowledge.py # In-memory BM25 knowledge base; 10 IT runbooks
│ ├── sla.py # SLA breach risk calculator
│ ├── simulator.py # Demo ticket flood generator
│ ├── memory.py # Redis-backed bot session memory
│ └── guardrails.py # Prompt injection detection
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Tab layout — Ticket Inbox, Queue Health, AI Bot
│ │ ├── api/index.js # Unified API client (queue + AI endpoints + SSE)
│ │ └── components/
│ │ ├── TicketInbox.jsx # Ticket submission with AI classification
│ │ ├── QueueHealth.jsx # Stats, SLA risk table, AI recommendations
│ │ └── AIBot.jsx # Streaming chat with ticket context
│ └── nginx.conf # Reverse proxy for SPA routing and API forwarding
├── infra/
│ ├── helm/dtq/ # Helm chart for all services
│ ├── terraform/ # EKS cluster, VPC, ECR, IAM
│ └── argocd/ # GitOps application manifests
├── docker-compose.yml
└── go.modRunning Locally
Prerequisites: Docker Desktop, a free Groq API key from https://console.groq.com
git clone https://github.com/apatha32/SmartQueue-ai-helpdesk-optimizer.git
cd SmartQueue-ai-helpdesk-optimizerAdd your key to .env:
GROQ_API_KEY=gsk_your-key-heredocker compose up --build -d- Frontend: http://localhost:3001
- Go API: http://localhost:8080
- AI Service: http://localhost:8000
Using the Application
Ticket Inbox — enter a support request description and click AI Classify to get a category, priority, SLA, and routing decision from LLaMA 3.3 70B. Click Submit to enqueue it. Use the flood simulator to submit up to 50 pre-classified tickets at once.
Queue Health — live stats updated every 5 seconds. SLA risk table shows tickets approaching their deadlines. Click Analyse Queue for AI-generated recommendations on the current workload state.
AI Bot — select an enqueued ticket from the dropdown and ask questions about it. The bot receives the ticket details plus relevant IT runbook excerpts and streams its response in real time.
REST API Reference
Queue (Go API — port 8080)
POST /api/v1/jobs Submit a new job
GET /api/v1/jobs List pending and processing jobs
GET /api/v1/jobs/:id Get a job by ID
GET /api/v1/jobs/dead List dead-letter jobs
POST /api/v1/jobs/:id/retry Re-enqueue a dead-letter job
GET /api/v1/stats Queue counters
GET /health Liveness probeAI Service (FastAPI — port 8000)
POST /api/ai/classify Classify a ticket
POST /api/ai/recommend Analyse queue state and return recommendations
POST /api/ai/bot/chat Streaming chat response (SSE)
POST /api/ai/bot/clear Clear session conversation history
POST /api/ai/simulate Submit N demo tickets
POST /api/ai/sla-check Compute SLA breach risk for a list of jobs
GET /health Liveness probeJob Lifecycle
submit --> pending --> processing --> completed
|
failure
|
failed (retries left) --> re-enqueued
|
retries exhausted
|
dead --> POST /retry --> pendingA background sweeper runs every 30 seconds and re-enqueues any jobs stuck in processing for more than 5 minutes.
Configuration
API Server
REDIS_ADDR— Redis connection address (default:localhost:6379)PORT— HTTP listen port (default:8080)
Worker
REDIS_ADDR— Redis connection addressWORKER_POOL_SIZE— concurrent goroutines per replica (default:5)
AI Service
REDIS_ADDR— Redis connection addressGROQ_API_KEY— required for LLM featuresOPENROUTER_API_KEY— optional fallback ifGROQ_API_KEYis not set
Scaling
docker compose up -d --scale worker=4The Kubernetes manifests in infra/helm/ include a HorizontalPodAutoscaler configured to scale the worker deployment based on Redis queue depth via the Prometheus Adapter.
Stopping
docker compose down # stop containers, preserve volumes
docker compose down -v # stop containers and remove all dataWhat It Does
Support teams face unpredictable ticket volume. SmartQueue addresses this with three capabilities:
- Ticket classification — incoming support requests are automatically categorised, prioritised (P1-P4), assigned an SLA deadline, and routed to the correct team tier using a large language model.
- Queue health and recommendations — the system continuously monitors queue state and generates actionable AI recommendations (escalate, batch, defer, reassign) when workload patterns indicate risk.
- AI worker bot — agents can open a chat with an AI assistant that has access to the ticket context and a knowledge base of IT runbooks, powered by streaming inference.
Technical Stack
Architecture
Browser
|
| HTTP / SSE
v
React Frontend (nginx :3001)
|--- /api/v1/* ---> Go API Server (:8080)
|--- /api/ai/* ---> Python AI Service (:8000)
|
+---------------+---------------+
| | |
Classifier Recommender Bot (SSE)
(LLaMA 3.3) (LLaMA 3.3) (LLaMA 3.3)
| | |
+----------> Groq API <---------+
|
In-memory BM25
(IT runbook search)
Go API Server <----> Redis <----> Go Worker Pool (2 replicas x 5 goroutines)
|
support_ticket handler
email / image_resize / report handlersKey Features
Distributed Task Queue
- Priority scheduling — jobs sorted by priority (P1-P4) then FIFO within the same level
- Automatic retries — configurable max retries per job; exhausted jobs move to dead-letter
- Dead-letter queue — failed jobs preserved with error context; retryable via API
- Stale job recovery — background sweeper rescues jobs stuck in processing for more than 5 minutes
- Horizontal scaling — worker replicas and pool size independently configurable
- Per-job timeout — each handler receives a context deadline; hung jobs are automatically failed
AI Capabilities
- Zero-shot ticket classification — category, priority, tier, SLA hours, effort estimate, tags
- Workload recommendation engine — analyses queue state and generates 4 prioritised actions
- Streaming bot — LLaMA 3.3 70B responses stream token-by-token via Server-Sent Events
- Knowledge base RAG — in-memory BM25 search across 10 pre-loaded IT runbooks; no external vector DB required
- Session memory — Redis-backed conversation history per bot session
- Rate limiting — 30 requests/minute per client
- Prompt injection detection — regex-based guardrails applied before every LLM call
- SLA tracking — breach risk scoring (ok / warning / at_risk / breached) computed in real time
- Demo simulator — generates up to 50 realistic classified tickets to demonstrate queue flood behaviour
Project Structure
.
├── cmd/
│ ├── api/main.go # API server entry point
│ └── worker/main.go # Worker pool entry point; registers all job handlers
├── internal/
│ ├── api/
│ │ ├── handler.go # HTTP handlers (submit, get, list, dead-letter, retry, stats)
│ │ └── router.go # Gin route registration
│ ├── queue/
│ │ ├── job.go # Job model, status constants, priority levels
│ │ ├── queue.go # Queue interface
│ │ └── redis_queue.go # Redis implementation (sorted set + hash + list)
│ └── worker/
│ ├── worker.go # Single worker goroutine
│ └── pool.go # Pool manager and stale-job sweeper
├── rag/
│ ├── main.py # FastAPI app; all /api/ai/* endpoints
├── classifier.py # Ticket classification via Groq (LLaMA 3.3 70B) with keyword fallback
├── recommender.py # Workload analysis and recommendations with rule-based fallback
├── bot.py # Streaming AI assistant with BM25 runbook context injection
├── knowledge.py # In-memory BM25 knowledge base; 10 IT runbooks
│ ├── sla.py # SLA breach risk calculator
│ ├── simulator.py # Demo ticket flood generator
│ ├── memory.py # Redis-backed bot session memory
│ ├── guardrails.py # Prompt injection detection
│ ├── requirements.txt
│ └── Dockerfile
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Tab layout — Ticket Inbox / Queue Health / AI Bot
│ │ ├── App.css # Dark-theme design system
│ │ ├── api/index.js # Unified API client (queue + AI endpoints + SSE)
│ │ └── components/
│ │ ├── TicketInbox.jsx # Ticket submission with AI classification
│ │ ├── QueueHealth.jsx # Stats, SLA risk table, AI recommendations
│ │ └── AIBot.jsx # Streaming chat with ticket context
│ ├── nginx.conf # Reverse proxy for SPA routing and API forwarding
│ ├── Dockerfile # Multi-stage: Vite build then nginx serve
│ └── vite.config.js
├── infra/
│ ├── helm/dtq/ # Helm chart for all services
│ ├── terraform/ # EKS cluster, VPC, ECR, IAM
│ └── argocd/ # GitOps application manifests
├── Dockerfile.api
├── Dockerfile.worker
├── Dockerfile.huggingface # Single-container build for HuggingFace Spaces
├── docker-compose.yml
├── supervisord.hf.conf # Supervisord config for HuggingFace deployment
└── go.modRunning Locally
Prerequisites
- Docker Desktop (includes Docker Compose v2)
- A free Groq API key — sign up at https://console.groq.com, go to API Keys, and create one
Steps
git clone https://github.com/apatha32/SmartQueue-ai-helpdesk-optimizer.git
cd SmartQueue-ai-helpdesk-optimizerAdd your API key to the .env file:
GROQ_API_KEY=gsk_your-key-hereBuild and start all services:
docker compose up --build -dServices start in dependency order: Redis first, then API and workers, then the AI service, then the frontend.
Testing the Application
1. Submit and classify a ticket
Open http://localhost:3001 and go to the Ticket Inbox tab.
Enter a description such as:
Production database is down. All users are getting 500 errors on login.Click AI Classify. The system calls LLaMA 3.3 70B via Groq and returns a classification within ~1-2 seconds. Expected output:
Priority: P1 Category: outage Tier: engineering
SLA: 1 hour Estimated effort: 30 min
Tags: database, production, 500-errorClick Submit to Queue to enqueue the ticket as a support_ticket job.
2. Simulate a ticket flood
On the same tab, set the count to 20 and click Simulate 20 Tickets. This submits 20 pre-defined IT support tickets across all categories and priorities. Each ticket is classified before submission.
3. Check queue health and get AI recommendations
Go to the Queue Health tab.
The stats row updates every 5 seconds. The SLA risk table shows any tickets at risk of breaching their deadline.
Click Analyse Queue to send the current queue state to the recommendation engine. The AI returns:
- A health score (0-100)
- A summary of the current situation
- Up to 4 prioritised actions (escalate / batch / defer / reassign / alert)
4. Use the AI bot to resolve a ticket
Go to the AI Bot tab.
Select a ticket from the dropdown. The bot receives the ticket details plus relevant excerpts from the IT runbook knowledge base.
Ask a question such as:
What are the immediate steps I should take to diagnose this database outage?The response streams in real time using Server-Sent Events. The bot maintains conversation history for the session.
5. Verify via the REST API directly
Check queue stats:
curl http://localhost:8080/api/v1/statsList pending jobs:
curl http://localhost:8080/api/v1/jobsSubmit a job manually:
curl -X POST http://localhost:8080/api/v1/jobs \
-H "Content-Type: application/json" \
-d '{
"type": "support_ticket",
"priority": 1,
"max_retries": 3,
"payload": {
"text": "VPN is not connecting for remote employees",
"category": "access",
"tier": "tier1",
"sla_hours": 4,
"estimated_minutes": 20,
"summary": "VPN connectivity issue affecting remote workers"
}
}'Check a job by ID:
curl http://localhost:8080/api/v1/jobs/<id>List dead-letter jobs:
curl http://localhost:8080/api/v1/jobs/deadRetry a dead-letter job:
curl -X POST http://localhost:8080/api/v1/jobs/<id>/retryClassify a ticket via AI:
curl -X POST http://localhost:8000/api/ai/classify \
-H "Content-Type: application/json" \
-d '{"text": "Cannot access email, getting authentication error", "customer_tier": "enterprise"}'Get queue recommendations:
curl -X POST http://localhost:8000/api/ai/recommend \
-H "Content-Type: application/json" \
-d '{"queue_stats": {"pending_count": 15, "processing_count": 3, "dead_count": 2}}'REST API Reference
Queue Endpoints (Go API — port 8080)
AI Endpoints (FastAPI — port 8000)
Job Lifecycle
submit
|
v
pending --> processing --> completed
|
| failure
v
failed (retries left) --> re-enqueued
|
| retries exhausted
v
dead --> POST /retry --> pendingA background sweeper runs every 30 seconds and re-enqueues any jobs that have been in processing for more than 5 minutes, handling crashed workers.
Configuration Reference
API Server
Worker
AI Service
Scaling
# Run 4 worker replicas
docker compose up -d --scale worker=4
# Increase goroutines per replica
# Set WORKER_POOL_SIZE=10 in docker-compose.ymlThe Kubernetes manifests in infra/helm/ include a HorizontalPodAutoscaler for the worker deployment, configured to scale based on Redis queue depth via the Prometheus Adapter.
Adding a New Job Type
Register a handler in cmd/worker/main.go:
handlers["send_sms"] = func(ctx context.Context, job *queue.Job) error {
phone, _ := job.Payload["phone"].(string)
message, _ := job.Payload["message"].(string)
return sendSMS(ctx, phone, message)
}Submit jobs of that type via the API:
curl -X POST http://localhost:8080/api/v1/jobs \
-H "Content-Type: application/json" \
-d '{"type": "send_sms", "payload": {"phone": "+1234567890", "message": "Your ticket has been resolved"}, "priority": 2}'Stopping the Stack
docker compose down # stop containers, keep volumes
docker compose down -v # stop containers and delete all data