# sharjilk/next-magento architecture

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

- Interactive diagram: https://gitdiagram.com/sharjilk/next-magento
- Repository: https://github.com/sharjilk/next-magento

## Overview

##### Main Components

a. Frontend Layer:
- Next.js Application (App Router)
- Component Structure
- Common Components (Header, Footer)
- Page-specific Components (Homepage, Product List, Product Detail)
- UI Components Library
- CMS Components

b. Data Layer:
- Apollo Client Integration
- GraphQL Operations
- Queries
- Mutations
- Context Providers

c. External Services:
- Magento Backend
- Contentful CMS
- Vercel (Deployment Platform)

**┌─────────────────────────────────────────────────────┐**
- Client Layer                       │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐   │
- Pages     │ │ Components  │ │    UI Kit   │   │
- ┘ └─────────────┘ └─────────────┘   │
- ┘
- ↕
**┌─────────────────────────────────────────────────────┐**
- Data Layer                         │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐   │
- Apollo Client│ │   GraphQL   │ │  Contexts   │   │
- ┘ └─────────────┘ └─────────────┘   │
- ┘
- ↕
**┌─────────────────────────────────────────────────────┐**
- External Services                      │
- ┌─────────────┐            ┌─────────────┐         │
- Magento   │            │  Contentful │         │
- ┘            └─────────────┘         │
- ┘

##### Detailed Component Breakdown

**Components/**
- CMS
- Common
- Header
- HeaderMenu
- HeaderSearch
- HeaderUserMenu
- StoreSwitcher
- Footer
- NotFound
- Homepage
- Product-Detail
- Product-List

##### Data Flow Representation

- Client Request → Next.js App Router
- App Router → Apollo Client
- Apollo Client → GraphQL Operations
- GraphQL Operations → External Services

##### Key Elements to Highlight

a. Architecture Patterns:
- Next.js App Router pattern
- Component-based architecture
- GraphQL data layer
- Headless CMS integration

b. Important Interactions:
- Product data flow
- Cart operations
- CMS content retrieval
- Category navigation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        direction TB
        NextRouter["Next.js App Router"]
        Components["Component Layer"]
        subgraph Components
            direction TB
            Common["Common Components"]
            UI["UI Components"]
            CMS["CMS Components"]
            Product["Product Components"]
            Homepage["Homepage Components"]
        end
    end

    subgraph Data["Data Layer"]
        direction TB
        Apollo["Apollo Client"]
        GraphQL["GraphQL Layer"]
        subgraph GraphQL
            direction TB
            Queries["Queries"]
            Mutations["Mutations"]
            Operations["Operations"]
        end
        Contexts["Context Providers"]
    end

    subgraph External["External Services"]
        direction TB
        Magento["Magento Backend"]
        Contentful["Contentful CMS"]
    end

    %% Relationships
    NextRouter --> Components
    Components --> Apollo
    Apollo --> GraphQL
    GraphQL --> Magento
    GraphQL --> Contentful
    Apollo --> Contexts

    %% Component Breakdown
    Common --> Header["Header"]
    Common --> Footer["Footer"]
    Product --> ProductDetail["Product Detail"]
    Product --> ProductList["Product List"]
    Operations --> CMSOps["CMS Operations"]
    Operations --> ProductOps["Product Operations"]
    Operations --> CategoryOps["Category Operations"]

    %% Click Events
    click NextRouter "https://github.com/sharjilk/next-magento/tree/main/app"
    click Common "https://github.com/sharjilk/next-magento/tree/main/components/common"
    click Header "https://github.com/sharjilk/next-magento/tree/main/components/common/Header"
    click Footer "https://github.com/sharjilk/next-magento/tree/main/components/common/Footer"
    click UI "https://github.com/sharjilk/next-magento/tree/main/components/ui"
    click CMS "https://github.com/sharjilk/next-magento/tree/main/components/cms"
    click ProductDetail "https://github.com/sharjilk/next-magento/tree/main/components/product-detail"
    click ProductList "https://github.com/sharjilk/next-magento/tree/main/components/product-list"
    click Homepage "https://github.com/sharjilk/next-magento/tree/main/components/homepage"
    click Apollo "https://github.com/sharjilk/next-magento/tree/main/framework/apollo"
    click Queries "https://github.com/sharjilk/next-magento/tree/main/framework/apollo/queries"
    click Mutations "https://github.com/sharjilk/next-magento/tree/main/framework/apollo/mutations"
    click Operations "https://github.com/sharjilk/next-magento/tree/main/framework/apollo/operations"
    click Contexts "https://github.com/sharjilk/next-magento/tree/main/contexts"
    click CMSOps "https://github.com/sharjilk/next-magento/tree/main/framework/apollo/operations/cms"
    click ProductOps "https://github.com/sharjilk/next-magento/tree/main/framework/apollo/operations/product"
    click CategoryOps "https://github.com/sharjilk/next-magento/tree/main/framework/apollo/operations/category"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#2ecc71,stroke:#27ae60,color:white
    classDef component fill:#e74c3c,stroke:#c0392b,color:white

    class NextRouter,Components,Common,UI,CMS,Product,Homepage frontend
    class Apollo,GraphQL,Queries,Mutations,Operations,Contexts data
    class Magento,Contentful external
    class Header,Footer,ProductDetail,ProductList,CMSOps,ProductOps,CategoryOps component
```
