kworkflow / patch-hub

patch-hub is a TUI that streamlines the interaction of Linux developers with patches archived on lore.kernel.org
GNU General Public License v2.0
8 stars 6 forks source link

Extract `app` and `ui` components to `lib` and better modularize them #7

Open davidbtadokoro opened 4 months ago

davidbtadokoro commented 4 months ago

Context:

Overall, the codebase is currently being split into the following components:

  1. src/lib.rs: Contains all the logic related to Lore API, as well as its data structure (patches, Atom feeds, and so on). Broadly, this component represents all the "back end stuff" of lore-peek.
  2. src/app.rs: Represents the state of the running application (the Model component of the MVC pattern). This structure and name are derived from this tutorial used to bootstrap the application TUI and seems on par with the Rustacean community consensus.
  3. src/ui.rs: Encapsulates all the logic to correctly draw the user interface (a View component of the MVC pattern). This component doesn't change the app state and only composes the UI elements through reading it.
  4. src/main.rs: Responsible for calling the application's setup, startup, and teardown while ALSO containing a beast of an implementation of the Controller component of the MVC pattern.

Proposal:

Although the current "front end" implementation proposes to be a vertical prototype, which means that much of components 2 to 4 will be mutated, we should aim to start better organizing them right now. In this context, components 2 and 3 (component 4 will be scrutinized in a dedicated issue) can be greatly cleaned in two ways:

  1. As it turns out, we can (and probably should) extract them to compose the lore-peek library crate, albeit well-separated from the current library scope. They are (or at least, should be) stable enough to be able to be in lib.
  2. Already, these components show signs of needing to be broken down into smaller modules. For example, the App structure has a field to represent the states related to consulting the latest patchsets from a target mailing list, which has well-delimited logic that can be encapsulated for better modularization and organization. In the ui component, this is also evident if we consider that we probably would want a dedicated UI drawn for each encapsulated subset of application states. Long story short, we must break these components down into dedicated modules/files.

Setup: