Id format
Every record's id reads the same way in every Agentfy product: what it is, two words, and a random tail.
user-calm-rivers-k8m4p2d7n9x3 — a person; site-project-brave-lions-q3x7m2k9d4p8 — a site. Agentfy, Bonsite, Securify, Shiffty and Store Deputy make and check ids by the same rules (BONS-132, October 15). Ids issued before that keep working exactly as they are.
Format
| Part | Rule |
|---|---|
| Shape | <prefix>-<adjective>-<noun>-<suffix> |
| Prefix | The model's whole name in kebab-case: user, team-api-key, site-copy-page. Never shortened. Which model gets which prefix is listed in api/src/slices/setup/id/README.md. |
| Adjective, noun | One word each from the adjectives and nouns dictionaries of the human-id package, exactly version 4.1.3, in lower case. A word with anything but a–z is dropped (4.1.3 has none). |
| Suffix | 12 characters of Crockford's base32 in lower case: 0123456789abcdefghjkmnpqrstvwxyz (no i, l, o, u), 60 random bits from crypto.randomBytes through nanoid exactly 3.3.11. |
| Uniqueness | The database primary key. A conflict means another attempt with a new id, at most five writes. The words are for people, not for uniqueness. |
| Code | api/src/slices/setup/id/domain/idFormat.ts, the same in all five products except its last part, LEGACY_ID_FORMATS. |
Generation, byte by byte
A source of randomness gives size bytes on request. The draws, in order:
- Adjective. The index is drawn from the fewest whole bytes that hold the dictionary length minus one, read big-endian and masked to the nearest power of two at or above the length. A value outside the dictionary is thrown away and the next bytes are read.
- Noun. The same, over the noun dictionary.
- Suffix.
nanoid3.3.11customRandom(alphabet, 12, source): one request of 19 bytes, read from the last one back, the low 5 bits of each, 12 kept.
Control vector. A source that gives the bytes 0, 1, 2, 3, … in order makes formatId('user') equal to user-afraid-swans-nmkjhgfedcba (22 bytes read). Every product's test asserts exactly this string.
Ids issued before
New ids are only ever made in the format above. Ids already issued are still accepted, never rewritten:
LEGACY_ID_FORMATS | Shape | Issued |
|---|---|---|
bonsite-words-3-20 | <prefix>-<adjective>-<noun>-<verb>-<20 characters of the same alphabet>, words of human-id 4.1.3 | BONS-130 to BONS-132 |
Older addresses — a UUID from before BONS-130, or a shortened prefix from before BONS-131 such as usr-… — are resolved through the id history to the record's id today.
The database checks the shape too: each table's id CHECK accepts its prefix followed by either form.