# nimasaghi-dev/nomnom-food-app architecture

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

- Interactive diagram: https://gitdiagram.com/nimasaghi-dev/nomnom-food-app
- Repository: https://github.com/nimasaghi-dev/nomnom-food-app

## Overview

##### Project Type & Purpose
- This is a full-stack online food ordering application that lets users browse menus, add items to a cart, place orders, and manage their account.
- The README specifies key features such as browsing food items, CRUD operations on orders, user authentication, and a responsive UI.

##### Analyzing the File Structure
- At the root, there is a codebase directory (“cohort49-project-group-B-develop”) that contains subdirectories for both client and server code.
- The "/client" folder is built with React, uses Context for state management, and includes components, pages, hooks, and styling. It is set up for unit testing (Jest, React Testing Library) as well as end-to-end testing (Cypress).
- The "/server" folder is a Node.js/Express application that exposes RESTful APIs, connects to MongoDB via Mongoose, uses JWT for authentication, and incorporates custom middleware.
- Supporting configurations such as ESLint, Prettier, Babel, Husky hooks, GitHub Actions, and a Procfile (for Heroku deployment) are also part of the ecosystem.

##### Key Components
a. Frontend (Client):
- UI Layer: React components divided into views (pages like Home, Menu, OrderTracking, etc.) and reusable components (Nav, CartItem, Filters, etc.).
- State Management: Context API (CartContext, SearchContext) which conveys global state across components.
- Asset & Build Tools: Webpack, Babel, CSS, and testing configurations (Jest, React Testing Library, Cypress).

b. Backend (Server):
- API Layer: Express controllers (auth, menu, restaurants, user) handling routes and REST API endpoints.
- Middleware: Custom middleware (such as AuthMiddleware) for request handling and authentication.
- Database Layer: MongoDB integration via Mongoose with corresponding models (User, Item, Order, Reviews, Restaurants) and seed scripts.
- Utility Modules: Functions for logging, secret token generation, field validation, etc.

c. Data Storage:
- MongoDB is used as the primary NoSQL database for storing users, orders, food items, etc.

d. Testing and DevOps:
- Testing frameworks across the stack (Jest, Cypress).
- CI/CD pipelines via GitHub Actions for code style and testing before deployment.
- Pre-commit hooks provided by Husky ensure quality before changes hit the repository.
- Deployment configuration includes a Procfile for Heroku.

##### Relationships & Interactions
- Frontend interacts with the Backend via REST API calls.
- The backend exposes endpoints for user authentication, menu management, and order processing.
- Middleware on the server validates incoming request data and secures endpoints (using JWT).
- Both client and server include their own testing suites that ensure system integrity.
- DevOps components (CI with GitHub Actions, pre-commit hooks, Heroku for deployment) interact with the development flow.

