# elma-123/forever-ecommerce-website architecture

> Architecture diagram of the GitHub repository elma-123/forever-ecommerce-website, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elma-123/forever-ecommerce-website
- Repository: https://github.com/elma-123/forever-ecommerce-website

## Overview

#### 1. System Purpose and Deployable Entry Points
This is a three-part MERN e-commerce system: a customer storefront, a separate administrator dashboard, and an Express REST API. The customer and admin applications are independent React/Vite SPAs; the backend owns authentication, catalog, carts, orders, payment initiation/verification, persistence, and image upload.
- `frontend/src/main.jsx`
- `admin/src/main.jsx`
- `backend/server.js`

#### 2. Customer Storefront
The storefront is the user-facing shopping workflow: browse collections and products, manage a cart, authenticate, place orders, view prior orders, and return from payment verification. `App.jsx` composes route-level pages, while `ShopContext` is the client state boundary for shared catalog, cart, auth, and backend interaction state.
- `frontend/src/App.jsx`
- `frontend/src/context/ShopContext.jsx`
- `frontend/src/pages/PlaceOrder.jsx`

#### 3. Admin Dashboard
The admin SPA provides authenticated operational workflows for creating products, reviewing the catalog, and processing/viewing orders. It is intentionally separate from the customer application and talks to the same backend API, carrying its own login/navigation shell and admin-oriented pages.
- `admin/src/App.jsx`
- `admin/src/components/Login.jsx`
- `admin/src/pages/Add.jsx`
- `admin/src/pages/List.jsx`
- `admin/src/pages/Orders.jsx`

#### 4. API Composition and Request Boundary
`server.js` is the Node/Express runtime entry point. It mounts domain route modules that dispatch HTTP requests into controllers. Controllers are the application-service boundary: they validate/process API input, apply auth context, invoke Mongoose models, and return frontend/admin-consumable responses. The API domains are users, products, carts, and orders.
- `backend/server.js`
- `backend/routes/userRoute.js`
- `backend/routes/productRoute.js`
- `backend/routes/cartRoute.js`
- `backend/routes/orderRoute.js`
- `backend/controllers/orderController.js`

#### 5. Identity and Authorization
User authentication is JWT-based. The normal auth middleware protects user-specific cart and order operations; a distinct admin middleware gates privileged product/order management actions. User records hold identity/authorization data and support the boundary between customer and administrator workflows.
- `backend/middleware/auth.js`
- `backend/middleware/adminAuth.js`
- `backend/controllers/userController.js`
- `backend/models/userModel.js`

#### 6. Commerce Data and Checkout Flow
Products, user carts, and orders are persisted in MongoDB through Mongoose models. A typical flow is: storefront fetches products, context records cart actions through cart APIs, checkout submits an order, then the order controller executes Cash on Delivery or Stripe payment handling. The verification page completes the client-facing online-payment return flow; orders remain accessible to users and admins.
- `backend/models/productModel.js`
- `backend/models/orderModel.js`
- `backend/controllers/cartController.js`
- `backend/controllers/orderController.js`
- `frontend/src/pages/Verify.jsx`

#### 7. External Infrastructure and Assets
MongoDB Atlas is the primary database, connected through the backend configuration layer. Cloudinary stores product imagery, with Multer handling incoming multipart uploads at the API boundary. Stripe is the external payment processor. Runtime secrets and service URLs are environment-driven; Vercel configuration exists for both SPAs and backend deployment configuration is also present.
- `backend/config/mongodb.js`
- `backend/config/cloudinary.js`
- `backend/middleware/multer.js`
- `frontend/vercel.json`
- `admin/vercel.json`
- `backend/vercel.json`

