# passw0rd404/mern-ecommerce-devops-version architecture

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

- Interactive diagram: https://gitdiagram.com/passw0rd404/mern-ecommerce-devops-version
- Repository: https://github.com/passw0rd404/mern-ecommerce-devops-version

## Overview

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: [`frontend/src/App.jsx`](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/App.jsx) (React SPA), [`infrastructure-live-v1/prod/main.tf`](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/prod/main.tf) (Terraform stack), [`backend/controllers/product.controller.js`](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/controllers/product.controller.js) (Controllers), [`.github/workflows/build_ship_deploy_backend.yml`](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/.github/workflows/build_ship_deploy_backend.yml) (GitHub Actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Frontend app"]
  node_node_browser(("Browser<br/>client"))
  node_node_spa["React SPA<br/>vite-react<br/>[App.jsx]"]
  node_node_pages["Pages<br/>ui screens<br/>[HomePage.jsx]"]
  node_node_components["Components<br/>ui widgets<br/>[ProductCard.jsx]"]
  node_node_stores["State stores<br/>zustand stores<br/>[useCartStore.js]"]
  node_node_api_client["API client<br/>axios boundary<br/>[axios.js]"]
end

subgraph group_group_backend["Backend API"]
  node_node_server["Express server<br/>api runtime<br/>[server.js]"]
  node_node_routes["Routes<br/>route modules<br/>[auth.route.js]"]
  node_node_controllers["Controllers<br/>business logic"]
  node_node_auth["Auth middleware<br/>security<br/>[auth.middleware.js]"]
  node_node_models[("Mongo models<br/>data model<br/>[order.model.js]")]
  node_node_backend_libs["Backend libs<br/>integrations<br/>[db.js]"]
end

subgraph group_group_infra["AWS infra"]
  node_node_ec2["EC2 backend<br/>aws runtime<br/>[main.tf]"]
  node_node_cloudfront["CloudFront<br/>cdn<br/>[main.tf]"]
  node_node_data_platform[("Data services<br/>aws services<br/>[main.tf]")]
  node_node_observability["Observability<br/>monitoring<br/>[output.tf]"]
  node_node_iac["Terraform stack<br/>iac<br/>[main.tf]"]
end

subgraph group_group_cicd["CI/CD"]
  node_node_packer["Packer AMI<br/>image build<br/>[main.pkr.hcl]"]
  node_node_github_actions["GitHub Actions<br/>ci/cd"]
  node_node_codedeploy["CodeDeploy hooks<br/>deployment scripts<br/>[appspec.yml]"]
end

node_node_browser -->|"uses"| node_node_spa
node_node_spa -->|"navigates"| node_node_pages
node_node_spa -->|"composes"| node_node_components
node_node_spa -->|"reads/writes"| node_node_stores
node_node_spa -->|"calls"| node_node_api_client
node_node_api_client -->|"HTTP"| node_node_server
node_node_server -->|"mounts"| node_node_routes
node_node_routes -->|"delegates"| node_node_controllers
node_node_controllers -->|"protects"| node_node_auth
node_node_controllers -->|"persists"| node_node_models
node_node_controllers -->|"integrates"| node_node_backend_libs
node_node_backend_libs -->|"uses"| node_node_data_platform
node_node_data_platform -->|"stores"| node_node_models
node_node_iac -->|"provisions"| node_node_ec2
node_node_iac -->|"provisions"| node_node_cloudfront
node_node_iac -->|"provisions"| node_node_data_platform
node_node_iac -->|"provisions"| node_node_observability
node_node_github_actions -->|"builds"| node_node_packer
node_node_github_actions -->|"applies"| node_node_iac
node_node_github_actions -->|"orchestrates"| node_node_codedeploy
node_node_codedeploy -->|"deploys to"| node_node_ec2
node_node_spa -->|"served by"| node_node_cloudfront
node_node_observability -.->|"watches"| node_node_server

click node_node_spa "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/App.jsx"
click node_node_pages "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/pages/HomePage.jsx"
click node_node_components "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/components/ProductCard.jsx"
click node_node_stores "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/stores/useCartStore.js"
click node_node_api_client "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/lib/axios.js"
click node_node_server "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/server.js"
click node_node_routes "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/routes/auth.route.js"
click node_node_controllers "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/controllers/product.controller.js"
click node_node_auth "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/middleware/auth.middleware.js"
click node_node_models "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/models/order.model.js"
click node_node_backend_libs "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/lib/db.js"
click node_node_ec2 "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/ec2/main.tf"
click node_node_cloudfront "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/cloud_front/main.tf"
click node_node_data_platform "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/mongo/main.tf"
click node_node_observability "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/cloud_watch/output.tf"
click node_node_iac "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/prod/main.tf"
click node_node_packer "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/packer/main.pkr.hcl"
click node_node_github_actions "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/.github/workflows/build_ship_deploy_backend.yml"
click node_node_codedeploy "https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/appspec.yml"

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_node_browser,node_node_spa,node_node_pages,node_node_components,node_node_stores,node_node_api_client toneBlue
class node_node_server,node_node_routes,node_node_controllers,node_node_auth,node_node_models,node_node_backend_libs toneAmber
class node_node_ec2,node_node_cloudfront,node_node_data_platform,node_node_observability,node_node_iac toneMint
class node_node_packer,node_node_github_actions,node_node_codedeploy toneRose
```

## Components

### Frontend app

React storefront and admin SPA.

- **Browser**: client · Shoppers and admins use the web app.
- [React SPA](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/App.jsx): vite-react · Single-page commerce and admin frontend. · `frontend/src/App.jsx`
- [Pages](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/pages/HomePage.jsx): ui screens · Home, cart, auth, category, and purchase screens. · `frontend/src/pages/HomePage.jsx`
- [Components](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/components/ProductCard.jsx): ui widgets · Reusable product, cart, navbar, and admin widgets. · `frontend/src/components/ProductCard.jsx`
- [State stores](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/stores/useCartStore.js): zustand stores · Cart, product, and user client state. · `frontend/src/stores/useCartStore.js`
- [API client](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/frontend/src/lib/axios.js): axios boundary · Frontend HTTP client for backend requests. · `frontend/src/lib/axios.js`

### Backend API

Express service, domain logic, and data access.

- [Express server](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/server.js): api runtime · Backend HTTP entrypoint and route wiring. · `backend/server.js`
- [Routes](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/routes/auth.route.js): route modules · Auth, product, cart, coupon, payment, analytics, and health endpoints. · `backend/routes/auth.route.js`
- [Controllers](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/controllers/product.controller.js): business logic · Domain operations for auth, catalog, cart, coupons, payments, and analytics. · `backend/controllers/product.controller.js`
- [Auth middleware](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/middleware/auth.middleware.js): security · JWT protection for secured backend routes. · `backend/middleware/auth.middleware.js`
- [Mongo models](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/models/order.model.js): data model · User, product, order, and coupon persistence schemas. · `backend/models/order.model.js`
- [Backend libs](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/backend/lib/db.js): integrations · MongoDB, Redis, S3, Stripe, and tracing adapters. · `backend/lib/db.js`

### AWS infra

Terraform, Packer, and runtime services.

- [EC2 backend](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/ec2/main.tf): aws runtime · Backend service host and deployment target. · `infrastructure-live-v1/modules/ec2/main.tf`
- [CloudFront](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/cloud_front/main.tf): cdn · Static frontend distribution and delivery edge. · `infrastructure-live-v1/modules/cloud_front/main.tf`
- [Data services](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/mongo/main.tf): aws services · Mongo, ElastiCache, and S3 infrastructure. · `infrastructure-live-v1/modules/mongo/main.tf`
- [Observability](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/modules/cloud_watch/output.tf): monitoring · CloudWatch and Grafana operational visibility. · `infrastructure-live-v1/modules/cloud_watch/output.tf`
- [Terraform stack](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/prod/main.tf): iac · VPC, service modules, and prod environment definition. · `infrastructure-live-v1/prod/main.tf`

### CI/CD

GitHub Actions and release orchestration.

- [Packer AMI](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/infrastructure-live-v1/packer/main.pkr.hcl): image build · Builds the backend machine image for release. · `infrastructure-live-v1/packer/main.pkr.hcl`
- [GitHub Actions](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/.github/workflows/build_ship_deploy_backend.yml): ci/cd · Build, ship, deploy, quality, infra, and rollback workflows. · `.github/workflows/build_ship_deploy_backend.yml`
- [CodeDeploy hooks](https://github.com/passw0rd404/mern-ecommerce-devops-version/blob/master/appspec.yml): deployment scripts · AppSpec and lifecycle scripts for backend rollout and validation. · `appspec.yml`

## Connections

- 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.
