Karyo
Documentation/ Decision records

ADR 0051: Business Unit names in storage, claims and the public API

Karyo 2.1.1rendered at build time
On this page

Status: Accepted. Supersedes the legacy client, tenant and OWNER vocabulary kept by ADR 0014, ADR 0015 and ADR 0040. ADR 0050 left these names as follow-up work.

Context

Karyo uses Company > Business Unit > Facility. Operational rows store only their Facility. Storage, identity and public API names still describe a Business Unit as a client or tenant. Karyo is unreleased and has no users, so a compatibility API or staged transition adds no value.

Decision

  • Rename clients to business_units and retire the SYS row at id 0.
  • Rename the remaining Business Unit columns to business_unit_id, event audiences included. Rename the warehouse-setup target column to target_business_unit_id.
  • Keep key 0 in system_properties, home_layouts and document_templates as the Company layer. It is not a Business Unit row. Configuration references expose a Company option to Company-level OPS principals.
  • Store BUSINESS_UNIT_USER instead of OWNER. The production kind claim and the user-create API accept ops and business_unit_user, and refuse owner. Session projections return the enum name.
  • Default the Business Unit claim to business_unit_id. Managed Keycloak uses the same user attribute. Both token clients and the agent scope emit it, and the legacy mappers are removed.
  • Use businessUnitId in public DTOs and events. Keep one Business Unit API, /api/v1/business-units, with its references and consistency routes. The console page is Business Units.
  • Remove the inert onlyClientLocation option. Facility scoping already determines every candidate.
  • Keep internal Kotlin names such as Client, TenantEntity and entity, service and SPI clientId. Keep OAuth client identifiers unchanged, including the actor_client_id agent columns, which hold the token's OAuth client (azp), not a Business Unit id. The issuer-less test identity keeps its synthetic client_id claim.

A new global migration follows every table it touches, and earlier migrations stay immutable. The test-classpath fixture function uses the final storage names because it runs after every production migration.

Consequences

Storage, the business_unit_id claim and Keycloak attribute, the public API businessUnitId fields, the removed /api/v1/clients and the BUSINESS_UNIT_USER kind use Business Unit vocabulary. The CLIENT and SYSTEM source values and the System properties screen copy keep their current names. Stored grants remain the only authority; the rename does not widen any reach. Company-default configuration works without a synthetic organization row. Existing developer principal rows receive the new kind in the same migration. A claim of owner is refused with invalid-principal-kind-claim. The demo tree, the pilot, the screenshots and the Atlas reset belong to the following change.

Alternatives considered

  • Convert configuration key 0 to NULL: rejected because it touches about 70 files and changes no behaviour.
  • A compatibility window, legacy API adapter, attribute-migration tool or staged cutover: not chosen; Karyo is unreleased and has no users.
  • Rename the synthetic test claim client_id: rejected because it touches about 240 test files and has no product effect.
  • Rename the agent actor_client_id columns: rejected because they hold OAuth client ids.

Evidence

  • services/karyo-app/src/main/resources/db/migration/auth/V1602__business_unit_storage_and_principal_kind.sql, karyo.clients, karyo.business_units, karyo.item_data, karyo.item_substitutions, karyo.inactive_products, karyo.system_properties, karyo.home_layouts, karyo.document_templates, karyo.outbox_events, karyo.alert_deliveries, karyo.webhook_delivery, karyo.warehouse_setup_runs, karyo.storage_strategies, karyo.principals - renames the table, columns and principal kind.
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt, PrincipalSecurityIdentityAugmentor.parsePrincipalKind - the strict kind parser that refuses owner.
  • services/karyo-app/src/main/resources/application.yaml, karyo.identity.claims.business-unit - the default claim business_unit_id.
  • services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/api/v1/BusinessUnitResource.kt, BusinessUnitResource.references - the references and consistency routes.
  • services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/api/v1/HomeLayoutResource.kt, HomeLayoutResource.targetClient - key 0 resolves to the Company layer without a row lookup.
  • services/karyo-app/src/test/kotlin/com/karyo/auth/BusinessUnitStorageTest.kt, BusinessUnitStorageTest - a fresh schema has final names and no SYS row.
  • services/karyo-app/src/test/kotlin/com/karyo/app/auth/ClaimRuleTest.kt, ClaimRuleTest.asCaller - a legacy owner claim is refused.
  • services/karyo-app/src/test/kotlin/com/karyo/webhooks/relay/DeliveryTest.kt, DeliveryTest.reload - a delivered payload carries businessUnitId.
  • services/karyo-app/src/test/kotlin/com/karyo/auth/BusinessUnitResourceTest.kt, BusinessUnitResourceTest - Company is an option but never a listed Business Unit.
  • ADR 0014 - the client vocabulary this record replaces.
  • ADR 0015 - the principal_kind this record renames.
  • ADR 0040 - the Business Unit key vocabulary.
  • ADR 0050 - the operational rows that no longer carry the key.