Main entry points: [`backend/controllers/orderController.js`](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/controllers/orderController.js) (Controllers), [`backend/server.js`](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/server.js) (Express server), [`backend/routes/orderRoute.js`](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/routes/orderRoute.js) (Domain routes), [`admin/src/App.jsx`](https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/App.jsx) (Admin shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Customer Storefront"]
  node_storefront_entry["Storefront SPA<br/>React/Vite entry<br/>[main.jsx]"]
  node_storefront_routes["Shopping routes<br/>React app<br/>[App.jsx]"]
  node_shop_context["Shop context<br/>client state<br/>[ShopContext.jsx]"]
  node_checkout["Checkout<br/>order page<br/>[PlaceOrder.jsx]"]
  node_payment_verify["Payment verification<br/>return page<br/>[Verify.jsx]"]
end

subgraph group_admin["Admin Dashboard"]
  node_admin_entry["Admin SPA<br/>React/Vite entry<br/>[main.jsx]"]
  node_admin_routes["Admin shell<br/>React app<br/>[App.jsx]"]
  node_admin_login["Admin login<br/>auth UI<br/>[Login.jsx]"]
  node_admin_catalog["Product management<br/>admin pages<br/>[Add.jsx]"]
  node_admin_orders["Order operations<br/>admin page<br/>[Orders.jsx]"]
end

subgraph group_api["Express API"]
  node_api_server["Express server<br/>API entry<br/>[server.js]"]
  node_api_routes["Domain routes<br/>route modules<br/>[orderRoute.js]"]
  node_controllers["Controllers<br/>application services<br/>[orderController.js]"]
  node_auth{{"JWT auth<br/>user middleware<br/>[auth.js]"}}
  node_admin_auth{{"Admin authorization<br/>admin middleware<br/>[adminAuth.js]"}}
  node_uploads["Image uploads<br/>multipart middleware<br/>[multer.js]"]
end

subgraph group_data["Data &amp; Integrations"]
  node_mongoose_models[("Commerce models<br/>Mongoose models<br/>[orderModel.js]")]
  node_mongodb[("MongoDB Atlas<br/>database<br/>[mongodb.js]")]
  node_cloudinary[("Cloudinary<br/>image storage<br/>[cloudinary.js]")]
  node_stripe{{"Stripe<br/>payment processor"}}
end

node_storefront_entry --> node_storefront_routes
node_storefront_routes -->|"uses"| node_shop_context
node_shop_context -->|"catalog, cart, auth APIs"| node_api_server
node_storefront_routes -->|"checkout"| node_checkout
node_checkout -->|"submits order"| node_api_server
node_payment_verify -->|"verifies payment"| node_api_server
node_admin_entry --> node_admin_routes
node_admin_routes -->|"authenticates"| node_admin_login
node_admin_routes -->|"manages products"| node_admin_catalog
node_admin_routes -->|"processes orders"| node_admin_orders
node_admin_catalog -->|"product APIs"| node_api_server
node_admin_orders -->|"order APIs"| node_api_server
node_api_server -->|"mounts"| node_api_routes
node_api_routes -->|"user operations"| node_auth
node_api_routes -->|"privileged operations"| node_admin_auth
node_api_routes -->|"product uploads"| node_uploads
node_auth -->|"authorized request"| node_controllers
node_admin_auth -->|"authorized request"| node_controllers
node_uploads -->|"multipart input"| node_controllers
node_api_routes -->|"dispatches"| node_controllers
node_controllers -->|"reads and writes"| node_mongoose_models
node_mongoose_models -->|"persists to"| node_mongodb
node_controllers -->|"stores images"| node_cloudinary
node_controllers -->|"initiates and verifies payments"| node_stripe

click node_storefront_entry "https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/main.jsx"
click node_storefront_routes "https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/App.jsx"
click node_shop_context "https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/context/ShopContext.jsx"
click node_checkout "https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/pages/PlaceOrder.jsx"
click node_payment_verify "https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/pages/Verify.jsx"
click node_admin_entry "https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/main.jsx"
click node_admin_routes "https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/App.jsx"
click node_admin_login "https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/components/Login.jsx"
click node_admin_catalog "https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/pages/Add.jsx"
click node_admin_orders "https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/pages/Orders.jsx"
click node_api_server "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/server.js"
click node_api_routes "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/routes/orderRoute.js"
click node_controllers "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/controllers/orderController.js"
click node_auth "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/middleware/auth.js"
click node_admin_auth "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/middleware/adminAuth.js"
click node_uploads "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/middleware/multer.js"
click node_mongoose_models "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/models/orderModel.js"
click node_mongodb "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/config/mongodb.js"
click node_cloudinary "https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/config/cloudinary.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_storefront_entry,node_storefront_routes,node_shop_context,node_checkout,node_payment_verify toneBlue
class node_admin_entry,node_admin_routes,node_admin_login,node_admin_catalog,node_admin_orders toneAmber
class node_api_server,node_api_routes,node_controllers,node_auth,node_admin_auth,node_uploads toneMint
class node_mongoose_models,node_mongodb,node_cloudinary,node_stripe toneRose
```

## Components

### Customer Storefront

- [Storefront SPA](https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/main.jsx): React/Vite entry · `frontend/src/main.jsx`
- [Shopping routes](https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/App.jsx): React app · `frontend/src/App.jsx`
- [Shop context](https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/context/ShopContext.jsx): client state · Shared catalog, cart, auth, and API state. · `frontend/src/context/ShopContext.jsx`
- [Checkout](https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/pages/PlaceOrder.jsx): order page · `frontend/src/pages/PlaceOrder.jsx`
- [Payment verification](https://github.com/elma-123/forever-ecommerce-website/blob/main/frontend/src/pages/Verify.jsx): return page · `frontend/src/pages/Verify.jsx`

### Admin Dashboard

- [Admin SPA](https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/main.jsx): React/Vite entry · `admin/src/main.jsx`
- [Admin shell](https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/App.jsx): React app · `admin/src/App.jsx`
- [Admin login](https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/components/Login.jsx): auth UI · `admin/src/components/Login.jsx`
- [Product management](https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/pages/Add.jsx): admin pages · Creates and reviews catalog products. · `admin/src/pages/Add.jsx`
- [Order operations](https://github.com/elma-123/forever-ecommerce-website/blob/main/admin/src/pages/Orders.jsx): admin page · `admin/src/pages/Orders.jsx`

### Express API

- [Express server](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/server.js): API entry · Mounts user, product, cart, and order routes. · `backend/server.js`
- [Domain routes](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/routes/orderRoute.js): route modules · `backend/routes/orderRoute.js`
- [Controllers](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/controllers/orderController.js): application services · Processes requests, auth context, models, and responses. · `backend/controllers/orderController.js`
- [JWT auth](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/middleware/auth.js): user middleware · `backend/middleware/auth.js`
- [Admin authorization](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/middleware/adminAuth.js): admin middleware · `backend/middleware/adminAuth.js`
- [Image uploads](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/middleware/multer.js): multipart middleware · `backend/middleware/multer.js`

### Data & Integrations

- [Commerce models](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/models/orderModel.js): Mongoose models · User, product, cart, and order persistence. · `backend/models/orderModel.js`
- [MongoDB Atlas](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/config/mongodb.js): database · `backend/config/mongodb.js`
- [Cloudinary](https://github.com/elma-123/forever-ecommerce-website/blob/main/backend/config/cloudinary.js): image storage · `backend/config/cloudinary.js`
- **Stripe**: payment processor

## Connections

- Storefront SPA → Shopping routes
- Shopping routes → Shop context: uses
- Shop context → Express server: catalog, cart, auth APIs
- Shopping routes → Checkout: checkout
- Checkout → Express server: submits order
- Payment verification → Express server: verifies payment
- Admin SPA → Admin shell
- Admin shell → Admin login: authenticates
- Admin shell → Product management: manages products
- Admin shell → Order operations: processes orders
- Product management → Express server: product APIs
- Order operations → Express server: order APIs
- Express server → Domain routes: mounts
- Domain routes → JWT auth: user operations
- Domain routes → Admin authorization: privileged operations
- Domain routes → Image uploads: product uploads
- JWT auth → Controllers: authorized request
- Admin authorization → Controllers: authorized request
- Image uploads → Controllers: multipart input
- Domain routes → Controllers: dispatches
- Controllers → Commerce models: reads and writes
- Commerce models → MongoDB Atlas: persists to
- Controllers → Cloudinary: stores images
- Controllers → Stripe: initiates and verifies payments
