How passw0rd404/mern-ecommerce-devops-version works
1. Overall shape
- This is a three-part e-commerce system: a React frontend, a Node/Express backend API, and a substantial AWS/Terraform infrastructure layer.
- The repo also includes GitHub Actions workflows for CI/CD, plus deployment scripts used by CodeDeploy on the backend host.
2. Frontend boundary
- frontend/ is a Vite + React single-page app styled with Tailwind CSS.
- The UI is organized by pages (HomePage, CartPage, LoginPage, AdminPage, etc.), reusable components (ProductCard, Navbar, OrderSummary, AnalyticsTab), and state stores (useCartStore, useProductStore, useUserStore).
- frontend/src/lib/axios.js is the API client boundary to the backend.
3. User-facing flows in the frontend
- The app covers the standard commerce journey: browse products, view categories, add to cart, sign up / log in, checkout, and post-payment success/cancel screens.
- There is also an admin experience for product creation and analytics, which indicates a second role-based UI surface beyond shoppers.
4. Backend API boundary
- backend/ is an Express-based HTTP API exposed through route modules and controller modules.
- The route structure is domain-oriented: auth, product, cart, coupon, payment, analytics, plus health.
- Controllers encapsulate the business logic; middleware handles cross-cutting concerns such as auth.
5. Domain data model
- The backend uses MongoDB models for the core commerce entities: user, product, order, and coupon.
- This suggests MongoDB is the system of record for catalog, users, orders, and discount rules.
- The presence of order.model.js and analytics.controller.js indicates order history is also the basis for reporting.
6. Authentication and session security
- auth.controller.js, auth.middleware.js, and the README’s env vars show a JWT-based auth system with access and refresh tokens.
- The frontend likely stores auth state in useUserStore, while the backend validates protected routes via middleware.
- This boundary separates anonymous browsing from authenticated checkout/admin actions.
7. Cart, coupon, and payment flow
- The cart and coupon subsystems are separate API areas, which implies pricing is assembled in the backend rather than trusted entirely from the client.
- backend/lib/stripe.js and payment.controller.js show Stripe is the payment processor.
- The purchase flow likely goes: cart contents → coupon application → Stripe checkout/payment → order creation/confirmation.
8. Caching and infrastructure services
- backend/lib/redis.js and the README’s Redis variables indicate Redis/Valkey is part of the runtime architecture, likely for caching and/or short-lived commerce state.
- backend/lib/s3.js shows S3 is used for object storage, probably for product images or other uploaded assets.
- These are separate from MongoDB, so the app has a clear split between persistent domain data, cache/state, and blob storage.
9. Observability and operational endpoints
- tracing.js plus the OTEL env vars point to OpenTelemetry tracing exported to an external collector.
- The infrastructure includes CloudWatch and Grafana, so metrics/logging/visualization are treated as first-class operational concerns.
- A dedicated health.route.js supports service health checks and deployment validation.
10. Deployment model for the backend
- The backend appears to run on EC2, packaged via Packer into an AMI, and deployed with CodeDeploy.
- The root appspec.yml and scripts such as before-install.sh, after-install.sh, application-start.sh, and validate-service.sh are the lifecycle hooks for that deployment pipeline.
- This implies a VM-based backend release process rather than containers.
11. Frontend delivery
- The infra tree includes a CloudFront module, which strongly suggests the frontend is distributed as static assets behind a CDN.
- The separate build_ship_deploy_frontend.yml workflow and rollback_frontend.yml indicate frontend releases are managed independently from backend releases.
12. Infrastructure as code
- infrastructure-live-v1/ is the AWS topology definition, with reusable modules for VPC, EC2, ElastiCache, Mongo, S3, CloudFront, CodeDeploy, CloudWatch, and Grafana.
- This repo is not just application code; it also owns the environment wiring, networking, managed services, and deployment targets.
13. CI/CD and release orchestration
- GitHub Actions workflows cover build/ship/deploy for backend and frontend, code quality, AMI creation, infrastructure apply/destroy, and frontend rollback.
- That makes the release architecture explicit: code changes flow through CI, backend artifacts become AMIs, infrastructure is managed separately, and frontend has its own deploy/rollback path.
14. How to draw the diagram
- A good diagram should show: browser → frontend SPA → backend API → MongoDB/Redis/S3/Stripe, with Stripe returning payment outcomes and MongoDB holding commerce records.
- Around that core, show the AWS runtime: EC2 backend, CloudFront frontend, ElastiCache, observability stack, and the CI/CD lane from GitHub Actions through Packer/CodeDeploy/Terraform.
Main entry points: App.jsx React SPA · main.tf Terraform stack · product.controller.js Controllers · build_ship_deploy_backend.yml GitHub Actions
Components 20
Frontend app
React storefront and admin SPA.
- Browser · Shoppers and admins use the web app.
- React SPA · Single-page commerce and admin frontend.
frontend/src/App.jsx - Pages · Home, cart, auth, category, and purchase screens.
frontend/src/pages/HomePage.jsx - Components · Reusable product, cart, navbar, and admin widgets.
frontend/src/components/ProductCard.jsx - State stores · Cart, product, and user client state.
frontend/src/stores/useCartStore.js - API client · Frontend HTTP client for backend requests.
frontend/src/lib/axios.js
Backend API
Express service, domain logic, and data access.
- Express server · Backend HTTP entrypoint and route wiring.
backend/server.js - Routes · Auth, product, cart, coupon, payment, analytics, and health endpoints.
backend/routes/auth.route.js - Controllers · Domain operations for auth, catalog, cart, coupons, payments, and analytics.
backend/controllers/product.controller.js - Auth middleware · JWT protection for secured backend routes.
backend/middleware/auth.middleware.js - Mongo models · User, product, order, and coupon persistence schemas.
backend/models/order.model.js - Backend libs · MongoDB, Redis, S3, Stripe, and tracing adapters.
backend/lib/db.js
AWS infra
Terraform, Packer, and runtime services.
- EC2 backend · Backend service host and deployment target.
infrastructure-live-v1/modules/ec2/main.tf - CloudFront · Static frontend distribution and delivery edge.
infrastructure-live-v1/modules/cloud_front/main.tf - Data services · Mongo, ElastiCache, and S3 infrastructure.
infrastructure-live-v1/modules/mongo/main.tf - Observability · CloudWatch and Grafana operational visibility.
infrastructure-live-v1/modules/cloud_watch/output.tf - Terraform stack · VPC, service modules, and prod environment definition.
infrastructure-live-v1/prod/main.tf
CI/CD
GitHub Actions and release orchestration.
- Packer AMI · Builds the backend machine image for release.
infrastructure-live-v1/packer/main.pkr.hcl - GitHub Actions · Build, ship, deploy, quality, infra, and rollback workflows.
.github/workflows/build_ship_deploy_backend.yml - CodeDeploy hooks · AppSpec and lifecycle scripts for backend rollout and validation.
appspec.yml
Connections 23
- Browser → React SPA: uses · Users interact with the web application.
- React SPA → Pages: navigates · Pages define primary user flows.
- React SPA → Components: composes · Reusable UI widgets power the screens.
- React SPA → State stores: reads/writes · Client state drives cart, product, and auth flows.
- React SPA → API client: calls · Frontend requests are sent through the API client.
- API client → Express server: HTTP · Browser traffic reaches the backend API.
- Express server → Routes: mounts · Server registers the domain routes.
- Routes → Controllers: delegates · Routes pass requests into controllers.
- Controllers → Auth middleware: protects · Protected actions require auth middleware.
- Controllers → Mongo models: persists · Business logic reads and writes commerce records.
- Controllers → Backend libs: integrates · Controllers use storage, cache, payment, and tracing clients.
- Backend libs → Data services: uses · Backend libraries connect to AWS data services.
- Data services → Mongo models: stores · MongoDB is the system of record for domain entities.
- Terraform stack → EC2 backend: provisions · Terraform defines the backend runtime host.
- Terraform stack → CloudFront: provisions · Terraform defines the frontend CDN.
- Terraform stack → Data services: provisions · Infrastructure modules manage AWS data services.
- Terraform stack → Observability: provisions · Infrastructure modules manage monitoring and dashboards.
- GitHub Actions → Packer AMI: builds · CI creates the backend AMI artifact.
- GitHub Actions → Terraform stack: applies · Workflows manage infrastructure lifecycle.
- GitHub Actions → CodeDeploy hooks: orchestrates · Release workflows invoke deployment hooks.
- CodeDeploy hooks → EC2 backend: deploys to · CodeDeploy rolls backend releases onto the EC2 host.
- React SPA → CloudFront: served by · Static frontend assets are delivered through CloudFront.
- Observability → Express server: watches · Logs, metrics, and traces observe the API runtime.