PrivateconstructorProtected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Protected_Private_Private_Private_Private_StaticgetGets the singleton instance of RecipeDatabase
The singleton RecipeDatabase instance
StaticresetTears down the singleton instance completely.
Closes the database connection, clears every registered store listener, and discards the cached singleton so the next getInstance call builds a fresh instance. Call this when the app reinitializes its data layer (e.g. a settings reset or full data wipe) to guarantee no stale instance keeps its listeners registered and firing store notifications alongside the new one.
Promise that resolves once teardown is complete. No-op if no instance currently exists.
StaticscaleScales a recipe's ingredient quantities to a different number of persons
Creates a new recipe object with ingredient quantities adjusted proportionally for the target number of persons. If the recipe doesn't have a valid person count or already matches the target, returns the recipe unchanged.
The recipe to scale
The target number of persons to scale for
New recipe object with scaled ingredient quantities
Subscribes a callback to notifications for a specific data slice.
Called by useSyncExternalStore to register a re-render callback. Returns
an unsubscribe function that removes the callback from the listener set.
The data slice to subscribe to
Function to call when the slice changes
Unsubscribe function
Closes the database connection and resets all internal state
Use this method in test teardown (afterEach) to properly cleanup database resources between tests.
Promise that resolves when cleanup is complete
Initializes the database by creating tables and loading data into local cache
This method must be called before using any other database operations. It creates the necessary tables if they don't exist and loads all data into memory for faster access.
Promise that resolves when initialization is complete
PrivateperformChecks if the database is empty
Determines whether the database contains any data by checking if all three main tables (recipes, ingredients, and tags) are empty. This is useful for preventing duplicate data insertion during app initialization.
True if all main tables are empty, false if any table contains data
Adds a new ingredient to the database
The ingredient object to add
Promise resolving to the added ingredient with database ID
Adds a new tag to the database
The tag object to add
Promise resolving to the added tag with database ID
Adds multiple ingredients to the database in a single batch operation
Performs a batch insert for improved performance when adding multiple ingredients. Uses a database transaction to ensure atomicity and efficiency.
Array of ingredient objects to add
await db.addMultipleIngredients([
{
name: "Flour",
unit: "cups",
type: ingredientType.grain,
season: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
},
{
name: "Sugar",
unit: "cups",
type: ingredientType.sweetener,
season: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
}
]);
Adds multiple tags to the database in a single batch operation
Performs a batch insert for improved performance when adding multiple tags. Uses a database transaction to ensure atomicity and efficiency.
Array of tag objects to add
Adds a new recipe to the database
This method verifies that all ingredients and tags exist in the database, adding them automatically if they don't exist.
The recipe object to add
The persisted recipe, decoded from the database with its assigned id
Adds multiple recipes to the database, skipping any that fail validation.
Prepares all recipes in parallel via Promise.allSettled, logs a warning
for each rejected one, then batch-inserts the valid ones.
Array of recipes to add
Updates an existing recipe in the database.
Verifies all tags and ingredients exist in the database and saves any
temporary image to permanent storage before persisting the update, then
refreshes the in-memory cache and notifies recipes subscribers.
The existing recipe to update, carrying its persisted id.
The prepared recipe object with verified tags and ingredients.
Updates an existing ingredient in the database.
After a successful update the in-memory ingredients cache is refreshed and
every cached recipe that references this ingredient is patched in place,
then both the ingredients and recipes store slices are notified.
The ingredient to update. Must have a valid id.
true if the update succeeded, false otherwise.
PrivateapplyPrivate
Re-resolves an updated ingredient inside a cached recipe
Recipes embed a copy of each ingredient they use, so an ingredient rename or unit change has to be reflected in every recipe referencing it. The recipe-specific quantity and note are preserved and the recipe season is recomputed. Recipes that do not use the ingredient are returned untouched.
Cached recipe to patch
Updated ingredient, matched by id
The patched recipe, or the original one when unaffected
PrivateapplyPrivate
Re-resolves an updated tag inside a cached recipe
Mirror of applyIngredientToRecipe for tags, which carry no recipe-specific fields and so are replaced outright.
Cached recipe to patch
Updated tag, matched by id
The patched recipe, or the original one when unaffected
Updates an existing tag in the database.
After a successful update the in-memory tags cache is refreshed and every
cached recipe that references this tag is patched in place, then both the
tags and recipes store slices are notified.
The tag to update. Must have a valid id.
true if the update succeeded, false otherwise.
Returns a random sample of tags from the local cache.
If the cache contains fewer tags than requested, all available tags are returned. When the cache is empty an empty array is returned immediately.
Number of distinct random tags to return.
Array of randomly selected tags, length ≤ numOfElements.
Gets random ingredients of a specific type
The ingredient type to filter by
Number of random ingredients to return
Array of random ingredients of the specified type
Gets random tags from the database
Number of random tags to return
Array of random tags
Deletes a recipe from the database and performs related cleanup.
In addition to removing the recipe row, this method:
The persisted recipe to delete, matched by its id.
true if the recipe was deleted, false otherwise.
Deletes an ingredient from the database and removes it from all recipes.
Any recipe that referenced the deleted ingredient is updated in-place to
drop that ingredient, and both the ingredients and recipes store slices
are notified after the operation completes.
The ingredient to delete. Matched by id if present, otherwise by name/unit/type.
true if the ingredient was deleted, false otherwise.
Deletes a tag from the database and removes it from all recipes.
Any recipe that referenced the deleted tag is updated in-place to drop
that tag, and both the tags and recipes store slices are notified after
the operation completes.
The tag to delete. Matched by id if present, otherwise by name.
true if the tag was deleted, false otherwise.
Checks if a recipe exists in the database
Recipe to search for
True if recipe exists, false otherwise
Appends a recipe to the in-memory cache without persisting to the database.
Used internally after a successful database insert. Prefer addRecipe or addMultipleRecipes for full persistence.
The recipe to append to the cache.
Appends an ingredient to the in-memory cache without persisting to the database.
Used internally after a successful database insert. Prefer addIngredient or addMultipleIngredients for full persistence.
The ingredient to append to the cache.
Appends a tag to the in-memory cache without persisting to the database.
Used internally after a successful database insert. Prefer addTag or addMultipleTags for full persistence.
The tag to append to the cache.
Removes a recipe from the in-memory cache without touching the database.
Matches by id. Logs a warning if the recipe is not found in the cache.
Prefer deleteRecipe for full persistence including cascaded cleanup.
The persisted recipe to remove from the cache.
Removes an ingredient from the in-memory cache without touching the database.
Matches by id when present, otherwise uses full equality. Logs a warning if
the ingredient is not found. Prefer deleteIngredient for full persistence.
The ingredient to remove from the cache.
Removes a tag from the in-memory cache without touching the database.
Matches by id when present, otherwise uses full equality. Logs a warning if
the tag is not found. Prefer deleteTag for full persistence.
The tag to remove from the cache.
Replaces an existing recipe in the in-memory cache by id without touching
the database. No-ops silently if the recipe is not found.
The updated recipe. Matched by id.
Replaces multiple recipes in the in-memory cache in a single pass.
Uses a pre-built id→index Map for O(n) performance. Logs a warning for
any recipe in updatedRecipes whose id is not found in the current cache.
Array of updated recipes. Each must have a valid id.
Replaces an existing ingredient in the in-memory cache by id without
touching the database. No-ops silently if the ingredient is not found.
The updated ingredient. Matched by id.
Replaces an existing tag in the in-memory cache by id without touching
the database. No-ops silently if the tag is not found.
The updated tag. Matched by id.
Looks up a recipe in the in-memory cache by its id.
Persisted recipe to search for.
The matching cached recipe, or undefined if not found.
Looks up an ingredient in the in-memory cache.
Uses strict id equality when the ingredient has an id; falls back to
full structural equality (isIngredientEqual) otherwise.
Ingredient to search for.
The matching cached ingredient, or undefined if not found.
Looks up a tag in the in-memory cache.
Uses strict id equality when the tag has an id; falls back to full
structural equality (isTagEqual) otherwise.
Tag to search for.
The matching cached tag, or undefined if not found.
Checks if a recipe is already in the menu
The recipe ID to check
True if recipe is in menu, false otherwise
Adds a recipe to the menu and regenerates the shopping list
If the recipe is already in the menu, increments its count. Otherwise, it adds the recipe to the menu table with count = 1.
The persisted recipe to add to the menu
Toggles the cooked status of a menu item
The menu item ID to toggle
True if successful, false otherwise
Decrements the count of a menu item, removing it if count reaches 0
The menu item ID to decrement/remove
True if successful, false otherwise
Clears the entire menu
Returns the map of purchased ingredient states Key is ingredient name, value is whether it's purchased
Sets the purchase state for an ingredient
The ingredient name
Whether the ingredient is purchased
Clears all purchased ingredient states Called when the menu is cleared to start fresh
PrivatepruneDrops purchase state for ingredients that left the shopping list
Purchase state is keyed by ingredient name and outlives the menu item that put the ingredient on the list, so it must be pruned whenever the menu changes: cooking or removing a recipe would otherwise leave a flag behind that reappears — still checked — the next time the ingredient is shopped for. Ingredients still required by another non-cooked menu item keep their state.
Only menu changes prune. The shopping list also derives from the recipe catalogue, so editing a recipe's ingredients or deleting an ingredient can leave a flag behind until the next menu mutation clears it.
PrivatecommitApplies the shared post-condition of every menu mutation
Purchase state is keyed by ingredient name and outlives the menu item that put the ingredient on the list, so it must be pruned wherever the menu changes — routing every mutation through here keeps that invariant in one place instead of at the call sites that happened to need it.
Scales and updates a single recipe in the database
Takes a pre-scaled recipe object and updates it in the database. This method is used for individual recipe updates during progressive scaling operations.
The recipe to persist, already scaled to target
persons. Carries its database id; its embedded tags/ingredients are
normally already resolved, but any unresolved one causes encodeRecipe
to throw before the row is touched.
Finds recipes with similar ingredients and quantities
Uses ingredient comparison and fuzzy text matching to find recipes that share similar ingredients and cooking methods.
The recipe to find similarities for
Array of similar recipes
Gets all imported recipe source URLs for a specific provider
Returns URLs of recipes that have been successfully imported from the given provider. These recipes should be hidden from future discovery.
The provider identifier (e.g., 'hellofresh')
Set of source URLs for imported recipes
Gets all seen-but-not-imported recipe URLs for a specific provider
Returns URLs of recipes that were discovered but not imported. These recipes should be shown with a visual indicator.
The provider identifier (e.g., 'hellofresh')
Set of URLs for seen-but-not-imported recipes
Marks recipe URLs as seen for a specific provider
Records that the user has seen these recipes during discovery. Only adds new entries for URLs not already tracked.
The provider identifier (e.g., 'hellofresh')
Array of recipe URLs to mark as seen
Removes recipe URLs from seen history for a specific provider
Called after successful import to remove URLs from the "seen" list since they are now tracked as imported recipes.
The provider identifier (e.g., 'hellofresh')
Array of recipe URLs to remove from seen history
Gets all permanently dismissed recipe URLs for a specific provider.
Dismissed recipes were explicitly hidden by the user and must be filtered out of every future bulk-import discovery run.
The provider identifier (e.g., 'hellofresh')
Set of URLs the user has dismissed
Gets dismissed recipe records, optionally scoped to a provider.
Returns the full records (including title) so the manage list can display
them without re-running discovery. Sorted most-recently-dismissed first.
When providerId is omitted, records from every provider are returned.
OptionalproviderId: string
Optional provider identifier to filter by (e.g., 'hellofresh')
Array of dismissed recipe records, newest first
Permanently dismisses recipes for a specific provider.
Records that the user never wants to see these recipes again. Already-dismissed URLs are skipped. Dismissed recipes are excluded from all future discovery runs.
The provider identifier (e.g., 'hellofresh')
Recipes to dismiss, each providing its url, title and optional imageUrl
Restores previously dismissed recipes for a specific provider.
Removes the dismissal so the recipes reappear in future discovery runs. Used by the undo action and the manage list. Deletion is keyed on provider + URL, so it works regardless of whether the in-memory record carries a database id yet.
The provider identifier (e.g., 'hellofresh')
Array of recipe URLs to restore
PrivateprepareValidates and prepares a single recipe for insertion.
Verifies that all referenced tags and ingredients exist in the database, then resolves the image source. Throws if any references are missing.
The recipe to prepare
Prepared recipe ready for encoding and insertion
PrivateinsertBatch-inserts prepared recipes into the database and updates the in-memory cache.
Already-validated and prepared recipes to insert
PrivategetLoads all purchased ingredients from the database
Map of ingredient name to purchased state
PrivateencodePrivatenotifyFires all registered callbacks for the given store slice.
Called after every mutation so that useSyncExternalStore subscribers
know to re-read the store snapshot.
The data slice whose listeners should be triggered.
PrivateresetResets all in-memory caches to their initial empty values.
Does not touch the database — use closeAndReset for a full teardown that also closes the SQLite connection.
PrivateconstructPrivate
Constructs a Map structure for updating recipe data in the database
Converts an encoded recipe element into a Map structure suitable for database update operations, mapping column names to their corresponding values.
The encoded recipe data to construct update structure from
Map with column names as keys and recipe data as values
PrivateconstructPrivate
Constructs a Map structure for updating ingredient data in the database
Converts an ingredient element into a Map structure suitable for database update operations, properly encoding seasonal data with separators.
The ingredient data to construct update structure from
Map with column names as keys and ingredient data as values
PrivateconstructPrivate
Constructs a Map structure for updating tag data in the database
Converts a tag element into a Map structure suitable for database update operations.
The tag data to construct update structure from
Map with column names as keys and tag data as values
PrivateopenPrivatedeletePrivateverifyPrivate
Verifies that all tags exist in the database and returns them with database IDs
Checks each tag against the local cache and returns the database versions. Throws an error listing all tags that are not found in the database.
Array of tags to verify
Array of tags with database IDs
PrivateverifyPrivate
Verifies that all ingredients exist in the database and returns them with database IDs
Checks each ingredient against the local cache and returns the database versions with recipe-specific quantities and optional usage notes. Throws an error listing all ingredients that are not found.
Array of ingredients to verify
Array of ingredients with database IDs, recipe-specific quantities, and notes
PrivateencodePrivate
Encodes a recipe object for database storage
Converts a recipe from the application format to the database storage format, encoding all nested objects (tags, ingredients, preparation steps, nutrition) into string representations using appropriate separators.
The recipe object to encode for database storage
Encoded recipe element ready for database insertion/update
PrivatepreparePrivate
Prepares recipe image URI for database storage
Handles temporary image URIs by saving them to permanent storage. If the image URI is already in permanent storage, returns it unchanged. This encapsulates all image preparation logic within the database layer.
The image URI from the recipe (temporary or permanent)
The recipe title used for filename generation
Promise resolving to the permanent image URI
PrivatedecodePrivate
Decodes a recipe from database storage format to application format
Converts an encoded recipe element from the database into the full application format, decoding all nested data structures (ingredients, tags, preparation, nutrition) and resolving file paths and database references.
The encoded recipe data from database
Promise resolving to fully decoded recipe object
PrivatedecodePrivate
Decodes an array of recipes from database storage format
Processes multiple encoded recipe elements from database queries, decoding each one into the full application format. The ingredient and tag lookup indexes are built once and shared across the whole batch.
Array of encoded recipe elements from database
Array of fully decoded recipe objects
PrivatebuildPrivate
Builds id-keyed lookup indexes over the cached ingredients and tags
Recipe rows only store ingredient and tag ids, so decoding needs to resolve each id to its full element. Both tables are already fully cached in memory, so the lookups are served from these maps instead of one query per reference.
Ingredient and tag lookup maps keyed by database id, plus the sets collecting the ids that decoding could not resolve
PrivatereportPrivate
Reports references that a decode pass could not resolve against the caches
Every ingredient and tag a recipe row points at must exist in the caches, which mirror their whole tables. An unresolved id therefore means either a cache that drifted from the database or a recipe row pointing at a deleted row — both silently drop data from the decoded recipe, so they are logged as errors. Ids are reported once per decode pass rather than once per reference.
Decode indexes carrying the unresolved id sets
Number of recipes the decode pass covered
PrivaterecordPrivate
Logs a corrupt-data condition found while decoding a table, and records it
Decoding resolves cross-table references and casts stored strings into application types; neither can be trusted blindly, and a failure means the decoded row silently loses data. Every failure is logged. In development and E2E builds the first one is also kept, so the UI layer can rethrow it during render and let the root error boundary replace the app with the recovery screen — making the corruption impossible to miss. Production keeps the log and degrades the affected row rather than taking the whole app down.
Logging and recording live together so a future check cannot do one without
the other, and publishes on the recipes slice so a subscriber mounted
before the failure re-renders and can surface it.
What was found to be corrupt, including the offending ids
Structured detail for the log entry
Returns the first corrupt-data condition found while decoding, if any.
Always null in production builds.
The recorded decode error, or null when every decode succeeded
PrivateencodePrivate
Encodes an ingredient for storage within a recipe's ingredients list
Converts an ingredient to a string representation containing the ingredient's database ID, quantity, and optional usage note. Used when storing ingredient references within recipe data.
Format: "ID--quantity" or "ID--quantity%%note" if note is present. This allows the same ingredient to appear multiple times with different usage contexts (e.g., "olive oil" for sauce vs garnish).
The ingredient object to encode
Encoded string representation of the ingredient
PrivatedecodePrivate
Decodes ingredients from a recipe's encoded ingredient string
Parses the encoded ingredient string from a recipe, looking up each ingredient by ID in the database and combining it with the recipe-specific quantities and optional usage notes. Also calculates the combined seasonal availability.
Supports both old format (without notes) and new format (with notes):
Encoded string containing ingredient IDs, quantities, and optional notes
Decode indexes providing the cached ingredients and collecting unresolved ids
Tuple of [decoded ingredients array, combined season array]
// Old format (backward compatible)
Input: "1--250__2--100"
Output: [[ingredient1 with quantity 250, ingredient2 with quantity 100], ["5","6","7"]]
// New format with notes
Input: "1--200%%For sauce__1--100%%For garnish"
Output: [[ingredient1 with quantity 200 and note "For sauce", ingredient1 with quantity 100 and note "For garnish"], ...]
PrivatecomputePrivate
Computes the seasonal availability of a recipe from its ingredients
Intersects the seasons of every ingredient the recipe uses. A recipe with no resolvable ingredients is available all year.
Ingredients composing the recipe
Months during which every ingredient is available
PrivateencodePrivate
Encodes a single ingredient for database storage
Converts an ingredient element from application format into the encoded format required for database insertion. Joins seasonal data into a string representation using the encoding separator.
The ingredient object in application format
Encoded ingredient ready for database storage
PrivateencodePrivate
Encodes a single tag for database storage
Converts a tag element from application format into the encoded format required for database insertion.
The tag object in application format
Encoded tag ready for database storage
PrivatedecodePrivate
Decodes a single ingredient from database storage format
Converts an encoded ingredient element from the database into the application format, parsing the seasonal data from its encoded string representation.
The encoded ingredient data from database
Decoded ingredient object in application format
PrivatedecodePrivate
Decodes an array of ingredients from database storage format
Processes multiple encoded ingredient elements from database queries, converting each one to the application format. Returns empty array if input is null, undefined, or empty.
Array of encoded ingredient elements from database
Array of decoded ingredient objects in application format
PrivatereportPrivate
Reports rows sharing a database id within a cached table
Recipe decoding resolves ingredient and tag references through id-keyed maps built over these caches, so two rows with the same id silently shadow one another and every recipe referencing that id gets whichever row was indexed last. Cheap to detect while the table is already in hand.
Decoded rows of a cached table
Table name used in the log and error message
PrivatedecodePrivate
Calculates the intersection of two seasonal availability arrays
Combines seasonal data from multiple ingredients to determine when a recipe can be made using seasonal ingredients. Returns months that are common to both seasons.
Previously calculated season array (accumulated from other ingredients)
Season array from current ingredient
Array of month strings that are available in both seasons
PrivateencodePrivate
Encodes a tag for storage within a recipe's tags list
Converts a tag to its database ID string representation for storage within recipe data. Looks up the tag in the local cache if ID is missing.
The tag object to encode
String representation of the tag's database ID
PrivatedecodePrivate
Decodes tags from a recipe's encoded tag string
Parses the encoded tag string from a recipe, looking up each tag by ID in the cached tags to get the full tag information including names.
Encoded string containing tag IDs separated by encoding separators
Decode indexes providing the cached tags and collecting unresolved ids
Array of decoded tag objects
PrivatedecodePrivate
Decodes a single tag from database storage format
Converts an encoded tag element from the database into the application format.
The encoded tag data from database
Decoded tag object in application format
PrivatedecodePrivate
Decodes an array of tags from database storage format
Processes multiple encoded tag elements from database queries, converting each one to the application format. Returns empty array if input is null, undefined, or empty.
Array of encoded tag elements from database
Array of decoded tag objects in application format
PrivateencodePrivate
Encodes nutrition information for database storage
Converts a nutrition object to a string representation by joining all nutritional values with text separators for compact storage within recipe data.
The nutrition object to encode
String representation of all nutrition values separated by text separators
PrivatedecodePrivate
Decodes nutrition information from database storage format
Parses an encoded nutrition string back into a nutrition object. Returns undefined if the string is empty or has invalid format.
Encoded string containing nutrition values separated by text separators
Decoded nutrition object or undefined if invalid/empty
PrivatedecodePrivate
Decodes preparation steps from database storage format
Parses an encoded preparation string back into an array of preparation step objects. Each step can have both a title and description, or just a description.
Encoded string containing preparation steps
Array of preparation step objects with title and description
PrivategetPrivate
Retrieves all recipes from the database
Fetches all recipe records from the database and decodes them into the application format for use in the local cache. Embedded ingredients and tags are resolved from the in-memory caches, which must already be loaded.
Promise resolving to array of all recipes in application format
PrivategetPrivate
Retrieves all tags from the database
Fetches all tag records from the database and decodes them into the application format for use in the local cache.
Promise resolving to array of all tags in application format
PrivategetPrivate
Retrieves all ingredients from the database
Fetches all ingredient records from the database and decodes them into the application format for use in the local cache.
Promise resolving to array of all ingredients in application format
PrivategetPrivate
Retrieves all menu items from the database
Fetches all menu records from the database and decodes them into the application format for use in the local cache.
Promise resolving to array of all menu items in application format
PrivateencodePrivate
Encodes a menu item for database storage
Converts a menu element from application format into the encoded format required for database insertion.
The menu item in application format
Encoded menu item ready for database storage
PrivatedecodePrivate
Decodes a menu item from database storage format
Converts an encoded menu element from the database into the application format.
The encoded menu data from database
Decoded menu item in application format
PrivatedecodePrivate
Decodes an array of menu items from database storage format
Processes multiple encoded menu elements from database queries, converting each one to the application format. Returns empty array if input is null, undefined, or empty.
Array of encoded menu elements from database
Array of decoded menu items in application format
PrivatereportPrivate
Reports menu rows pointing at a recipe that no longer exists
Menu rows keep only a recipe id, resolved against the recipe cache when the menu is rendered. A row whose recipe was deleted therefore renders as an empty entry rather than failing outright, so it is surfaced here instead.
Checked against the caches rather than inside the menu decoder, because both sides are plain cached data — decoding a menu row cannot see the recipes. Resolved from the cache, so it costs no query.
PrivatearePrivate
Compares two ingredient lists for similarity
Determines if two ingredient lists are similar by comparing both ingredient names and quantities per person. Uses a 20% threshold for quantity differences. Used in the similar recipes feature to find recipes with comparable ingredients.
First ingredient list to compare
Second ingredient list to compare
True if ingredients lists are similar, false otherwise
PrivatemigratePrivate
Migrates the database to add source tracking columns if they don't exist
This migration adds SOURCE_URL and SOURCE_PROVIDER columns to the recipes table to support bulk import tracking. Runs safely even if columns already exist.
PrivategetPrivate
Retrieves all import history records from the database
Promise resolving to array of all import history records
PrivatedecodePrivate
Decodes an import history record from database format
PrivateencodePrivate
Encodes an import history record for database storage
PrivategetPrivate
Retrieves all dismissed recipe records from the database
Promise resolving to array of all dismissed recipe records
PrivatedecodePrivate
Decodes a dismissed recipe record from database format
PrivateencodePrivate
Encodes a dismissed recipe record for database storage
RecipeDatabase - Singleton class for managing recipe data storage and operations
This class provides a comprehensive interface for managing recipes, ingredients, tags, and shopping lists using SQLite database. It implements the singleton pattern to ensure a single database instance throughout the application lifecycle.
Key Features:
Example