> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/development/locations.md).

# Locations

Locations, Devices, and User Management

Audience: Programmer

## Overview

pyck provides a comprehensive location and device management system within the Management Service. This system enables physical warehouse layout mapping, device tracking, user check-in/check-out functionality, and inventory repository association with specific locations.

## Core Entities

### Location

Represents a physical area within the warehouse (e.g., workstation, zone, dock).

| Field        | Type   | Description                        |
| ------------ | ------ | ---------------------------------- |
| `id`         | UUID   | Unique identifier                  |
| `name`       | String | Location name (unique per tenant)  |
| `tenantID`   | UUID   | Owning tenant                      |
| `dataTypeID` | UUID   | Optional custom data type          |
| `data`       | Map    | Custom fields defined by data type |

### Device

Represents a physical device (scanner, tablet, workstation terminal).

| Field        | Type   | Description                        |
| ------------ | ------ | ---------------------------------- |
| `id`         | UUID   | Unique identifier                  |
| `name`       | String | Device name (unique per tenant)    |
| `tenantID`   | UUID   | Owning tenant                      |
| `dataTypeID` | UUID   | Optional custom data type          |
| `data`       | Map    | Custom fields defined by data type |

### DeviceLocation

Associates a device with a location. A device can only be assigned to one location at a time.

| Field        | Type | Description         |
| ------------ | ---- | ------------------- |
| `id`         | UUID | Unique identifier   |
| `deviceID`   | UUID | Associated device   |
| `locationID` | UUID | Associated location |

### DeviceUser

Tracks which user is currently checked-in to a device. Only one user can be checked-in to a device at a time.

| Field      | Type | Description       |
| ---------- | ---- | ----------------- |
| `id`       | UUID | Unique identifier |
| `deviceID` | UUID | Associated device |
| `userID`   | UUID | Checked-in user   |

## Entity Relationships

```
Location ──────────────────────────────────────────┐
    │                                              │
    ▼                                              │
DeviceLocation ◄─── Device ◄─── DeviceUser ───► User
                        │
                        │
                        ▼
              InventoryRepository
                 (location_id)
```

Key relationships:

* **Location → DeviceLocation**: One-to-many (a location can have multiple devices)
* **Device → DeviceLocation**: One-to-one (a device is at one location)
* **Device → DeviceUser**: One-to-one (only one user per device)
* **User → DeviceUser**: One-to-many (a user can have check-in history)
* **Location → Repository**: One-to-many (repositories can reference a location)

## GraphQL Operations

### Creating a Location

```graphql
mutation CreateLocation($input: CreateLocationInput!) {
  createLocation(input: $input) {
    location {
      id
      name
      data
    }
  }
}
```

**Variables:**

```json
{
  "input": {
    "name": "Workstation-A1"
  }
}
```

### Creating a Device

```graphql
mutation CreateDevice($input: CreateDeviceInput!) {
  createDevice(input: $input) {
    device {
      id
      name
      data
    }
  }
}
```

**Variables:**

```json
{
  "input": {
    "name": "Scanner-001"
  }
}
```

### Assigning a Device to a Location

```graphql
mutation SetDeviceLocation($input: CreateDeviceLocationInput!) {
  setDeviceLocation(input: $input) {
    DeviceLocation {
      id
      deviceID
      locationID
    }
  }
}
```

**Variables:**

```json
{
  "input": {
    "deviceID": "device-uuid-here",
    "locationID": "location-uuid-here"
  }
}
```

To remove a device from its location:

```graphql
mutation UnsetDeviceLocation($id: ID!) {
  unsetDeviceLocation(id: $id) {
    deletedID
  }
}
```

### User Check-In

When a user starts working at a device:

```graphql
mutation CheckInUserDevice($input: CheckInUserDeviceInput!) {
  checkInUserDevice(input: $input) {
    deviceUser {
      id
      deviceID
      userID
    }
  }
}
```

**Variables:**

```json
{
  "input": {
    "deviceID": "device-uuid-here"
  }
}
```

The `userID` is automatically derived from the authenticated user's token.

### User Check-Out

When a user finishes working at a device:

```graphql
mutation CheckOutUserDevice($input: CheckOutUserDeviceInput!) {
  checkOutUserDevice(input: $input) {
    deviceUser {
      id
      deviceID
      userID
    }
  }
}
```

**Variables:**

```json
{
  "input": {
    "deviceID": "device-uuid-here"
  }
}
```

### Assigning a Location to a Repository

When creating or updating an inventory repository, you can associate it with a management location:

```graphql
mutation CreateInventoryRepository($input: CreateInventoryRepositoryInput!) {
  createInventoryRepository(input: $input) {
    inventoryRepository {
      id
      name
      locationID
    }
  }
}
```

**Variables:**

```json
{
  "input": {
    "name": "Shelf-A1-001",
    "type": "static",
    "locationID": "location-uuid-here"
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/development/locations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
