Skip to content

About

Mini Ticket Tracker for tracking support tickets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

58 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Mini Ticket Tracker

A lightweight full-stack ticket tracking application built for the Lodwar Services Mid-Level Full-Stack Developer take-home assessment.

The application provides a REST API and a web interface for creating, viewing, and managing support tickets.

Live Demo: Mini Ticket Tracker

Tech Stack

Frontend

  • React
  • TypeScript
  • Vite

Backend

  • Node.js
  • Express
  • TypeScript
  • Drizzle ORM
  • Zod for request validation

Database

  • PostgreSQL (hosted on Neon)

Testing

  • Node.js built-in test runner
  • Supertest for API integration tests

Project Structure

mini-ticket-tracker/
├── client/                         # React frontend
│   ├── src/
│   │   ├── components/             # Dashboard and UI components
│   │   ├── services/ticketApi.ts   # API requests
│   │   ├── types/ticket.ts         # Frontend ticket types
│   │   └── App.tsx                 # Main application
│   ├── package.json
│   └── vite.config.ts
│
├── server/                         # Express backend
│   ├── src/
│   │   ├── db/
│   │   │   ├── index.ts            # PostgreSQL connection and Drizzle instance
│   │   │   └── schema.ts           # Drizzle database table definitions
│   │   ├── models/
│   │   │   └── ticket.ts           # Types inferred from the Drizzle schema
│   │   ├── schemas/
│   │   │   └── ticketSchema.ts     # Zod request validation schemas
│   │   ├── routes/
│   │   │   └── ticketRoute.ts          # Ticket API route definitions
│   │   ├── controllers/
│   │   │   └── ticketController.ts # HTTP request and response handling
│   │   ├── services/
│   │   │   └── ticketService.ts    # Ticket operations and database queries
│   │   ├── middleware/
│   │   │   └── validate.ts         # Reusable request body validation
│   │   ├── app.ts                  # Express configuration and route registration
│   │   └── server.ts               # HTTP server entry point
│   │
│   ├── drizzle/                    # Database migration files
│   ├── tests/                      # API integration tests
│   ├── drizzle.config.ts           # Drizzle Kit configuration
│   ├── tsconfig.json               # TypeScript compiler configuration
│   ├── package.json                # Backend dependencies and scripts
│   └── .env.example                # Example environment configuration
│
├── .gitignore
└── README.md

Architecture

The backend follows a layered structure to separate HTTP handling, validation, application logic, and database access.

  1. Routes: Map HTTP methods and URL paths to controllers and middleware.
  2. Middleware: Handles reusable request processing, including request body validation.
  3. Controllers: Validate incoming parameters where required, invoke services, and return HTTP responses.
  4. Services: Implement ticket operations and execute database queries through Drizzle ORM.
  5. Schemas: Define request validation rules using Zod.
  6. Database: PostgreSQL stores ticket records, while Drizzle defines the schema and provides type-safe database operations.

The Express application is exported separately from the HTTP server entry point. This allows the API to be tested with Supertest without starting a separate listening server.

Data Model

Each ticket contains the following fields:

Field Description
id Automatically generated primary key
title Required ticket title, up to 200 characters
description Optional ticket description
status open, in_progress, or closed
priority low, medium, or high
created_at Database timestamp generated when the ticket is created

New tickets default to open status and medium priority unless other valid values are provided.

The database uses indexes to support ticket listing and status-filtering query patterns.

Getting Started

Prerequisites

  • Node.js and npm
  • PostgreSQL
  • Git

1. Clone the repository

git clone <repository-url>
cd mini-ticket-tracker

Replace <repository-url> with the actual repository URL.

2. Set up the database

Create a PostgreSQL database named ticket_tracker:

CREATE DATABASE ticket_tracker;

3. Configure the backend

Navigate to the server directory and install dependencies:

cd server
npm install

Create a .env file using .env.example as a reference.

Example configuration:

PORT=3000
DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@localhost:5432/ticket_tracker
CLIENT_URL=http://localhost:5173

Replace the database credentials with your local PostgreSQL configuration.

Do not commit your .env file to version control.

4. Run database migrations

From the server directory:

npm run db:migrate

This applies the existing migration files to the configured database.

When the database schema changes during development, generate a migration using:

npm run db:generate

Review the generated migration before applying it.

5. Start the backend

From the server directory:

npm run dev

