# dhrefund/amazonenextjs15 architecture

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

- Interactive diagram: https://gitdiagram.com/dhrefund/amazonenextjs15
- Repository: https://github.com/dhrefund/amazonenextjs15

## Overview

##### Project type and purpose
- This is a full-stack e-commerce web application built with Next.js (v15) and MongoDB/Mongoose.
- It supports user authentication (Auth.js with credentials, Google, magic link), shopping cart, checkout (Stripe & PayPal), order management, product catalog, browsing history, and an admin dashboard (orders, products, settings, users, web pages).

##### File structure
- Top-level “app” folder: Next.js 13+ App Router pages, split by locale and route groups (auth, home, root, admin, checkout, API).
- “app/api”: serverless route handlers for auth (NextAuth), product browsing history, file uploads (uploadthing), Stripe webhooks.
- “components”: shared UI pieces and domain components (cart sidebar, product cards, forms).
- “components/ui”: foundational primitives (buttons, dialogs, inputs) – a design system layer.
- “lib”: business logic/actions (order, product, review, setting, user, web-page), database client and models, utilities, validators, third-party wrappers (PayPal, uploadthing).
- “hooks”: client state and behavior hooks (cart store, browsing history, theme, device type).
- Configuration files for Tailwind, i18n, Next.js, ESLint, TypeScript.

##### README for additional insights
- Tech stack: Next.js 15, React 19, Tailwind CSS, Shadcn/UI, Recharts for charts.
- Database: MongoDB via Mongoose.
- Payments: PayPal & Stripe.
- Auth: Auth.js (NextAuth).
- Deployment: GitHub & Vercel.
- Utilities: uploadthing (file upload), resend (emails), zod (validation).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Client["Client (Browser/Mobile)"]:::frontend
        CDN["CDN / Static Assets"]:::frontend
    end

    %% Server & API Layer
    subgraph "Next.js Server & API" 
        direction TB
        NextServer["Next.js App Server\n(Frontend/SSR)"]:::backend
        API["API Routes\n(app/api)"]:::backend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        Services["lib/actions\n(Service Layer)"]:::business
        DBClient["Database Client & Models\n(lib/db)"]:::datastore
    end

    %% Data Stores
    subgraph "Data Stores & File Storage"
        direction TB
        MongoDB["MongoDB Cluster"]:::datastore
        FileStorage["File Storage (uploadthing/S3)"]:::external
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Stripe["Stripe"]:::external
        PayPal["PayPal"]:::external
        EmailSvc["Email Service (resend/SMTP)"]:::external
        AuthProvider["External Auth\n(Google, Magic Link)"]:::external
        UploadService["uploadthing Service"]:::external
    end

    %% Connections
    Client -->|"requests"| NextServer
    Client -->|"fetch static"| CDN
    CDN --> NextServer
    NextServer -->|"calls"| API
    API -->|"invokes"| Services
    Services -->|"uses"| DBClient
    DBClient -->|"data stored"| MongoDB
    Services -->|"calls payment"| Stripe
    Services -->|"calls payment"| PayPal
    Services -->|"sends email"| EmailSvc
    Services -->|"uploads files"| UploadService
    UploadService --> FileStorage
    API -->|"OAuth callbacks"| AuthProvider

    %% Click Events
    click NextServer "https://github.com/dhrefund/amazonenextjs15/tree/main/app/"
    click API "https://github.com/dhrefund/amazonenextjs15/tree/main/app/api/"
    click Services "https://github.com/dhrefund/amazonenextjs15/tree/main/lib/actions/"
    click DBClient "https://github.com/dhrefund/amazonenextjs15/tree/main/lib/db/"
    click MongoDB "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/db/client.ts"
    click Stripe "https://github.com/dhrefund/amazonenextjs15/blob/main/app/api/webhooks/stripe/route.tsx"
    click PayPal "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/paypal.ts"
    click UploadService "https://github.com/dhrefund/amazonenextjs15/blob/main/app/api/uploadthing/route.ts"
    click EmailSvc "https://github.com/dhrefund/amazonenextjs15/blob/main/emails/index.tsx"
    click AuthProvider "https://github.com/dhrefund/amazonenextjs15/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Client "https://github.com/dhrefund/amazonenextjs15/tree/main/public/"
    click CDN "https://github.com/dhrefund/amazonenextjs15/tree/main/public/"
    click Services "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/actions/order.actions.ts"
    click Services "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/actions/product.actions.ts"
    click Services "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/actions/review.actions.ts"
    click Services "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/actions/setting.actions.ts"
    click Services "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/actions/user.actions.ts"
    click Services "https://github.com/dhrefund/amazonenextjs15/blob/main/lib/actions/web-page.actions.ts"

    %% Feature Pages
    subgraph "Feature Pages"
        direction TB
        ProductPages["Product Catalog Pages"]:::frontend
        BrowsingAPI["Browsing History API"]:::backend
        CartPages["Shopping Cart Pages"]:::frontend
        CartHook["Cart Store Hook & Sidebar"]:::frontend
        CheckoutPages["Checkout Pages"]:::frontend
        AdminDashboard["Admin Dashboard Pages"]:::frontend
    end

    Client --> ProductPages
    Client --> CartPages
    Client --> CheckoutPages
    Client --> AdminDashboard
    API --> BrowsingAPI

    click ProductPages "https://github.com/dhrefund/amazonenextjs15/blob/main/app/[locale]/(root)/product/[slug]/page.tsx"
    click BrowsingAPI "https://github.com/dhrefund/amazonenextjs15/blob/main/app/api/products/browsing-history/route.ts"
    click BrowsingAPI "https://github.com/dhrefund/amazonenextjs15/blob/main/hooks/use-browsing-history.ts"
    click BrowsingAPI "https://github.com/dhrefund/amazonenextjs15/blob/main/components/shared/browsing-history-list.tsx"
    click CartPages "https://github.com/dhrefund/amazonenextjs15/blob/main/app/[locale]/(root)/cart/page.tsx"
    click CartPages "https://github.com/dhrefund/amazonenextjs15/blob/main/app/[locale]/(root)/cart/[itemId]/page.tsx"
    click CartHook "https://github.com/dhrefund/amazonenextjs15/blob/main/hooks/use-cart-store.ts"
    click CartHook "https://github.com/dhrefund/amazonenextjs15/blob/main/components/shared/cart-sidebar.tsx"
    click CheckoutPages "https://github.com/dhrefund/amazonenextjs15/tree/main/app/[locale]/checkout/"
    click AdminDashboard "https://github.com/dhrefund/amazonenextjs15/tree/main/app/[locale]/admin/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0066cc,color:#003366
    classDef backend fill:#d4edda,stroke:#228B22,color:#155724
    classDef business fill:#fff3cd,stroke:#FF8C00,color:#8a6d3b
    classDef datastore fill:#e2e3e5,stroke:#6c757d,color:#343a40
    classDef external fill:#f8d7da,stroke:#dc3545,color:#721c24
```
