# slartibartfass2/ingredient_collector architecture

> Architecture diagram of the GitHub repository slartibartfass2/ingredient_collector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/slartibartfass2/ingredient_collector
- Repository: https://github.com/slartibartfass2/ingredient_collector

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Targets Subgraph
    subgraph "Deployment Targets"
        direction TB
        Android("Android"):::deploy
        Web("Web"):::deploy
        Windows("Windows"):::deploy
        Linux("Linux"):::deploy
    end

    %% Core System Subgraph
    subgraph "Core System"
        direction TB

        %% Presentation Layer: Flutter UI (UI Components)
        subgraph "Presentation Layer (Flutter UI)"
            direction TB
            UI_Pages("Pages"):::ui
            UI_Widgets("Widgets"):::ui
        end

        %% Business Logic: Recipe Controller
        RecipeController("Recipe Controller"):::controller

        %% Parser Module: Strategy Pattern for Recipe Parsing
        subgraph "Parser Module"
            direction TB
            RecipeParserInterface("RecipeParser Interface"):::parser
            ChefkochParser("ChefkochParser"):::parser
            EatThisParser("EatThisParser"):::parser
        end

        %% Domain Models & Logging
        subgraph "Domain Models & Logging"
            direction TB
            DataModels("Models"):::domain
            JobLogs("Job Logs"):::domain
        end

        %% Local Storage Component
        LocalStorage("Local Storage"):::local
       
        %% External HTTP Network for fetching recipe data
        HTTPNetwork("HTTP API (Recipe Website)"):::network
    end

    %% Connections: UI to Controller
    UI_Pages -->|"UserInput"| RecipeController
    UI_Widgets -->|"UserInput"| RecipeController

    %% Connections: Controller to Parsers
    RecipeController -->|"SelectParser"| RecipeParserInterface
    RecipeParserInterface -->|"DelegateRequest"| ChefkochParser
    RecipeParserInterface -->|"DelegateRequest"| EatThisParser
    ChefkochParser -->|"HTTPCall"| HTTPNetwork
    EatThisParser -->|"HTTPCall"| HTTPNetwork
    HTTPNetwork -->|"ResponseData"| RecipeParserInterface
    RecipeParserInterface -->|"ParsedResult"| RecipeController

    %% Connections: Controller to UI for output display
    RecipeController -->|"DisplayResults"| UI_Pages
    RecipeController -->|"DisplayResults"| UI_Widgets

    %% Connections: Controller logs events
    RecipeController -->|"LogEvent"| JobLogs

    %% Connections: Controller persists data
    RecipeController -->|"PersistData"| LocalStorage

    %% Deployment Targets connected to Flutter UI (indicating cross-platform builds)
    Android ---|"Deploy"| UI_Pages
    Web ---|"Deploy"| UI_Pages
    Windows ---|"Deploy"| UI_Pages
    Linux ---|"Deploy"| UI_Pages

    %% Click Event Mappings
    click UI_Pages "https://github.com/slartibartfass2/ingredient_collector/tree/main/lib/src/pages"
    click UI_Widgets "https://github.com/slartibartfass2/ingredient_collector/tree/main/lib/src/widgets"
    click RecipeController "https://github.com/slartibartfass2/ingredient_collector/tree/main/lib/src/recipe_controller"
    click RecipeParserInterface "https://github.com/slartibartfass2/ingredient_collector/tree/main/lib/src/recipe_parser"
    click DataModels "https://github.com/slartibartfass2/ingredient_collector/tree/main/lib/src/models"
    click JobLogs "https://github.com/slartibartfass2/ingredient_collector/tree/main/lib/src/job_logs"
    click LocalStorage "https://github.com/slartibartfass2/ingredient_collector/blob/main/lib/src/local_storage_controller.dart"

    %% Styles
    classDef ui fill:#9ef,stroke:#333,stroke-width:2px;
    classDef controller fill:#bbf,stroke:#333,stroke-width:2px;
    classDef parser fill:#ff9,stroke:#333,stroke-width:2px;
    classDef domain fill:#f99,stroke:#333,stroke-width:2px;
    classDef local fill:#fc9,stroke:#333,stroke-width:2px;
    classDef network fill:#cfc,stroke:#333,stroke-width:2px;
    classDef deploy fill:#dda0dd,stroke:#333,stroke-width:2px;
```
