# mharis0801/chef-ai architecture

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

- Interactive diagram: https://gitdiagram.com/mharis0801/chef-ai
- Repository: https://github.com/mharis0801/chef-ai

## Overview

##### Project Type and Purpose
- This is a single‐page AI‐powered recipe generator built with React and Vite.
- It lives entirely in the browser (static hosting on Netlify) and calls out to the Hugging Face AI API to generate recipes from user-provided ingredients.

##### File Structure Analysis
- Top-level config: package.json, vite.config.js, eslint.config.js
- Public assets: index.html, public/ (favicon, static images)
- Source code under src/:
- App.jsx, Header.jsx, Main1.jsx – high-level layout
- ai.js – encapsulates calls to the external Hugging Face AI service
- components/ – reusable UI pieces (IngredientsList, Recipe display, ThemeToggle)
- context/ThemeContext.jsx – global theming state
- index.css, main.jsx – entrypoint and global styles

##### Key Insights from README
- Core feature: generate a recipe from at least four ingredients
- Live deployment: static site served by Netlify
- External dependency: Hugging Face AI inference API

##### Main Components
a. Frontend (React SPA)
- UI Layer: Header, IngredientsList input, ThemeToggle, Recipe display
- State Management: ThemeContext (dark/light mode)
- Business Logic: ai.js module orchestrates API calls
b. External Service
- Hugging Face AI Inference API – receives JSON payload of ingredients, returns recipe text
c. Hosting/Delivery
- Netlify (or any static host) serves the compiled bundle

##### Component Interactions & Data Flow
- User enters ingredients in IngredientsList → Main1 (or App) collects input
- On submit, ai.js sends HTTP POST to Hugging Face endpoint
- Hugging Face returns generated recipe → ai.js resolves promise
- App updates state → Recipe component renders the result
- ThemeToggle dispatches actions to ThemeContext → UI theme updates

##### Architectural Patterns & Design Principles
- Unidirectional data flow (React hooks + context)
- Separation of concerns: UI components vs. API logic vs. global state
- Modular file organization (components, context, assets)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Static Hosting
    subgraph "Static Hosting"
        Netlify["Netlify / Static Hosting"]:::infra
    end

    %% External Service
    subgraph "External Service"
        HF["Hugging Face AI Service"]:::external
    end

    %% Frontend SPA
    subgraph "Frontend (React SPA)"
        %% Entry & Configuration
        subgraph "Entry & Configuration"
            IndexHTML["index.html"]:::ui
            MainJS["main.jsx"]:::ui
        end

        %% UI Layout
        subgraph "UI Layout"
            App["App.jsx"]:::ui
            Header["Header.jsx"]:::ui
            Main1["Main1.jsx"]:::ui
        end

        %% UI Components
        subgraph "UI Components"
            Ingredients["IngredientsList.jsx"]:::ui
            RecipeComp["Recipe.jsx"]:::ui
            ThemeToggle["ThemeToggle.jsx"]:::ui
        end

        %% Global State
        subgraph "Global State"
            ThemeContext["ThemeContext.jsx"]:::service
        end

        %% Business Logic
        subgraph "Business Logic"
            AIjs["ai.js – HF API client"]:::client
        end

        GlobalCSS["index.css"]:::ui
        Config["package.json\nvite.config.js\neslint.config.js\npackage-lock.json"]:::infra
    end

    %% Data Flows
    Ingredients -->|"user input"| App
    App -->|"submit ingredients"| AIjs
    AIjs -->|"HTTPS REST API"| HF
    HF -->|"recipe response"| AIjs
    AIjs -->|"resolve promise"| App
    App -->|"renders recipe"| RecipeComp
    ThemeToggle -->|"toggle theme"| ThemeContext
    ThemeContext -->|"provides theme"| App

    %% Hosting Flow
    Netlify -->|"serves"| IndexHTML
    IndexHTML -->|"boots"| MainJS
    MainJS -->|"renders"| App

    %% Click Events
    click IndexHTML "https://github.com/mharis0801/chef-ai/blob/main/index.html"
    click MainJS "https://github.com/mharis0801/chef-ai/blob/main/src/main.jsx"
    click App "https://github.com/mharis0801/chef-ai/blob/main/src/App.jsx"
    click Header "https://github.com/mharis0801/chef-ai/blob/main/src/Header.jsx"
    click Main1 "https://github.com/mharis0801/chef-ai/blob/main/src/Main1.jsx"
    click Ingredients "https://github.com/mharis0801/chef-ai/blob/main/src/components/IngredientsList.jsx"
    click RecipeComp "https://github.com/mharis0801/chef-ai/blob/main/src/components/Recipe.jsx"
    click ThemeToggle "https://github.com/mharis0801/chef-ai/blob/main/src/components/ThemeToggle.jsx"
    click ThemeContext "https://github.com/mharis0801/chef-ai/blob/main/src/context/ThemeContext.jsx"
    click AIjs "https://github.com/mharis0801/chef-ai/blob/main/src/ai.js"

    %% Styles
    classDef ui fill:#D1E8FF,stroke:#036,stroke-width:1px
    classDef client fill:#D0F0C0,stroke:#3F7F3F,stroke-width:1px
    classDef service fill:#CFFFCF,stroke:#4F8A10,stroke-width:1px
    classDef external fill:#FFDFBA,stroke:#E67E22,stroke-width:1px
    classDef infra fill:#E0E0E0,stroke:#888,stroke-width:1px
```
