How sussman-dev/ticket-management works
Purpose and Entry Points
Repair Ticket Management System manages the full repair lifecycle: intake through diagnosis, quotation, inventory, repair, billing, delivery, and review. The backend is a Node.js/Express REST API started through src/server.ts, composed in src/app.ts, and versioned routes are mounted from src/routes/index.ts. The React client starts at frontend/src/main.tsx, with application routing in frontend/src/app/router.tsx.
Backend Layering and Request Boundary
The API follows a strict Route → Middleware → Controller → Service → Repository → MySQL flow. Route modules expose endpoints; controllers translate HTTP requests; services own workflow/authorization rules; repositories are the only SQL boundary. Representative paths: src/modules/repair-tickets/repair-ticket.route.ts, src/modules/repair-tickets/repair-ticket.service.ts, src/modules/repair-tickets/repair-ticket.repository.ts. Shared error translation, validation, authentication, and authorization sit in src/middlewares/error-handler.middleware.ts, src/middlewares/validation.middleware.ts, and src/middlewares/authentication.middleware.ts.
Identity, Roles, and Session Control
Authentication supports JWT Bearer access tokens and rotating refresh tokens in HttpOnly cookies. Role-based access is enforced before protected controllers, while services additionally constrain ownership and workflow actors. Core implementation: src/modules/auth/auth.service.ts, src/middlewares/authorization.middleware.ts, src/common/constants/roles.ts. User profile and administrative user management are separate from authentication in src/modules/users/user.service.ts.
Repair Ticket Workflow Core
Repair tickets are the central aggregate joining customer/device intake with operational progression. The ticket module manages intake, lifecycle state, attachments, assignment context, and ticket-scoped operations; assignment, diagnosis, quotation, parts, repair actions, delivery, and review extend that aggregate through their services. Core paths: src/modules/repair-tickets/repair-ticket.service.ts, src/modules/ticket-assignments/ticket-assignment.service.ts, src/common/constants/ticket-status.ts.
Technical Work and Inventory Flow
Assigned technicians produce diagnoses, request parts, record repair work, and complete testing. Managers approve/revise diagnoses and quotations; inventory staff maintain parts, decide requests, and fulfill stock. These state-changing processes cross module boundaries and require transactions where multiple records or stock movements change together. Paths: src/modules/diagnoses/diagnosis.service.ts, src/modules/inventory/inventory.service.ts, src/modules/repair-actions/repair-action.service.ts.
Commercial Closure and Customer Communication
Approved quotations are versioned and responded to by the customer, feeding server-calculated invoicing, partial payments, refunds, delivery, closure, and reviews. Notifications provide recipient-scoped read state for workflow events. Paths: src/modules/quotations/quotation.service.ts, src/modules/payments/payment.service.ts, src/modules/deliveries/delivery.service.ts, src/modules/notifications/notification.service.ts.
Persistence, Infrastructure, and Frontend Boundary
MySQL 8 is accessed through mysql2/promise and raw parameterized SQL; schema, migrations, and seed data define the persistence contract in src/database/schema.sql, src/database/migrations/, and src/config/database.ts. Transaction coordination is centralized in src/common/utils/transaction.util.ts; image handling is abstracted by src/common/services/image-storage.service.ts. The Vite/React frontend calls the API through its shared client and token store, then uses TanStack-style query caching and route guards: frontend/src/lib/api/client.ts, frontend/src/app/query-client.ts, frontend/src/routes/route-guards.tsx.
Main entry points: repair-ticket.service.ts Repair tickets · repair-ticket.repository.ts Repositories · diagnosis.service.ts Technical work · router.tsx App routing
Components 20
React Client
- Vite entry
frontend/src/main.tsx - App routing · Provides screens and protected navigation.
frontend/src/app/router.tsx - Route guards
frontend/src/routes/route-guards.tsx - API client · Manages API calls and token state.
frontend/src/lib/api/client.ts - Query cache
frontend/src/app/query-client.ts
Express API
- Server entry
src/server.ts - Express app
src/app.ts - Versioned API routes
src/routes/index.ts - Request middleware · Validates requests, authenticates JWTs, authorizes roles, and translates errors.
src/middlewares/authentication.middleware.ts - Controllers · Translate HTTP requests into service calls.
Repair Workflow
- Identity and users · Issues rotating sessions and manages profiles and administrative users.
src/modules/auth/auth.service.ts - Repair tickets · Central aggregate for intake, lifecycle, attachments, and ticket-scoped operations.
src/modules/repair-tickets/repair-ticket.service.ts - Technical work · Coordinates assignment, diagnosis, parts, repair actions, and testing.
src/modules/diagnoses/diagnosis.service.ts - Inventory · Maintains parts, approves requests, and fulfills stock.
src/modules/inventory/inventory.service.ts - Commercial closure · Handles quotations, payments, delivery, closure, and reviews.
src/modules/quotations/quotation.service.ts - Notifications · Tracks recipient-scoped workflow messages and read state.
src/modules/notifications/notification.service.ts
Persistence
- Repositories · Only layer issuing parameterized SQL.
src/modules/repair-tickets/repair-ticket.repository.ts - Transaction coordinator · Coordinates atomic multi-record and stock changes.
src/common/utils/transaction.util.ts - MySQL 8 · Schema, migrations, and seed data define the persistence contract.
src/database/schema.sql - Image storage
src/common/services/image-storage.service.ts
Connections 25
- Vite entry → App routing: starts
- App routing → Route guards: protects routes with
- App routing → Query cache: uses
- Query cache → API client: fetches through
- API client → Versioned API routes: REST requests
- Server entry → Express app: starts
- Express app → Versioned API routes: mounts
- Versioned API routes → Request middleware: passes through
- Request middleware → Controllers: admits requests to
- Controllers → Identity and users: identity requests
- Controllers → Repair tickets: ticket requests
- Repair tickets → Technical work: extends ticket workflow
- Technical work → Inventory: requests and fulfills parts
- Repair tickets → Commercial closure: feeds approved work
- Repair tickets → Notifications: emits workflow events
- Technical work → Transaction coordinator: uses
- Inventory → Transaction coordinator: uses
- Commercial closure → Transaction coordinator: uses
- Identity and users → Repositories: persists through
- Repair tickets → Repositories: persists through
- Technical work → Repositories: persists through
- Inventory → Repositories: persists through
- Commercial closure → Repositories: persists through
- Repositories → MySQL 8: parameterized SQL
- Repair tickets → Image storage: stores attachments