# sussman-dev/ticket-management architecture

> Architecture diagram of the GitHub repository sussman-dev/ticket-management, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sussman-dev/ticket-management
- Repository: https://github.com/sussman-dev/ticket-management

## Overview

#### 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: [`src/modules/repair-tickets/repair-ticket.service.ts`](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/repair-tickets/repair-ticket.service.ts) (Repair tickets), [`src/modules/repair-tickets/repair-ticket.repository.ts`](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/repair-tickets/repair-ticket.repository.ts) (Repositories), [`src/modules/diagnoses/diagnosis.service.ts`](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/diagnoses/diagnosis.service.ts) (Technical work), [`frontend/src/app/router.tsx`](https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/app/router.tsx) (App routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React Client"]
  node_web_entry["Vite entry<br/>React bootstrap<br/>[main.tsx]"]
  node_web_router["App routing<br/>route layer<br/>[router.tsx]"]
  node_route_guards["Route guards<br/>auth guard<br/>[route-guards.tsx]"]
  node_api_client["API client<br/>HTTP client<br/>[client.ts]"]
  node_query_cache["Query cache<br/>client state<br/>[query-client.ts]"]
end

subgraph group_api["Express API"]
  node_server["Server entry<br/>Node entry<br/>[server.ts]"]
  node_app["Express app<br/>application composition<br/>[app.ts]"]
  node_api_routes["Versioned API routes<br/>route registry<br/>[index.ts]"]
  node_request_security["Request middleware<br/>validation and access control"]
  node_controllers["Controllers<br/>HTTP adapter"]
end

subgraph group_workflow["Repair Workflow"]
  node_auth_users["Identity and users<br/>auth and user services<br/>[auth.service.ts]"]
  node_ticket_core["Repair tickets<br/>ticket service"]
  node_technical_work["Technical work<br/>operations services"]
  node_inventory["Inventory"]
  node_commercial_closure["Commercial closure<br/>commercial services"]
  node_notifications["Notifications<br/>notification service"]
end

subgraph group_data["Persistence"]
  node_repositories["Repositories<br/>SQL boundary"]
  node_transactions["Transaction coordinator<br/>transaction utility"]
  node_mysql[("MySQL 8<br/>relational database<br/>[schema.sql]")]
  node_image_storage["Image storage<br/>storage abstraction"]
end

node_web_entry -->|"starts"| node_web_router
node_web_router -->|"protects routes with"| node_route_guards
node_web_router -->|"uses"| node_query_cache
node_query_cache -->|"fetches through"| node_api_client
node_api_client -->|"REST requests"| node_api_routes
node_server -->|"starts"| node_app
node_app -->|"mounts"| node_api_routes
node_api_routes -->|"passes through"| node_request_security
node_request_security -->|"admits requests to"| node_controllers
node_controllers -->|"identity requests"| node_auth_users
node_controllers -->|"ticket requests"| node_ticket_core
node_ticket_core -->|"extends ticket workflow"| node_technical_work
node_technical_work -->|"requests and fulfills parts"| node_inventory
node_ticket_core -->|"feeds approved work"| node_commercial_closure
node_ticket_core -->|"emits workflow events"| node_notifications
node_technical_work -->|"uses"| node_transactions
node_inventory -->|"uses"| node_transactions
node_commercial_closure -->|"uses"| node_transactions
node_auth_users -->|"persists through"| node_repositories
node_ticket_core -->|"persists through"| node_repositories
node_technical_work -->|"persists through"| node_repositories
node_inventory -->|"persists through"| node_repositories
node_commercial_closure -->|"persists through"| node_repositories
node_repositories -->|"parameterized SQL"| node_mysql
node_ticket_core -->|"stores attachments"| node_image_storage

