# rufnul/shopnexus architecture

> Architecture diagram of the GitHub repository rufnul/shopnexus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rufnul/shopnexus
- Repository: https://github.com/rufnul/shopnexus

## Overview

ShopNexus is an e-commerce storefront with a Next.js frontend and an Express/MongoDB backend. The principal documented journey is browsing products and categories; account registration and login, contact messages, and email subscriptions are distinct supporting workflows. Backend route mounting and controller/model calls are visible in the excerpts and source index. The frontend-to-API wiring and several frontend page implementations were not shown, so their connections are left out.

Main entry points: [`backend/server.js`](https://github.com/rufnul/shopnexus/blob/main/backend/server.js) (API server), [`backend/controllers/authController.js`](https://github.com/rufnul/shopnexus/blob/main/backend/controllers/authController.js) (Auth handling), [`backend/routes/productRoutes.js`](https://github.com/rufnul/shopnexus/blob/main/backend/routes/productRoutes.js) (Product API), [`backend/routes/contactRoutes.js`](https://github.com/rufnul/shopnexus/blob/main/backend/routes/contactRoutes.js) (Contact routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_home["Home storefront<br/>[page.js]"]
  node_shop["Category browsing"]
  node_product_detail["Product detail<br/>[page.js]"]
  node_contact_page["Contact form<br/>[page.js]"]
  node_account_pages["Account pages<br/>[page.js]"]
  node_subscribe_ui["Subscription UI<br/>[Page.js]"]
end

subgraph group_api["API workflows"]
  node_server["API server<br/>[server.js]"]
  node_product_api["Product API<br/>[productRoutes.js]"]
  node_product_controller["Product controller"]
  node_contact_routes["Contact routes<br/>[contactRoutes.js]"]
  node_contact_controller["Contact handling"]
  node_subscribe_routes["Subscribe routes<br/>[subscribeRoutes.js]"]
  node_subscribe_controller["Subscribe handling"]
end

subgraph group_identity["Identity"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_auth_controller["Auth handling<br/>[authController.js]"]
  node_auth_middleware["Token protection<br/>[authMiddleware.js]"]
  node_token["JWT generation<br/>[generateToken.js]"]
end

subgraph group_data["Persistence"]
  node_mongo[("MongoDB")]
  node_db_connection["DB connection<br/>[db.js]"]
  node_product_model["Product model<br/>[Product.js]"]
  node_contact_model["Contact model<br/>[Contact.js]"]
  node_subscribe_model["Subscription model<br/>[Subscribe.js]"]
  node_user_model["User model<br/>[User.js]"]
end

node_shopper(("Shopper"))

node_shopper -->|"browses"| node_home
node_shopper -->|"browses categories"| node_shop
node_server -->|"mounts route"| node_product_api
node_server -->|"mounts route"| node_auth_routes
node_server -->|"mounts route"| node_contact_routes
node_server -->|"mounts route"| node_subscribe_routes
node_product_api -->|"queries and saves"| node_product_model
node_contact_routes -->|"routes requests"| node_contact_controller
node_contact_controller -->|"creates and queries"| node_contact_model
node_subscribe_routes -->|"routes requests"| node_subscribe_controller
node_subscribe_controller -->|"creates and queries"| node_subscribe_model
node_auth_routes -->|"routes requests"| node_auth_controller
node_auth_controller -->|"finds and creates"| node_user_model
node_auth_controller -->|"generates token"| node_token
node_auth_middleware -->|"loads user"| node_user_model
node_server -->|"connects database"| node_db_connection
node_db_connection -->|"opens connection"| node_mongo

click node_home "https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/page.js"
click node_shop "https://github.com/rufnul/shopnexus/tree/main/frontend/src/app/shop"
click node_product_detail "https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/product/%5Bid%5D/page.js"
click node_contact_page "https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/contact/page.js"
click node_account_pages "https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/login/page.js"
click node_subscribe_ui "https://github.com/rufnul/shopnexus/blob/main/frontend/src/components/Footer/Page.js"
click node_server "https://github.com/rufnul/shopnexus/blob/main/backend/server.js"
click node_product_api "https://github.com/rufnul/shopnexus/blob/main/backend/routes/productRoutes.js"
click node_product_controller "https://github.com/rufnul/shopnexus/blob/main/backend/controllers/productController.js"
click node_contact_routes "https://github.com/rufnul/shopnexus/blob/main/backend/routes/contactRoutes.js"
click node_contact_controller "https://github.com/rufnul/shopnexus/blob/main/backend/controllers/contactController.js"
click node_subscribe_routes "https://github.com/rufnul/shopnexus/blob/main/backend/routes/subscribeRoutes.js"
click node_subscribe_controller "https://github.com/rufnul/shopnexus/blob/main/backend/controllers/subscribeController.js"
click node_auth_routes "https://github.com/rufnul/shopnexus/blob/main/backend/routes/authRoutes.js"
click node_auth_controller "https://github.com/rufnul/shopnexus/blob/main/backend/controllers/authController.js"
click node_auth_middleware "https://github.com/rufnul/shopnexus/blob/main/backend/middleware/authMiddleware.js"
click node_token "https://github.com/rufnul/shopnexus/blob/main/backend/utils/generateToken.js"
click node_db_connection "https://github.com/rufnul/shopnexus/blob/main/backend/config/db.js"
click node_product_model "https://github.com/rufnul/shopnexus/blob/main/backend/models/Product.js"
click node_contact_model "https://github.com/rufnul/shopnexus/blob/main/backend/models/Contact.js"
click node_subscribe_model "https://github.com/rufnul/shopnexus/blob/main/backend/models/Subscribe.js"
click node_user_model "https://github.com/rufnul/shopnexus/blob/main/backend/models/User.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_home,node_shop,node_product_detail,node_contact_page,node_account_pages,node_subscribe_ui toneBlue
class node_server,node_product_api,node_product_controller,node_contact_routes,node_contact_controller,node_subscribe_routes,node_subscribe_controller toneAmber
class node_auth_routes,node_auth_controller,node_auth_middleware,node_token toneMint
class node_mongo,node_db_connection,node_product_model,node_contact_model,node_subscribe_model,node_user_model toneRose
class node_shopper toneIndigo
```

## Components

### Storefront

- [Home storefront](https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/page.js): `frontend/src/app/page.js`
- [Category browsing](https://github.com/rufnul/shopnexus/tree/main/frontend/src/app/shop): `frontend/src/app/shop`
- [Product detail](https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/product/%5Bid%5D/page.js): `frontend/src/app/product/[id]/page.js`
- [Contact form](https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/contact/page.js): `frontend/src/app/contact/page.js`
- [Account pages](https://github.com/rufnul/shopnexus/blob/main/frontend/src/app/login/page.js): `frontend/src/app/login/page.js`
- [Subscription UI](https://github.com/rufnul/shopnexus/blob/main/frontend/src/components/Footer/Page.js): `frontend/src/components/Footer/Page.js`

### API workflows

- [API server](https://github.com/rufnul/shopnexus/blob/main/backend/server.js): `backend/server.js`
- [Product API](https://github.com/rufnul/shopnexus/blob/main/backend/routes/productRoutes.js): `backend/routes/productRoutes.js`
- [Product controller](https://github.com/rufnul/shopnexus/blob/main/backend/controllers/productController.js): `backend/controllers/productController.js`
- [Contact routes](https://github.com/rufnul/shopnexus/blob/main/backend/routes/contactRoutes.js): `backend/routes/contactRoutes.js`
- [Contact handling](https://github.com/rufnul/shopnexus/blob/main/backend/controllers/contactController.js): `backend/controllers/contactController.js`
- [Subscribe routes](https://github.com/rufnul/shopnexus/blob/main/backend/routes/subscribeRoutes.js): `backend/routes/subscribeRoutes.js`
- [Subscribe handling](https://github.com/rufnul/shopnexus/blob/main/backend/controllers/subscribeController.js): `backend/controllers/subscribeController.js`

### Identity

- [Auth routes](https://github.com/rufnul/shopnexus/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Auth handling](https://github.com/rufnul/shopnexus/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Token protection](https://github.com/rufnul/shopnexus/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [JWT generation](https://github.com/rufnul/shopnexus/blob/main/backend/utils/generateToken.js): `backend/utils/generateToken.js`

### Persistence

- **MongoDB**
- [DB connection](https://github.com/rufnul/shopnexus/blob/main/backend/config/db.js): `backend/config/db.js`
- [Product model](https://github.com/rufnul/shopnexus/blob/main/backend/models/Product.js): `backend/models/Product.js`
- [Contact model](https://github.com/rufnul/shopnexus/blob/main/backend/models/Contact.js): `backend/models/Contact.js`
- [Subscription model](https://github.com/rufnul/shopnexus/blob/main/backend/models/Subscribe.js): `backend/models/Subscribe.js`
- [User model](https://github.com/rufnul/shopnexus/blob/main/backend/models/User.js): `backend/models/User.js`

### Other components

- **Shopper**

## Connections

- Shopper → Home storefront: browses
- Shopper → Category browsing: browses categories
- API server → Product API: mounts route (evidence: `backend/server.js`)
- API server → Auth routes: mounts route (evidence: `backend/server.js`)
- API server → Contact routes: mounts route (evidence: `backend/server.js`)
- API server → Subscribe routes: mounts route (evidence: `backend/server.js`)
- Product API → Product model: queries and saves (evidence: `backend/routes/productRoutes.js`)
- Contact routes → Contact handling: routes requests (evidence: `backend/routes/contactRoutes.js`)
- Contact handling → Contact model: creates and queries (evidence: `backend/controllers/contactController.js`)
- Subscribe routes → Subscribe handling: routes requests (evidence: `backend/routes/subscribeRoutes.js`)
- Subscribe handling → Subscription model: creates and queries (evidence: `backend/controllers/subscribeController.js`)
- Auth routes → Auth handling: routes requests (evidence: `backend/routes/authRoutes.js`)
- Auth handling → User model: finds and creates (evidence: `backend/controllers/authController.js`)
- Auth handling → JWT generation: generates token (evidence: `backend/controllers/authController.js`)
- Token protection → User model: loads user (evidence: `backend/middleware/authMiddleware.js`)
- API server → DB connection: connects database (evidence: `backend/server.js`)
- DB connection → MongoDB: opens connection (evidence: `backend/config/db.js`)
