WebNest
Team/Md Abir Hossain/teamBinaryDIU-ticket-analyzer

Repository

teamBinaryDIU-ticket-analyzer

View on GitHub ↗
TypeScript0 stars0 forks

README

AI Ticket Analyzer

An intelligent support ticket management platform that uses Hugging Face machine learning models to automatically classify, prioritize, and summarize customer support tickets.

Built with React, FastAPI, PostgreSQL, and Docker — designed for workshop demos, production deployment on Ubuntu VMs, and real-world support workflows.


Table of Contents


Overview

AI Ticket Analyzer helps support teams triage incoming tickets faster by applying NLP models at submission time. When a ticket is created, the system:

  1. Classifies it into a category (Billing, Technical, Account, etc.)
  2. Assigns a priority level (Low → Critical)
  3. Generates a concise AI summary
  4. Scores confidence for each prediction

A modern SaaS-style React dashboard provides ticket management, filtering, analytics, and one-click AI analysis — all backed by a clean-architecture FastAPI service and PostgreSQL database.

LayerTechnology
FrontendReact 18, TypeScript, Vite, TailwindCSS, Axios, React Router
BackendFastAPI, SQLAlchemy (async), Alembic, Pydantic
DatabasePostgreSQL 16
AIHugging Face Transformers (DistilBERT + DistilBART)
InfrastructureDocker Compose, Nginx, Let's Encrypt

Features

Ticket Management

  • Create, read, update, and delete support tickets
  • Paginated ticket table with search and filters (category, priority, analyzed status)
  • Ticket detail page with full description and action buttons

AI Analysis

  • Automatic classification on ticket submission
  • On-demand re-analysis for existing tickets
  • Stateless preview endpoint (no database write)
  • Three inference modes: local, api, auto (with keyword fallback)
  • Confidence scoring with visual progress bars

Dashboard

  • Real-time stats: total tickets, analyzed today, average confidence
  • Bar charts by category and priority
  • Recent tickets table with quick navigation
  • One-click demo data seeding

Developer Experience

  • OpenAPI / Swagger docs at /docs
  • Docker Compose for local and production
  • Alembic database migrations
  • Pytest test suite
  • VM deployment scripts with SSL automation

UI / UX

  • Modern SaaS design with sidebar navigation
  • Responsive layout (mobile, tablet, desktop)
  • Lucide icons, Inter font, indigo brand palette
  • Empty states, loading spinners, error handling

Architecture

System Diagram

