# satyaveerjaligama/food-parcel-frontend architecture

> Architecture diagram of the GitHub repository satyaveerjaligama/food-parcel-frontend, 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/satyaveerjaligama/food-parcel-frontend
- Repository: https://github.com/satyaveerjaligama/food-parcel-frontend

## Overview

##### Main System Components
- Frontend Application: This is the user interface part built using Next.js. It includes:
- Pages (under the “app” directory) that provide separate flows for account creation, login, home pages, order management, cart pages, payment success, etc.
- Distinct user flows for Customers, Restaurants, and Delivery Agents, each with their own subdirectories and components.
- UI Components: The “components” folder contains core/reusable UI elements (Header, Layout, Button, Modal, etc.) as well as page-specific components (for cart, home, restaurant-view, etc.).
- Styling & Assets: The “assets” directory (including images) and “styles” folder for CSS and theme configurations (including Tailwind & Material UI customizations).
- State & Data Management: The “store” directory (Redux store and slice files) along with the “thunks” directory (for side-effect management and async API calls) that orchestrate data-fetching and interactions with a backend.
- Utilities & Configurations: Utility functions, constants, routing definitions, validations (in the “utilities” folder) support configuration and business logic across the app.
- Environment & Configuration Files: Configuration files like next.config.mjs, .env files, and additional build tools configuration which play a role in deployment and environment management.

