Bridge Training

Overview

What @workspace/training is, how its domain and application layers are organised, which sub-paths exist, and where each module is documented.

@workspace/training is the product model of Bridge Training: teachers, students, groups, sessions, boards, collections, plans and entitlements, ads, telemetry and usage. It is a pure-TypeScript hexagonal core: the domain layer holds entities, value objects and pure rules; the application layer holds services, input DTOs, query objects and the ports that infrastructure adapters implement. Nothing in the package touches a database, a queue or HTTP.

Runtime dependencies: @workspace/bridge (deal types and rules), @workspace/rich-text (comment and review model), @workspace/shared (logger, time and error helpers), @workspace/i18n and @workspace/i18n-messages (languages and theme labels). No React, no DOM, no vendor SDK.

Quick start

A service is a factory taking its ports; the consuming app passes an adapter and threads a ServiceContext as the last argument of every call.

index.ts
// Adapters (packages/database) implement the ports; the app wires them once.
export function listGroups(
  deps: GroupsServiceDeps,
  ctx: ServiceContext
): Promise<Group[]> {
  const groups = createGroupsService(deps);
  return groups.list(ctx); // ctx is always the last argument
}

Domain errors are AppError subclasses carrying a stable code; the API translates them at its boundary, the app never sees them.

index.ts
export async function renameGroup(
  deps: GroupsServiceDeps,
  groupId: string,
  name: string,
  ctx: ServiceContext
) {
  const groups = createGroupsService(deps);
  try {
    return await groups.update(groupId, { name }, ctx);
  } catch (error) {
    if (isAppError(error)) {
      error.code; // => "GROUP_NOT_FOUND"
      error.isExpected; // => true
    }
    throw error;
  }
}

See Usage for the wiring in each app, Service Context for the ctx rule and Errors for the error family.

Sub-path exports

Every symbol is reached through one of the sub-paths of the package exports map. A module's index.ts is its public surface; the other files of the folder are internal.

Import pathContentsPage
@workspace/trainingOnly the cross-cutting part of domain/shared: the AppError family and ErrorCode, AppEvent, ServiceContext, supported languages, localized fields, calendar and month helpers, label sortingErrors, Shared, Service Context
@workspace/training/domain/<module>The module's entities, value objects, constants, guards, pure functions and domain errorsThe module page
@workspace/training/application/<module>The module's services (createXxxService), input DTOs, query objects and projections, and its repository ports under ports/The module page
@workspace/training/application/sharedThe query layer every repository port is built from: QueryObject, Criteria, Projection, Aggregation, pagination, ReadRepository, WriteRepositoryQueries
@workspace/training/application/portsCross-cutting ports: queue, event bus, email, auth admin, storage, session tokens, webhook verification, current accountPorts
@workspace/training/factoriesOne (faker, overrides) factory per type, for tests, mocks and dev scenariosFactories
@workspace/training/testingFakes and mocks of the ports for the consumers' testsTesting

Rule: a module is imported through its own path; there is no forwarding file. Inside the package, imports are direct relative paths, never the root barrel.

Modules

Each page documents the domain/<module> and application/<module> folders of one module.

Teaching

ModuleContentsPage
accountsAccounts (persons and organisations), owners, roles, preferences, onboarding, identity snapshots from the auth provider, impersonation logAccounts
studentsStudents of a teacher and their group countsStudents
groupsGroups of students with a schedule, their next sessionGroups
sessionsGroup sessions, occurrences of recurring groups, session codes, public links and public content, linked collectionsSessions
boardsBoards (a deal with teaching metadata): codes, levels, scoring, writing through the gate, claiming, queries and filters, comments, analytics, bookmarks and votesBoards
editor-boardsThe editor's view of boards: list queries, projections, rotation, prepared writesEditor boards
themesBoard themes, system and user-defined, their labels and the query object familyThemes
collectionsDeal collections, governed by the stock ceiling of the planCollections
sharingSharing modes and sharing groups between teachersSharing
publicDeal views and the reads served to the public player without a contextPublic

