# plawangshishugit/nutriapp architecture

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

- Interactive diagram: https://gitdiagram.com/plawangshishugit/nutriapp
- Repository: https://github.com/plawangshishugit/nutriapp

## Overview

##### Project Type & Purpose
- NutriApp is a full‐stack application that delivers personalized diet plans with both a rich, dynamic front end and a backend that supports REST/API endpoints (via Next.js API routes) along with a machine learning (ML) component. It leverages modern technologies (React, Tailwind CSS, Node.js, Express, MongoDB, Python/FastAPI for ML) to provide users with customized dietary guidance.

##### Main Components to Highlight
a. Frontend (Client):
- The “app” folder contains Next.js pages (e.g., home, login, register, profile, diet-plan) that define the user interface.
- The “components” and “hooks” directories harbor reusable UI components and custom hooks, showcasing a component-based architecture.
- Global styling files (e.g., globals.css, tailwind.config.ts) define the dark, cosmic UI look.

b. Backend API Endpoints:
- The “app/api” folder includes multiple endpoints for authentication (login, signup) and user functionalities (diet-plan, profile, profile-status). These endpoints represent the server side of the Next.js application.
- Middleware (e.g., middleware.ts) can be illustrated as an interstitial layer processing requests.

c. Database & Authentication:

d. ML Model Service:
- Despite its absence in the file tree, the README references a separate ML model setup (using Python, FastAPI, Pandas). Include a distinct “ML Model Service” component that the backend calls to generate the personalized diet plans.

e. Deployment & Configuration:

##### Relationships & Data Flow
- From the Backend, show a connection to the MongoDB database (illustrate data persistence for user profiles, authentication tokens, and diet plan data).
- Optionally, indicate any middleware layers that process requests between the client and the API endpoints.

##### Architectural Patterns & Design Principles
- A clear separation of concerns—UI components are isolated from API business logic.
- That API endpoints in the “app/api” folder serve as controllers in an MVC-like pattern within Next.js.
- Integration points such as authentication (e.g., login/signup endpoints using JWT) and data fetching (using Axios in the frontend).
- Recognize the platform’s modularity: separate directories for UI, utility functions (lib/), and custom hooks, making the design highly maintainable.

