# hammadshykh/eccommerce-with-sanity architecture

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

- Interactive diagram: https://gitdiagram.com/hammadshykh/eccommerce-with-sanity
- Repository: https://github.com/hammadshykh/eccommerce-with-sanity

## Overview

##### Main System Components

A. Frontend Layer (Next.js Application)
- Client-Side Components (src/components)
- App Router Pages (src/app)
- Store Management (src/store.ts)

B. Backend Services
- Sanity CMS (Content Management)
- Stripe Payment Processing
- Next.js API Routes (for webhooks)

C. Data Layer
- Sanity Database (for content)
- Stripe Payment Records

##### Component Relationships

- Client → Next.js Server (App Router)
- Next.js Server → Sanity CMS
- Next.js Server → Stripe API
- Webhook Routes → Stripe Events

##### Detailed Component Breakdown

Frontend Section:
- Store Routes (src/app/(store))
- Product Pages
- Category Pages
- Basket
- Orders
- Search
- UI Components (src/components)
- Layout Components
- Product Components
- Shared UI Elements

Backend Section:
- Sanity Integration
- Schema Types
- Content Management
- Queries
- Stripe Integration
- Checkout Sessions
- Payment Processing
- Webhooks

##### Infrastructure Layer

At the bottom, include:
- Vercel hosting
- CDN layer
- Edge functions (if used)

Key Elements to Emphasize:
##### API routes for webhooks and server actions

Remember to:
- Notes for important architectural decisions
- Both synchronous and asynchronous flows

This architecture represents a modern full-stack e-commerce application with headless CMS capabilities, secure payment processing, and a robust frontend built on Next.js.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph "Next.js Frontend"
        AppRouter["App Router"]
        StoreRoutes["Store Routes"]:::frontend
        Components["UI Components"]:::frontend
        Store["Store Management"]:::frontend
        Layout["Layout Components"]:::frontend
        UIComps["Shared UI Elements"]:::frontend
        Basket["Shopping Basket"]:::frontend
        Orders["Order Pages"]:::frontend
        Products["Product Pages"]:::frontend
    end

    subgraph "Backend Services"
        SanityCMS["Sanity CMS"]:::sanity
        StripeAPI["Stripe API"]:::stripe
        WebhookHandler["Webhook Handler"]:::api
        CheckoutActions["Checkout Actions"]:::stripe
    end

    subgraph "Data Management"
        SanityClient["Sanity Client"]:::sanity
        ProductMgmt["Product Management"]:::sanity
        OrderMgmt["Order Management"]:::sanity
        SalesMgmt["Sales Management"]:::sanity
        SchemaTypes["Schema Definitions"]:::sanity
    end

    subgraph "Infrastructure"
        CDN["CDN Layer"]
        Vercel["Vercel Hosting"]
    end

    Browser --> AppRouter
    AppRouter --> StoreRoutes
    StoreRoutes --> Components
    Components --> Layout
    Components --> UIComps
    StoreRoutes --> Store
    Store --> Basket
    Store --> Orders
    Store --> Products
    
    AppRouter --> SanityClient
    SanityClient --> SanityCMS
    SanityClient --> ProductMgmt
    SanityClient --> OrderMgmt
    SanityClient --> SalesMgmt
    SanityCMS --> SchemaTypes
    
    AppRouter --> StripeAPI
    StripeAPI --> CheckoutActions
    WebhookHandler --> StripeAPI
    
    AppRouter --> CDN
    CDN --> Vercel

    %% Click Events
    click Components "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/components"
    click StoreRoutes "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/app/(store)"
    click Store "https://github.com/hammadshykh/eccommerce-with-sanity/blob/main/src/store.ts"
    click SanityCMS "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/sanity"
    click StripeAPI "https://github.com/hammadshykh/eccommerce-with-sanity/blob/main/src/lib/stripe.ts"
    click WebhookHandler "https://github.com/hammadshykh/eccommerce-with-sanity/blob/main/src/app/(store)/webhook/route.ts"
    click ProductMgmt "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/sanity/lib/products"
    click OrderMgmt "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/sanity/lib/orders"
    click SchemaTypes "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/sanity/schemaTypes"
    click SanityClient "https://github.com/hammadshykh/eccommerce-with-sanity/blob/main/src/sanity/lib/client.ts"
    click Basket "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/app/(store)/basket"
    click Orders "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/app/(store)/orders"
    click Products "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/app/(store)/product"
    click CheckoutActions "https://github.com/hammadshykh/eccommerce-with-sanity/blob/main/actions/createCheckoutSession.ts"
    click UIComps "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/components/ui"
    click Layout "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/components/layout"
    click SalesMgmt "https://github.com/hammadshykh/eccommerce-with-sanity/tree/main/src/sanity/lib/sales"

    %% Styling
    classDef frontend fill:#3498db,color:white
    classDef sanity fill:#2ecc71,color:white
    classDef stripe fill:#9b59b6,color:white
    classDef api fill:#e74c3c,color:white
    classDef infrastructure fill:#95a5a6,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        Sanity["Sanity CMS"]:::sanity
        Stripe["Stripe"]:::stripe
        API["API Routes"]:::api
        Infra["Infrastructure"]:::infrastructure
    end
```
