Skip to content

ADR-0001. Publish a type-only-ish ./contracts subpath instead of mounting pricing as a component

FieldValue
StatusAccepted
Date2026-03
Deciderspricing-team, sale-team
Supersedes

Context

  • Sale must price carts at checkout, but pricing is a separate runtime service with its own DB schema, Kafka consumer, and calculators.
  • Mounting pricing as an embeddable IGNIS component inside sale would drag pricing's repositories, Kafka component, and DB coupling into the sale process.
  • Sale still needs strongly-typed request/response shapes, and a few runtime constants (e.g. TransactionDirections.SALE, PartyRoles keys) to build requests and read the snapshot's byBearer ledger.

Decision

Pricing exposes a dedicated @nx/pricing/contracts subpath export (src/contracts/index.ts) that is mostly export type declarations, plus a small set of frozen runtime const containers (AppliedRuleSourceTypes, FareSourceTypes, FeeScopes, PartyRoles, RuleBasises, Snapshot{Discount,Fee,Tax}Types, TransactionDirections). Sale calls pricing over HTTP (PricingNetworkService, BASIC auth) and imports only from this subpath. Sale never mounts pricing as a component.

Consequences

ProsCons
Sale ships only erasable types + tiny const tables — no pricing runtime in its bundleTwo services must stay reachable at checkout (network hop)
Clean service boundary; pricing can evolve internals freelyConst containers are a real (small) runtime dependency to version-manage
Type safety across the HTTP boundary without a shared schema packageContract drift only caught at type-check time, not at the wire

Alternatives Considered

OptionProsConsWhy rejected
Mount pricing as an embeddable component in saleNo network hopDrags DB/Kafka/repo coupling into sale; breaks service isolationDefeats the standalone-service design
Share all types via @nx/core onlyOne place for typesPricing-internal snapshot shapes don't belong in corePollutes core with engine-specific contracts
Pure-type contracts (no runtime consts)Zero runtime dependencySale would re-declare TransactionDirections / PartyRoles values, risking divergenceDuplication is worse than a frozen const export

References

  • pricing/src/contracts/index.ts
  • sale/src/services/pricing-network.service.ts
  • sale/src/services/checkout.service.ts

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.