# webpagesbypatel/ditewise architecture

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

- Interactive diagram: https://gitdiagram.com/webpagesbypatel/ditewise
- Repository: https://github.com/webpagesbypatel/ditewise

## Overview

##### Project Type and Purpose
- Ditewise is a full-stack, AI-powered web application built on Next.js (using the App Router).
- It provides personalized meal plans, progress tracking, and an AI chatbot, leveraging OpenAI (and potentially TensorFlow.js) for the AI/ML layer.

##### File Structure
- Top-level:
- next.config.ts, tsconfig.json, tailwind.config.ts → Next.js and styling configuration
- src/app → Next.js App Router pages (chat, community, dashboard, diet-plan, etc.)
- src/components → Reusable UI components and layout (Radix/UI primitives, forms, cards, charts)
- src/ai → Server-side business logic (“flows” for chatbot, diet-plan generator, nutrient analyzer, ingredient swapper)
- src/lib & src/hooks → Shared utilities, constants, actions, and custom React hooks
- README.md → Project description and tech stack (React, Node.js/Express, MongoDB, OpenAI API, TensorFlow.js)

##### Key Insights from README
- Frontend: React with Next.js (App Router), Tailwind CSS
- Backend: Node.js, Express (though the repo embeds server logic in Next.js)
- AI/ML: OpenAI API (and placeholder for TensorFlow.js)
- Database: MongoDB (not explicitly in code but mentioned for persistence)

##### Main Components
a. User Clients (Web Browser / Mobile)
b. Next.js Application
- App Router (React UI)
- API Routes or Server Actions invoking AI Flows
c. AI Business-Logic Layer (src/ai):
- ai-chatbot-assistant
- ai-diet-plan-generator
- nutrient-deficiency-analyzer
- smart-ingredient-swapper
d. Data Persistence (MongoDB)
e. External AI Service (OpenAI API, optional TensorFlow.js)
f. Utility Layer (src/lib, src/hooks)

