Sekcja 3 z 17

Architektura na jednej stronie

Spis treści
maintenancefleetbookingbillingsharedapiapiapiapiapifeaturefeature-*feature-*feature-*feature-*uiui-*ui-*ui-*ui-*ui-*data-accessdata-accessdata-accessdata-accessdata-accessdata-accessmodelmodelmodelmodelmodelmodelutilutil-*util-*util-*util-*util-*
apps/<app>/                         thin: bootstrap, root routes, root providers
libs/<domain>/feature-<use-case>/   smart components for one use case (a page or a flow)
libs/<domain>/ui-<name>/            presentational components: inputs in, events out
libs/<domain>/data-access/          state, effects, HTTP, facade
libs/<domain>/model/                types and pure domain functions, no framework
libs/<domain>/util-<name>/          technical helpers for this domain
libs/<domain>/api/                  the only thing other domains may import
libs/<domain>/feature-shell/        the domain's routes and providers
libs/shared/<type>-<name>/          used by every domain, knows none of them

Sześć zdań do zapamiętania:

  1. Każda biblioteka ma jedną domenę i jeden typ, zapisane jako tagi, a tagi decydują, co może importować.
  2. Importy wskazują w dół drabiny typów: feature → ui, data-access → model → util. Nigdy w górę, nigdy w bok między feature'ami.
  3. Domena widzi inną domenę tylko przez jej bibliotekę api. Cała reszta domeny jest prywatna.
  4. shared nie zna żadnej domeny. Jeśli „wspólny” plik wspomina o zleceniach serwisowych, należy do maintenance.
  5. Komponenty nigdy nie rozmawiają z HTTP. Dane płyną przez data-access; feature widzi fasadę albo selektory, nigdy URL.
  6. Aplikacje są cienkie. Aplikacja spina trasy i providery; funkcje mieszkają w bibliotekach, więc druga aplikacja nic nie kosztuje.