APPFLOWY_SYSTEM_DESIGN.md 4.9 KB

๐Ÿฅณ AppFlowy - Event Driven System

  • Goals of the System
  • Some Design Considerations
  • High Level Design
  • Component Design

๐ŸŽฏ Goals of the System

The AppFlowy project is an attempt to build a high performance application. Here are the top-level requirements for out system.

  1. High Performance.
  2. Cross-platform.
  3. Reliability
  4. Safety

๐Ÿค” Some Design Considerations

๐Ÿ“œ High Level Design

๐Ÿ“š Component Design

๐Ÿ“™ Event Dispatch

                        Frontend                                                     FLowySDK
                                                             โ”‚                                              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                                             โ”‚                                          โ”Œ7โ”€โ–ถโ”‚Handler Aโ”‚
                                                             โ”‚                                          โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                             โ”‚                             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”‚                        โ”Œโ”€โ”€โ”€โ–ถโ”‚Module A โ”‚โ”€โ”€โ”ผโ”€โ”€โ–ถโ”‚Handler Bโ”‚
โ”‚Widgetโ”‚โ”€1โ”€โ–ถโ”‚Blocโ”‚โ”€2โ”€โ–ถโ”‚ Repository A โ”‚โ”€3โ”€โ”                   โ”‚                        โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚                   โ”‚                        โ”‚                 โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”ดโ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ””โ”€โ”€โ–ถโ”‚Handler Cโ”‚
                      โ”‚ Repository B โ”‚โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ–ถโ”‚ Event โ”‚โ”€4โ”€โ–ถโ”‚FFI โ”‚โ”€5โ”€โ”€โ–ถโ”‚Dispatcher โ”‚โ”€6โ”€โ”ผโ”€โ”€โ”€โ–ถโ”‚Module B โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”ฌโ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚                   โ”‚                        โ”‚
                      โ”‚ Repository C โ”‚โ”€โ”€โ”€โ”˜                   โ”‚                        โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ”‚                        โ””โ”€โ”€โ”€โ–ถโ”‚Module C โ”‚
                                                             โ”‚                             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                             โ”‚
                                                             โ”‚

Here are the event flow:

  1. User click on the Widget(The user interface) that invokes the Bloc actions
  2. Bloc calls the repositories to perform additional operations to handle the actions.
  3. Repository offers the functionalities by combining the event, defined in the FlowySDK.
  4. Events will be passed in the FlowySDK through the FFI interface.
  5. Dispatcher parses the event and generates the specific action scheduled in the FlowySDK runtime.
  6. Dispatcher find the event handler declared by the modules.
  7. Handler consumes the event and generates the response. The response will be returned to the widget through the FFI.

The event flow will be discussed in two parts: the frontend implemented in flutter and the FlowySDK implemented in Rust.

FlowySDK

Frontend

The Frontend follows the DDD design pattern, you can recap from here.

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”Œโ”€โ”€โ”€โ”€โ”        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚Widgetโ”‚โ”€โ”€1โ”€โ”€โ”€โ”€โ–ถโ”‚Blocโ”‚โ”€โ”€2โ”€โ”€โ”€โ”€โ–ถโ”‚ Repository A โ”‚โ”€3โ”€โ”€โ”
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ””โ”€โ”€โ”€โ”€โ”˜        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
                                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                  โ”‚ Repository B โ”‚โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ–ถโ”‚ Event โ”‚
                                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
                                  โ”‚ Repository C โ”‚โ”€โ”€โ”€โ”€โ”˜
                                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