Skip to content

Type Hierarchy: Arda API Proxy

Analysis of duplicate and redundant type definitions across module .types.ts files. Types are grouped by duplication pattern.

PlantUML diagram

Each Domain and Module can have its own set of types, plus a shared set for the whole platform, so there may be as many as these type sets:

- shared/types.ts
- system/
- types.ts
- invitation/types.ts
- tenant/types.ts
- user-account/types.ts
- agent-for/types.ts
- reference/
- shared/types.ts
- item/types.ts
- business-affiliate/types.ts
- resources/
- shared/types.ts
- kanban/types.ts
- procurement/
- shared/types.ts
- order/types.ts

But it is not required that they are all present.

  1. If the type represents a concept closely tied to a module, it goes in that module’s types.ts file.
  2. If the type is used by multiple modules in a domain and cannot be closely tied to one of them, it goes in the <domain>/types.ts file.
  3. If the type is used by multiple domains and cannot be closely associated with any of them, it goes in the shared/types.ts file.
  4. When in doubt, put it in the smallest scope possible (module —> domain —> shared) and in the “bottom” of the dependnecy hierarchy.
  1. Imports should follow the dependency hierarchy and NEVER violate it.
  2. Each domain should have a barrel export file that contains all neccesary symbols to use all the proxies for the domain.
  3. Each module should also have a barrel export file that contains all neccessary symbols to use the proxy for the module.
  4. There should be no barrel export at the root level.

Reorganization of the api-proxy repository

Section titled “Reorganization of the api-proxy repository”
api-proxy/
shared/ // shared types and utilities
types.ts // General language extension types (errors, structured wrappers, etc.)
domain-types.ts // Shared Types that represent widely used concepts in the real world (manufacturing and supply chains)
system/
index.ts // barrel export for system proxy
shared/types.ts
invitation/
proxy.ts
types.ts
utils.ts
tenant/
proxy.ts
types.ts
utils.ts
user-account/
proxy.ts
types.ts
utils.ts
agent-for/
proxy.ts
types.ts
utils.ts
reference/
shared/types.ts
item/
proxy.ts
types.ts
utils.ts
business-affiliate/
proxy.ts
types.ts
utils.ts
resources/
shared/types.ts
kanban/
proxy.ts
types.ts
utils.ts
procurement/
shared/types.ts
order/
proxy.ts
types.ts
utils.ts

11-value string union defined identically in two files.

FileLine
src/reference/item.types.ts23–34
src/procurement/order.types.ts24–35
type OrderMethod =
| "UNKNOWN" | "PURCHASE_ORDER" | "EMAIL" | "PHONE" | "IN_STORE"
| "ONLINE" | "RFQ" | "PRODUCTION" | "TASK" | "THIRD_PARTY" | "OTHER";

2. SubscriptionState / UserAccountSubscriptionState

Section titled “2. SubscriptionState / UserAccountSubscriptionState”

Same 4-value union, different names.

FileNameLine
src/system/tenant.types.tsSubscriptionState6
src/system/user-account.types.tsUserAccountSubscriptionState44
type SubscriptionState = "PENDING" | "ACTIVE" | "SUSPENDED" | "CANCELLED";

Structural Duplicates (different names, identical shape)

Section titled “Structural Duplicates (different names, identical shape)”

Identical { fqn, networkLocator, authority } shape under 4 different names.

FileNameLines
src/system/tenant.types.tsResourceHome12–16
src/system/user-account.types.tsUserAccountResourceHome30–34
src/system/agent-for.types.tsAgentForResourceHome14–18
src/system/invitation.types.tsInvitationResourceHome17–21
interface ResourceHome {
fqn: string;
networkLocator: string;
authority: string;
}

12 identical properties, different names.

