# arpit164/e-commerce_with_next-js-15 architecture

> Architecture diagram of the GitHub repository arpit164/e-commerce_with_next-js-15, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arpit164/e-commerce_with_next-js-15
- Repository: https://github.com/arpit164/e-commerce_with_next-js-15

## Overview

##### Main Components
- Frontend (Next.js): Represent the “app” directory as the core UI. This includes pages for general content (e.g., home, sign in, sign up) and the Sanity Studio (found under src/app/studio) for content management.
- Authentication Module: Highlight components and actions under src/app/auth and src/components/auth (SignIn.tsx, SignUp.tsx) plus the auth actions (src/actions/auth.ts).
- Business Logic/Actions: Include separate modules for cart handling (src/actions/cart-actions.ts), Stripe integration (src/actions/stripe-actions.ts), and the “wheel-of-fortune” feature (src/actions/wheel-of-fortune-actions.ts).
- Sanity CMS Integration: Represent the Sanity configuration files (.sanity directory, sanity.config.ts, etc.) and the client libraries under src/sanity. Also include the schema types and structure that show how content is defined.
- Database Interaction: Represent Prisma, with its dedicated schema (prisma/schema.prisma), and the utilities in src/lib (like prisma.ts) that interact with the database.
- External Services: Indicate integration with external services such as Stripe (for payments) and possibly Umami (analytics in src/lib/umami.ts).

##### Relationships and Interactions
- The Frontend (Next.js) interacts with the various action modules (auth, cart, stripe, etc.) to process user requests.
- These actions then interface with the backend systems:
- Authentication actions manage sessions and user state.
- Cart and Stripe actions work together to process payments.
- The Sanity integration is used for content delivery and management, with the Studio offering a dedicated interface.
- Prisma serves as the ORM layer that communicates with the underlying database.
- External endpoints (such as Stripe’s API) will be communicated with through designated action modules.
- The Next.js app’s routing (with its various pages) ensures proper separation of concerns, while the shared lib utilities handle cross-cutting concerns.

##### Architectural Patterns and Design Principles
- Modular Design: The codebase is divided into clear modules (actions, components, lib functions, etc.), each serving a distinct purpose.
- Separation of Concerns: The UI components, business logic, and data access layers (Prisma and Sanity) are clearly separated.

##### Key Technologies/Frameworks Used
- Next.js – for server-side rendering and the app routing.
- Sanity – for the CMS component, with runtime configuration and schema definitions.
- Prisma – for database modeling and access.
- Stripe – for handling payments.
- Vercel – suggested by the README for deployment.
- Additional tools such as eslint, postcss, and possibly Vite (as seen in the dist/static files) may be mentioned peripherally if relevant to your component build processes.

##### Additional Details
- Mention that the Sanity runtime scripts (found in .sanity/runtime) support the content management system, while the distributed static assets (in dist/static) may include built/optimized versions of components.
- If desired, note that middleware.ts is likely used for server-side logic or redirection, and can be indicated as a supporting layer for request handling.

- Frontend (Next.js App – UI pages, Studio UI)
- Business Logic/Action Handlers (auth, cart, stripe, wheel-of-fortune)
- CMS Integration (Sanity configuration and schemas)
- Data Access Layer (Prisma and database)
- External Services (Stripe, analytics, Vercel for deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Next.js App)"
        FE1["UI Pages (src/app)"]:::frontend
        FE2["Studio UI (src/app/studio/[[...tool]]/page.tsx)"]:::frontend
        FE3["Auth Pages (src/app/auth)"]:::frontend
    end

    %% Authentication Module
    subgraph "Authentication Module"
        AU1["SignIn Component (src/components/auth/SignIn.tsx)"]:::auth
        AU2["SignUp Component (src/components/auth/SignUp.tsx)"]:::auth
        AU3["Auth Actions (src/actions/auth.ts)"]:::auth
    end

    %% Business Logic / Action Handlers
    subgraph "Business Logic/Action Handlers"
        BL1["Cart Actions (src/actions/cart-actions.ts)"]:::action
        BL2["Stripe Actions (src/actions/stripe-actions.ts)"]:::action
        BL3["Wheel-of-Fortune Actions (src/actions/wheel-of-fortune-actions.ts)"]:::action
    end

    %% CMS Integration (Sanity)
    subgraph "CMS Integration (Sanity)"
        CM1["Sanity Config Directory (.sanity)"]:::cms
        CM2["Sanity Config File (sanity.config.ts)"]:::cms
        CM3["Sanity Types (sanity.types.ts)"]:::cms
        CM4["Sanity Client & Schemas (src/sanity)"]:::cms
        CM5["Sanity Schema Types (src/sanity/schemaTypes)"]:::cms
    end

    %% Data Access Layer
    subgraph "Data Access Layer (Prisma)"
        DB1["Prisma Schema (prisma/schema.prisma)"]:::database
        DB2["Prisma Utility (src/lib/prisma.ts)"]:::database
    end

    %% External Services
    subgraph "External Services"
        ES1["Stripe Payments"]:::external
        ES2["Umami Analytics (src/lib/umami.ts)"]:::external
    end

    %% Connections between components
    FE1 -->|"calls"| AU3
    FE1 -->|"initiates"| BL1
    FE1 -->|"initiates"| BL2
    FE1 -->|"initiates"| BL3
    FE1 -->|"fetches content from"| CM4
    FE3 -->|"triggers auth"| AU3

    AU1 -->|"handles auth"| AU3
    AU2 -->|"handles auth"| AU3

    AU3 -->|"performs data ops"| DB2

    BL1 -->|"updates data"| DB2
    BL2 -->|"calls API"| ES1
    BL3 -->|"triggers game feature"| ES1

    CM4 -->|"fetches content"| DB2
    CM4 -->|"integrates with"| CM5

    DB2 -->|"executes ORM ops"| DB1

    %% Analytics integration
    FE1 -.->|"sends metrics"| ES2

    %% Class Styles
    classDef frontend fill:#BBDEFB,stroke:#1E88E5,stroke-width:2px;
    classDef auth fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef action fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef cms fill:#F8BBD0,stroke:#D81B60,stroke-width:2px;
    classDef database fill:#D1C4E9,stroke:#673AB7,stroke-width:2px;
    classDef external fill:#FFCC80,stroke:#FB8C00,stroke-width:2px;

    %% Click Events
    click FE1 "https://github.com/arpit164/e-commerce_with_next-js-15/tree/main/src/app"
    click FE2 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/app/studio/[[...tool]]/page.tsx"
    click FE3 "https://github.com/arpit164/e-commerce_with_next-js-15/tree/main/src/app/auth"
    click AU1 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/components/auth/SignIn.tsx"
    click AU2 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/components/auth/SignUp.tsx"
    click AU3 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/actions/auth.ts"
    click BL1 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/actions/cart-actions.ts"
    click BL2 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/actions/stripe-actions.ts"
    click BL3 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/actions/wheel-of-fortune-actions.ts"
    click CM1 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/.sanity"
    click CM2 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/sanity.config.ts"
    click CM3 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/sanity.types.ts"
    click CM4 "https://github.com/arpit164/e-commerce_with_next-js-15/tree/main/src/sanity"
    click CM5 "https://github.com/arpit164/e-commerce_with_next-js-15/tree/main/src/sanity/schemaTypes"
    click DB1 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/prisma/schema.prisma"
    click DB2 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/lib/prisma.ts"
    click ES2 "https://github.com/arpit164/e-commerce_with_next-js-15/blob/main/src/lib/umami.ts"
```
