How rodriguecyber/shopnow works
Purpose and Entry Points
ShopNow is a containerized e-commerce system with a Next.js frontend, Express API, PostgreSQL persistence, and Redis product caching. It supports local Docker Compose, AWS ECS Fargate, and AWS EKS deployments.
Runtime entry points are backend/src/index.ts for the API server and frontend/app/page.tsx for the primary storefront route. Local composition begins at docker-compose.yml.
Frontend Application and API Boundary
The frontend is a Next.js 16/React 19 application with SSR product and order pages plus a client-side cart/checkout flow. Its API client selects an internal server-side URL for SSR versus a browser-facing URL for client fetches, preserving the network boundary between VPC/cluster traffic and public traffic.
Core paths:
• frontend/app/api/client.ts
• frontend/app/cart-context.tsx
• frontend/app/orders/[id]/page.tsx
Backend HTTP and Commerce Logic
The Node.js 20/Express service exposes health, product CRUD, and order APIs. Route modules hand requests to product/order controllers; app.ts composes middleware and routes while index.ts starts the listener. The API is the sole application boundary to PostgreSQL and Redis.
Core paths:
• backend/src/app.ts
• backend/src/routes/productRoutes.ts
• backend/src/controllers/orderController.ts
Persistence, Migration, and Cache
PostgreSQL holds products, users, orders, and order items. Startup/runtime connections are isolated in the database layer; migrations create and seed schema data. Redis caches product list and item reads for one hour. Product mutations invalidate relevant cache keys, while order operations use the database flow directly.
Core paths:
• backend/src/db/connection.ts
• backend/src/db/migrations.ts
• backend/src/db/redis.ts
• backend/src/utils/cache.ts
Local Container Runtime
Docker Compose runs frontend, backend, PostgreSQL, and Redis as the local integrated topology. Application Dockerfiles package the independently deployable frontend and backend images. Environment files provide host, port, database, Redis, and API URL boundaries.
Core paths:
• docker-compose.yml
• backend/Dockerfile
• frontend/Dockerfile
AWS Infrastructure and ECS Deployment
Terraform provisions shared AWS infrastructure: VPC networking, ECR repositories, private RDS PostgreSQL, private ElastiCache Redis, and a public ALB. The ECS module runs frontend and backend Fargate services; Cloud Map lets frontend SSR tasks resolve the backend internally, while the ALB routes browser /api traffic to it.
Core paths:
• .infra/main.tf
• .infra/modules/ecs/backend.tf
• .infra/modules/ecs/frontend.tf
• .infra/modules/rds/main.tf
• .infra/modules/elasticache/main.tf
EKS Deployment Topology
The alternative Kubernetes deployment runs both application containers in the shopnow namespace. ClusterIP services abstract pods; an internet-facing ALB Ingress routes /api to backend and all other paths to frontend. Production pods consume Terraform-provisioned RDS and ElastiCache; included PostgreSQL/Redis manifests are development-only.
Core paths:
• .k8s/ingress.yaml
• .k8s/backend/deployment.yaml
• .k8s/frontend/deployment.yaml
• .infra/modules/eks/main.tf
Delivery and Trust Boundary
GitHub Actions validates backend compilation and frontend lint/build, then pushes versioned and latest images to ECR on main. AWS authentication uses GitHub OIDC and a narrowly scoped Terraform-created IAM role; CI publishes images but does not perform deployment.
Core paths:
• .github/workflows/ci-cd.yml
• .infra/modules/github-oidc/main.tf
• .infra/modules/ecr/main.tf
Main entry points: index.ts Express API · main.tf Terraform foundation · page.tsx Next.js storefront · connection.ts PostgreSQL
Components 21
Frontend
- Next.js storefront · SSR product/order pages and client cart checkout.
frontend/app/page.tsx - API client · Uses internal SSR or browser-facing API URLs.
frontend/app/api/client.ts - Cart state
frontend/app/cart-context.tsx - Order page
frontend/app/orders/[id]/page.tsx
Backend
- Express API · Sole application boundary to PostgreSQL and Redis.
backend/src/index.ts - Middleware and routes
backend/src/app.ts - Product routes
backend/src/routes/productRoutes.ts - Order controller
backend/src/controllers/orderController.ts
Data
- PostgreSQL · Products, users, orders, and order items.
backend/src/db/connection.ts - Migrations and seeds
backend/src/db/migrations.ts - Redis product cache · Caches product list and item reads for one hour.
backend/src/db/redis.ts - Cache invalidation · Product mutations invalidate relevant cache keys.
backend/src/utils/cache.ts
Local runtime
- Docker Compose · Runs frontend, backend, PostgreSQL, and Redis.
docker-compose.yml - Backend image
backend/Dockerfile - Frontend image
frontend/Dockerfile
AWS deployment
- Terraform foundation · Provisions VPC, ECR, ALB, RDS, ElastiCache, and compute foundations.
.infra/main.tf - ECS Fargate services · Frontend SSR resolves backend through Cloud Map; ALB sends /api to backend.
.infra/modules/ecs/backend.tf - EKS cluster · Runs frontend and backend in the shopnow namespace.
.infra/modules/eks/main.tf - ALB Ingress · Routes /api to backend and other paths to frontend.
.k8s/ingress.yaml
Delivery
- GitHub Actions · Validates builds and pushes versioned/latest images to ECR; does not deploy.
.github/workflows/ci-cd.yml - GitHub OIDC role · Narrowly scoped IAM role for CI authentication.
.infra/modules/github-oidc/main.tf
Connections 31
- Next.js storefront → API client: uses
- Cart state → API client: checkout requests
- Order page → API client: SSR fetches
- API client → Express API: HTTP API
- Express API → Middleware and routes: starts
- Middleware and routes → Product routes: mounts
- Middleware and routes → Order controller: routes orders
- Product routes → PostgreSQL: product CRUD
- Product routes → Cache invalidation: cache reads and invalidation
- Cache invalidation → Redis product cache: product keys
- Order controller → PostgreSQL: orders flow
- Migrations and seeds → PostgreSQL: creates and seeds
- Docker Compose → Next.js storefront: runs locally
- Docker Compose → Express API: runs locally
- Docker Compose → PostgreSQL: runs locally
- Docker Compose → Redis product cache: runs locally
- Backend image → Express API: packages
- Frontend image → Next.js storefront: packages
- Terraform foundation → ECS Fargate services: provisions
- Terraform foundation → EKS cluster: provisions
- Terraform foundation → PostgreSQL: private RDS
- Terraform foundation → Redis product cache: private ElastiCache
- ECS Fargate services → Express API: runs backend task
- ECS Fargate services → Next.js storefront: runs frontend task
- EKS cluster → ALB Ingress: exposes
- ALB Ingress → Express API: /api
- ALB Ingress → Next.js storefront: all other paths
- GitHub Actions → GitHub OIDC role: authenticates through
- GitHub OIDC role → Terraform foundation: IAM role provisioned by
- GitHub Actions → Backend image: publishes to ECR
- GitHub Actions → Frontend image: publishes to ECR