FileNameLines
src/shared/domain-types.tsContact84–97
src/system/user-account.types.tsIdentity11–24
interface Contact {
salutation?: string | null;
firstName?: string | null;
middleName?: string | null;
lastName: string;
jobTitle?: string | null;
email?: string | null;
phone?: string | null;
postalAddress?: PostalAddress | null;
emails: Record<string, string>;
phones: Record<string, string>;
addresses: Record<string, PostalAddress>;
sites: Record<string, string>;
}

5. SubscriptionReference / UserAccountSubscription

Section titled “5. SubscriptionReference / UserAccountSubscription”

Same shape once ResourceHome and SubscriptionState are unified.

FileNameLines
src/system/tenant.types.tsSubscriptionReference19–25
src/system/user-account.types.tsUserAccountSubscription47–53
interface SubscriptionReference {
state: SubscriptionState;
acceptedTC?: number | null;
local: string;
revision: string;
homes: ResourceHome[];
}

Same shape once ResourceHome is unified.

FileNameLines
src/system/agent-for.types.tsEntityReference8–11
src/system/invitation.types.tsInvitationReference11–14
interface EntityReference {
local: string;
homes: ResourceHome[];
}

Identical { jobId, status, url? } shape.

FileNameLines
src/reference/item.types.tsRenderResult180–184
src/resources/kanban.types.tsKanbanPrintResult128–132
interface RenderResult {
jobId: string;
status: string;
url?: string | null;
}

8. CardSize / LabelSize / BreadcrumbSize — 3 copies in one file

Section titled “8. CardSize / LabelSize / BreadcrumbSize — 3 copies in one file”

Same 15-value union defined three times with different names in src/reference/item.types.ts.

NameLines
CardSize37–52
LabelSize55–70
BreadcrumbSize73–88
type PrintSize =
| "X_SMALL" | "SMALL" | "MEDIUM" | "LARGE" | "X_LARGE"
| "SPECIAL_01" | "SPECIAL_02" | "SPECIAL_03" | "SPECIAL_04" | "SPECIAL_05"
| "SPECIAL_06" | "SPECIAL_07" | "SPECIAL_08" | "SPECIAL_09" | "SPECIAL_10";

9. Empty metadata — Record<string, never> — 3 copies

Section titled “9. Empty metadata — Record<string, never> — 3 copies”
FileNameLine
src/system/tenant.types.tsTenantMetadata47
src/system/user-account.types.tsUserAccountMetadata79
src/system/agent-for.types.tsAgentForMetadata40

10. Tenant-scoped metadata — { tenantId: string } — 4 copies

Section titled “10. Tenant-scoped metadata — { tenantId: string } — 4 copies”
FileNameLines
src/system/invitation.types.tsInvitationMetadata49–51
src/reference/business-affiliate.types.tsBusinessAffiliateMetadata36–38
src/reference/item.types.tsItemMetadata143–145
src/resources/kanban.types.tsKanbanCardMetadata86–88

11. Sub-entity metadata — { parentEId: string } — 2+ copies

Section titled “11. Sub-entity metadata — { parentEId: string } — 2+ copies”
FileNameLinesNotes
src/reference/business-affiliate.types.tsBusinessRoleMetadata66–68{ parentEId: string }
src/reference/item.types.tsItemSupplyMetadata162–164{ parentEId: string }
src/procurement/order.types.tsOrderLineMetadata112–115{ parentEId: string; rank: number } — extends pattern

#Duplication GroupCopiesRecommended Action
1OrderMethod2Move to shared
2SubscriptionState2Move to shared
3ResourceHome4Move to shared
4Contact / Identity2Unify naming, move to shared
5SubscriptionReference2Move to shared (depends on #2, #3)
6EntityReference2Move to shared (depends on #3)
7RenderResult2Move to shared
8PrintSize aliases3Single type with aliases
9Empty metadata3Shared EmptyMetadata type
10{ tenantId } metadata4Shared TenantScopedMetadata type
11{ parentEId } metadata2–3Shared SubEntityMetadata type

Total: ~25 redundant type definitions across 12 duplication groups.