klaufel / typescript-ddd-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

😈 TypeScript DDD example

A TypeScript DDD example is a skeleton of contain all business logic to be used in the application.

Based on @sui-domain package.

πŸ‘©β€πŸ’» Use domain

Execute use cases

import domain from "@typescript-ddd-example";

await domain.get("get_recipe_list_use_case").execute(/* params */);

All execute methods will return promises to be more consistent.

Subsribers of use cases

import domain from "@typescript-ddd-example";

const { unsubscribe } = domain
  .get("get_recipe_list_use_case")
  .subscribe(({ params, error, result }) => {
    // Callback
  });

Use subscribe method to subscribe to this use case.

πŸ”¬ Test

pnpm run domain:test pnpm run domain:test:ci

πŸ—‚ Conventions

Folder structure

- domain
  β”œβ”€β”€ src
  β”‚   β”œβ”€β”€ contexts
  β”‚   β”‚   └── [context]
  β”‚   β”‚       β”œβ”€β”€ entities
  β”‚   β”‚       β”‚   β”œβ”€β”€ factory.ts
  β”‚   β”‚       β”‚   └── [Entity].ts
  β”‚   β”‚       β”œβ”€β”€ mappers
  β”‚   β”‚       β”‚   β”œβ”€β”€ factory.ts
  β”‚   β”‚       β”‚   └── [Mapper].ts
  β”‚   β”‚       β”œβ”€β”€ repository
  β”‚   β”‚       β”‚   β”œβ”€β”€ factory.ts
  β”‚   β”‚       β”‚   └── [Repository].ts
  β”‚   β”‚       β”œβ”€β”€ services
  β”‚   β”‚       β”‚   β”œβ”€β”€ factory.ts
  β”‚   β”‚       β”‚   └── [Service].ts
  β”‚   β”‚       β”œβ”€β”€ useCases
  β”‚   β”‚       β”‚   β”œβ”€β”€ factories
  β”‚   β”‚       β”‚   β”‚   └── [useCaseFactory].ts
  β”‚   β”‚       β”‚   └── [UseCase].ts
  β”‚   β”‚       └── valueObjects
  β”‚   β”‚           β”œβ”€β”€ factories
  β”‚   β”‚           └── [valueObject].ts
  β”‚   └── index.ts
  └── test
      β”œβ”€β”€ contexts
      β”‚   └── [context]
      β”‚       └── [useCase].spec.ts
      └── fixtures
          └── [context]
              └── [useCase|Feature].ts

About


Languages

Language:TypeScript 100.0%