|
1 |
| -# ddd |
| 1 | +# @angular-architects/ddd -- DDD Plugin for Nx |
2 | 2 |
|
3 |
| -This library was generated with [Nx](https://nx.dev). |
| 3 | +This plugin installs some schematics which automate slicing your Nx workspace into domains and layers according to Nrwl's best practices and our ideas about [client-side DDD with Angular](https://www.softwarearchitekt.at/aktuelles/sustainable-angular-architectures-1/): |
4 | 4 |
|
5 |
| -## Building |
| 5 | + |
6 | 6 |
|
7 |
| -Run `nx build ddd` to build the library. |
| 7 | +The generated access restrictions prevent unwanted access between libraries respecting layers and domains: |
8 | 8 |
|
9 |
| -## Running unit tests |
| 9 | + |
10 | 10 |
|
11 |
| -Run `nx test ddd` to execute the unit tests via [Jest](https://jestjs.io). |
| 11 | +## Features |
| 12 | + |
| 13 | +- 🗺️ Generating domains with domain libraries including a facades, models, and data services |
| 14 | +- ⚙️ Generating feature libraries including a feature components using the facades |
| 15 | +- 🙅♂️ Adding linting rules for access restrictions between domains as proposed by Nrwl |
| 16 | +- 🙅♀️ Adding linting rules for access restrictions between layers as proposed by Nrwl (supports tslint and eslint) |
| 17 | +- 🔥 Optionally generates skeleton for NGRX and integrates it into the DDD design (`--ngrx` switch) |
| 18 | +- 💥 Supports Standalone Components |
| 19 | + |
| 20 | +### Features Overview Video |
| 21 | + |
| 22 | +<a href="https://www.youtube.com/watch?v=39JLXMEE7Ds" target="_blank"></a> |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Add this plugin to a Nx workspace: |
| 27 | + |
| 28 | +``` |
| 29 | +npm i @angular-architects/ddd |
| 30 | +ng g @angular-architects/ddd:init |
| 31 | +``` |
| 32 | + |
| 33 | +Instead, you can also use ng add, however, Nx currently emits a warning when using ng add: |
| 34 | + |
| 35 | +``` |
| 36 | +ng add @angular-architects/ddd |
| 37 | +``` |
| 38 | + |
| 39 | +Add domains and features manually: |
| 40 | + |
| 41 | +``` |
| 42 | +ng g @angular-architects/ddd:domain booking --addApp |
| 43 | +ng g @angular-architects/ddd:domain boarding --addApp |
| 44 | +ng g @angular-architects/ddd:feature search --domain booking --entity flight |
| 45 | +ng g @angular-architects/ddd:feature cancel --domain booking |
| 46 | +ng g @angular-architects/ddd:feature manage --domain boarding |
| 47 | +``` |
| 48 | + |
| 49 | +For NGRX support, just add the `--ngrx` switch: |
| 50 | + |
| 51 | +``` |
| 52 | +ng g @angular-architects/ddd:domain luggage --addApp --ngrx |
| 53 | +ng g @angular-architects/ddd:feature checkin --domain luggage --entity luggage-list --ngrx |
| 54 | +[...] |
| 55 | +``` |
| 56 | + |
| 57 | +This example assumes that you have an app `flight-app` in place. |
| 58 | + |
| 59 | +These schematics also wire up the individual libs. To see the result, create a dependency graph: |
| 60 | + |
| 61 | +``` |
| 62 | +npm run dep-graph |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +To see that the skeleton works end-to-end, call the generated feature component in your `app.component.html`: |
| 68 | + |
| 69 | +```html |
| 70 | +<booking-search></booking-search> |
| 71 | +``` |
| 72 | + |
| 73 | +You don't need any TypeScript or Angular imports. The plugin already took care about that. After running the example, you should see something like this: |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +## Standalone Components |
| 78 | + |
| 79 | +All generators have a switch ``--standalone`` to support Standalone Components: |
| 80 | + |
| 81 | +``` |
| 82 | +ng g @angular-architects/ddd:domain booking --addApp --standalone |
| 83 | +
|
| 84 | +ng g @angular-architects/ddd:feature search --domain booking --entity flight --standalone |
| 85 | +``` |
| 86 | + |
| 87 | +Don't mix Standalone Components and traditional ones within the same domain. |
| 88 | + |
| 89 | +## Generated Structure |
| 90 | + |
| 91 | +The included schematics generate a folder for each domain. This folder contains feature libs as well as a library with the domain logic: |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +The domain layer is subdivided into three parts: |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +### Generated Structure for Domain Library |
| 100 | + |
| 101 | +- **application:** Contains application services. This is a DDD term for what we call facades in Angular nowadays. They orchestrate everything for a use case given so that a feature component only needs to communicate with one such facade. Also, it hides details for state management. While the generates facades just use a `BehaviorSubject`, feel free to add a library like NGRX underneath. As such a modifications changes nothing from the component's perspective, you can use facades to introduce NGRX later on demand. |
| 102 | +- **entities:** Client-side data model including logic operating on it (like validations). |
| 103 | +- **infrastructure:** Services for communicating with the backend. |
| 104 | + |
| 105 | +## Consider Automatically Checking Access Restrictions |
| 106 | + |
| 107 | +As the access restrictions defined with Nx use linting, you can check against them at the command line too. Hence, you might consider including this into your automated build process. |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +## Example Application |
| 112 | + |
| 113 | +see https://github.com/angular-architects/ddd-demo |
| 114 | + |
| 115 | +## Credits |
| 116 | + |
| 117 | +- [Nx](https://nx.dev/web) |
| 118 | +- [Nrwl's eBook about monorepos and best practices](https://go.nrwl.io/angular-enterprise-monorepo-patterns-new-book) |
| 119 | +- [Recording of session about this architecture](https://www.youtube.com/watch?v=94HFD391zkE&t=1s) |
| 120 | +- [Article series about DDD with Angular](https://www.softwarearchitekt.at/aktuelles/sustainable-angular-architectures-1/) |
| 121 | +- [Our eBook on Angular and architectures](https://leanpub.com/enterprise-angular) |
| 122 | +- [Thomas Burlison's article about facades in Angular](https://medium.com/@thomasburlesonIA/push-based-architectures-with-rxjs-81b327d7c32d) |
| 123 | + |
| 124 | +## More |
| 125 | + |
| 126 | +- [Angular Architecture Workshop](https://www.angulararchitects.io/en/angular-workshops/advanced-angular-enterprise-architecture-incl-ivy/) |
| 127 | +- [Follow us on Twitter](https://twitter.com/ManfredSteyer) |
0 commit comments