Skip to content

Domain Layer (contexts/{context}/domain/)

@azure-net/kit does not provide specific components for working with the Domain layer, as the domain layer is quite unique in each project.

General Guidelines

  • Create folders in the domain layer by entities
  • Divide folders into ports and model, the first stores repository response types, the second the entity itself that is relevant for our frontend
  • You can store constants and enums from business entities in this layer, but do not store UI-layer constants here (those responsible for translations or text associations to some entity enumeration)
  • If an entity that came from the backend needs to be transformed for use on the frontend - use mapUsing or mapCollectionUsing in the infrastructure layer (methods are available in ResponseBuilder, documentation and description with examples in the documentation for this layer)
  • Business logic of the entity is located in this layer
  • You can create repository interfaces in this layer if you want to fully follow DDD and replace implementations in providers
  • When describing entities use interfaces, as classes are not serialized when working with SSR and you will still have to convert the class to an object if you want to return it from the server to the client
  • Implement business logic from the domain layer in the scenario logic of the application layer
  • Always think about the appropriateness of business logic, as the presence of complex business logic and calculations is inherent to the backend rather than the frontend, and business logic in its pure form is rare

Example of Domain Layer Organization


├── domain
│   ├── article
│   │   ├── enums
│   │   │   ├── ArticleStatuses.ts
│   │   │   ├── ArticleTypes.ts
│   │   │   └── index.ts
│   │   ├── index.ts
│   │   ├── model
│   │   │   └── index.ts
│   │   └── ports
│   │       └── index.ts
│   ├── auth
│   │   ├── index.ts
│   │   └── ports
│   │       ├── ILoginRequest.ts
│   │       ├── ILoginResponse.ts
│   │       └── index.ts