# navassherif98/recipe-generation-from-food-image architecture

> Architecture diagram of the GitHub repository navassherif98/recipe-generation-from-food-image, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/navassherif98/recipe-generation-from-food-image
- Repository: https://github.com/navassherif98/recipe-generation-from-food-image

## Overview

##### Main Components
- User Interface (Frontend): Represented by the “Templates” (HTML files) and “static” directories. This component handles user interactions, displays forms, and shows the recipe output.
- Backend Server/Routes: Files like run.py, startup.py, routes.py, and __init__.py indicate that a web framework (likely Flask or a similar lightweight Python framework) is responsible for routing and handling requests.
- Deep Learning Model & Modules: The file “model.py” along with modules in the “modules” directory (e.g., encoder.py, multihead_attention.py, transformer_decoder.py) represent the core deep learning components for analyzing the food image and generating text.
- Data & Assets: The “data” directory holds the pretrained model (modelbest.ckpt) and vocabulary files (ingr_vocab.pkl and instr_vocab.pkl) which are essential for inference. Also include the “utils” folder for supporting functions (image processing, metrics, and visualization) that assist the core logic.
- Configuration & Deployment: Files like Procfile, requirements.txt, and potentially run.py/startup.py indicate deployment and runtime configurations.

##### Relationships and Interactions
- User requests come into the web server through browser interaction with the UI.
- The backend (via routes.py) processes the image input and calls the deep learning model functions in model.py.
- The deep learning modules (encoder, multihead attention, transformer decoder) are integrated with the model to perform inference, using data from the “data” folder.
- Utility modules provide additional support like file handling and output processing.
- The output is then rendered back to the user via the frontend templates.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project separates concerns into UI (templates/static), business logic (routes, model inference), and data/model configuration.
- Modular Design: The use of submodules (modules and utils directories) exemplifies a modular architecture facilitating easier maintenance and scalability.
- Integration of Deep Learning with Web: Combining deep learning inference components with a web backend indicates the use of a “service” architecture where the model is one of the core services behind the UI.

##### Relevant Technologies and Libraries
- Python as the programming language with associated libraries (as noted by requirements.txt).
- A deep learning framework (implied by the use of .ckpt files and modules like transformer_decoder) that might be PyTorch or TensorFlow.
- Web framework (likely Flask) for routing and rendering HTML templates.
- HTML/CSS/JavaScript for the front-end.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend"
        UI1["Templates (HTML)"]:::frontend
        UI2["Static Assets (CSS/JS)"]:::frontend
    end

    %% Backend Server/Routes
    subgraph "Backend Server"
        BE1["routes.py"]:::backend
        BE2["run.py"]:::backend
        BE3["startup.py"]:::backend
        BE4["__init__.py"]:::backend
    end

    %% Deep Learning Model & Modules
    subgraph "Deep Learning Model & Modules"
        DL1["model.py"]:::model
        subgraph "Modules"
            M1["encoder.py"]:::model
            M2["multihead_attention.py"]:::model
            M3["transformer_decoder.py"]:::model
            M4["utils.py"]:::model
        end
    end

    %% Data & Assets
    subgraph "Data & Assets"
        DATA["Data Folder (ingr_vocab, instr_vocab, modelbest.ckpt)"]:::data
    end

    %% Utility Functions
    subgraph "Utility Functions"
        UTL["Utils Folder (ims2file.py, metrics.py, output_utils.py, tb_visualizer.py)"]:::utils
    end

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        CONF1["Procfile"]:::config
        CONF2["requirements.txt"]:::config
    end

    %% Data Flow from Frontend to Backend and Deep Learning
    UI1 -->|"HTTP_Request"| BE1
    UI1 -->|"HTTP_Request"| BE2
    UI1 -->|"HTTP_Request"| BE3
    UI1 -->|"HTTP_Request"| BE4

    BE1 -->|"Calls_Model_Inference"| DL1
    BE2 -->|"Calls_Model_Inference"| DL1
    BE3 -->|"Calls_Model_Inference"| DL1
    BE4 -->|"Initializes_Model"| DL1

    %% Deep Learning uses its modules
    DL1 -->|"Uses"| M1
    DL1 -->|"Uses"| M2
    DL1 -->|"Uses"| M3
    DL1 -->|"Uses"| M4

    %% Deep Learning accesses Data and Utilities
    DL1 -->|"Loads_Data"| DATA
    DL1 -->|"Utilizes_Utilities"| UTL

    %% Response Flow: Model returns output through backend back to UI
    DL1 -->|"Returns_Recipe"| BE1
    BE1 -->|"Sends_Response"| UI1

    %% Configuration influence
    CONF1 -->|"Deployment_Config"| BE1
    CONF2 -->|"Dependencies"| BE1
    CONF2 -->|"Dependencies"| DL1

    %% Click Events for Component Mappings
    click UI1 "https://github.com/navassherif98/recipe-generation-from-food-image/tree/main/Foodimg2Ing/Templates"
    click UI2 "https://github.com/navassherif98/recipe-generation-from-food-image/tree/main/Foodimg2Ing/static"
    click BE1 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/routes.py"
    click BE2 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/run.py"
    click BE3 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/startup.py"
    click BE4 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/__init__.py"
    click DL1 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/model.py"
    click M1 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/modules/encoder.py"
    click M2 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/modules/multihead_attention.py"
    click M3 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/modules/transformer_decoder.py"
    click M4 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/Foodimg2Ing/modules/utils.py"
    click DATA "https://github.com/navassherif98/recipe-generation-from-food-image/tree/main/Foodimg2Ing/data"
    click UTL "https://github.com/navassherif98/recipe-generation-from-food-image/tree/main/Foodimg2Ing/utils"
    click CONF1 "https://github.com/navassherif98/recipe-generation-from-food-image/tree/main/Procfile"
    click CONF2 "https://github.com/navassherif98/recipe-generation-from-food-image/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#e1f5fe,stroke:#0277bd,stroke-width:2px;
    classDef backend fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px;
    classDef model fill:#fff3e0,stroke:#ef6c00,stroke-width:2px;
    classDef data fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px;
    classDef utils fill:#fce4ec,stroke:#d81b60,stroke-width:2px;
    classDef config fill:#ede7f6,stroke:#5e35b1,stroke-width:2px;
```
