How benwys06/ecommerce-store works
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: product.controller.js Domain controllers · PublicLayout.jsx Public & admin shells · server.js API server · auth.route.js Account & admin routes
Components 22
React frontend
- App bootstrap & routes · Composes client routing and application startup.
frontend/src/main.jsx - Public & admin shells
frontend/src/layout/PublicLayout.jsx - Storefront pages · Home, product listing, detail, and reusable product/review views.
frontend/src/pages/HomePage.jsx - Commerce client state · Coordinates product, cart, user, and review state.
frontend/src/stores/useProductStore.js - Login & signup
frontend/src/pages/LoginPage.jsx - Purchase result pages
frontend/src/pages/PurchaseSuccessPage.jsx - Admin analytics UI · Dashboard and visualization scenes for reporting.
frontend/src/admin/scenes/dashboard/index.jsx - API client
frontend/src/lib/axios.js
Commerce API
- API server · Startup and API composition boundary.
backend/server.js - Commerce routes · Product, cart, order, coupon, and payment endpoints.
backend/routes/order.route.js - Account & admin routes · Auth, user, analytics, and subscription endpoints.
backend/routes/auth.route.js - Domain controllers · Implements route behavior across commerce, accounts, analytics, and newsletter flows.
backend/controllers/product.controller.js - Authentication & authorization · Passport authentication and protected-route enforcement.
backend/middleware/auth.middleware.js - Checkout pricing & coupons · Centralizes pricing calculation and coupon handling.
backend/lib/checkoutPricing.js - Commerce data models · Users, products, reviews, orders, coupons, newsletters, and notifications.
backend/models/order.model.js - Database connection
backend/lib/db.js - Media upload pipeline · Processes uploads before cloud media storage.
backend/middleware/multer.middleware.js - Email events & templates · Handles transactional account, order, and newsletter email.
backend/emails/emailHandlers.js
External services
- Stripe
backend/lib/stripe.js - Cloudinary
backend/lib/cloudinary.js - Redis
backend/lib/redis.js - Resend
backend/lib/resend.js
Connections 23
- 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