> ## 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.

# Data model overview

> High-level overview of the database schema and entity groups

MUZE uses Prisma ORM with PostgreSQL. The schema is defined in one file:

**File:** `backend/prisma/schema.prisma` (single source of truth, \~30 models)

## Entity groups

```mermaid theme={null}
graph TB
    subgraph Organization["Organization & access"]
        Client
        Region
        Department
        Store
        User
        UserRole
        Session
    end

    subgraph Catalog["Catalog"]
        UniformCategory
        Product
        ProductSize
    end

    subgraph People["People"]
        Employee
        EmployeeSizeProfile
    end

    subgraph Entitlements["Entitlements"]
        EntitlementRuleSet
        EntitlementRuleItem
        EntitlementRuleCriteria
        EntitlementPeriod
    end

    subgraph Orders["Orders"]
        StoreOrder
        Order
        OrderItem
        OrderStatusHistory
    end

    subgraph System["System"]
        Notification
        EmailLog
        AuditLog
        ImportBatch
        SystemSetting
        NumberSequence
    end
```

Supporting models not drawn above: `Account` and `Verification` (better-auth), `NotificationTemplate`, and `InventoryStockLevel`.

## Key relationships

| From               | To                                                                           | Cardinality  | Description                                              |
| ------------------ | ---------------------------------------------------------------------------- | ------------ | -------------------------------------------------------- |
| Client             | Region / Store / Department / UniformCategory / Product / EntitlementRuleSet | 1:N          | Client owns its configuration data                       |
| Region             | Store                                                                        | N:1          | Each store belongs to exactly one region                 |
| Store              | Employee                                                                     | 1:N          | Each employee belongs to one store                       |
| Employee           | EmployeeSizeProfile                                                          | 1:1 (unique) | One sizing profile per employee                          |
| UniformCategory    | Employee                                                                     | 1:N          | Each employee belongs to one category                    |
| EntitlementRuleSet | EntitlementRuleItem / EntitlementRuleCriteria                                | 1:N          | Rule sets contain allocation items and matching criteria |
| Employee + RuleSet | EntitlementPeriod                                                            | 1:N          | One period record per cycle                              |
| Store              | StoreOrder                                                                   | 1:N          | One batch per submission from a store                    |
| Order              | OrderItem / OrderStatusHistory                                               | 1:N          | Items and full status history                            |

The full diagram with cascade behaviour and unique constraints is in [Entity relationships](/data/entity-relationships).

## Client scoping

Most domain models include a `clientId` foreign key for multi-tenant isolation. Client-scoped models:

* `Region`, `Department`, `Store`, `UniformCategory`, `Product`
* `EntitlementRuleSet`
* `Employee` (via store), `Order` (via store/employee)

Models **not** client-scoped: `User`, `UserRole`, `Session`, `AuditLog`, `ImportBatch`, `SystemSetting`: users can hold roles across clients, and system records are org-wide by design.

## Timestamps

Domain models carry `createdAt` and `updatedAt` managed by Prisma:

```prisma theme={null}
model Store {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
```
