Przeglądaj źródła

update README with DDD Event flow

appflowy 3 lat temu
rodzic
commit
2053cd7f05
3 zmienionych plików z 61 dodań i 18 usunięć
  1. 3 0
      .gitignore
  2. 2 0
      .idea/appflowy_client.iml
  3. 56 18
      doc/architecture.md

+ 3 - 0
.gitignore

@@ -8,3 +8,6 @@ Cargo.lock
 
 # These are backup files generated by rustfmt
 **/*.rs.bk
+
+/rust-lib/flowy-ast
+/rust-lib/flowy-derive

+ 2 - 0
.idea/appflowy_client.iml

@@ -2,6 +2,7 @@
 <module type="CPP_MODULE" version="4">
   <component name="NewModuleRootManager">
     <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-ast/src" isTestSource="false" />
       <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.pub" />
       <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.dart_tool" />
       <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/build" />
@@ -26,6 +27,7 @@
       <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/flowy_protobuf/.dart_tool" />
       <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/flowy_protobuf/.pub" />
       <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/flowy_protobuf/build" />
+      <excludeFolder url="file://$MODULE_DIR$/rust-lib/target" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />

+ 56 - 18
doc/architecture.md

@@ -167,27 +167,65 @@ The AppFlowy Client consists of lots of modules. Each of them follows the DDD de
 to communication with other module.
 
 ```
-     Client
-    ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
-    │                                                                                                      │
-    │   User                                 Editor                   Setting                              │
-    │  ┌───────────────────┐                ┌───────────────────┐    ┌───────────────────┐                 │
-    │  │ presentation      │   Dependency   │ presentation      │    │ presentation      │                 │
-    │  │                   │   Injection    │                   │    │                   │                 │
-    │  │ application       ├───────────────▶│ application       │    │ application       │                 │
-    │  │                   │◀───────────────│                   │    │                   │    ◉  ◉  ◉      │
-    │  │ domain            │                │ domain            │    │ domain            │                 │
-    │  │                   │                │                   │    │                   │                 │
-    │  │ Infrastructure    │                │ Infrastructure    │    │ Infrastructure    │                 │
-    │  └───────────────────┘                └───────────────────┘    └───────────────────┘                 │
-    │            ▲                                                             │                           │
-    │            │                       Dependency Injection                  │                           │
-    │            └─────────────────────────────────────────────────────────────┘                           │
-    │                                                                                                      │
-    └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
+
+   Client
+  ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
+  │                                                                                                      │
+  │   Module A                             Module B                 Module C                             │
+  │  ┌───────────────────┐                ┌───────────────────┐    ┌───────────────────┐                 │
+  │  │ presentation      │   Dependency   │ presentation      │    │ presentation      │                 │
+  │  │                   │   Injection    │                   │    │                   │                 │
+  │  │ application       ├───────────────▶│ application       │    │ application       │                 │
+  │  │                   │◀───────────────│                   │    │                   │    ◉  ◉  ◉      │
+  │  │ domain            │                │ domain            │    │ domain            │                 │
+  │  │                   │                │                   │    │                   │                 │
+  │  │ Infrastructure    │                │ Infrastructure    │    │ Infrastructure    │                 │
+  │  └───────────────────┘                └───────────────────┘    └───────────────────┘                 │
+  │            ▲                                                             │                           │
+  │            │                       Dependency Injection                  │                           │
+  │            └─────────────────────────────────────────────────────────────┘                           │
+  │                                                                                                      │
+  └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
 ```
 
 Let's dig it how can I construct each module. I take `User` module for demonstration.
 
+```
+
+     presentation            Application                      domain                           Infrastructure
+
+                  │
+                                              │                                  │
+                     7                                 Data Model
+       ┌──────────────────────────────┐       │       ┌────────────────────────┐ │         ┌───────────────────────────┐
+       │          │                   │               │ ┌─────────────┐        │    ┌─────▶│ Repository implementation │
+       ▼             Bloc             │         2.1   │ │  Aggregate  │        │ │  │      └───────────────────────────┘
+┌─────────────┐   │ ┌─────────────────┴─────┐         │ └─────────────┘        │    │                    │  4
+│   Widget    │     │ ┌────────┐ ┌────────┐ │ │       │ ┌────────┐             │ │  │                    ▼
+└─────────────┘   │ │ │ Event  │ │ State  │ │───┬────▶│ │ Entity │             │    │         ┌─────────────────────┐
+       │            │ └────────┘ └────────┘ │ │ │     │ └────────┘             │ │  │         │    Unit of Work     │
+       │          │ └──────▲────────────────┘   │     │ ┌─────────────────┐    │    │         └─────────────────────┘
+       │                   │                  │ │     │ │  Value Object   │    │ │  │                    │  5
+       └──────────┼────────┘                    │     │ └─────────────────┘    │    │                    ▼
+             1                                │ │     └────────────────────────┘ │  │         ┌─────────────────────┐
+                  │                             │                  ◈                │         │ Persistence Service │
+                                              │ │                  │ contain     │  │         └─────────────────────┘
+                  │                             │       ┌────────────────────┐      │
+                                              │ │       │      Service       │   │  │
+                  │                             │       └────────────────────┘      │
+                                              │   2.2                            │  │
+                  │                             │    ┌───────────────────────┐      │
+                                              │ └───▶│ Repository interface  │   │  │
+                  │                                  └───────────────────────┘      │
+                                              │                  │               │  │
+                  │                                              │          3       │
+                                              │                  └───────────────┼──┘
+```
+
 
+1.  Send event using the bloc. The bloc does not know about the `Widget`. It should communicate through events.
+2.  The bloc dispatching the event to the appropriate handler of the `Domain`
+    1. Conversion between, DTO (Data Transfer Object) to domain model and Domain Model to DTO.
+    2.  Handling the business logic using the repository interface
+3.  Repository are used to store the domain model data and calls respective service to finish the jobs.
 # Event-Driven