Plans and billing

ModuleContentsPage
entitlementsFeatures and limits, grants and their merge over time, flow quotas, diffusion debits, stock overflow and the degraded modeEntitlements
plansPlans, plan grids, prices and the catalogue providerPlans
subscriptionsSubscriptions, provider events, reconciliation into grants, termination, admin viewsSubscriptions
billingBilling customers, hosted checkout and portal sessionsBilling

Platform

ModuleContentsPage
adsAd banners, campaigns, sponsorships and their rules, the ads policy resolver, brand assetsAds
announcementsAnnouncements and the per-account feedAnnouncements
eventsIngested webhook events: statuses, ingestion, replay, handler registryEvents
telemetryPlayer telemetry events, trace tokens and decoding, ingest with serve debitTelemetry
usageUsage statistics and analytics: serves, play rollups, perceived difficulty, perseverance, owner activityUsage analytics

Architecture

Layer first, module second: the lint rule is the layer rule, domain ↛ application ↛ infrastructure. Modules are too intertwined (a session links boards and collections, entitlements govern collections) to be the first boundary.

packages/training/src/
├── domain/
│   ├── shared/              # AppError family, ErrorCode, ServiceContext, languages, localized fields
│   └── <module>/            # entities, value objects, errors, pure rules
├── application/
│   ├── shared/              # QueryObject, Criteria, Projection, pagination, Read/WriteRepository
│   ├── ports/               # cross-cutting ports (queue, event bus, email, storage, tokens…)
│   └── <module>/            # services, input DTOs, query objects
│       └── ports/           # the module's repositories
├── factories/               # (faker, overrides) factories, one per type
└── testing/                 # fakes and mocks of the ports
  • The layer rule is linted. A domain file imports sibling domain modules only; an application file imports domain and application; neither imports an infrastructure or UI package, the package's own public entry points, or factories/ outside tests.
  • Primitives imported, product model injected. bridge, rich-text and shared are imported directly by anyone. training is reached by infrastructure adapters through its ports, and by the UI through ViewModels built in the apps: no ui-* package imports it.
  • Services are plain factories. createXxxService(deps) returns an object of methods; every method acting on a user's data takes ctx: ServiceContext last. Authorization is decided by the app before the call.
  • One regime per service. A service either calls repositories request by request or runs a unit of work; it never mixes the two.
  • Errors are data. Services throw AppError subclasses with an ErrorCode; the API handlers translate them into wire errors.

The package rules shared with the rest of the monorepo are on Architecture and Adapter packages.

Source layout