##### Relationships and Interactions
- User → HTTP(s) → Next.js Frontend (renders pages, components)
- Frontend → Server Actions/API Routes → AI Business-Logic Modules
- AI Modules → HTTP(s) → OpenAI API (and/or TensorFlow.js in-browser)
- AI Module Results → Next.js → UI (meal plans, chatbot responses)
- Frontend & AI Modules → Database (MongoDB) for user profiles, progress logs, preferences
- Utility Layer (src/lib) supports both Frontend and Server logic with shared functions/constants

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- UI Layer (React components under src/app, src/components)
- Business Logic Layer (AI flows under src/ai)
- Data Layer (MongoDB) abstracted via utility actions (src/lib/actions.ts)
- Serverless or Server-Side Rendering: Next.js App Router can run server actions close to the data layer
- Component-Driven Development: Reusable UI components, hooks, and providers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User Client"]:::external

    subgraph "UI Layer"
        direction TB
        UIAppRouter["Next.js App Router"]:::ui
        RootLayout["Root Layout"]:::ui
        AppShell["App Shell"]:::ui
        ChatPage["Chat Page"]:::ui
        CommunityPage["Community Page"]:::ui
        DashboardPage["Dashboard Page"]:::ui
        DietPlanPage["Diet Plan Page"]:::ui
        FoodLogPage["Food Log Page"]:::ui
        GoalsPage["Goals Page"]:::ui
        IngredientSwapperPage["Ingredient Swapper Page"]:::ui
        LearnListPage["Learn Listing Page"]:::ui
        LearnDetailPage["Learn Detail Page"]:::ui
        MealPlannerPage["Meal Planner Page"]:::ui
        ProfilePage["Profile Page"]:::ui
        ProgressPage["Progress Page"]:::ui
        SettingsPage["Settings Page"]:::ui
        GlobalsCSS["Global CSS"]:::ui
    end

    subgraph "Server Layer"
        direction TB
        APIRoutes["Server Actions / API Routes"]:::business
    end

    subgraph "AI Business Logic"
        direction TB
        ChatbotFlow["Chatbot Assistant Flow"]:::business
        DietPlanFlow["Diet Plan Generator Flow"]:::business
        NutrientAnalyzer["Nutrient Deficiency Analyzer"]:::business
        IngredientSwapperFlow["Smart Ingredient Swapper Flow"]:::business
        AIBootstrapper["AI Flow Bootstrapper"]:::business
        AIDev["AI Dev Entry"]:::business
    end

    subgraph "Utility Layer"
        direction TB
        Actions["Actions"]:::utility
        Constants["Constants"]:::utility
        Utils["Helper Utilities"]:::utility
        PlaceholderData["Placeholder Data"]:::utility
        MobileHook["use-mobile Hook"]:::utility
        ToastHook["use-toast Hook"]:::utility
    end

    subgraph "External Services"
        direction TB
        OpenAI["OpenAI API"]:::external
        MongoDB["MongoDB"]:::external
    end

    %% Connections
    User -->|"Interacts with"| UIAppRouter
    UIAppRouter --> RootLayout
    RootLayout --> AppShell
    AppShell --> ChatPage
    AppShell --> CommunityPage
    AppShell --> DashboardPage
    AppShell --> DietPlanPage
    AppShell --> FoodLogPage
    AppShell --> GoalsPage
    AppShell --> IngredientSwapperPage
    AppShell --> LearnListPage
    LearnListPage --> LearnDetailPage
    AppShell --> MealPlannerPage
    AppShell --> ProfilePage
    AppShell --> ProgressPage
    AppShell --> SettingsPage
    AppShell --> GlobalsCSS

    AppShell --> APIRoutes
    APIRoutes --> ChatbotFlow
    APIRoutes --> DietPlanFlow
    APIRoutes --> NutrientAnalyzer
    APIRoutes --> IngredientSwapperFlow
    ChatbotFlow --> OpenAI
    DietPlanFlow --> OpenAI
    IngredientSwapperFlow --> OpenAI
    ChatbotFlow --> MongoDB
    DietPlanFlow --> MongoDB
    NutrientAnalyzer --> MongoDB
    IngredientSwapperFlow --> MongoDB

    ChatbotFlow -->|uses| AIBootstrapper
    DietPlanFlow -->|uses| AIBootstrapper
    NutrientAnalyzer -->|uses| AIBootstrapper
    IngredientSwapperFlow -->|uses| AIBootstrapper
    AIBootstrapper --> AIDev

    %% Utility connections
    Actions -.-> APIRoutes
    Actions -.-> ChatbotFlow
    Constants -.-> ChatbotFlow
    Utils -.-> DietPlanFlow
    PlaceholderData -.-> LearnListPage
    MobileHook -.-> UIAppRouter
    ToastHook -.-> UIAppRouter

    %% Click events
    click UIAppRouter "https://github.com/webpagesbypatel/ditewise/tree/main/src/app"
    click ChatPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/chat/page.tsx"
    click CommunityPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/community/page.tsx"
    click DashboardPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/dashboard/page.tsx"
    click DietPlanPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/diet-plan/page.tsx"
    click FoodLogPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/food-log/page.tsx"
    click GoalsPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/goals/page.tsx"
    click IngredientSwapperPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/ingredient-swapper/page.tsx"
    click LearnListPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/learn/page.tsx"
    click LearnDetailPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/learn/[articleId]/page.tsx"
    click MealPlannerPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/meal-planner/page.tsx"
    click ProfilePage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/profile/page.tsx"
    click ProgressPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/progress/page.tsx"
    click SettingsPage "https://github.com/webpagesbypatel/ditewise/blob/main/src/app/(app)/settings/page.tsx"
    click Actions "https://github.com/webpagesbypatel/ditewise/blob/main/src/lib/actions.ts"
    click Constants "https://github.com/webpagesbypatel/ditewise/blob/main/src/lib/constants.ts"
    click Utils "https://github.com/webpagesbypatel/ditewise/blob/main/src/lib/utils.ts"
    click PlaceholderData "https://github.com/webpagesbypatel/ditewise/blob/main/src/lib/placeholder-data.ts"
    click MobileHook "https://github.com/webpagesbypatel/ditewise/blob/main/src/hooks/use-mobile.tsx"
    click ToastHook "https://github.com/webpagesbypatel/ditewise/blob/main/src/hooks/use-toast.ts"
    click ChatbotFlow "https://github.com/webpagesbypatel/ditewise/blob/main/src/ai/flows/ai-chatbot-assistant.ts"
    click DietPlanFlow "https://github.com/webpagesbypatel/ditewise/blob/main/src/ai/flows/ai-diet-plan-generator.ts"
    click NutrientAnalyzer "https://github.com/webpagesbypatel/ditewise/blob/main/src/ai/flows/nutrient-deficiency-analyzer.ts"
    click IngredientSwapperFlow "https://github.com/webpagesbypatel/ditewise/blob/main/src/ai/flows/smart-ingredient-swapper.ts"
    click AIBootstrapper "https://github.com/webpagesbypatel/ditewise/blob/main/src/ai/genkit.ts"
    click AIDev "https://github.com/webpagesbypatel/ditewise/blob/main/src/ai/dev.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef business fill:#D5F5E3,stroke:#333,stroke-width:1px
    classDef utility fill:#F5F5F5,stroke:#333,stroke-width:1px
    classDef external fill:#FFE5B4,stroke:#333,stroke-width:1px
```