##### Interactions and Relationships
- Frontend UI (Pages) ↔ Components: Pages import and compose reusable components to build the interactive screens.
- UI ↔ State Management (Redux Store/Slices): UI components send actions (or dispatch thunks) which update the Redux store. This state propagation is crucial for flows like login, order management, and user account updates.
- Thunks and API Integrations: Thunks (under thunks/*) encapsulate the asynchronous actions such as login, registration, fetching orders, adding menu items, etc. They serve as the conduit between UI actions and external API calls to the backend service.
- External Backend Service: Although not part of this repository, the frontend communicates with the separate backend repo (linked in the README) for data persistence, user account management, order processing, and more.

##### Architectural Patterns and Design Principles
- Next.js File-based Routing: The “app” directory shows an architecture based on pages corresponding to routes in the application.
- Component-Based Design: Reusable components encapsulate common functionality or UI elements.
- Unidirectional Data Flow: With Redux Toolkit managing the state, actions, and thunks, data flows in one direction, ensuring predictable state changes.
- Separation of Concerns: There’s a clear delineation between UI (pages and components), business logic (thunks and validations), and state management (store and slices).

##### Additional Details
- User journeys: registration, login, order placement (for customer), menu management (for restaurant), and order status updates (for delivery agent).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend UI Layer
    subgraph "Frontend UI Layer"
        %% Next.js Pages Subgraph
        subgraph "Next.js Pages"
            CartPage["Cart Page"]
            CreateAccount["Create Account Page"]
            CustomerPage["Customer Page"]
            HomePage["Home Page"]
            LoginPage["Login Page"]
            MyAccountPage["My Account Page"]
            PaymentSuccess["Payment Success Page"]
        end
        %% UI Components Subgraph
        subgraph "UI Components"
            Button["Button Component"]
            Header["Header Component"]
            Layout["Layout Component"]
            PageComponents["Page-Specific Components"]
        end
        %% Styling & Assets Subgraph
        subgraph "Styling & Assets"
            Styles["Styles"]
            Images["Images"]
            ReadmeImages["Readme Images"]
        end
    end

    %% State Management & Business Logic
    subgraph "State Management & Business Logic"
        %% Redux Subgraph
        subgraph "Redux"
            ReduxStore["Redux Store"]
            ReduxSlices["Redux Slices"]
        end
        %% Thunks Subgraph
        subgraph "Thunks"
            CommonThunks["Common Thunks"]
            DeliveryAgentThunks["Delivery Agent Thunks"]
            OrderThunks["Order Thunks"]
            RestaurantThunks["Restaurant Thunks"]
        end
        %% Utilities & Configurations Subgraph
        subgraph "Utilities & Configurations"
            Constants["Constants"]
            Routes["Routes"]
            UtilityFunctions["Utility Functions"]
            Validations["Validations"]
            BuildEnv["Build & Env Configs"]
        end
    end

    %% External Backend Service
    Backend["External Backend Service"]

    %% Connections within Frontend UI Layer
    CartPage -->|"renders"| Header
    CreateAccount -->|"renders"| Layout
    PaymentSuccess -->|"renders"| PageComponents
    HomePage -->|"composes"| Button
    CustomerPage -->|"composes"| Layout

    %% Connections from Frontend UI Layer to State Management
    Header -->|"dispatches"| ReduxStore
    Button -->|"dispatches"| ReduxStore
    PageComponents -->|"dispatches"| ReduxStore

    %% Connections within State Management & Business Logic
    ReduxStore -->|"uses"| ReduxSlices
    ReduxSlices -->|"triggers"| CommonThunks
    ReduxSlices -->|"triggers"| DeliveryAgentThunks
    ReduxSlices -->|"triggers"| OrderThunks
    ReduxSlices -->|"triggers"| RestaurantThunks

    %% Thunks calling External Backend Service
    CommonThunks -->|"APICalls"| Backend
    DeliveryAgentThunks -->|"APICalls"| Backend
    OrderThunks -->|"APICalls"| Backend
    RestaurantThunks -->|"APICalls"| Backend

    %% Utilities usage
    Layout -->|"uses"| Constants
    Button -->|"uses"| Routes
    CommonThunks -->|"validates"| Validations

    %% Build & Env Configs influence Pages
    BuildEnv -->|"configures"| HomePage

    %% Styling connections
    CartPage -->|"styledBy"| Styles
    CreateAccount -->|"styledBy"| Styles
    HomePage -->|"usesAssets"| Images
    HomePage -->|"usesAssets"| ReadmeImages

    %% Classes for color coding
    class CartPage,CreateAccount,CustomerPage,HomePage,LoginPage,MyAccountPage,PaymentSuccess frontendUI;
    class Button,Header,Layout,PageComponents uiComponents;
    class Styles,Images,ReadmeImages stylingAssets;
    class ReduxStore,ReduxSlices redux;
    class CommonThunks,DeliveryAgentThunks,OrderThunks,RestaurantThunks thunks;
    class Constants,Routes,UtilityFunctions,Validations,BuildEnv utilities;
    class Backend externalBackend;

    %% Class Definitions
    classDef frontendUI fill:#fde2e4,stroke:#d62828,stroke-width:2px;
    classDef uiComponents fill:#e0fbfc,stroke:#0077b6,stroke-width:2px;
    classDef stylingAssets fill:#e9f8f9,stroke:#023e8a,stroke-width:2px;
    classDef redux fill:#f1e9da,stroke:#9c6644,stroke-width:2px;
    classDef thunks fill:#e2f0cb,stroke:#6a994e,stroke-width:2px;
    classDef utilities fill:#fff1e6,stroke:#d68a59,stroke-width:2px;
    classDef externalBackend fill:#fcefee,stroke:#b5179e,stroke-width:2px;

    %% Click Events for Frontend Application (Pages)
    click CartPage "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/cart"
    click CreateAccount "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/create-account"
    click CustomerPage "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/customer"
    click HomePage "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/home"
    click LoginPage "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/login"
    click MyAccountPage "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/my-account"
    click PaymentSuccess "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/app/payment-success"

    %% Click Events for UI Components
    click Button "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/components/Button.tsx"
    click Header "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/components/Header.tsx"
    click Layout "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/components/Layout.tsx"
    click PageComponents "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/components/pages"

    %% Click Events for Styling & Assets
    click Styles "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/styles"
    click Images "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/assets/images"
    click ReadmeImages "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/assets/readme-file-images"

    %% Click Events for State Management (Redux)
    click ReduxStore "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/store/store.ts"
    click ReduxSlices "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/store/slices"

    %% Click Events for Thunks
    click CommonThunks "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/thunks/common"
    click DeliveryAgentThunks "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/thunks/delivery-agent"
    click OrderThunks "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/thunks/order"
    click RestaurantThunks "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/thunks/restaurant"

    %% Click Events for Utilities & Configurations
    click Constants "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/utilities/constants.ts"
    click Routes "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/utilities/routes.ts"
    click UtilityFunctions "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/utilities/utilityFunctions.ts"
    click Validations "https://github.com/satyaveerjaligama/food-parcel-frontend/tree/master/utilities/validations"
    click BuildEnv "https://github.com/satyaveerjaligama/food-parcel-frontend/blob/master/next.config.mjs"
```
