Section 7 of 17
Domains and boundaries
Contents
A domain is a folder with an explicit door. Inside the folder, the type rules of section 6 apply. Across folders, a single rule applies: you may import another domain's api library and nothing else.
7.1. The API library
fleet/api decides what fleet offers to the rest of the company. Everything not listed is private to the Workshop team and can change without asking anybody.
libs/fleet/api/src/index.ts
export type { VehicleSummary, VehicleId } from '@fleetline/fleet/model';
export { VehicleSummaryStore } from '@fleetline/fleet/data-access';
export { VehicleBadgeComponent } from '@fleetline/fleet/ui-vehicle-badge';
The store it exports is an NgRx Signal Store, while maintenance uses the classic NgRx Store. Maintenance does not need to know; it only sees VehicleSummaryStore.
libs/fleet/data-access/src/lib/vehicle-summary.store.ts
import { inject } from '@angular/core';
import { patchState, signalStore, withMethods } from '@ngrx/signals';
import { upsertEntities, withEntities } from '@ngrx/signals/entities';
import { rxMethod } from '@ngrx/signals/rxjs-interop';
import { tapResponse } from '@ngrx/operators';
import { filter, map, mergeMap, pipe } from 'rxjs';
import type { VehicleSummary } from '@fleetline/fleet/model';
import { FleetApi } from './fleet.api';
export const VehicleSummaryStore = signalStore(
{ providedIn: 'root' },
withEntities<VehicleSummary>(),
withMethods((store, api = inject(FleetApi)) => ({
ensureLoaded: rxMethod<readonly string[]>(
pipe(
map((ids) => [...new Set(ids)].filter((id) => !store.entityMap()[id])),
filter((ids) => ids.length > 0),
mergeMap((ids) =>
api.summaries(ids).pipe(
tapResponse({
next: (vehicles) => patchState(store, upsertEntities(vehicles)),
error: (error: unknown) => console.error('fleet summaries', error),
}),
),
),
),
),
})),
);
7.2. Shared is a domain too
shared has the tag domain:shared and may import only domain:shared. It knows no business term. A rule of thumb for reviews: if a file in shared contains the word of a domain (work order, invoice, vehicle), it moves into that domain.
7.3. When two domains need the same thing
| Situation | Answer |
|---|---|
| Billing shows a vehicle's plate | Billing imports fleet/api. |
| Maintenance and inventory both need the depot list | Depots are a concept of their own: a small depots domain, or fleet exports them in its API. Not shared. |
| Booking needs to open a work order after a booking | Booking calls the back-end; the back-end creates the work order. Front-end domains do not orchestrate each other's writes. |
| Two domains need the same date picker | It is technical, not business: shared/ui-design-system. |
| Two API libraries want to import each other | The domains are cut wrong. Merge them or move the shared concept into a third domain. |