index.ts
account.ts
ads.ts
announcement.ts
auction-system.ts
board-deal.ts
board-summary.ts
board-theme.ts
board.ts
bookmark.ts
code.ts
deal-collection.ts
deal-view.ts
entitlement-grant.ts
group.ts
identity-snapshot.ts
index.ts
ingested-event.ts
outbound-email.ts
owner.ts
persistable-board-write.ts
persistable-editor-board-write.ts
plan.ts
play-rollup.ts
public-link.ts
session-occurrence.ts
session.ts
sharing-group.ts
student.ts
subscription.ts
usage-perseverance-window.ts
accounts.fake.ts
ads-sponsorships.fake.ts
announcements.fake.ts
auction-systems.fake.ts
billing-customers.fake.ts
board-themes.fake.ts
boards-write-service.mock.ts
bookmarks.fake.ts
brand-assets.fake.ts
deal-collection-boards.fake.ts
deal-collections.fake.ts
deal-read.fake.ts
editor-boards-read.fake.ts
email-suppressions.fake.ts
entitlements-gate.fake.ts
entitlements.fake.ts
fake-where.ts
group-session-boards.fake.ts
group-session-collections.fake.ts
group-sessions.fake.ts
group-students.fake.ts
groups.fake.ts
impersonation-log.fake.ts
index.ts
ingested-events.fake.ts
outbound-emails.fake.ts
plans.fake.ts
play-rollup-runs.fake.ts
play-rollups-read.fake.ts
queue.fake.ts
repository.mock.ts
serves.fake.ts
sharing-group-members.fake.ts
sharing-groups.fake.ts
students.fake.ts
subscriptions.fake.ts
telemetry-events.fake.ts
themes.fake.ts
unit-of-work.fake.ts
usage-perseverance-read.fake.ts
voting.fake.ts
ad-banner.ts
ads-campaign.ts
ads-policy.ts
ads-sponsorship-rule.ts
ads-sponsorship.ts
brand-asset-upload.ts
brand-asset.ts
index.ts
billing-customer.ts
index.ts
announcement.ts
index.ts
account-audience.ts
account-handle.ts
account-onboarding.ts
account-preferences.ts
account.ts
index.ts
owner.ts
signup-source.ts
user-role.ts
user-search-result.ts
auction-system.ts
board-entry.ts
board-language.ts
board-not-in-trash.ts
board-summary.ts
board.ts
boards-to-pbn.ts
bookmark.ts
comment-rules.ts
contract-level.ts
counter-status.ts
deal-code.ts
index.ts
invalid-board-reference.ts
level.ts
scoring-mode.ts
sequence-adapters.ts
vote-type.ts
vulnerability.ts
author-badges.ts
catalog-author.ts
catalog-collection.ts
catalog-exposure.ts
index.ts
deal-collection.ts
index.ts
entitlement-grant.ts
entitlements-actions.ts
entitlements-defaults.ts
entitlements-keys.ts
entitlements-merge.ts
entitlements-period.ts
entitlements-presenters.ts
entitlements-proration.ts
entitlements.ts
grant-quota.ts
index.ts
quota-period-split.ts
stock-overflow.ts
group.ts
index.ts
email-feedback.ts
email-message.ts
email-status.ts
email-suppression.ts
index.ts
outbound-email.ts
index.ts
plan-grid.ts
plan-price.ts
plan.ts
index.ts
ingested-event-status.ts
invalid-replay-state-error.ts
webhook-verification-error.ts
deal-view.ts
index.ts
sort-hands.ts
assert-no-duplicate-boards.ts
duplicate-board-in-session.ts
index.ts
public-content.ts
recurring-sessions.ts
session-code.ts
session-completeness.ts
session-occurrence.ts
session.ts
access-denied.ts
app-error.ts
app-event.ts
calendar-day.ts
conflict-error.ts
duplicate.ts
error-code.ts
feature-disabled.ts
limit-reached.ts
localized-labels.ts
not-found.ts
public-window.ts
required-text.ts
resource-degraded.ts
rich-text-validation.ts
rotater.ts
service-context.ts
session-token-verification-error.ts
supported-language.ts
unexpected.ts
validation.ts
index.ts
student.ts
index.ts
subscription.ts
index.ts
telemetry-bounds.ts
telemetry-event.ts
trace-decode.ts
trace-token.ts
difficulty-zone.ts
index.ts
perceived-difficulty.ts
usage-analytics.ts
board-theme.ts
index.ts
theme-title.ts
index.ts
sharing-group.ts
sharing.ts
entitlements-gate-fake.test.ts
queue-fake.test.ts
sharing-groups-fake.test.ts
announcements-admin.test.ts
announcements.test.ts
billing-customers.test.ts
service.test.ts
accounts-service.test.ts
apply-account-identity-snapshot.test.ts
impersonation-service.test.ts
ads-policy-service.test.ts
ads-sponsorships-admin.test.ts
brand-assets-service.test.ts
catalog-fixture.ts
catalog-service.test.ts
auction-systems-service.test.ts
board-bulk-claim.test.ts
board-claim.test.ts
board-derived-fields.test.ts
board-filters-utils.test.ts
board-service-fixture.ts
board-service-remove.test.ts
board-service.test.ts
board-soft-delete.test.ts
boards-analytics-service.test.ts
boards-comments-service.test.ts
boards-write-service.test.ts
bookmarks-service.test.ts
bulk-claim-rows.test.ts
comments-rewrite-service.test.ts
deal-write-gate-canonical.test.ts
deal-write-gate.test.ts
pbn-import-service.test.ts
project-board-entries.test.ts
readable-boards.ts
voting-service.test.ts
deal-collections-service.test.ts
editor-board-query.test.ts
editor-boards-service.test.ts
editor-boards-write-service.test.ts
emails.test.ts
decide-check.test.ts
diffusion-debit.test.ts
entitlements-gate.test.ts
flow-quota.test.ts
serve-diffusion.test.ts
service.test.ts
stock-overflow-resolver.test.ts
event-ingestion.test.ts
groups-service.test.ts
plan-pricing.test.ts
service.test.ts
deal-service.test.ts
public-deals-service.test.ts
public-sessions-service.test.ts
group-sessions-service.test.ts
pagination.test.ts
sharing-groups-service.test.ts
students-service.test.ts
admin-service.test.ts
service.test.ts
subscription-fixtures.ts
termination-service.test.ts
telemetry-ingest.test.ts
telemetry-retention.test.ts
themes-service.test.ts
owner-period-activity.test.ts
play-rollups.test.ts
rollup-boundary.test.ts
serves-service.test.ts
usage-analytics-feature-gate.test.ts
usage-analytics-service.test.ts
usage-perseverance-windows.test.ts
usage-stats-service.test.ts
account-audience.test.ts
account-handle.test.ts
account-onboarding.test.ts
account.test.ts
ads-campaign.test.ts
ads-sponsorship-rule.test.ts
brand-asset-upload.test.ts
brand-asset.test.ts
board-entry.test.ts
board-language.test.ts
boards-to-pbn.test.ts
comment-rules.test.ts
counter-status.test.ts
deal-code.test.ts
level.test.ts
scoring-mode.test.ts
vote-type.test.ts
vulnerability.test.ts
catalog.test.ts
plan-fixtures.ts
actions.test.ts
defaults.test.ts
entitlements-keys.test.ts
entitlements-proration.test.ts
grant-fixtures.ts
grant-quota.test.ts
grant.test.ts
merge.test.ts
period.test.ts
presenters.test.ts
quota-period-split.test.ts
stock-overflow.test.ts
public-content.test.ts
recurring-sessions.test.ts
session-board-ids.test.ts
session-completeness.test.ts
calendar-day.test.ts
localized-labels.test.ts
public-window.test.ts
required-text.test.ts
rich-text-validation.test.ts
board-theme-labels.test.ts
theme-title.test.ts
telemetry-bounds.test.ts
trace-decode.test.ts
trace-token.test.ts
perceived-difficulty.test.ts
usage-analytics-period.test.ts
account-aggregations.ts
account-criteria.ts
account-handle-availability.ts
account-projections.ts
account-query.ts
account-update-patch.ts
account-where.ts
account.dto.ts
accounts.ts
apply-account-identity-snapshot.ts
impersonation.ts
index.ts
accounts-read.ts
accounts.ts
identity-provider.ts
impersonation-log.ts
ad-banners.ts
ads-policy.ts
ads-sponsorship-aggregations.ts
ads-sponsorship-criteria.ts
ads-sponsorship-projections.ts
ads-sponsorship-query.ts
ads-sponsorship-sort.ts
ads-sponsorship-update-patch.ts
ads-sponsorship-where.ts
ads-sponsorships-admin.ts
brand-asset-criteria.ts
brand-asset-projections.ts
brand-asset-query.ts
brand-asset-sort.ts
brand-asset-update-patch.ts
brand-asset-where.ts
brand-assets.ts
index.ts
ads-sponsorships-read.ts
ads-sponsorships.ts
brand-assets-read.ts
brand-assets.ts
announcement-aggregations.ts
announcement-criteria.ts
announcement-projections.ts
announcement-query.ts
announcement-update-patch.ts
announcement-where.ts
announcements-admin.ts
announcements.ts
index.ts
announcement-reads.ts
announcements-read.ts
announcements.ts
billing-customer-criteria.ts
billing-customer-patch.ts
billing-customer-projections.ts
billing-customer-query.ts
billing-customer-where.ts
billing-customers.ts
billing.ts
index.ts
billing-customers-read.ts
billing-customers.ts
billing-provider.ts
assert-boards-accessible.ts
auction-system-projections.ts
auction-system-query.ts
auction-system-where.ts
auction-systems.ts
board-aggregations.ts
board-claim.ts
board-criteria.ts
board-derived-fields.ts
board-filters-limits.ts
board-filters-utils.ts
board-filters.ts
board-list.dto.ts
board-projections.ts
board-query-builder.ts
board-query.ts
board-sort.ts
board-themes-criteria.ts
board-themes-projections.ts
board-themes-query.ts
board-themes-where.ts
board-update-patch.ts
board-where.ts
board-write-diff.ts
board.dto.ts
board.ts
boards-analytics.ts
boards-comments.ts
boards-write.ts
bookmark-criteria.ts
bookmark-projections.ts
bookmark-query.ts
bookmark-where.ts
bookmarks.ts
comments-rewrite.ts
deal-write-gate.internal.ts
index.ts
project-board-entries.ts
vote-criteria.ts
vote-projections.ts
vote-query.ts
vote-where.ts
voting.dto.ts
voting.ts
apply-bulk-claim.ts
board-bulk-claim.ts
bulk-claim-rows.ts
bulk-claim-types.ts
plan-bulk-claim.ts
apply-pbn-import.ts
invalid-theme-titles-error.ts
pbn-import-rows.ts
pbn-import-types.ts
pbn-import.ts
plan-pbn-import.ts
unknown-system-themes-error.ts
auction-systems.ts
board-read.ts
board-themes.ts
board-write-unit-of-work.ts
board.ts
bookmarks.ts
voting.ts
author-badges.ts
catalog.ts
index.ts
deal-collection-aggregations.ts
deal-collection-boards-criteria.ts
deal-collection-boards-projections.ts
deal-collection-boards-query.ts
deal-collection-boards-where.ts
deal-collection-criteria.ts
deal-collection-projections.ts
deal-collection-query.ts
deal-collection-sort.ts
deal-collection-update-patch.ts
deal-collection-where.ts
deal-collection.dto.ts
deal-collections.ts
index.ts
collection-deals.ts
deal-collection-boards.ts
deal-collections-read.ts
deal-collections.ts
editor-board-aggregations.ts
editor-board-criteria.ts
editor-board-projections.ts
editor-board-query.ts
editor-board-sort.ts
editor-board-update-patch.ts
editor-board-where.ts
editor-boards-write.ts
editor-boards.ts
index.ts
rotation-projection.ts
editor-boards-read.ts
editor-boards.ts
email-suppression-projections.ts
email-suppression-query.ts
email-suppression-where.ts
emails.ts
index.ts
outbound-email-aggregations.ts
outbound-email-criteria.ts
outbound-email-patch.ts
outbound-email-projections.ts
outbound-email-query.ts
outbound-email-where.ts
email-suppressions.ts
outbound-emails-read.ts
outbound-emails.ts
diffusion-debit.ts
entitlements-gate.ts
entitlements.ts
flow-quota.ts
index.ts
serve-diffusion.ts
stock-overflow.ts
campaign-deliveries.ts
diffusion-debit.ts
entitlements.ts
event-ingestion.ts
index.ts
ingested-event-handler.ts
ingested-events.ts
group-aggregations.ts
group-criteria.ts
group-ownership.ts
group-projections.ts
group-query.ts
group-sort.ts
group-students-criteria.ts
group-students-projections.ts
group-students-query.ts
group-students-where.ts
group-update-patch.ts
group-where.ts
group.dto.ts
groups.ts
index.ts
group-students.ts
groups-read.ts
groups.ts
index.ts
plan-criteria.ts
plan-grid-criteria.ts
plan-grid-projections.ts
plan-grid-query.ts
plan-grid-where.ts
plan-price-criteria.ts
plan-price-projections.ts
plan-price-query.ts
plan-price-where.ts
plan-pricing.ts
plan-projections.ts
plan-query.ts
plan-where.ts
plans.ts
catalogue-provider.ts
plans-read.ts
plans.ts
ad-banners-storage.ts
brand-assets-storage.ts
email-sender.ts
event-bus.ts
index.ts
queue.ts
session-token-service.ts
webhook-verifier.ts
group-session-aggregations.ts
group-session-boards-criteria.ts
group-session-boards-projections.ts
group-session-boards-query.ts
group-session-boards-where.ts
group-session-collections-criteria.ts
group-session-collections-projections.ts
group-session-collections-query.ts
group-session-collections-where.ts
group-session-criteria.ts
group-session-projections.ts
group-session-query.ts
group-session-sort.ts
group-session-update-patch.ts
group-session-where.ts
group-sessions.ts
index.ts
session.dto.ts
group-session-boards.ts
group-session-collections.ts
group-sessions-read.ts
group-sessions.ts
session-deals.ts
deal-projections.ts
deal-query.ts
deal-sort.ts
deal-where.ts
deal.ts
index.ts
public-collections.ts
public-deals.ts
public-sessions.ts
deal-read.ts
aggregation.ts
criteria.ts
index.ts
pagination.ts
projection.ts
query-object.ts
query-params.ts
sort.ts
where-operators.ts
read-repository.ts
scoped-deal.ts
write-repository.ts
index.ts
sharing-group-aggregations.ts
sharing-group-criteria.ts
sharing-group-members-aggregations.ts
sharing-group-members-criteria.ts
sharing-group-members-projections.ts
sharing-group-members-query.ts
sharing-group-members-where.ts
sharing-group-projections.ts
sharing-group-query.ts
sharing-group-update-patch.ts
sharing-group-where.ts
sharing-group.dto.ts
sharing-groups.ts
sharing-group-members.ts
sharing-groups-read.ts
sharing-groups.ts
index.ts
subscription-aggregations.ts
subscription-grants.ts
subscription-projections.ts
subscription-query.ts
subscription-reconciliation.ts
subscription-termination.ts
subscription-where.ts
subscriptions-admin.ts
subscriptions.ts
subscriptions-read.ts
subscriptions.ts
index.ts
telemetry-event-criteria.ts
telemetry-event-where.ts
telemetry-ingest.ts
telemetry-retention.ts
telemetry-events.ts
index.ts
student-aggregations.ts
student-criteria.ts
student-ownership.ts
student-projections.ts
student-query.ts
student-sort.ts
student-update-patch.ts
student-where.ts
student.dto.ts
students.ts
students-read.ts
students.ts
index.ts
owner-period-activity.ts
play-rollup-aggregations.ts
play-rollup-criteria.ts
play-rollup-run-aggregations.ts
play-rollup-run-criteria.ts
play-rollup-run-where.ts
play-rollup-where.ts
play-rollups.ts
rollup-boundary.ts
serves.ts
usage-analytics.ts
usage-perseverance-projections.ts
usage-perseverance-query.ts
usage-perseverance-where.ts
usage-perseverance-windows.ts
usage-stats.ts
owner-period-activity.ts
play-rollup-runs.ts
play-rollups-read.ts
play-rollups.ts
serves.ts
usage-perseverance-read.ts
usage-perseverance-windows.ts
usage-stats.ts
ensure-owner-themes.ts
index.ts
theme-aggregations.ts
theme-criteria.ts
theme-projections.ts
theme-query.ts
theme-sort.ts
theme-update-patch.ts
theme-where.ts
theme.dto.ts
themes.ts
theme-read.ts
theme.ts