click node_web_entry "https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/main.tsx"
click node_web_router "https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/app/router.tsx"
click node_route_guards "https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/routes/route-guards.tsx"
click node_api_client "https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/lib/api/client.ts"
click node_query_cache "https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/app/query-client.ts"
click node_server "https://github.com/sussman-dev/ticket-management/blob/main/src/server.ts"
click node_app "https://github.com/sussman-dev/ticket-management/blob/main/src/app.ts"
click node_api_routes "https://github.com/sussman-dev/ticket-management/blob/main/src/routes/index.ts"
click node_request_security "https://github.com/sussman-dev/ticket-management/blob/main/src/middlewares/authentication.middleware.ts"
click node_auth_users "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/auth/auth.service.ts"
click node_ticket_core "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/repair-tickets/repair-ticket.service.ts"
click node_technical_work "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/diagnoses/diagnosis.service.ts"
click node_inventory "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/inventory/inventory.service.ts"
click node_commercial_closure "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/quotations/quotation.service.ts"
click node_notifications "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/notifications/notification.service.ts"
click node_repositories "https://github.com/sussman-dev/ticket-management/blob/main/src/modules/repair-tickets/repair-ticket.repository.ts"
click node_transactions "https://github.com/sussman-dev/ticket-management/blob/main/src/common/utils/transaction.util.ts"
click node_mysql "https://github.com/sussman-dev/ticket-management/blob/main/src/database/schema.sql"
click node_image_storage "https://github.com/sussman-dev/ticket-management/blob/main/src/common/services/image-storage.service.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_entry,node_web_router,node_route_guards,node_api_client,node_query_cache toneBlue
class node_server,node_app,node_api_routes,node_request_security,node_controllers toneAmber
class node_auth_users,node_ticket_core,node_technical_work,node_inventory,node_commercial_closure,node_notifications toneMint
class node_repositories,node_transactions,node_mysql,node_image_storage toneRose
```

## Components

### React Client

- [Vite entry](https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/main.tsx): React bootstrap · `frontend/src/main.tsx`
- [App routing](https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/app/router.tsx): route layer · Provides screens and protected navigation. · `frontend/src/app/router.tsx`
- [Route guards](https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/routes/route-guards.tsx): auth guard · `frontend/src/routes/route-guards.tsx`
- [API client](https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/lib/api/client.ts): HTTP client · Manages API calls and token state. · `frontend/src/lib/api/client.ts`
- [Query cache](https://github.com/sussman-dev/ticket-management/blob/main/frontend/src/app/query-client.ts): client state · `frontend/src/app/query-client.ts`

### Express API

- [Server entry](https://github.com/sussman-dev/ticket-management/blob/main/src/server.ts): Node entry · `src/server.ts`
- [Express app](https://github.com/sussman-dev/ticket-management/blob/main/src/app.ts): application composition · `src/app.ts`
- [Versioned API routes](https://github.com/sussman-dev/ticket-management/blob/main/src/routes/index.ts): route registry · `src/routes/index.ts`
- [Request middleware](https://github.com/sussman-dev/ticket-management/blob/main/src/middlewares/authentication.middleware.ts): validation and access control · Validates requests, authenticates JWTs, authorizes roles, and translates errors. · `src/middlewares/authentication.middleware.ts`
- **Controllers**: HTTP adapter · Translate HTTP requests into service calls.

### Repair Workflow

- [Identity and users](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/auth/auth.service.ts): auth and user services · Issues rotating sessions and manages profiles and administrative users. · `src/modules/auth/auth.service.ts`
- [Repair tickets](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/repair-tickets/repair-ticket.service.ts): ticket service · Central aggregate for intake, lifecycle, attachments, and ticket-scoped operations. · `src/modules/repair-tickets/repair-ticket.service.ts`
- [Technical work](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/diagnoses/diagnosis.service.ts): operations services · Coordinates assignment, diagnosis, parts, repair actions, and testing. · `src/modules/diagnoses/diagnosis.service.ts`
- [Inventory](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/inventory/inventory.service.ts): inventory service · Maintains parts, approves requests, and fulfills stock. · `src/modules/inventory/inventory.service.ts`
- [Commercial closure](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/quotations/quotation.service.ts): commercial services · Handles quotations, payments, delivery, closure, and reviews. · `src/modules/quotations/quotation.service.ts`
- [Notifications](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/notifications/notification.service.ts): notification service · Tracks recipient-scoped workflow messages and read state. · `src/modules/notifications/notification.service.ts`

### Persistence

- [Repositories](https://github.com/sussman-dev/ticket-management/blob/main/src/modules/repair-tickets/repair-ticket.repository.ts): SQL boundary · Only layer issuing parameterized SQL. · `src/modules/repair-tickets/repair-ticket.repository.ts`
- [Transaction coordinator](https://github.com/sussman-dev/ticket-management/blob/main/src/common/utils/transaction.util.ts): transaction utility · Coordinates atomic multi-record and stock changes. · `src/common/utils/transaction.util.ts`
- [MySQL 8](https://github.com/sussman-dev/ticket-management/blob/main/src/database/schema.sql): relational database · Schema, migrations, and seed data define the persistence contract. · `src/database/schema.sql`
- [Image storage](https://github.com/sussman-dev/ticket-management/blob/main/src/common/services/image-storage.service.ts): storage abstraction · `src/common/services/image-storage.service.ts`

## Connections

- 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
