---
title: Identity (TypeID)
description: How Shield uses prefix-qualified, globally unique identifiers for every entity.
---

Every entity in Shield has a TypeID. TypeIDs are globally unique, sortable, URL-safe identifiers built on UUIDv7 with a human-readable prefix that tells you what kind of entity you're looking at.

A TypeID looks like this:

```
scan_01h455vb4pex5vsknk084sn02q
```

The `scan` prefix identifies this as a scan. The suffix is a base32-encoded UUIDv7 that encodes creation time, so IDs sort chronologically.

## The `id` package

The `id` package wraps the [TypeID Go library](https://github.com/jetify-com/typeid-go) (v2) with a single `ID` struct. All entity types share the same struct -- the prefix distinguishes them.

### Creating IDs

```go
import "github.com/xraph/shield/id"

scanID             := id.New(id.PrefixScan)              // scan_01h455vb...
policyID           := id.New(id.PrefixPolicy)            // pol_01h455vb...
findingID          := id.New(id.PrefixFinding)           // find_01h455vb...
piiTokenID         := id.New(id.PrefixPIIToken)          // pii_01h455vb...
complianceReportID := id.New(id.PrefixComplianceReport)  // crpt_01h455vb...
checkID            := id.New(id.PrefixCheck)             // schk_01h455vb...
instinctID         := id.New(id.PrefixInstinct)          // inst_01h455vb...
judgmentID         := id.New(id.PrefixJudgment)          // jdg_01h455vb...
awarenessID        := id.New(id.PrefixAwareness)         // awr_01h455vb...
valueID            := id.New(id.PrefixValue)             // val_01h455vb...
reflexID           := id.New(id.PrefixReflex)            // rflx_01h455vb...
boundaryID         := id.New(id.PrefixBoundary)          // bnd_01h455vb...
safetyProfileID    := id.New(id.PrefixSafetyProfile)     // sprf_01h455vb...
```

Convenience constructors: `id.NewScanID()`, `id.NewPolicyID()`, `id.NewFindingID()`, `id.NewPIITokenID()`, `id.NewComplianceReportID()`, `id.NewCheckID()`, `id.NewInstinctID()`, `id.NewJudgmentID()`, `id.NewAwarenessID()`, `id.NewValueID()`, `id.NewReflexID()`, `id.NewBoundaryID()`, `id.NewSafetyProfileID()`.

### Parsing IDs

```go
parsed, err := id.Parse("scan_01h455vb4pex5vsknk084sn02q")
parsed, err := id.ParseWithPrefix("scan_01h455vb...", id.PrefixScan)  // validates prefix
parsed, err := id.ParseScanID("scan_01h455vb...")                     // convenience
```

### Nil ID

```go
var empty id.ID
empty.IsNil()  // true
empty.String() // ""
id.Nil.IsNil() // true
```

### Database storage

`id.ID` implements `Scanner` and `driver.Valuer`. Stores as a string, returns `NULL` for nil IDs.

### JSON serialization

`id.ID` implements `TextMarshaler` and `TextUnmarshaler`. Nil IDs serialize as empty strings.

## Prefix reference

| Constant | Prefix | Entity |
|----------|--------|--------|
| `id.PrefixScan` | `scan` | Scan |
| `id.PrefixPolicy` | `pol` | Policy |
| `id.PrefixFinding` | `find` | Finding |
| `id.PrefixPIIToken` | `pii` | PII token |
| `id.PrefixComplianceReport` | `crpt` | Compliance report |
| `id.PrefixCheck` | `schk` | Safety check |
| `id.PrefixInstinct` | `inst` | Instinct |
| `id.PrefixJudgment` | `jdg` | Judgment |
| `id.PrefixAwareness` | `awr` | Awareness |
| `id.PrefixValue` | `val` | Value |
| `id.PrefixReflex` | `rflx` | Reflex |
| `id.PrefixBoundary` | `bnd` | Boundary |
| `id.PrefixSafetyProfile` | `sprf` | Safety profile |