##### Elements
- Use clear labels for every component (e.g., “Frontend UI (Next.js)”, “Authentication Service”, “Diet Plan API”, “MongoDB Database”, “ML Model Service (FastAPI)”).
- From the user/browser to the Frontend.
- From the Frontend to the API endpoints.
- From API endpoints to the Database and ML Model Service.
- Middleware as an overlay between client requests and backend processing.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Top-level User
    UB("User/Browser"):::frontend

    %% Frontend (Client UI)
    subgraph "Frontend (Client UI)"
        %% Pages & Routing
        subgraph "Pages & Routing"
            Home["Home Page"]:::pages
            Login["Login Page"]:::pages
            Register["Register Page"]:::pages
            Profile["Profile Page"]:::pages
            DietPlan["Diet Plan Page"]:::pages
        end
        %% Layout & Styling
        subgraph "Layout & Styling"
            Layout["Layout"]:::styling
            GlobalCSS["Global Styles"]:::styling
            StylesCSS["Styles CSS"]:::styling
            Tailwind["Tailwind Config"]:::styling
        end
        %% Reusable Components & Hooks
        subgraph "Reusable Components & Hooks"
            Components["UI Components"]:::components
            Hooks["Custom Hooks"]:::components
        end
    end

    %% Backend (API & Middleware)
    subgraph "Backend (API & Middleware)"
        Middleware["Middleware"]:::middleware
        
        subgraph "API Endpoints"
            API_AuthLogin["Login API"]:::api
            API_AuthSignup["Signup API"]:::api
            API_DietPlan["Diet Plan API"]:::api
            API_ProfileStatus["Profile Status API"]:::api
            API_Profile["Profile API"]:::api
        end
        
        subgraph "Configuration"
            NextConfig["Next Config"]:::config
            TSConfig["TS Config"]:::config
            PostCSS["PostCSS Config"]:::config
            PNPM["PNPM Lock"]:::config
        end
        
        DB["MongoDB Database"]:::database
    end

    %% ML Service
    ML["ML Model Service (FastAPI)"]:::ml

    %% Connections
    UB -->|"uses"| Home
    UB -->|"uses"| Login
    UB -->|"uses"| Register
    UB -->|"uses"| Profile
    UB -->|"uses"| DietPlan

    %% Frontend to Backend Connection via Middleware
    Home -->|"apiCall"| Middleware
    Login -->|"apiCall"| Middleware
    Register -->|"apiCall"| Middleware
    Profile -->|"apiCall"| Middleware
    DietPlan -->|"apiCall"| Middleware

    %% Middleware routing to API Endpoints
    Middleware -->|"auth"| API_AuthLogin
    Middleware -->|"auth"| API_AuthSignup
    Middleware -->|"user"| API_Profile
    Middleware -->|"user"| API_ProfileStatus
    Middleware -->|"dietPlan"| API_DietPlan

    %% API Endpoints interacting with Database
    API_AuthLogin -->|"store/fetch"| DB
    API_AuthSignup -->|"store/fetch"| DB
    API_Profile -->|"store/fetch"| DB
    API_ProfileStatus -->|"store/fetch"| DB
    API_DietPlan -->|"store/fetch"| DB

    %% API Endpoint calling ML Service for diet plan generation
    API_DietPlan -->|"callML"| ML

    %% Click Events for Frontend Pages & Styling
    click Home "https://github.com/plawangshishugit/nutriapp/blob/main/app/page.tsx"
    click Login "https://github.com/plawangshishugit/nutriapp/blob/main/app/login/page.tsx"
    click Register "https://github.com/plawangshishugit/nutriapp/blob/main/app/register/page.tsx"
    click Profile "https://github.com/plawangshishugit/nutriapp/blob/main/app/profile/page.tsx"
    click DietPlan "https://github.com/plawangshishugit/nutriapp/blob/main/app/diet-plan/page.tsx"
    click Layout "https://github.com/plawangshishugit/nutriapp/blob/main/app/layout.tsx"
    click GlobalCSS "https://github.com/plawangshishugit/nutriapp/blob/main/app/globals.css"
    click StylesCSS "https://github.com/plawangshishugit/nutriapp/blob/main/styles/globals.css"
    click Tailwind "https://github.com/plawangshishugit/nutriapp/blob/main/tailwind.config.ts"
    click Components "https://github.com/plawangshishugit/nutriapp/tree/main/components/"
    click Hooks "https://github.com/plawangshishugit/nutriapp/tree/main/hooks/"

    %% Click Events for Backend API Endpoints & Config/Middleware
    click API_AuthLogin "https://github.com/plawangshishugit/nutriapp/blob/main/app/api/auth/login/route.ts"
    click API_AuthSignup "https://github.com/plawangshishugit/nutriapp/blob/main/app/api/auth/signup/route.ts"
    click API_DietPlan "https://github.com/plawangshishugit/nutriapp/blob/main/app/api/user/diet-plan/route.ts"
    click API_ProfileStatus "https://github.com/plawangshishugit/nutriapp/blob/main/app/api/user/profile-status/route.ts"
    click API_Profile "https://github.com/plawangshishugit/nutriapp/blob/main/app/api/user/profile/route.ts"
    click Middleware "https://github.com/plawangshishugit/nutriapp/blob/main/middleware.ts"
    click NextConfig "https://github.com/plawangshishugit/nutriapp/blob/main/next.config.mjs"
    click TSConfig "https://github.com/plawangshishugit/nutriapp/blob/main/tsconfig.json"
    click PostCSS "https://github.com/plawangshishugit/nutriapp/blob/main/postcss.config.mjs"
    click PNPM "https://github.com/plawangshishugit/nutriapp/blob/main/pnpm-lock.yaml"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#0d47a1,stroke-width:2px;
    classDef pages fill:#C5E1A5,stroke:#7CB342,stroke-width:2px;
    classDef styling fill:#B3E5FC,stroke:#0288D1,stroke-width:2px;
    classDef components fill:#F0F4C3,stroke:#9E9D24,stroke-width:2px;
    classDef middleware fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef api fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef config fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef database fill:#F8BBD0,stroke:#D81B60,stroke-width:2px;
    classDef ml fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
```