##### Architectural Patterns & Principles
- Separation of Concerns: Clearly divided responsibilities between the client (UI and state management) and server (business logic, database interactions).
- MVC-like Structure on the server: Controllers, models, and routes (with middleware for cross-cutting concerns).
- Modular design on the client: Components, context providers, hooks, and routing based on pages.
- Continuous Integration and Deployment strategies are evident with GitHub Actions and Husky hooks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User Browser"]:::user

    %% Frontend (Client) Subgraph
    subgraph "Frontend (Client)"
        UI["UI/Presentation Layer"]:::frontend
        STATE["State Management (Context)"]:::frontend
        BUILD["Build & Testing Tools"]:::frontend

        %% UI Children
        COMPONENTS["Components"]:::component
        PAGES["Pages"]:::component
        UI --> COMPONENTS
        UI --> PAGES

        %% Build Tools Children
        BUILD_TOOLS["Build Tools"]:::tool
        TEST_CONFIG["Testing Configs"]:::tool
        BUILD --> BUILD_TOOLS
        BUILD --> TEST_CONFIG

        %% Build Tools Details
        WEBPACK["Webpack Config"]:::tool
        BABEL["Babel Config"]:::tool
        BUILD_TOOLS --> WEBPACK
        BUILD_TOOLS --> BABEL

        %% Testing Configs Details
        JEST["Jest Config"]:::tool
        CYPRESS["Cypress Config"]:::tool
        TEST_CONFIG --> JEST
        TEST_CONFIG --> CYPRESS
    end

    %% Backend (Server) Subgraph
    subgraph "Backend (Server)"
        API["REST API Layer"]:::backend
        Middleware["Custom Middleware"]:::backend
        DB_ACCESS["Database Access Layer"]:::backend
        UTIL["Utility Modules"]:::backend
        B_TEST["Backend Testing"]:::backend

        %% API Details
        CONTROLLERS["Controllers"]:::backend
        ROUTES["Routes"]:::backend
        API --> CONTROLLERS
        API --> ROUTES

        %% DB Access Details
        MODELS["Models"]:::db
        DB_CONN["DB Connection & Seeds"]:::db
        DB_ACCESS --> MODELS
        DB_ACCESS --> DB_CONN
    end

    %% Database
    DB["MongoDB (Database)"]:::database

    %% DevOps / CI & Deployment Subgraph
    subgraph "DevOps / CI & Deployment"
        CI["CI/CD Tools"]:::devops
        PRECOMMIT["Pre-commit Hooks"]:::devops
        GH_ACTIONS["GitHub Actions"]:::devops
        DEPLOY["Deployment (Heroku)"]:::devops
        FORMAT["Code Formatting Tools"]:::devops

        CI -->|triggers| PRECOMMIT
        CI -->|triggers| GH_ACTIONS
        CI -->|triggers| DEPLOY
        CI -->|triggers| FORMAT

        %% Code Formatting Details
        PRETTIER["Prettier Config"]:::devops
        ESLINT["ESLint Configs"]:::devops
        FORMAT --> PRETTIER
        FORMAT --> ESLINT
    end

    %% Relationships
    User -->|"accesses"| UI
    UI -->|"calls REST API"| API
    DB_ACCESS -->|"reads/writes"| DB
    CI -->|"tests Frontend"| BUILD
    CI -->|"tests Backend"| B_TEST

    %% Backend Relationships
    API --> Middleware
    Middleware --> DB_ACCESS
    API --> UTIL

    %% Click Events for Frontend
    click COMPONENTS "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/client/src/components"
    click PAGES "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/client/src/pages"
    click STATE "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/client/src/context"
    click WEBPACK "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/client/webpack.config.js"
    click BABEL "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/client/.babelrc"
    click JEST "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/client/jest.config.js"
    click CYPRESS "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/cypress.config.js"
    click CYPRESS "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/cypress"

    %% Click Events for Backend
    click CONTROLLERS "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/server/src/controllers"
    click ROUTES "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/server/src/routes"
    click Middleware "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/server/src/middlewares/AuthMiddleware.js"
    click MODELS "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/server/src/models"
    click DB_CONN "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/server/src/db"
    click UTIL "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/server/src/util"
    click B_TEST "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/server/src/__tests__"
    
    %% Click Events for DevOps / Deployment
    click GH_ACTIONS "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/.github/workflows"
    click PRECOMMIT "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/.husky/pre-commit"
    click DEPLOY "https://github.com/nimasaghi-dev/nomnom-food-app/tree/master/cohort49-project-group-B-develop/Procfile"
    click PRETTIER "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/.prettierrc.json"
    click ESLINT "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/client/.eslintrc.js"
    click ESLINT "https://github.com/nimasaghi-dev/nomnom-food-app/blob/master/cohort49-project-group-B-develop/server/.eslintrc.cjs"

    %% Styles
    classDef user fill:#f9f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef backend fill:#cfc,stroke:#333,stroke-width:2px;
    classDef db fill:#fc9,stroke:#333,stroke-width:2px;
    classDef devops fill:#ff9,stroke:#333,stroke-width:2px;
    classDef tool fill:#eef,stroke:#333,stroke-width:2px;
    classDef component fill:#efe,stroke:#333,stroke-width:2px;
```
