# nehasssharma/healthy-bites architecture

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

- Interactive diagram: https://gitdiagram.com/nehasssharma/healthy-bites
- Repository: https://github.com/nehasssharma/healthy-bites

## Overview

##### Main Components
- Frontend – Represented by the files in public/front-end:
- HTML pages (e.g., Caloriecount.html, HealthBenefits.html, MealPlanning.css/HTML pages)
- CSS and JavaScript files that manage UI interactions.
- Backend – There are multiple layers:
- Node.js server logic (likely run from Health.js, which appears to serve as the entry point or orchestrator).
- EJS Templates in the “views” folder (MealPlanning.ejs, Search.ejs, etc.) that render dynamic pages.
- API or helper scripts in “public/back-end” (Search.js, caloriecount.js, food.js) which might handle AJAX requests or server-side processing.
- Data Storage – The “data” directory contains JSON files (foodData.json, meals.json, nonVegMeals.json, vegMeals.json) that act as the application’s data store.
- Static Assets – Managed under “public/images” and additional frontend assets.
- Development Tools – Tools like the VSCode configuration in “.vscode”, package configuration files (package.json, package-lock.json), and node_modules indicate the Node.js ecosystem usage.

##### Interactions and Relationships
- The Frontend (public/front-end) sends user requests (either direct navigations or AJAX calls) to the Backend.
- The Backend receives those requests through route handlers (potentially defined in Health.js), processes business logic, and either:
- Communicates directly with the JSON data files (data folder) to fetch or update information.
- Calls functions in the “public/back-end” folder (e.g., Search.js) to support dynamic operations.
- The EJS templates in the “views” folder are rendered with processed data from the backend.
- Static assets (images, videos) are served from the “public/images” and other public directories.
- Data flow is mostly from data (JSON) -> backend logic -> views/frontend, and user interactions trigger this flow in a cyclical manner.

##### Architectural Patterns and Design Principles
- MVC/MV* Pattern: The separation between “views” (EJS templates) and the business logic (backend scripts in Health.js and public/back-end) indicates that an MVC-like pattern is utilized.
- Layered Architecture: You see distinct layers for static serving (frontend assets), dynamic rendering (views/EJS), API logic (backend scripts), and data storage (JSON files).
- Modular Design: By breaking out functionality into separate files and folders (e.g., different CSS/HTML pages and separate JavaScript modules for different health features), the project supports extensibility and maintainability.

a. Start by placing nodes for the “User Interface” (Frontend) and label them (e.g., “Calorie Count Page”, “Meal Planning Page”).
c. Within the server layer, show two sub-components:
- “API/Business Logic” which includes functions from the public/back-end scripts.
- “View Engine” which handles the EJS templates present in the “views” folder.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FP["Static Pages (HTML/CSS)"]:::frontend
        FA["Static Assets (Images)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BS["Node.js Server (Health.js)"]:::backend
        subgraph "Server Components"
            AP["API/Helper Modules"]:::backend
            VE["View Engine (EJS Templates)"]:::view
        end
    end

    %% Data Storage
    DS["Data Storage (JSON Data Files)"]:::data

    %% Interactions
    FP -->|"requests"| BS
    BS -->|"processes"| AP
    BS -->|"renders"| VE
    AP -->|"uses"| DS
    VE -->|"retrieves"| DS
    BS -->|"delivers"| FP
    BS -->|"serves"| FA

    %% Click Events
    click FP "https://github.com/nehasssharma/healthy-bites/tree/main/public/front-end"
    click FA "https://github.com/nehasssharma/healthy-bites/tree/main/public/images"
    click BS "https://github.com/nehasssharma/healthy-bites/blob/main/Health.js"
    click VE "https://github.com/nehasssharma/healthy-bites/tree/main/views"
    click AP "https://github.com/nehasssharma/healthy-bites/tree/main/public/back-end"
    click DS "https://github.com/nehasssharma/healthy-bites/tree/main/data"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef view fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef data fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
