Skip to content

Architecture

nick42d edited this page Aug 20, 2024 · 9 revisions

Youtui & ytmapi-rs Architecture

Design constraints

App has been designed for me to learn Rust, and therefore I have implemented the following constraints to learn some features. I am aware these may not be the most efficient ways to code.

  1. Avoid shared mutable state: The app will avoid shared mutable state primitives such as Mutex and RefCell and instead communicate via messaging.
  2. Concurrency over parralelism: Where possible, the app will use use an asynchronous mode of operation (such as futures::join! and tokio::select) over parallel equivalents such as tokio::spawn and thread::spawn.
  3. Avoid cloning: Where possible, the app will avoid cloning as a method to beat the borrow checker. Instead, we will try to safely borrow.
  4. Encode state into the type system: Where possible use the type system to represent actions that are not possible in the current state.
  5. Avoid dynamic dispatch: Where possible, static dispatch will be used over dynamic dispatch

Youtui Architecture Diagram

WIP

flowchart TD
M("youtui::main()")-->Clap-->Config-->CLI
Config-->TUI
CLI-->Error
TUI-->Error
Error
CLI
subgraph TUI
subgraph App
subgraph "App.run()"
direction TB
H("handle_next_event()")==>C("process_callbacks()")
C-.->TaskManager
C==>S("synchronize_state()")==>D("draw")
D==>H
end
EventHandler
TaskManager
EventHandler
UI
CallbackQueue

EventHandler-.->H
H-.->UI
CallbackQueue-.->C
C-.->UI
TaskManager<-.->Server
TaskManager-.->S
S-.->UI
UI-.->D
end
Server
end
Loading

Proposed file structure

  1. Module documentation
  2. Traits
  3. Structs
    1. Major struct implementations
  4. Implementations (Grouped by trait)
  5. Functions