Overview
What @workspace/bridge exports, how it is layered, and where each part is documented.
@workspace/bridge is the pure-TypeScript bridge package: rules, engine, parsers, notation, deal validation and PBN/LIN conversion. It has no React or DOM dependency.
Runtime dependencies: @workspace/shared (error base classes, string and function helpers) and zod (validation schemas). Everything else is plain functions and constants.
Quick start
The engine is the configured entry point for everything that depends on the teaching mode or the locale; direct sub-path imports give the context-free functions.
const engine = createBridgeEngine(
createBridgeContext({ teachingMode: "auction", locale: "fr" })
);
engine.notation.parseRanks("RDV"); // => ["K", "Q", "J"]
engine.auction.calculateContract(new AuctionBuilder().fromCompact("N / 1S pass 2S AP").build());getPlayersInTrickOrder("W"); // => ["W", "N", "E", "S"]
calculateContract(new AuctionBuilder().fromCompact("N / 1H pass pass pass").build());See Usage for when to pick one over the other.
Sub-path exports
There is no root import: every symbol is reached through one of the sub-paths declared in the package exports map. Each rules module (auction, card, hands, locale, notation, play, player, rotation, teaching) is a sub-path whose index.ts exposes the public surface of its own folder; the other files of the folder stay internal, and the matching engine module binds the context-dependent functions.
Rule: each module is imported through its own path; there is no forwarding file. A file whose exports come from another folder without a definition of its own does not exist in the package: an index.ts only exposes its own folder, and a definition lives in exactly one module.
Rule: a function is public outside the engine if and only if it is independent of the context. A function that takes a CoreConfig, BridgeContext, TeachingMode, SuitVariant or Locale is only reachable through engine.<module>, which binds those arguments from the BridgeContext. The exceptions are the entry points createBridgeContext and createBridgeEngine (with the BridgeContext type), and validateDeal, which receives the mode as data of the deal it validates.
| Import path | Contents | Page |
|---|---|---|
@workspace/bridge/engine | createBridgeEngine, createBridgeContext, BridgeContext and module config types | Engine |
@workspace/bridge/auction | Per-call view (auctionEntries, auctionTurn), building an auction, bid validation, contract calculation, bid parsing (BidInput, CallInput), contract level, opener and counter status (isCounterStatus), expected result | Auction |
@workspace/bridge/card | Card/rank/suit parsing and guards (CardInput, CardParts), rank sorting (DEFAULT_RANK_ORDER), suit display order | Card |
@workspace/bridge/hands | Hand analysis, conversions, areEmpty, queries, transforms, HCP and Top-Honor-Tricks computers, PBN hand strings; completeness and filling are on engine.hands | Hands |
@workspace/bridge/locale | The rank mapping reader and the suit mapping tables | Notation |
@workspace/bridge/notation | PETIT_BRIDGE_RANK_ORDER, RankMapping, RankFormatter; parsing and formatting are on engine.notation | Notation |
@workspace/bridge/play | Trick building, trick winner, follow-suit rules, legal cards | Play |
@workspace/bridge/player | Seat navigation, rotation, partnerships and roles | Player |
@workspace/bridge/rotation | createRotater for deals and comment text, comment rotation matchers | Rotation |
@workspace/bridge/teaching | parseTeaching, canonicalizeDealShapeForMode | Teaching |
@workspace/bridge/constants | Suits, ranks, players, bids, vulnerability, scoring, defaults, board numbering, teaching constants | Constants |
@workspace/bridge/factories | Factories for hands, random auctions and whole board games | Factories |
@workspace/bridge/errors | Validation error types and factories, PBN error classes | Errors |
@workspace/bridge/lin | LIN serialization (serializeDealToLIN) | LIN |
@workspace/bridge/pbn | PBN file parsing and serialization, DealCommentSummary | PBN |
@workspace/bridge/schemas/* | Zod schemas, one file per concept (see below) | Schemas |
@workspace/bridge/types | All domain types | Types |
@workspace/bridge/testing | makeDeal, builders with random defaults (DealBuilder, AuctionBuilder, …) and named scenarios for tests and docs | Testing |
@workspace/bridge/parsers | Contract, scoring and vulnerability string parsers | Parsers |
@workspace/bridge/utils/* | Stateless utilities that belong to no rules module, one file each (see below) | Utils |
@workspace/bridge/format/* | Display formatting (see below) | Format |
@workspace/bridge/validation | Full deal validation and save decision | Validation |
utils/*
| Sub-path | Contents |
|---|---|
utils/contract | getTrumpFromContract, formatContractForIndex |
utils/scoring | Scoring-mode guards and duplicate-bridge scoring (computeDuplicateScore, duplicateScore, contractScore) |
utils/vulnerability | Per-player vulnerability status and guards, isSideVulnerable |
schemas/*
bid, card, deal, game-params, hands, play, player, scoring, teach-params, vulnerability.
format/*
auction, contract, contract-outcome, hands, play.
Architecture
The source is organised in five layers, from foundation to integration (a few cross-layer imports exist, such as constants/core-config reading card/suit-order).
- Foundation —
types,constants,errors. - Primitives —
card,player,notation,format,parsers: stateless helpers. - Domain —
auction,hands,play,rotation,teaching: game rules, some parameterised by aCoreConfig. - Cross-cutting —
schemas,validation,utils,pbn,lin,factories,testing. - Integration —
engine: resolves aCoreConfigfrom theBridgeContextand composes the 13 modules.
The teaching mode decides the CoreConfig (card count, valid ranks, auction kind, denominations, deck); the locale decides notation. Both are described in Game Modes.