# benwys06/ecommerce-store architecture

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

- Interactive diagram: https://gitdiagram.com/benwys06/ecommerce-store
- Repository: https://github.com/benwys06/ecommerce-store

## Overview

#### Purpose and Runtime
A full-stack e-commerce store with a public shopping experience, checkout/payment flow, user accounts, reviews, newsletter subscriptions, and a separate admin analytics interface. The frontend is a Vite React application; the backend is an Express-style API server. Root container support is present in `docker-compose.yml`.

#### Application Entry Points
- Backend startup and API composition: `backend/server.js`
- Frontend bootstrap and route/application composition: `frontend/src/main.jsx`, `frontend/src/App.jsx`
- Public and administrative shells are separated by `frontend/src/layout/PublicLayout.jsx` and `frontend/src/layout/AdminLayout.jsx`.

#### API and Domain Boundary
Routes expose domain-specific HTTP endpoints and delegate behavior to controllers:
- Authentication/users: `backend/routes/auth.route.js`, `backend/controllers/auth.controller.js`, `backend/controllers/user.controller.js`
- Catalog and reviews: `backend/routes/product.route.js`, `backend/controllers/product.controller.js`, `backend/controllers/review.controller.js`
- Cart, orders, coupons, and payment: `backend/routes/cart.route.js`, `backend/routes/order.route.js`, `backend/routes/payment.route.js`
- Admin/reporting and subscriptions: `backend/routes/analytics.route.js`, `backend/controllers/analytics.controller.js`, `backend/controllers/newsletter.controller.js`

This routing/controller layer is the principal boundary between frontend clients and persistence/external integrations.

#### Persistence and Core Entities
The backend models define the durable commerce state:
- Users and account-related state: `backend/models/user.model.js`, `backend/models/notification.model.js`
- Product catalog and customer feedback: `backend/models/product.model.js`, `backend/models/review.model.js`
- Transactional and promotion data: `backend/models/order.model.js`, `backend/models/coupon.model.js`
- Mailing-list records: `backend/models/newsletter.model.js`

Database connectivity is centralized in `backend/lib/db.js`. Redis is separately integrated through `backend/lib/redis.js`, likely for cache/session-like or ephemeral application concerns.

#### Commerce and Checkout Flow
Product browsing reaches catalog APIs, with client state coordinated through `frontend/src/stores/useProductStore.js`. Cart interactions use `frontend/src/stores/useCartStore.js` and backend cart endpoints. Checkout pricing logic is centralized in `backend/lib/checkoutPricing.js`; coupon handling is isolated in `backend/lib/coupon.js`. Payment endpoints/controllers integrate Stripe via `backend/lib/stripe.js`, leading to success/cancel pages at `frontend/src/pages/PurchaseSuccessPage.jsx` and `frontend/src/pages/PurchaseCancelPage.jsx`.

#### Identity, Authorization, and Media
Authentication is handled by backend auth controllers and middleware:
- `backend/config/passport.js`
- `backend/middleware/auth.middleware.js`
- `backend/controllers/auth.controller.js`

The frontend owns user session/UI state in `frontend/src/stores/useUserStore.js` and login/signup entry screens in `frontend/src/pages/LoginPage.jsx` and `frontend/src/pages/SignUpPage.jsx`. Upload handling crosses `backend/middleware/multer.middleware.js` before media is sent through `backend/lib/cloudinary.js`.

#### Frontend Experiences and State
The public storefront is page/component based: `frontend/src/pages/HomePage.jsx`, `frontend/src/pages/ProductPage.jsx`, and `frontend/src/pages/ProductDetailPage.jsx`. Reusable product and review presentation is concentrated in `frontend/src/components/ProductCard.jsx`, `frontend/src/components/ProductGallery.jsx`, and `frontend/src/components/ReviewList.jsx`; review API state is managed by `frontend/src/stores/useReviewStore.js`. HTTP client setup is centralized in `frontend/src/lib/axios.js`.