The API runs at http://localhost:3000 by default.

A health-check endpoint is available at:

GET /health

Expected response:

{
  "status": "ok"
}

6. Start the frontend

Open a second terminal:

cd client
npm install
npm run dev

Vite displays the local URL where the frontend is available.

Deployment

The application is deployed using Vercel, Render, and Neon.

Frontend: https://mini-ticket-tracker.vercel.app/

Backend: Hosted on Render.

Database: PostgreSQL hosted on Neon.

API Endpoints

All ticket endpoints are prefixed with /tickets.

1. Create a ticket

POST /tickets

Creates a new ticket.

Example request:

{
  "title": "Unable to log in",
  "description": "The user receives an authentication error.",
  "priority": "high"
}

The status and priority fields are optional. If omitted, the database defaults are applied.

Success response: 201 Created

The response contains the created ticket, including its generated ID and creation timestamp.

2. List tickets

GET /tickets

Returns a paginated list of tickets, ordered by creation time with the newest tickets first.

Supported query parameters:

Parameter Description Default
status Filter by open, in_progress, or closed No filter
page Page number, starting at 1 1
limit Number of tickets per page, from 1 to 100 10

Example requests:

GET /tickets
GET /tickets?status=open
GET /tickets?page=2&limit=5
GET /tickets?status=in_progress&page=1&limit=10

Example response:

{
  "data": [
    {
      "id": 1,
      "title": "Unable to log in",
      "description": "The user receives an authentication error.",
      "status": "open",
      "priority": "high",
      "createdAt": "2026-10-11T09:00:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 1,
    "totalPages": 1
  }
}

The example data is illustrative. The actual response depends on the database contents.

Invalid status values and invalid pagination parameters return 400 Bad Request.

3. Update a ticket

PATCH /tickets/:id

Updates a ticket's status, priority, or both.

Example request:

PATCH /tickets/1
Content-Type: application/json
{
  "status": "in_progress",
  "priority": "high"
}

Only status and priority can be updated through this endpoint.

Possible responses:

  • 200 OK — ticket updated successfully.
  • 400 Bad Request — invalid ticket ID, invalid field values, empty body, or unsupported fields.
  • 404 Not Found — ticket does not exist.

4. Get ticket statistics

GET /tickets/stats

Returns ticket counts grouped by status.

Example response:

{
  "open": 8,
  "in_progress": 3,
  "closed": 2
}

All three statuses are included, even when a status has no tickets.

API Documentation

Interactive API documentation is available through Postman:

View Mini Ticket Tracker API Documentation

The documentation provides a reference for the available endpoints, request parameters, request bodies, and expected responses.

Testing

The backend uses Node.js's built-in test runner and Supertest for integration testing.

Run the tests from the server directory:

npm test

The current suite has 27 passing tests.

Test coverage includes:

  • Ticket creation and successful responses.
  • Request validation and invalid input.
  • Listing tickets and status filtering.
  • Pagination behaviour and parameter validation.
  • Updating ticket status and priority.
  • Handling nonexistent tickets and invalid IDs.
  • Ticket statistics grouped by status.

The tests exercise the Express application and PostgreSQL database. They create test records and clean them up after the test suite completes.

Run the tests against a dedicated development or test database, never a production database.

Decisions and Trade-offs

  1. Drizzle ORM: Chosen for its TypeScript support and SQL-like query building, providing type safety without hiding too much of the underlying SQL.

  2. Zod Validation: Used to validate incoming request data at the API boundary, ensuring invalid inputs are rejected before reaching the database.

  3. Layered Architecture: Separating routes, controllers, services, and database access improves maintainability and testability, with a small amount of additional structure.

  4. Database Indexing: Indexes support common filtering and sorting operations, trading additional storage and write overhead for improved query performance.

  5. Pagination: Offset-based pagination keeps the API simple and supports page navigation. Cursor-based pagination could be considered as the dataset grows and deep pagination becomes less efficient.

  6. Database-Side Aggregation: Ticket statistics are calculated in PostgreSQL rather than fetching all tickets into the application, reducing data transfer and application-side processing.

Future Improvements

  • Expand test coverage for edge cases and concurrent requests.
  • Evaluate query performance as the dataset grows.
  • Add configurable sorting and consider cursor-based pagination if needed.
  • Introduce structured logging and monitoring for production observability.

About

Mini Ticket Tracker for tracking support tickets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages