# kerokerokohei/nutri_pruner architecture

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

- Interactive diagram: https://gitdiagram.com/kerokerokohei/nutri_pruner
- Repository: https://github.com/kerokerokohei/nutri_pruner

## Overview

##### Main Components
- User Interface Layers:
- PC Interface: Located in src/PC. This includes components like PCApp.js which stitches together UI elements such as Header, ModalOpen variations, CalcNutri, Chat, ChatGPT, NutriDatabase, and WebGL.
- Mobile Interface: Located in src/SP. Similar to the PC view, MobileApp.js handles layout and contains similar components adapted for smartphone display.
- State Management & Business Logic:
- Redux Store: Represented by src/store. Actions and reducers (with separate implementations under src/PC/actions, src/PC/reducers, src/SP/actions, and src/SP/reducers) manage state changes such as setting modes (to ChatGPT, to WebGL, or simple state changes) and updating selected dishes.
- Data and External Services:
- Firebase Integration: Found in src/FireBase (firebase.js & TodosProvider.js). This is used for persisting data and possibly handling authentication or real-time updates.
- ChatGPT Integration: Both PC and mobile actions include “setToChatGPT” which suggests the system interacts with the ChatGPT API to fetch recipe recommendations based on nutritional imbalances.
- Unity/WebGL Integration: Unity builds (under public/unity) expose a WebGL interactive component that visualizes the nutritional balance evaluation. The WebGL.js components on both platforms manage the embedding and communication with these Unity builds.
- Styling & Build Tools:
- Tailwind CSS: Configured via tailwind.config.js and used for styling.
- Build/Config Files: Other support files such as postcss.config.js and package.json indicate the build process and dependency management.