The admin surface contains dashboard and visualization scenes, including `frontend/src/admin/scenes/dashboard/index.jsx`, `frontend/src/admin/scenes/bar/index.jsx`, and `frontend/src/admin/scenes/geography/index.jsx`, backed by the analytics API layer.

#### External Services and Notifications
Material external service boundaries are Stripe payments (`backend/lib/stripe.js`), Cloudinary media storage (`backend/lib/cloudinary.js`), Redis (`backend/lib/redis.js`), and Resend email (`backend/lib/resend.js`). Email events and templates are separated from controllers in `backend/emails/emailHandlers.js` and `backend/emails/emailTemplates.js`, supporting order/account/newsletter-related communication.

Main entry points: [`backend/controllers/product.controller.js`](https://github.com/benwys06/ecommerce-store/blob/main/backend/controllers/product.controller.js) (Domain controllers), [`frontend/src/layout/PublicLayout.jsx`](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/layout/PublicLayout.jsx) (Public & admin shells), [`backend/server.js`](https://github.com/benwys06/ecommerce-store/blob/main/backend/server.js) (API server), [`backend/routes/auth.route.js`](https://github.com/benwys06/ecommerce-store/blob/main/backend/routes/auth.route.js) (Account & admin routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React frontend"]
  node_frontend_bootstrap["App bootstrap &amp; routes<br/>Vite React app<br/>[main.jsx]"]
  node_frontend_shells["Public &amp; admin shells<br/>layout layer<br/>[PublicLayout.jsx]"]
  node_storefront["Storefront pages<br/>shopping UI<br/>[HomePage.jsx]"]
  node_client_state["Commerce client state<br/>Zustand stores<br/>[useProductStore.js]"]
  node_auth_screens["Login &amp; signup<br/>account UI<br/>[LoginPage.jsx]"]
  node_checkout_result["Purchase result pages<br/>checkout UI"]
  node_admin_analytics["Admin analytics UI<br/>dashboard scenes<br/>[index.jsx]"]
  node_http_client["API client<br/>Axios client<br/>[axios.js]"]
end

subgraph group_backend["Commerce API"]
  node_api_server["API server<br/>Express server<br/>[server.js]"]
  node_commerce_routes["Commerce routes<br/>HTTP routes<br/>[order.route.js]"]
  node_account_routes["Account &amp; admin routes<br/>HTTP routes<br/>[auth.route.js]"]
  node_controllers["Domain controllers<br/>controller layer"]
  node_auth_security["Authentication &amp; authorization<br/>security middleware<br/>[auth.middleware.js]"]
  node_checkout["Checkout pricing &amp; coupons<br/>commerce logic<br/>[checkoutPricing.js]"]
  node_commerce_data[("Commerce data models<br/>durable entities<br/>[order.model.js]")]
  node_database[("Database connection<br/>persistence adapter<br/>[db.js]")]
  node_media_upload["Media upload pipeline<br/>upload middleware"]
  node_email_service["Email events &amp; templates<br/>notification service<br/>[emailHandlers.js]"]
end

subgraph group_external["External services"]
  node_stripe{{"Stripe<br/>payment service<br/>[stripe.js]"}}
  node_cloudinary{{"Cloudinary<br/>media storage<br/>[cloudinary.js]"}}
  node_redis[("Redis<br/>ephemeral store<br/>[redis.js]")]
  node_resend{{"Resend<br/>email delivery<br/>[resend.js]"}}
end

node_frontend_bootstrap -->|"selects shell"| node_frontend_shells
node_frontend_shells -->|"hosts public pages"| node_storefront
node_frontend_shells -->|"hosts admin UI"| node_admin_analytics
node_storefront -->|"uses"| node_client_state
node_auth_screens -->|"updates session"| node_client_state
node_client_state -->|"calls API"| node_http_client
node_admin_analytics -->|"queries analytics"| node_http_client
node_http_client -->|"HTTP"| node_api_server
node_api_server -->|"mounts"| node_commerce_routes
node_api_server -->|"mounts"| node_account_routes
node_commerce_routes -->|"delegates"| node_controllers
node_account_routes -->|"delegates"| node_controllers
node_account_routes -->|"protects endpoints"| node_auth_security
node_controllers -->|"calculates checkout"| node_checkout
node_controllers -->|"reads and writes"| node_commerce_data
node_commerce_data -->|"persists through"| node_database
node_controllers -->|"creates payments"| node_stripe
node_stripe -->|"success or cancel"| node_checkout_result
node_controllers -->|"accepts uploads"| node_media_upload
node_media_upload -->|"stores media"| node_cloudinary
node_controllers -.->|"uses ephemeral state"| node_redis
node_controllers -->|"triggers notifications"| node_email_service
node_email_service -->|"delivers email"| node_resend

click node_frontend_bootstrap "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/main.jsx"
click node_frontend_shells "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/layout/PublicLayout.jsx"
click node_storefront "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/pages/HomePage.jsx"
click node_client_state "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/stores/useProductStore.js"
click node_auth_screens "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/pages/LoginPage.jsx"
click node_checkout_result "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/pages/PurchaseSuccessPage.jsx"
click node_admin_analytics "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/admin/scenes/dashboard/index.jsx"
click node_http_client "https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/lib/axios.js"
click node_api_server "https://github.com/benwys06/ecommerce-store/blob/main/backend/server.js"
click node_commerce_routes "https://github.com/benwys06/ecommerce-store/blob/main/backend/routes/order.route.js"
click node_account_routes "https://github.com/benwys06/ecommerce-store/blob/main/backend/routes/auth.route.js"
click node_controllers "https://github.com/benwys06/ecommerce-store/blob/main/backend/controllers/product.controller.js"
click node_auth_security "https://github.com/benwys06/ecommerce-store/blob/main/backend/middleware/auth.middleware.js"
click node_checkout "https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/checkoutPricing.js"
click node_commerce_data "https://github.com/benwys06/ecommerce-store/blob/main/backend/models/order.model.js"
click node_database "https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/db.js"
click node_media_upload "https://github.com/benwys06/ecommerce-store/blob/main/backend/middleware/multer.middleware.js"
click node_email_service "https://github.com/benwys06/ecommerce-store/blob/main/backend/emails/emailHandlers.js"
click node_stripe "https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/stripe.js"
click node_cloudinary "https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/cloudinary.js"
click node_redis "https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/redis.js"
click node_resend "https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/resend.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_frontend_bootstrap,node_frontend_shells,node_storefront,node_client_state,node_auth_screens,node_checkout_result,node_admin_analytics,node_http_client toneBlue
class node_api_server,node_commerce_routes,node_account_routes,node_controllers,node_auth_security,node_checkout,node_commerce_data,node_database,node_media_upload,node_email_service toneAmber
class node_stripe,node_cloudinary,node_redis,node_resend toneMint
```

## Components

### React frontend

- [App bootstrap & routes](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/main.jsx): Vite React app · Composes client routing and application startup. · `frontend/src/main.jsx`
- [Public & admin shells](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/layout/PublicLayout.jsx): layout layer · `frontend/src/layout/PublicLayout.jsx`
- [Storefront pages](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/pages/HomePage.jsx): shopping UI · Home, product listing, detail, and reusable product/review views. · `frontend/src/pages/HomePage.jsx`
- [Commerce client state](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/stores/useProductStore.js): Zustand stores · Coordinates product, cart, user, and review state. · `frontend/src/stores/useProductStore.js`
- [Login & signup](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/pages/LoginPage.jsx): account UI · `frontend/src/pages/LoginPage.jsx`
- [Purchase result pages](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/pages/PurchaseSuccessPage.jsx): checkout UI · `frontend/src/pages/PurchaseSuccessPage.jsx`
- [Admin analytics UI](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/admin/scenes/dashboard/index.jsx): dashboard scenes · Dashboard and visualization scenes for reporting. · `frontend/src/admin/scenes/dashboard/index.jsx`
- [API client](https://github.com/benwys06/ecommerce-store/blob/main/frontend/src/lib/axios.js): Axios client · `frontend/src/lib/axios.js`

### Commerce API

- [API server](https://github.com/benwys06/ecommerce-store/blob/main/backend/server.js): Express server · Startup and API composition boundary. · `backend/server.js`
- [Commerce routes](https://github.com/benwys06/ecommerce-store/blob/main/backend/routes/order.route.js): HTTP routes · Product, cart, order, coupon, and payment endpoints. · `backend/routes/order.route.js`
- [Account & admin routes](https://github.com/benwys06/ecommerce-store/blob/main/backend/routes/auth.route.js): HTTP routes · Auth, user, analytics, and subscription endpoints. · `backend/routes/auth.route.js`
- [Domain controllers](https://github.com/benwys06/ecommerce-store/blob/main/backend/controllers/product.controller.js): controller layer · Implements route behavior across commerce, accounts, analytics, and newsletter flows. · `backend/controllers/product.controller.js`
- [Authentication & authorization](https://github.com/benwys06/ecommerce-store/blob/main/backend/middleware/auth.middleware.js): security middleware · Passport authentication and protected-route enforcement. · `backend/middleware/auth.middleware.js`
- [Checkout pricing & coupons](https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/checkoutPricing.js): commerce logic · Centralizes pricing calculation and coupon handling. · `backend/lib/checkoutPricing.js`
- [Commerce data models](https://github.com/benwys06/ecommerce-store/blob/main/backend/models/order.model.js): durable entities · Users, products, reviews, orders, coupons, newsletters, and notifications. · `backend/models/order.model.js`
- [Database connection](https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/db.js): persistence adapter · `backend/lib/db.js`
- [Media upload pipeline](https://github.com/benwys06/ecommerce-store/blob/main/backend/middleware/multer.middleware.js): upload middleware · Processes uploads before cloud media storage. · `backend/middleware/multer.middleware.js`
- [Email events & templates](https://github.com/benwys06/ecommerce-store/blob/main/backend/emails/emailHandlers.js): notification service · Handles transactional account, order, and newsletter email. · `backend/emails/emailHandlers.js`

### External services

- [Stripe](https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/stripe.js): payment service · `backend/lib/stripe.js`
- [Cloudinary](https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/cloudinary.js): media storage · `backend/lib/cloudinary.js`
- [Redis](https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/redis.js): ephemeral store · `backend/lib/redis.js`
- [Resend](https://github.com/benwys06/ecommerce-store/blob/main/backend/lib/resend.js): email delivery · `backend/lib/resend.js`

## Connections

- App bootstrap & routes → Public & admin shells: selects shell
- Public & admin shells → Storefront pages: hosts public pages
- Public & admin shells → Admin analytics UI: hosts admin UI
- Storefront pages → Commerce client state: uses
- Login & signup → Commerce client state: updates session
- Commerce client state → API client: calls API
- Admin analytics UI → API client: queries analytics
- API client → API server: HTTP
- API server → Commerce routes: mounts
- API server → Account & admin routes: mounts
- Commerce routes → Domain controllers: delegates
- Account & admin routes → Domain controllers: delegates
- Account & admin routes → Authentication & authorization: protects endpoints
- Domain controllers → Checkout pricing & coupons: calculates checkout
- Domain controllers → Commerce data models: reads and writes
- Commerce data models → Database connection: persists through
- Domain controllers → Stripe: creates payments
- Stripe → Purchase result pages: success or cancel
- Domain controllers → Media upload pipeline: accepts uploads
- Media upload pipeline → Cloudinary: stores media
- Domain controllers → Redis: uses ephemeral state
- Domain controllers → Email events & templates: triggers notifications
- Email events & templates → Resend: delivers email
