# whoyoux/ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/whoyoux/ecommerce
- Repository: https://github.com/whoyoux/ecommerce

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js App Router structure (/src/app/*)
- Client Components (/src/components/*)
- Server Actions (/src/actions/*)

b) Backend Services:
- Authentication System (NextAuth.js integration)
- Payment Processing (Stripe integration)
- Email Service (Resend integration)
- Database Layer (Prisma ORM)

c) External Services:
- Stripe Payment Gateway
- Email Service Provider
- Database (likely PostgreSQL based on Prisma schema)

##### Key Relationships to Highlight

- Client-Server interaction through Server Actions
- Authentication flow with NextAuth.js
- Database operations through Prisma
- Payment processing flow with Stripe
- Email notifications system

##### Specific Implementation Details

Important architectural elements:
- Next.js App Router structure
- Server Actions for data mutations
- API routes for external integrations
- Prisma schema for data modeling
- Authentication flow with NextAuth.js
- Payment processing with Stripe
- Form validation with validators

##### Component Relationships

Key interactions:
- User authentication flow
- Shopping cart operations
- Checkout process
- Order management
- Product management (admin)
- Customer management

**[Client Layer]**
- ↕
**[Server Actions & API Routes]**
- ↕
**[Database & External Services]**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        MainPages["Main Pages"]
        ProductPages["Product Pages"]
        CartPages["Cart Pages"]
        CheckoutPages["Checkout Pages"]
        AccountPages["Account Pages"]
        AdminDash["Admin Dashboard"]
        
        subgraph Components
            UIComps["UI Components"]
            ProductComps["Product Components"]
            CheckoutComps["Checkout Components"]
        end
    end

    subgraph ServerLayer
        subgraph ServerActions
            CartOps["Cart Operations"]
            CheckoutProcess["Checkout Process"]
            UserMgmt["User Management"]
            ProductMgmt["Product Management"]
        end

        subgraph Auth
            AuthConfig["Auth Configuration"]
            AuthRoutes["Auth API Routes"]
        end

        subgraph Payment
            StripeInteg["Stripe Integration"]
            PaymentWebhook["Payment Webhook"]
        end

        subgraph Email
            ResendInteg["Email Service"]
        end

        subgraph Database
            PrismaConfig["Prisma Schema"]
            DBClient["Database Client"]
        end

        subgraph Validation
            UserSchemas["User Schemas"]
            CartSchemas["Cart Schemas"]
            ProductSchemas["Product Schemas"]
        end

        SiteConfig["Site Configuration"]
    end

    subgraph ExternalServices
        DB[(Database)]
        StripeGateway["Stripe Gateway"]
        EmailService["Email Provider"]
    end

    %% Relationships
    MainPages --> ServerActions
    ProductPages --> ServerActions
    CartPages --> CartOps
    CheckoutPages --> CheckoutProcess
    AccountPages --> UserMgmt
    AdminDash --> ProductMgmt

    ServerActions --> DBClient
    DBClient --> DB
    PrismaConfig --> DB

    CheckoutProcess --> StripeInteg
    StripeInteg --> StripeGateway
    PaymentWebhook --> StripeGateway

    UserMgmt --> AuthConfig
    AuthConfig --> AuthRoutes
    AuthRoutes --> DBClient

    ServerActions --> ResendInteg
    ResendInteg --> EmailService

    %% Click Events
    click MainPages "https://github.com/whoyoux/ecommerce/blob/main/src/app/page.tsx"
    click ProductPages "https://github.com/whoyoux/ecommerce/tree/main/src/app/product"
    click CartPages "https://github.com/whoyoux/ecommerce/tree/main/src/app/cart"
    click CheckoutPages "https://github.com/whoyoux/ecommerce/tree/main/src/app/checkout"
    click AccountPages "https://github.com/whoyoux/ecommerce/tree/main/src/app/account"
    click AdminDash "https://github.com/whoyoux/ecommerce/tree/main/src/app/admin"
    click UIComps "https://github.com/whoyoux/ecommerce/tree/main/src/components/ui"
    click ProductComps "https://github.com/whoyoux/ecommerce/tree/main/src/components/product"
    click CheckoutComps "https://github.com/whoyoux/ecommerce/tree/main/src/components/checkout-page"
    click CartOps "https://github.com/whoyoux/ecommerce/blob/main/src/actions/cart.ts"
    click CheckoutProcess "https://github.com/whoyoux/ecommerce/blob/main/src/actions/checkout.ts"
    click UserMgmt "https://github.com/whoyoux/ecommerce/blob/main/src/actions/user.ts"
    click ProductMgmt "https://github.com/whoyoux/ecommerce/blob/main/src/actions/admin/product.ts"
    click AuthConfig "https://github.com/whoyoux/ecommerce/blob/main/src/lib/auth.ts"
    click AuthRoutes "https://github.com/whoyoux/ecommerce/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click StripeInteg "https://github.com/whoyoux/ecommerce/blob/main/src/lib/stripe.ts"
    click PaymentWebhook "https://github.com/whoyoux/ecommerce/blob/main/src/app/api/payment/webhook/route.ts"
    click ResendInteg "https://github.com/whoyoux/ecommerce/blob/main/src/lib/resend.ts"
    click PrismaConfig "https://github.com/whoyoux/ecommerce/blob/main/prisma/schema.prisma"
    click DBClient "https://github.com/whoyoux/ecommerce/blob/main/src/lib/prisma.ts"
    click UserSchemas "https://github.com/whoyoux/ecommerce/blob/main/src/validators/userSchemas.ts"
    click CartSchemas "https://github.com/whoyoux/ecommerce/blob/main/src/validators/cartSchema.ts"
    click ProductSchemas "https://github.com/whoyoux/ecommerce/blob/main/src/validators/admin/productSchema.ts"
    click SiteConfig "https://github.com/whoyoux/ecommerce/blob/main/src/config/site-config.ts"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white

    class MainPages,ProductPages,CartPages,CheckoutPages,AccountPages,AdminDash,UIComps,ProductComps,CheckoutComps frontend
    class CartOps,CheckoutProcess,UserMgmt,ProductMgmt,SiteConfig server
    class PrismaConfig,DBClient,DB database
    class StripeGateway,EmailService external
    class AuthConfig,AuthRoutes auth
```