##### Relationships and Interactions
- The user interacts with either the PC or Mobile UI to input food data.
- This interaction triggers actions (e.g., updateSelectedDishes, setToState, setToChatGPT, and setToWebGL) that update the application state via reducers.
- The state is centrally managed in the store which provides coordinated data to components like CalcNutri (for nutritional calculations) and the various Modal/Chat components.
- When the nutritional balance indicates deficiencies, the ChatGPT actions invoke external API calls to fetch recipe suggestions.
- In parallel, the computed results are fed into the Unity WebGL interface (via the WebGL component) which then displays the interactive, visual representation (including elements like rotating “komas” and animated Unity character).
- Firebase might handle data persistence and user session management.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Distinct directories for PC and Mobile interfaces allow specialized layouts while sharing business logic.
- Component-based Architecture: Each UI section (Nutrition Calculator, Chat, Modal Pop-Ups, etc.) is modular.
- Redux-like Data Flow: Actions dispatch changes to reducers and lead to UI updates.
- External Integration: Clear divisions between local business logic and external services like Firebase, ChatGPT, and Unity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Node
    User("User Input"):::external

    %% User Interfaces
    subgraph "User Interfaces"
        direction TB
        %% PC Interface
        subgraph "PC Interface"
            direction TB
            PCApp["PC App"]:::ui
            PC_Header["Header"]:::ui
            PC_CalcNutri["CalcNutri"]:::ui
            PC_Chat["Chat"]:::ui
            PC_ChatGPT["ChatGPT"]:::ui
            PC_Modal["ModalOpen"]:::ui
            PC_NutriDB["NutriDatabase"]:::ui
            PC_WebGL["WebGL"]:::ui
        end
        %% Mobile Interface
        subgraph "Mobile Interface"
            direction TB
            MobileApp["Mobile App"]:::ui
            Mobile_Header["Header"]:::ui
            Mobile_CalcNutri["CalcNutri"]:::ui
            Mobile_Chat["Chat"]:::ui
            Mobile_ChatGPT["ChatGPT"]:::ui
            Mobile_Modal["ModalOpen"]:::ui
            Mobile_NutriDB["NutriDatabase"]:::ui
            Mobile_WebGL["WebGL"]:::ui
            Mobile_Button["Button"]:::ui
        end
    end

    %% State Management
    subgraph "State Management (Redux)"
        direction TB
        ReduxStore["Redux Store"]:::state
        Redux_setToState["setToState"]:::state
        Redux_setToChatGPT["setToChatGPT"]:::state
        Redux_setToWebGL["setToWebGL"]:::state
        Redux_updateSelectedDishes["updateSelectedDishes"]:::state
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Firebase["Firebase"]:::external
        TodosProvider["TodosProvider"]:::external
        ChatGPT_API["ChatGPT API"]:::external
        Unity["Unity/WebGL"]:::external
    end

    %% Build & Styling Tools
    subgraph "Build & Styling Tools"
        direction TB
        Tailwind["TailwindCSS Config"]:::build
        PostCSS["PostCSS Config"]:::build
        PackageJSON["Package Manager"]:::build
    end

    %% Connections from User to Interfaces
    User -->|"interacts with"| PCApp
    User -->|"interacts with"| MobileApp

    %% PC Interface internal structure
    PCApp --> PC_Header
    PCApp --> PC_CalcNutri
    PCApp --> PC_Chat
    PCApp --> PC_ChatGPT
    PCApp --> PC_Modal
    PCApp --> PC_NutriDB
    PCApp --> PC_WebGL

    %% Mobile Interface internal structure
    MobileApp --> Mobile_Header
    MobileApp --> Mobile_CalcNutri
    MobileApp --> Mobile_Chat
    MobileApp --> Mobile_ChatGPT
    MobileApp --> Mobile_Modal
    MobileApp --> Mobile_NutriDB
    MobileApp --> Mobile_WebGL
    MobileApp --> Mobile_Button

    %% UI to State Management interactions
    PCApp -->|"dispatches actions"| ReduxStore
    MobileApp -->|"dispatches actions"| ReduxStore

    %% State actions flow
    ReduxStore --> Redux_setToState
    ReduxStore --> Redux_setToChatGPT
    ReduxStore --> Redux_setToWebGL
    ReduxStore --> Redux_updateSelectedDishes

    %% State Updates to UI Components
    ReduxStore -->|"updates"| PC_CalcNutri
    ReduxStore -->|"updates"| Mobile_CalcNutri

    %% ChatGPT Integration Flow
    Redux_setToChatGPT -->|"calls"| ChatGPT_API
    ChatGPT_API -->|"responds to"| PC_ChatGPT
    ChatGPT_API -->|"responds to"| Mobile_ChatGPT

    %% WebGL/Unity Integration Flow
    Redux_setToWebGL -->|"triggers"| PC_WebGL
    Redux_setToWebGL -->|"triggers"| Mobile_WebGL
    PC_WebGL -->|"renders in"| Unity
    Mobile_WebGL -->|"renders in"| Unity

    %% Firebase Data Persistence Flow
    ReduxStore <-->|"syncs data"| Firebase
    Firebase -->|"provides realtime updates"| TodosProvider

    %% Styling & Build Tools influence (ancillary)
    Tailwind --- PostCSS
    PostCSS --- PackageJSON

    %% Click Events for PC Interface
    click PCApp "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/PCApp.js"
    click PC_Header "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/Header.js"
    click PC_CalcNutri "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/CalcNutri.js"
    click PC_Chat "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/Chat.js"
    click PC_ChatGPT "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/ChatGPT.js"
    click PC_Modal "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/ModalOpen.js"
    click PC_NutriDB "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/NutriDatabase.js"
    click PC_WebGL "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/component/WebGL.js"

    %% Click Events for Mobile Interface
    click MobileApp "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/MobileApp.js"
    click Mobile_Header "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/Header.js"
    click Mobile_CalcNutri "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/CalcNutri.js"
    click Mobile_Chat "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/Chat.js"
    click Mobile_ChatGPT "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/ChatGPT.js"
    click Mobile_Modal "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/ModalOpen.js"
    click Mobile_NutriDB "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/NutriDatabase.js"
    click Mobile_WebGL "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/WebGL.js"
    click Mobile_Button "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/SP/component/button.js"

    %% Click Events for State Management
    click ReduxStore "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/store/index.js"
    click Redux_setToState "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/actions/setToState.js"
    click Redux_setToChatGPT "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/actions/setToChatGPT.js"
    click Redux_setToWebGL "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/actions/setToWebGL.js"
    click Redux_updateSelectedDishes "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/PC/actions/updateSelectedDishes.js"

    %% Click Events for External Services
    click Firebase "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/FireBase/firebase.js"
    click TodosProvider "https://github.com/kerokerokohei/nutri_pruner/blob/main/src/FireBase/TodosProvider.js"
    click Unity "https://github.com/kerokerokohei/nutri_pruner/tree/main/public/unity"
    
    %% Click Events for Build & Styling Tools
    click Tailwind "https://github.com/kerokerokohei/nutri_pruner/blob/main/tailwind.config.js"
    click PostCSS "https://github.com/kerokerokohei/nutri_pruner/blob/main/postcss.config.js"
    click PackageJSON "https://github.com/kerokerokohei/nutri_pruner/blob/main/package.json"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef state fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef build fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
```