┌─────────────────────────────────────────────────────────────────┐
│                         Client (Browser)                        │
└──────────────────────────────┬──────────────────────────────────┘
                               │ HTTPS
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│              Host Nginx (production VM — SSL termination)       │
└──────────────────────────────┬──────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│  Frontend Container (React + Nginx)                             │
│  • Serves static SPA                                            │
│  • Proxies /api/* → backend                                   │
└──────────────────────────────┬──────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│  Backend Container (FastAPI)                                    │
│  ┌──────────┐  ┌────────────┐  ┌──────────────┐  ┌──────────┐ │
│  │ API v1   │→ │ Services   │→ │ Repositories │→ │ Models   │ │
│  └──────────┘  └─────┬──────┘  └──────────────┘  └──────────┘ │
│                      │                                          │
│                      ▼                                          │
│               ┌──────────────┐                                  │
│               │ AI Pipeline  │                                  │
│               │ DistilBERT   │                                  │
│               │ DistilBART   │                                  │
│               └──────────────┘                                  │
└──────────────────────────────┬──────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│  PostgreSQL 16                                                  │
│  • tickets table (single-table design)                           │
│  • ENUM types, indexes, full-text search                         │
└─────────────────────────────────────────────────────────────────┘

Backend Layers (Clean Architecture)

Presentation   →  app/api/v1/          (route handlers)
DTO            →  app/schemas/         (Pydantic models)
Business       →  app/services/        (ticket + analysis logic)
Data Access    →  app/repositories/    (SQLAlchemy queries)
ORM            →  app/models/          (database models)
Infrastructure →  app/db/, config.py   (engine, settings)
AI             →  app/ai/              (Hugging Face pipeline)
Core           →  app/core/            (exceptions, handlers)

AI Pipeline

Title + Description
       │
       ▼
  Preprocess (truncate, format)
       │
       ├─► Zero-shot (DistilBERT) ──► Category + score
       ├─► Zero-shot (DistilBERT) ──► Priority + score
       └─► Summarization (DistilBART) ► Summary
       │
       ▼
  Confidence scorer ──► ai_confidence (0.0 – 1.0)

Frontend Routes

PathPageDescription
/DashboardStats, charts, recent tickets
/ticketsTicket ListFilterable data table
/tickets/:idTicket DetailDescription + inline AI results
/tickets/:id/aiAI ResultsDedicated analysis view
/createCreate TicketForm with submit & preview
/ai-resultsAI PreviewStateless analysis results

Database Design

Entity: tickets

Single-table design — AI analysis fields are stored inline on the ticket row (no separate analysis table).

ColumnTypeDescription
idUUIDPrimary key (gen_random_uuid())
titleVARCHAR(200)Ticket title (min 3 chars)
descriptionTEXTFull description (min 10 chars)
categoryticket_category ENUMAI category — NULL until analyzed
priorityticket_priority ENUMAI priority — NULL until analyzed
summaryTEXTAI-generated summary
ai_confidenceNUMERIC(5,4)Blended confidence score (0–1)
created_atTIMESTAMPTZCreation timestamp
updated_atTIMESTAMPTZAuto-updated on every change

ENUM Types

ticket_category: Billing, Technical, Account, Feature Request, Other

ticket_priority: low, medium, high, critical

Indexes

IndexPurpose
idx_tickets_categoryFilter by category
idx_tickets_priorityFilter by priority
idx_tickets_created_at_descRecent-first listing
idx_tickets_pendingPartial — unanalyzed tickets only
idx_tickets_analyzedPartial — analyzed tickets for reporting
idx_tickets_ftsGIN full-text search on title + description

ER Diagram

┌─────────────────────────────────────────────┐
│                  tickets                     │
├─────────────────────────────────────────────┤
│ PK  id              UUID                    │
│     title           VARCHAR(200)  NOT NULL  │
│     description     TEXT          NOT NULL  │
│     category        ENUM          NULLABLE  │
│     priority        ENUM          NULLABLE  │
│     summary         TEXT          NULLABLE  │
│     ai_confidence   NUMERIC(5,4)  NULLABLE  │
│     created_at      TIMESTAMPTZ     NOT NULL  │
│     updated_at      TIMESTAMPTZ     NOT NULL  │
└─────────────────────────────────────────────┘

Full reference schema: backend/db/schema.sql

Migrations managed by Alembic: backend/alembic/versions/


Installation

Prerequisites

ToolVersion
Node.js20+
Python3.12
PostgreSQL16+
Docker24+ (optional)
Docker Composev2+ (optional)

1. Clone the repository

git clone https://github.com/YOUR_ORG/teamBinaryDIU-ticket-analyzer.git
cd teamBinaryDIU-ticket-analyzer

2. Configure environment

cp .env.example .env

Edit .env as needed. Key variables:

VariableDescription
POSTGRES_USERDatabase username
POSTGRES_PASSWORDDatabase password
POSTGRES_DBDatabase name
DATABASE_URLAsync SQLAlchemy connection string
CORS_ORIGINSAllowed frontend origins
AI_INFERENCE_MODElocal | api | auto
HF_API_TOKENHugging Face token (optional)

3. Backend (local)

cd backend
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt
alembic upgrade head
uvicorn app.main:app --reload --port 8000

4. Frontend (local)

cd frontend
npm install
npm run dev
ServiceURL
Frontendhttp://localhost:5173
Backend APIhttp://localhost:8000
Swagger Docshttp://localhost:8000/docs

Docker Setup

Works on macOS (Intel + Apple Silicon), Linux, and Windows (Docker Desktop + WSL2).

Full cross-platform guide: docs/DOCKER_CROSS_PLATFORM.md

Production (single command)

cp .env.example .env
docker compose up --build
ServiceURLContainer
Frontendhttp://localhost:80ticket-analyzer-ui
Backendhttp://localhost:8000ticket-analyzer-api
API Docshttp://localhost:8000/docs
PostgreSQLlocalhost:5432ticket-analyzer-db

Development (hot reload)

docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
ServiceURL
Frontendhttp://localhost:5173
Backendhttp://localhost:8000

Docker files

FilePurpose
docker-compose.ymlProduction stack (3 services)
docker-compose.dev.ymlDev overrides (volume mounts, reload)
backend/DockerfileMulti-stage: development / production
frontend/DockerfileMulti-stage: development / build / production
deploy/docker-compose.prod.ymlVM overrides (localhost-only ports)

Useful commands

# View logs
docker compose logs -f

# Stop all services
docker compose down

# Reset database (destructive)
docker compose down -v

# Rebuild a single service
docker compose up -d --build backend

Deployment

Production deployment on Ubuntu 22.04/24.04 with host Nginx reverse proxy and Let's Encrypt SSL.

Full guide: deploy/DEPLOYMENT.md

Quick start (VM)

# 1. VM setup + Docker
sudo bash deploy/scripts/vm-setup.sh
sudo bash deploy/scripts/install-docker.sh

# 2. Configure
cp deploy/.env.production.example .env
nano .env   # set DOMAIN, passwords, CORS

# 3. Deploy containers
bash deploy/scripts/deploy.sh

# 4. Nginx + SSL
sudo bash deploy/scripts/nginx-http-setup.sh
sudo bash deploy/scripts/ssl-setup.sh

Production architecture

Internet → Nginx :443 (SSL) → Docker frontend :8080 → /api → backend :8000 → postgres

All Docker ports bind to 127.0.0.1 — only host Nginx is exposed publicly.

VM requirements

ResourceMinimum
OSUbuntu 22.04 / 24.04 LTS
CPU2 vCPU
RAM4 GB
Disk20 GB
Ports22, 80, 443

API Documentation

Interactive docs available at http://localhost:8000/docs (Swagger UI) and /redoc.

Base URL: /api/v1

Health

MethodEndpointDescription
GET/healthLiveness check
GET/health/readyReadiness check (includes DB ping)

Response GET /health:

{ "status": "ok" }

Response GET /health/ready:

{ "status": "ready", "database": "connected" }

Categories

MethodEndpointDescription
GET/categoriesList supported ticket categories

Tickets

MethodEndpointDescription
POST/ticketsCreate a new ticket
GET/ticketsList tickets (paginated, filterable)
GET/tickets/{id}Get ticket by ID
PATCH/tickets/{id}Update ticket title/description
DELETE/tickets/{id}Delete ticket
POST/tickets/{id}/analyzeRun AI analysis and persist results

Create ticket POST /tickets:

{
  "title": "Unable to login",
  "description": "User cannot login after password reset. Error 401 shown."
}

Response 201 Created:

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "title": "Unable to login",
  "description": "User cannot login after password reset. Error 401 shown.",
  "category": null,
  "priority": null,
  "summary": null,
  "ai_confidence": null,
  "created_at": "2026-06-19T10:00:00Z",
  "updated_at": "2026-06-19T10:00:00Z"
}

List tickets GET /tickets:

Query paramTypeDescription
pageintPage number (default: 1)
page_sizeintItems per page (1–100, default: 20)
analyzedboolFilter by analysis status
categorystringFilter by category
prioritystringFilter by priority
searchstringFull-text search

Response:

{
  "items": [ { "...ticket" } ],
  "total": 42,
  "page": 1,
  "page_size": 20
}

Analyze ticket POST /tickets/{id}/analyze:

Persists AI results on the ticket row and returns the updated ticket with category, priority, summary, and ai_confidence populated.


AI (Stateless)

MethodEndpointDescription
POST/ai/analyzeAnalyze text without saving to database

Request:

{
  "title": "URGENT: Payment failed",
  "description": "Money was deducted from my card but payment shows as failed."
}

Response:

{
  "category": "Billing",
  "priority": "High",
  "summary": "Customer reports payment failure despite card charge.",
  "confidence": 0.87
}

Dashboard

MethodEndpointDescription
GET/dashboard/statsAggregated metrics
GET/dashboard/recentLatest tickets
POST/dashboard/seedLoad demo tickets

Response GET /dashboard/stats:

{
  "total_tickets": 15,
  "analyzed_today": 3,
  "by_category": { "Billing": 5, "Technical": 4, "Account": 3 },
  "by_priority": { "high": 4, "medium": 6, "low": 3, "critical": 2 },
  "avg_confidence": 0.84
}

Screenshots

Add screenshots to docs/screenshots/ and uncomment the images below.

Dashboard

<!-- ![Dashboard](docs/screenshots/dashboard.png) -->

Dashboard with stats cards, category/priority charts, and recent tickets table.

Ticket List

<!-- ![Ticket List](docs/screenshots/ticket-list.png) -->

Paginated ticket table with search, category, priority, and status filters.

Create Ticket

<!-- ![Create Ticket](docs/screenshots/create-ticket.png) -->

Ticket creation form with submit-and-analyze and preview-only options.

Ticket Detail

<!-- ![Ticket Detail](docs/screenshots/ticket-detail.png) -->

Ticket detail page showing description, badges, and AI analysis panel.

AI Results

<!-- ![AI Results](docs/screenshots/ai-results.png) -->

AI analysis results with category, priority, summary, and confidence score.


Project Structure

teamBinaryDIU-ticket-analyzer/
├── backend/                    # FastAPI application
│   ├── app/
│   │   ├── api/v1/             # REST route handlers
│   │   ├── ai/                 # Hugging Face inference pipeline
│   │   ├── core/               # Exceptions, error handlers
│   │   ├── db/                 # SQLAlchemy engine & session
│   │   ├── models/             # ORM models
│   │   ├── repositories/       # Data access layer
│   │   ├── schemas/            # Pydantic DTOs
│   │   ├── services/           # Business logic
│   │   ├── config.py           # Environment settings
│   │   └── main.py             # Application entry point
│   ├── alembic/                # Database migrations
│   ├── db/schema.sql           # Reference PostgreSQL schema
│   ├── scripts/                # Seed & Docker entrypoint
│   ├── tests/                  # Pytest suite
│   ├── Dockerfile
│   └── requirements.txt
│
├── frontend/                   # React SPA
│   ├── src/
│   │   ├── api/                # Axios HTTP clients
│   │   ├── components/         # UI, layout, tickets, dashboard
│   │   ├── hooks/              # Data-fetching hooks
│   │   ├── pages/              # Route-level pages
│   │   ├── routes/             # React Router config
│   │   └── types/              # TypeScript interfaces
│   ├── Dockerfile
│   └── nginx.conf              # Container reverse proxy
│
├── deploy/                     # Production VM deployment
│   ├── DEPLOYMENT.md           # Full deployment guide
│   ├── docker-compose.prod.yml
│   ├── nginx/                  # Host Nginx configs
│   └── scripts/                # Setup & deploy automation
│
├── docs/
│   └── screenshots/            # README screenshots
│
├── docker-compose.yml          # Production Docker stack
├── docker-compose.dev.yml      # Development overrides
├── .env.example                # Local environment template
└── README.md                   # This file

AI / Hugging Face

Models

TaskModelSize
Category + Prioritytypeform/distilbert-base-uncased-mnli~250 MB
Summarysshleifer/distilbart-cnn-12-6~300 MB

Both are CPU-optimized Distil variants — no GPU required.

Inference Modes

ModeBehaviorToken Required
localCPU inference inside Docker containerNo
apiHugging Face Inference APIYes (HF_API_TOKEN)
autoTry local → API → keyword fallbackOptional

Set via AI_INFERENCE_MODE in .env.

Confidence Scoring

SignalWeight
Category (zero-shot softmax)50%
Priority (zero-shot + keywords)30%
Summary (source heuristic)20%

Full design document: backend/app/ai/AI_DESIGN.md


Future Improvements

Product

  • User authentication and role-based access (admin, agent, viewer)
  • Ticket assignment and agent workload balancing
  • Email / webhook ingestion for automatic ticket creation
  • Ticket status workflow (open → in progress → resolved → closed)
  • Comments and internal notes on tickets
  • Export tickets to CSV / PDF

AI / ML

  • Fine-tune models on domain-specific support data
  • Multi-language ticket support
  • Sentiment analysis and urgency detection
  • Suggested reply generation for agents
  • Model versioning and A/B testing
  • GPU inference option for higher throughput

Infrastructure

  • Kubernetes manifests (Helm chart)
  • CI/CD pipeline (GitHub Actions)
  • Centralized logging (ELK / Loki)
  • Metrics and alerting (Prometheus + Grafana)
  • Redis caching for dashboard stats
  • Database read replicas for scale

Frontend

  • Dark mode toggle
  • Real-time updates via WebSockets
  • Bulk ticket actions (analyze, delete, export)
  • Advanced analytics dashboard
  • Keyboard shortcuts for power users

Demo Flow

See docs/COMPETITION_REVIEW.md for judge evaluation and a 2-minute demo script.

  1. Open the dashboard at http://localhost (or your deployed domain)
  2. Click Load Demo Data or create a ticket manually
  3. Submit: "URGENT: Payment failed but money was deducted from my card"
  4. View AI classification: Billing, High/Critical, with summary
  5. Check dashboard stats and charts update in real time

License

This project was built for educational and workshop purposes. See repository license for terms.


<p align="center"> Built with React · FastAPI · PostgreSQL · Docker · Hugging Face </p>
← Back to profile