Architecture - Brewken/brewken GitHub Wiki
The changes to the database layer we are currently working on aim to get us to a more modular architecture.
The existing database code, from Brewtarget, works a particular way in part for historical reasons, specifically that the original version of the program used BeerXML files as its primary storage, and then was migrated to using a relational database. What's good about the Brewtarget database layer is that table definitions are all in one place. What's more challenging is that it's largely a database-first approach. If you want to do something in the object model - eg create a new Hop or add a Fermentable to a Recipe - you have to ask the Database class to do the change first in the database and then the consequences will show up in the object model. This means the Database class has to be quite big and to have lots of understanding of the object model.
We would like to move to a having a clearer separation between object model and object storage, where changes such as creating a new Hop or adding a Fermentable to a Recipe are done first in the object model and then pushed down to object storage.
+---------------------------------------------------------------------------------------------------------------------+
| Model |
| - The details of Recipe, Equipment, Instruction, etc |
| - Knows how to create, copy and modify objects |
| - Asks ObjectStore to store/retrieve objects |
| - No knowledge of inner workings of ObjectStore |
+---------------------------------------------------------------------------------------------------------------------+
| ObjectStore |
| - Knows how to serialise/deserialise objects to a SQL database |
| - Maintains an in-memory cache of objects |
| - No knowledge of which type of DB we're using |
| - No knowledge of credentials, DB file locations, etc |
| - No knowledge of inner workings of object model |
+---------------------------------------------------------------------------------------------------------------------+
| Database class |
| - Presents neutral interface for accessing the database |
| - Knows how to connect to different databases (SQLite, PostgreSQL) |
| - Deals with credentials, file locations, etc |
| - Handles database backups |
| - No knowledge of DB schema |
| - No knowledge of object model |
+---------------------------------------------------------------------------------------------------------------------+