# mustafa-j-wardeh17/full-stack-ecommerce-mnrn architecture

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

- Interactive diagram: https://gitdiagram.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn
- Repository: https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn

## Overview

##### Project type and purpose
- ByteVault is a full-stack eCommerce platform.
- Frontend: Next.js + Tailwind + shadcn UI, CSR/SSR hybrid, Context API for user state.
- Backend: NestJS monolith with modules (cart, products, orders, users), uses Mongoose/MongoDB, JWT auth, Stripe payment, Cloudinary image storage, Nodemailer mailer.

##### File structure
- Top level:
- backend/ – NestJS application (controllers, services, modules, schemas, repositories, middleware, interceptors, exception filters)
- frontend/ – Next.js app (app directory with nested layouts/pages, shared components, context, utilities)
- backend/src folders indicate a layered architecture:
- controllers → services → shared/repositories → shared/schemas
- middleware (auth, roles), interceptors, exception filters
- frontend/src shows feature-oriented routing under app/(auth), app/(root), app/dashboard
- Config and env: backend config/default.json, frontend .env.local, CI/ESLint, Prettier, Tailwind, PostCSS, Next config

##### README for additional insights
- Confirms tech stack, architectural patterns (global error handling, standardized API responses, modular design)
- Third-party integrations: Stripe, Cloudinary, Nodemailer, MongoDB, JWT

##### Main components & relationships
a. Components
- Client Browser (React/Next.js)
- Next.js App Server (SSR/CSR)
- API Gateway (NestJS application)
- MongoDB database
- File Storage
- Local uploads folder (temporary)
- Cloudinary (product image management)
- External Services: Stripe (checkout/webhook), Mailgun/Nodemailer (email notifications)
b. Interactions
1. Client ↔ Next.js: page requests, API calls (using fetch/Axios to NEXT_PUBLIC_API_URL)
2. Next.js ↔ NestJS: calls REST API under prefix /api/v1
3. NestJS controllers → service layer → repositories → MongoDB
4. On image upload: NestJS → Cloudinary API → store URL
5. On checkout: NestJS → Stripe API (redirect to Stripe, handle webhook)
6. On auth/email events: NestJS → Nodemailer/Mailgun → send emails
c. Architectural patterns
- Monolithic service with modularization
- Layered architecture: controller → service → repository → data source
- Global interceptors (response formatting) and exception filters
- Middleware for authentication & role-based authorization
- Next.js file-system routing for frontend features
d. Key technologies
- NestJS, Mongoose, JWT, Stripe SDK, Cloudinary SDK, Nodemailer
- Next.js, shadcn UI, Tailwind CSS, Framer Motion, React Context API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    Browser["User Browser"]:::frontend

    %% Frontend Container
    subgraph "Frontend"
        NextJsApp["Next.js App Server"]:::frontend
        ReactContext["React Context (useUserContext)"]:::frontend
        AuthPages["Auth Pages"]:::frontend
        ShopPages["Shop Pages"]:::frontend
        AccountPages["My-Account Pages"]:::frontend
        DashboardPages["Dashboard Pages"]:::frontend
        LibUtils["Utils (lib)"]:::frontend
        UtilUtils["Utils (util)"]:::frontend
    end

    %% Backend Container
    subgraph "Backend (NestJS API /api/v1)"
        Entry["NestJS Entry Point (main.ts)"]:::backend
        RootModule["App Module & Controller"]:::backend
        CartMod["Cart Module"]:::backend
        ProdMod["Products Module"]:::backend
        OrdMod["Orders Module"]:::backend
        UserMod["Users Module"]:::backend
        Repos["Shared Repositories"]:::backend
        Schemas["Shared Schemas"]:::backend
        AuthMW["Auth Middleware"]:::backend
        RoleMW["Role-Based Authorization"]:::backend
        MailerMW["Mailer Middleware"]:::backend
        RespInt["Global Response Interceptor"]:::backend
        ExFilter["Global Exception Filter"]:::backend
        Utils["Utility Functions"]:::backend
        Uploads["Local File Uploads"]:::backend
        StripeDoc["Stripe Integration Doc"]:::backend
    end

    %% Database
    DB["MongoDB"]:::database

    %% External Services
    subgraph "External Services"
        Stripe["Stripe (Checkout/Webhook)"]:::external
        Cloudinary["Cloudinary (Image Upload)"]:::external
        MailerExt["Mailer (Nodemailer/Mailgun)"]:::external
    end

    %% Connections - Frontend to Backend
    Browser -->|HTTP| NextJsApp
    NextJsApp -->|REST /api/v1| Entry
    NextJsApp -->|Uses| ReactContext
    NextJsApp -->|Renders| AuthPages
    NextJsApp -->|Renders| ShopPages
    NextJsApp -->|Renders| AccountPages
    NextJsApp -->|Renders| DashboardPages

    %% Internal Backend flow
    Entry --> RootModule
    RootModule --> CartMod
    RootModule --> ProdMod
    RootModule --> OrdMod
    RootModule --> UserMod
    CartMod --> Repos
    ProdMod --> Repos
    OrdMod --> Repos
    UserMod --> Repos
    Repos --> Schemas
    CartMod -->|Mongoose| DB
    ProdMod -->|Mongoose| DB
    OrdMod -->|Mongoose| DB
    UserMod -->|Mongoose| DB

    %% Middleware and global
    RootModule --> AuthMW
    RootModule --> RoleMW
    RootModule --> MailerMW
    RootModule --> RespInt
    RootModule --> ExFilter
    RootModule --> Utils

    %% File storage and docs
    RootModule --> Uploads
    RootModule --> StripeDoc

    %% External calls
    CartMod -->|HTTP| Stripe
    Stripe -->|Webhook| Entry
    ProdMod -->|HTTP| Cloudinary
    UserMod -->|SMTP/API| MailerExt

    %% Shared Utilities
    NextJsApp --> LibUtils
    NextJsApp --> UtilUtils

    %% Click Events - Frontend
    click NextJsApp "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/frontend/src/app/layout.tsx"
    click AuthPages "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/frontend/src/app/(auth)"
    click ShopPages "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/frontend/src/app/(root)/shop"
    click AccountPages "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/frontend/src/app/(root)/my-account"
    click DashboardPages "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/frontend/src/app/dashboard"
    click ReactContext "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/frontend/src/context/index.tsx"
    click LibUtils "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/frontend/src/lib/utils.ts"
    click UtilUtils "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/frontend/src/util/utils.ts"

    %% Click Events - Backend
    click Entry "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/main.ts"
    click RootModule "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/app.module.ts"
    click CartMod "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/cart/cart.module.ts"
    click ProdMod "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/products/products.module.ts"
    click OrdMod "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/orders/orders.module.ts"
    click UserMod "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/users/users.module.ts"
    click Repos "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/backend/src/shared/repositories/"
    click Schemas "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/backend/src/shared/schema/"
    click AuthMW "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/middleware/auth.ts"
    click RoleMW "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/middleware/role.decorator.ts"
    click MailerMW "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/middleware/mailer.ts"
    click RespInt "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/responseInterceptor.ts"
    click ExFilter "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/httpExceptionFilter.ts"
    click Utils "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/src/utility/password-manager.ts"
    click Uploads "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/tree/main/backend/uploads/"
    click StripeDoc "https://github.com/mustafa-j-wardeh17/full-stack-ecommerce-mnrn/blob/main/backend/Stripe.md"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,color:#0d47a1;
    classDef backend fill:#ffe0b2,stroke:#ef6c00,color:#e65100;
    classDef database fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20;
    classDef external fill:#e0e0e0,stroke:#616161,color:#212121;
```
