How slartibartfass2/ingredient_collector works
Main Components
• User Interface (Presentation Layer):
– Represented by the “lib/src/pages” and “lib/src/widgets” directories. These files build the home screen, recipe modification form, and input/output display.
• Recipe Controller (Business / Application Logic):
– Located in “lib/src/recipe_controller”. This component handles the orchestration between user actions and data processing and routes recipe URLs to the appropriate parser.
• Recipe Parsers (Processing / Strategy Pattern):
– Found in “lib/src/recipe_parser”. There’s a clear “RecipeParser” interface alongside various implementations like ChefkochParser, EatThisParser, BiancaZapatkaParser, etc. This design indicates a pluggable parser strategy based on the website.
• Data Models and Job Logging (Domain and Data Layer):
– The “lib/src/models” holds domain classes for recipes, ingredients, parsing results, etc.
– “lib/src/job_logs” captures logging related to each parsing job, useful for debugging or tracking failures.
• Local Storage:
– “lib/src/local_storage_controller.dart” abstracts storage concerns for saving user settings or cache data.
• Infrastructure / Network:
– Although not in a separate directory, the parsers themselves use HTTP requests to fetch recipe data. This may be displayed as a network module (or integration point) that many parser components rely upon.
Component Relationships
• The UI layer (pages and widgets) sends user input (a recipe URL or form data) to the Recipe Controller.
• The Recipe Controller, upon receiving a request, selects the correct RecipeParser from its collection (as defined in “recipe_website.dart”) based on the entered URL.
• The chosen RecipeParser makes HTTP requests to the recipe website, parses the response to extract ingredients, and produces a RecipeParsingResult.
• The Recipe Controller then aggregates the parsing results, logs important events (via the job logs module), and forwards the processed data back to the UI for display.
• Separately, the Local Storage Controller may persist settings or cache data between runs.
Architectural Patterns and Design Principles
• Separation of Concerns: Each layer (UI, controller, parsing, data models) is well-defined in its own module.
• Strategy Pattern: Different parsing implementations extend the “RecipeParser” interface to cater to various recipe websites.
• Modularization: By splitting parsers, controllers, and logging, the system is easily extendable—for example, to add support for a new website.
• Cross-Platform Consideration: The project supports multiple platforms (Android, Web, Windows, Linux) as seen from separate directories (android/, web/, windows/, linux/), which can be depicted as deployment targets surrounding the core Flutter-based architecture.