# bradtraversy/proshop-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/bradtraversy/proshop-v2
- Repository: https://github.com/bradtraversy/proshop-v2

## Overview

##### Project type and purpose
- This is a full-stack eCommerce platform (“ProShop v2”) built with the MERN stack (MongoDB, Express, React, Node) plus Redux Toolkit/RTK Query.
- Provides product browsing, shopping cart, checkout (shipping/payment), order management, user profiles, and admin CRUD (products, users, orders).

##### File structure
- Top-level separation into **backend/** and **frontend/** directories (standard client–server split).
- **backend/** follows an MVC/layered structure:
- config (DB connection)
- models (Mongoose schemas)
- controllers (business logic)
- routes (Express endpoints)
- middleware (auth, error handling, ID checking, async wrapper)
- utils (JWT token gen, PayPal helper, price calc)
- seeder script (populate/destroy sample data)
- server.js (app setup, static file serving in production)
- **frontend/** is a React SPA (CRA) with:
- src/components (reusable UI bits, protected/admin route wrappers)
- src/screens (page-level containers: Home, Product, Cart, Checkout steps, Admin screens)
- src/slices (Redux Toolkit slices and RTK Query API slices)
- src/store.js (store configuration)
- src/utils (cart helpers)
- react-router for routing, Bootstrap for styling.
- Root also contains deployment artifacts: .env.example, uploads/ for image storage, package.json scripts (dev, server, build).

##### Key insights from the README
- Project description, feature list (cart, reviews, pagination, search, admin CRUD, PayPal & card payments).
- Env vars: MongoDB URI, JWT_SECRET, PayPal client ID, pagination limit, PORT.
- Run commands: `npm run dev` to launch concurrently front (3000) & back (5000).
- Production build: front `npm run build` → served from backend's static folder.
- Seeder commands to import/destroy sample data.

- Client (React SPA)
- API Server (Node/Express)
- Database (MongoDB Atlas or self-hosted)
- File Storage (uploads folder, served via Express static)
- External Payment Service (PayPal REST API)
1. User → React SPA: HTTP(S) to port 3000 (dev) or served static (prod)
2. React SPA → Express API: RESTful calls under `/api` (products, users, orders, upload)
3. API Server → MongoDB: Mongoose queries for models (Product, User, Order)
4. API Server → File System (or S3): file uploads via multer, stored in uploads/
5. API Server → PayPal: payment creation/verification via PayPal SDK util
6. React SPA uses Redux Toolkit & RTK Query to manage state and caching of API calls
c. Architectural patterns & design principles:
- Client–Server separation
- Layered backend (Router → Controller → Service/Model → DB)
- MVC-style Organization on backend
- Unidirectional data flow on frontend (React → Redux actions → RTK Query → API → Redux store → React)
- Middleware for cross-cutting concerns (auth, error handling, async)
- Token-based authentication (JWT in HTTP-only cookie)
d. Key technologies & frameworks (annotate components):
- React, React Router, Redux Toolkit, RTK Query, Bootstrap (frontend)
- Node.js, Express, Mongoose, MongoDB, multer, dotenv, jsonwebtoken, bcrypt, PayPal SDK (backend)

##### Detail without over-splitting
- **uploadRoutes → multer → uploads folder** if image handling is critical.
- Don’t forget static asset serving in production: Express static middleware pointing to `/frontend/build` or `/frontend/dist`.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Frontend Layer"
    direction TB
    Client["React SPA"]:::frontend
    Store["Redux Store\n(store.js)"]:::frontend
    Components["Components"]:::frontend
    Screens["Screens"]:::frontend
    Slices["Slices & API Slices"]:::frontend
    CartUtils["Cart Utils"]:::frontend

    Client -->|"uses Redux Toolkit\n& RTK Query"| Store
    Client -->|"renders UI"| Components
    Client -->|"renders Pages"| Screens
    Store -->|"contains"| Slices
    Components -->|"uses"| CartUtils
  end

  subgraph "Backend Layer"
    direction TB
    API["Express API Server\n(server.js:5000)"]:::backend

    subgraph "Configuration"
      DBConfig["DB Config\n(db.js)"]:::backend
    end

    subgraph "Models"
      ProdModel["ProductModel"]:::backend
      UserModel["UserModel"]:::backend
      OrderModel["OrderModel"]:::backend
    end

    subgraph "Controllers"
      ProdCtrl["ProductController"]:::backend
      UserCtrl["UserController"]:::backend
      OrderCtrl["OrderController"]:::backend
    end

    subgraph "Routes (/api)"
      ProdRoutes["productRoutes"]:::backend
      UserRoutes["userRoutes"]:::backend
      OrderRoutes["orderRoutes"]:::backend
      UploadRoutes["uploadRoutes"]:::backend
    end

    subgraph "Middleware"
      AsyncHL["asyncHandler"]:::backend
      AuthMid["authMiddleware"]:::backend
      CheckObj["checkObjectId"]:::backend
      ErrMid["errorMiddleware"]:::backend
    end

    subgraph "Utilities"
      JWTUtil["generateToken.js"]:::backend
      PriceUtil["calcPrices.js"]:::backend
      PayPalUtil["paypal.js"]:::backend
    end

    Seeder["Seeder Script\n(seeder.js)"]:::backend
    Uploads["File Storage\n(uploads/)"]:::datastore

    API --> DBConfig
    API --> ProdRoutes
    API --> UserRoutes
    API --> OrderRoutes
    API --> UploadRoutes
    API --> AsyncHL
    API --> AuthMid
    API --> CheckObj
    API --> ErrMid
    API --> JWTUtil
    API --> PriceUtil
    API --> PayPalUtil
    API --> Seeder

    DBConfig --> MongoDB[(MongoDB)]:::datastore

    ProdRoutes --> ProdCtrl
    UserRoutes --> UserCtrl
    OrderRoutes --> OrderCtrl
    UploadRoutes -->|"uses multer"| Uploads

    ProdCtrl --> ProdModel
    UserCtrl --> UserModel
    OrderCtrl --> OrderModel

    ProdModel --> MongoDB
    UserModel --> MongoDB
    OrderModel --> MongoDB
  end

  Client -->|"REST API calls\n/api/*"| API
  Store -->|"API calls"| API
  PayPalUtil -->|"calls PayPal API"| PayPal[(PayPal Service)]:::external

  click Client "https://github.com/bradtraversy/proshop-v2/tree/main/frontend/"
  click Store "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/store.js"
  click Components "https://github.com/bradtraversy/proshop-v2/tree/main/frontend/src/components/"
  click Screens "https://github.com/bradtraversy/proshop-v2/tree/main/frontend/src/screens/"
  click Slices "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/slices/apiSlice.js"
  click Slices "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/slices/productsApiSlice.js"
  click Slices "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/slices/usersApiSlice.js"
  click Slices "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/slices/ordersApiSlice.js"
  click Slices "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/slices/authSlice.js"
  click Slices "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/slices/cartSlice.js"
  click CartUtils "https://github.com/bradtraversy/proshop-v2/blob/main/frontend/src/utils/cartUtils.js"

  click API "https://github.com/bradtraversy/proshop-v2/blob/main/backend/server.js"
  click DBConfig "https://github.com/bradtraversy/proshop-v2/blob/main/backend/config/db.js"
  click ProdModel "https://github.com/bradtraversy/proshop-v2/blob/main/backend/models/productModel.js"
  click UserModel "https://github.com/bradtraversy/proshop-v2/blob/main/backend/models/userModel.js"
  click OrderModel "https://github.com/bradtraversy/proshop-v2/blob/main/backend/models/orderModel.js"
  click ProdCtrl "https://github.com/bradtraversy/proshop-v2/blob/main/backend/controllers/productController.js"
  click UserCtrl "https://github.com/bradtraversy/proshop-v2/blob/main/backend/controllers/userController.js"
  click OrderCtrl "https://github.com/bradtraversy/proshop-v2/blob/main/backend/controllers/orderController.js"
  click ProdRoutes "https://github.com/bradtraversy/proshop-v2/blob/main/backend/routes/productRoutes.js"
  click UserRoutes "https://github.com/bradtraversy/proshop-v2/blob/main/backend/routes/userRoutes.js"
  click OrderRoutes "https://github.com/bradtraversy/proshop-v2/blob/main/backend/routes/orderRoutes.js"
  click UploadRoutes "https://github.com/bradtraversy/proshop-v2/blob/main/backend/routes/uploadRoutes.js"
  click AsyncHL "https://github.com/bradtraversy/proshop-v2/blob/main/backend/middleware/asyncHandler.js"
  click AuthMid "https://github.com/bradtraversy/proshop-v2/blob/main/backend/middleware/authMiddleware.js"
  click CheckObj "https://github.com/bradtraversy/proshop-v2/blob/main/backend/middleware/checkObjectId.js"
  click ErrMid "https://github.com/bradtraversy/proshop-v2/blob/main/backend/middleware/errorMiddleware.js"
  click JWTUtil "https://github.com/bradtraversy/proshop-v2/blob/main/backend/utils/generateToken.js"
  click PriceUtil "https://github.com/bradtraversy/proshop-v2/blob/main/backend/utils/calcPrices.js"
  click PayPalUtil "https://github.com/bradtraversy/proshop-v2/blob/main/backend/utils/paypal.js"
  click Seeder "https://github.com/bradtraversy/proshop-v2/blob/main/backend/seeder.js"
  click Uploads "https://github.com/bradtraversy/proshop-v2/tree/main/uploads/"

  classDef frontend fill:#cce5ff,stroke:#333
  classDef backend fill:#d4edda,stroke:#333
  classDef datastore fill:#fff3cd,stroke:#333
  classDef external fill:#e2e3e5,stroke:#333
```
