> ## Documentation Index
> Fetch the complete documentation index at: https://system.muzemus.online/llms.txt
> Use this file to discover all available pages before exploring further.

# Prisma schema

> How the Prisma schema is organized and the conventions it follows

## Schema organization

The Prisma schema is a single file at `backend/prisma/schema.prisma`. It is organized into logical sections with comment dividers:

```prisma theme={null}
// ─── Client & Organization ───────────────────────────────
model Client { ... }
model Region { ... }
model Department { ... }
model Store { ... }

// ─── Users & Auth ────────────────────────────────────────
model User { ... }
model UserRole { ... }
model Session { ... }

// ─── Catalog ─────────────────────────────────────────────
model UniformCategory { ... }
model Product { ... }
// ... etc
```

## Schema conventions

| Convention         | Example                                                                             |
| ------------------ | ----------------------------------------------------------------------------------- |
| Primary keys       | `id String @id @default(cuid())`                                                    |
| Timestamps         | `createdAt DateTime @default(now())` + `updatedAt DateTime @updatedAt`              |
| Soft delete        | `active Boolean @default(true)` flag on domain records                              |
| Client scoping     | `clientId String` + `client Client @relation(fields: [clientId], references: [id])` |
| Optional relations | `departmentId String?` + `department Department? @relation(...)`                    |
| Enums              | PascalCase names (`OrderStatus`, `EmploymentType`)                                  |
| JSON fields        | `values Json` for criteria values, `before`/`after Json?` for audit                 |
| Unique constraints | `@@unique([clientId, code])` for client-scoped codes                                |
| Indexes            | `@@index([clientId])` for scoping filters                                           |

## Enum definitions

| Enum                             | Values                                                                                                                                            |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Role`                           | SUPER\_ADMIN, MUZE\_ADMIN, HR, STORE\_MANAGER, EMPLOYEE                                                                                           |
| `AccountStatus`                  | PENDING\_ACTIVATION, ACTIVE, DISABLED                                                                                                             |
| `EmploymentType`                 | PERMANENT, CASUAL, CONTRACT                                                                                                                       |
| `AllocationPhase` / `PeriodType` | INITIAL, REPLACEMENT (allocation items also allow BOTH)                                                                                           |
| `PeriodStatus`                   | PENDING, ACTIVE, RESERVED, CONSUMED, EXHAUSTED, CANCELLED                                                                                         |
| `PaymentType`                    | COMPANY\_PAID, EMPLOYEE\_PAID                                                                                                                     |
| `OrderStatus`                    | PENDING\_APPROVAL, SUBMITTED, APPROVED, REJECTED, CANCELLED, PROCESSING, MANUFACTURING, EMBROIDERY, QUALITY\_CHECK, PACKED, DISPATCHED, DELIVERED |
| `NotificationChannel`            | IN\_APP, EMAIL, WHATSAPP (reserved)                                                                                                               |
| `ProductType`                    | GOLFER, SHIRT, TROUSERS and other garment types                                                                                                   |

## Client

```prisma theme={null}
generator client {
  provider = "prisma-client-js"
  output   = "../node_modules/.prisma/client"
}
```

All backend code imports from `@prisma/client`.

## Database provider

```prisma theme={null}
datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}
```

| Field       | Purpose                                                        |
| ----------- | -------------------------------------------------------------- |
| `url`       | Pooled connection (via PgBouncer) used for application queries |
| `directUrl` | Direct connection used for migrations                          |

## Schema as source of truth

`schema.prisma` is the single source of truth for the database structure. Migration workflow is covered in [Transactions and migrations](/data/transactions-migrations).
