# liu-ziting/what-to-eat architecture

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

- Interactive diagram: https://gitdiagram.com/liu-ziting/what-to-eat
- Repository: https://github.com/liu-ziting/what-to-eat

## Overview

##### Project type and purpose
- This is a full-stack-style Single-Page Application (SPA) focused on “intelligent recipe generation” using AI.
- There is no custom backend server in the repo—everything runs in the browser (Vue 3 + TypeScript + Tailwind) and calls out to external AI APIs (302.AI for text, BigModel/智谱 AI for images).
- Core features: recipe generation, nutrition analysis, image generation, wine pairing, sauce design, favorites management, dynamic AI config, and a “food fortune” mini-game.

##### File structure
- Top-level:
- Public/statically served assets (public/, index.html)
- Config and build scripts (.env.example, netlify.toml, vercel.json, build.sh, deployment guides)
- Source code under src/
- src/ breakdown:
- views/ – page‐level Vue components (Home, Favorites, FortuneCooking, etc.)
- components/ – reusable UI building blocks (RecipeCard, SettingsModal, FloatingChefAssistant, etc.)
- services/ – API wrappers for AI text (aiService.ts), AI image (imageService.ts), favorites (favoriteService.ts), gallery (galleryService.ts)
- stores/ – runtime config state (settings.js persisted locally)
- config/ – static lookup data (cuisines, ingredients, sauces, default AI settings)
- utils/ – low‐level helpers (apiConfig, envWatcher)
- types/ – TS type definitions
- main.ts – SPA bootstrap and router mount

##### README for additional insights
- Tech stack: Vue 3.4, TS 5.3, Tailwind 3.4, Vite 5.0
- Deployment: Netlify & Vercel for static hosting
- AI services: dynamic config allowing runtime switching of base URLs, keys, models, temperature, timeouts
- Architectural notes: “Dynamic Config System,” “service layer,” “stores,” “views/components” separation

a. Main components
- Client Browser (SPA)
- UI Layer (Vue Views & Components)
- State Management (stores/settings, localStorage)
- Service Layer (aiService, imageService, favoriteService, galleryService)
- Utility Layer (apiConfig, envWatcher)
- External AI Providers (302.AI for text gen; BigModel/智谱 for image gen; any OpenAI‐compatible API)
- Deployment Platform (Vercel / Netlify serving static assets)

b. Relationships & interactions
- UI Layer binds to State Management (reads/writes settings, favorites)
- UI dispatches service calls via Service Layer → External AI Providers
- Service Layer uses Utility Layer (apiConfig) to assemble requests
- Responses flow back to Service Layer → State / UI for rendering
- User actions (save favorite) call favoriteService → localStorage
- Dynamic Config UI modifies store → envWatcher picks up changes → apiConfig updated at runtime

c. Architectural patterns & design principles
- MVVM (Vue views bound to reactive state in stores)
- Layered architecture: UI → State → Services → External APIs
- Separation of concerns:
- Components vs Views
- Service abstraction for API calls
- Utility modules for config management
- Runtime configurability & persistence of settings (demo of dynamic config)

d. Key technologies & frameworks
- Vue 3 + TypeScript
- Vite build
- Tailwind CSS styling
- Pinia or Vue-reactive store (settings.js)
- REST/HTTP client (fetch or axios inside services)
- LocalStorage for favorites & config persistence
- External AI APIs (OpenAI-compatible)

##### Key takeaways
- Layers: Presentation, State Management, Service Abstraction, Utilities, External APIs, Deployment
- Detail relationships: how config flows at runtime, how services decouple from UI, how state persists
- Every module from the file tree appears in the appropriate layer

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Deployment Platform"
        NetlifyVercel["Netlify / Vercel"]:::external
    end

    subgraph "Client Browser (SPA)" 
        direction TB
        subgraph "UI Layer" 
            direction TB
            subgraph "Views (Pages)"
                Home["Home View"]:::ui
                Favorites["Favorites View"]:::ui
                FortuneCooking["FortuneCooking View"]:::ui
                Gallery["Gallery View"]:::ui
                HowToCook["HowToCook View"]:::ui
                SauceDesign["SauceDesign View"]:::ui
                SettingsDemo["SettingsDemo View"]:::ui
                TableDesign["TableDesign View"]:::ui
                TodayEat["TodayEat View"]:::ui
                About["About View"]:::ui
            end
            subgraph "Components"
                RecipeCard["RecipeCard"]:::ui
                RecipeModal["RecipeModal"]:::ui
                NutritionAnalysis["NutritionAnalysis"]:::ui
                WinePairing["WinePairing"]:::ui
                SauceRecipe["SauceRecipe"]:::ui
                FavoriteButton["FavoriteButton"]:::ui
                SettingsButton["SettingsButton"]:::ui
                SettingsModal["SettingsModal"]:::ui
                FloatingChefAssistant["FloatingChefAssistant"]:::ui
                GlobalNavigation["GlobalNavigation"]:::ui
                GlobalFooter["GlobalFooter"]:::ui
                ConfirmModal["ConfirmModal"]:::ui
                ImageModal["ImageModal"]:::ui
                NotesModal["NotesModal"]:::ui
                CookingLoader["CookingLoader"]:::ui
                FortuneCard["FortuneCard"]:::ui
                FloatingDonation["FloatingDonation"]:::ui
                ConfigTest["ConfigTest"]:::ui
            end
        end

        subgraph "State Management"
            SettingsStore["Settings Store"]:::state
        end

        subgraph "Service Layer"
            aiService["aiService.ts"]:::service
            imageService["imageService.ts"]:::service
            favoriteService["favoriteService.ts"]:::service
            galleryService["galleryService.ts"]:::service
        end

        subgraph "Utility Layer"
            apiConfig["apiConfig.js"]:::util
            envWatcher["envWatcher.js"]:::util
            sauceHelpers["sauceHelpers.ts"]:::util
        end

        subgraph "Configuration Data"
            aiConfig["ai.ts (AI Defaults)"]:::util
            cuisines["cuisines.ts"]:::util
            ingredients["ingredients.ts"]:::util
            saucesList["sauces.ts"]:::util
            fortuneSpec["fortune.ts"]:::util
        end

    end

    subgraph "External Dependencies"
        TextAI["302.AI (Text Generation)"]:::external
        ImageAI["BigModel/智谱 (Image Generation)"]:::external
        LocalStorage[(LocalStorage)]:::storage
    end

    %% Connections
    Home -->|reads/writes| SettingsStore
    Favorites -->|reads/writes| SettingsStore
    FortuneCooking -->|reads/writes| SettingsStore
    Gallery -->|reads/writes| SettingsStore
    HowToCook -->|reads/writes| SettingsStore
    SauceDesign -->|reads/writes| SettingsStore
    SettingsDemo -->|reads/writes| SettingsStore
    TableDesign -->|reads/writes| SettingsStore
    TodayEat -->|reads/writes| SettingsStore
    About -->|reads/writes| SettingsStore

    Home -->|uses| aiService
    FortuneCooking -->|uses| aiService
    SettingsDemo -->|uses| aiService
    Home -->|uses| imageService
    SauceDesign -->|uses| imageService
    Gallery -->|uses| galleryService
    Favorites -->|uses| favoriteService

    aiService -->|uses| apiConfig
    imageService -->|uses| apiConfig
    favoriteService -->|uses| apiConfig
    galleryService -->|uses| apiConfig

    aiService -->|triggers| envWatcher
    imageService -->|triggers| envWatcher

    aiService -->|calls| TextAI
    imageService -->|calls| ImageAI

    favoriteService -->|stores| LocalStorage
    Favorites -->|reads| LocalStorage

    SettingsStore -->|persisted in| LocalStorage
    envWatcher -->|updates| apiConfig

    %% Click Events
    click index.html "https://github.com/liu-ziting/what-to-eat/blob/master/index.html"
    click main.ts "https://github.com/liu-ziting/what-to-eat/blob/master/src/main.ts"
    click App.vue "https://github.com/liu-ziting/what-to-eat/blob/master/src/App.vue"

    click Home "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/Home.vue"
    click Favorites "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/Favorites.vue"
    click FortuneCooking "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/FortuneCooking.vue"
    click Gallery "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/Gallery.vue"
    click HowToCook "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/HowToCook.vue"
    click SauceDesign "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/SauceDesign.vue"
    click SettingsDemo "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/SettingsDemo.vue"
    click TableDesign "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/TableDesign.vue"
    click TodayEat "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/TodayEat.vue"
    click About "https://github.com/liu-ziting/what-to-eat/blob/master/src/views/About.vue"

    click RecipeCard "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/RecipeCard.vue"
    click RecipeModal "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/RecipeModal.vue"
    click NutritionAnalysis "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/NutritionAnalysis.vue"
    click WinePairing "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/WinePairing.vue"
    click SauceRecipe "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/SauceRecipe.vue"
    click FavoriteButton "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/FavoriteButton.vue"
    click SettingsButton "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/SettingsButton.vue"
    click SettingsModal "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/SettingsModal.vue"
    click FloatingChefAssistant "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/FloatingChefAssistant.vue"
    click GlobalNavigation "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/GlobalNavigation.vue"
    click GlobalFooter "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/GlobalFooter.vue"
    click ConfirmModal "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/ConfirmModal.vue"
    click ImageModal "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/ImageModal.vue"
    click NotesModal "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/NotesModal.vue"
    click CookingLoader "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/CookingLoader.vue"
    click FortuneCard "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/FortuneCard.vue"
    click FloatingDonation "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/FloatingDonation.vue"
    click ConfigTest "https://github.com/liu-ziting/what-to-eat/blob/master/src/components/ConfigTest.vue"

    click SettingsStore "https://github.com/liu-ziting/what-to-eat/blob/master/src/stores/settings.js"

    click aiService "https://github.com/liu-ziting/what-to-eat/blob/master/src/services/aiService.ts"
    click imageService "https://github.com/liu-ziting/what-to-eat/blob/master/src/services/imageService.ts"
    click favoriteService "https://github.com/liu-ziting/what-to-eat/blob/master/src/services/favoriteService.ts"
    click galleryService "https://github.com/liu-ziting/what-to-eat/blob/master/src/services/galleryService.ts"

    click aiConfig "https://github.com/liu-ziting/what-to-eat/blob/master/src/config/ai.ts"
    click cuisines "https://github.com/liu-ziting/what-to-eat/blob/master/src/config/cuisines.ts"
    click ingredients "https://github.com/liu-ziting/what-to-eat/blob/master/src/config/ingredients.ts"
    click saucesList "https://github.com/liu-ziting/what-to-eat/blob/master/src/config/sauces.ts"
    click fortuneSpec "https://github.com/liu-ziting/what-to-eat/blob/master/src/config/fortune.ts"

    click apiConfig "https://github.com/liu-ziting/what-to-eat/blob/master/src/utils/apiConfig.js"
    click envWatcher "https://github.com/liu-ziting/what-to-eat/blob/master/src/utils/envWatcher.js"
    click sauceHelpers "https://github.com/liu-ziting/what-to-eat/blob/master/src/utils/sauceHelpers.ts"

    classDef ui fill:#cce5ff,stroke:#333
    classDef state fill:#d4edda,stroke:#333
    classDef service fill:#fff3cd,stroke:#333
    classDef util fill:#e2e3e5,stroke:#333
    classDef external fill:#e2d5f9,stroke:#333
    classDef storage fill:#f0fff0,stroke:#333
```
