# rodriguecyber/shopnow architecture

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

- Interactive diagram: https://gitdiagram.com/rodriguecyber/shopnow
- Repository: https://github.com/rodriguecyber/shopnow

## Overview

#### 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: [`backend/src/index.ts`](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/index.ts) (Express API), [`.infra/main.tf`](https://github.com/rodriguecyber/shopnow/blob/main/.infra/main.tf) (Terraform foundation), [`frontend/app/page.tsx`](https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/page.tsx) (Next.js storefront), [`backend/src/db/connection.ts`](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/connection.ts) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_storefront["Next.js storefront<br/>Next.js app<br/>[page.tsx]"]
  node_api_client["API client<br/>frontend boundary<br/>[client.ts]"]
  node_cart["Cart state<br/>React context<br/>[cart-context.tsx]"]
  node_orders_page["Order page<br/>SSR route<br/>[page.tsx]"]
end

subgraph group_backend["Backend"]
  node_api["Express API<br/>Node.js service<br/>[index.ts]"]
  node_api_composition["Middleware and routes<br/>Express composition<br/>[app.ts]"]
  node_product_routes["Product routes<br/>HTTP routes<br/>[productRoutes.ts]"]
  node_order_controller["Order controller<br/>commerce logic<br/>[orderController.ts]"]
end

subgraph group_data["Data"]
  node_postgres[("PostgreSQL<br/>relational store<br/>[connection.ts]")]
  node_migrations["Migrations and seeds<br/>schema lifecycle<br/>[migrations.ts]"]
  node_redis[("Redis product cache<br/>[redis.ts]")]
  node_cache_logic["Cache invalidation<br/>cache utility<br/>[cache.ts]"]
end

subgraph group_local["Local runtime"]
  node_compose["Docker Compose<br/>local topology<br/>[docker-compose.yml]"]
  node_backend_image["Backend image<br/>Docker image"]
  node_frontend_image["Frontend image<br/>Docker image"]
end

subgraph group_aws["AWS deployment"]
  node_terraform{{"Terraform foundation<br/>AWS infrastructure<br/>[main.tf]"}}
  node_ecs["ECS Fargate services<br/>ECS deployment<br/>[backend.tf]"]
  node_eks["EKS cluster<br/>Kubernetes deployment<br/>[main.tf]"]
  node_ingress["ALB Ingress<br/>Kubernetes ingress<br/>[ingress.yaml]"]
end

subgraph group_delivery["Delivery"]
  node_ci["GitHub Actions<br/>CI image publisher<br/>[ci-cd.yml]"]
  node_oidc{{"GitHub OIDC role<br/>AWS trust boundary<br/>[main.tf]"}}
end

node_storefront -->|"uses"| node_api_client
node_cart -->|"checkout requests"| node_api_client
node_orders_page -->|"SSR fetches"| node_api_client
node_api_client -->|"HTTP API"| node_api
node_api -->|"starts"| node_api_composition
node_api_composition -->|"mounts"| node_product_routes
node_api_composition -->|"routes orders"| node_order_controller
node_product_routes -->|"product CRUD"| node_postgres
node_product_routes -->|"cache reads and invalidation"| node_cache_logic
node_cache_logic -->|"product keys"| node_redis
node_order_controller -->|"orders flow"| node_postgres
node_migrations -->|"creates and seeds"| node_postgres
node_compose -->|"runs locally"| node_storefront
node_compose -->|"runs locally"| node_api
node_compose -->|"runs locally"| node_postgres
node_compose -->|"runs locally"| node_redis
node_backend_image -.->|"packages"| node_api
node_frontend_image -.->|"packages"| node_storefront
node_terraform -->|"provisions"| node_ecs
node_terraform -->|"provisions"| node_eks
node_terraform -.->|"private RDS"| node_postgres
node_terraform -.->|"private ElastiCache"| node_redis
node_ecs -->|"runs backend task"| node_api
node_ecs -->|"runs frontend task"| node_storefront
node_eks -->|"exposes"| node_ingress
node_ingress -->|"/api"| node_api
node_ingress -->|"all other paths"| node_storefront
node_ci -->|"authenticates through"| node_oidc
node_oidc -.->|"IAM role provisioned by"| node_terraform
node_ci -->|"publishes to ECR"| node_backend_image
node_ci -->|"publishes to ECR"| node_frontend_image

click node_storefront "https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/page.tsx"
click node_api_client "https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/api/client.ts"
click node_cart "https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/cart-context.tsx"
click node_orders_page "https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/orders/%5Bid%5D/page.tsx"
click node_api "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/index.ts"
click node_api_composition "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/app.ts"
click node_product_routes "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/routes/productRoutes.ts"
click node_order_controller "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/controllers/orderController.ts"
click node_postgres "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/connection.ts"
click node_migrations "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/migrations.ts"
click node_redis "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/redis.ts"
click node_cache_logic "https://github.com/rodriguecyber/shopnow/blob/main/backend/src/utils/cache.ts"
click node_compose "https://github.com/rodriguecyber/shopnow/blob/main/docker-compose.yml"
click node_backend_image "https://github.com/rodriguecyber/shopnow/blob/main/backend/Dockerfile"
click node_frontend_image "https://github.com/rodriguecyber/shopnow/blob/main/frontend/Dockerfile"
click node_terraform "https://github.com/rodriguecyber/shopnow/blob/main/.infra/main.tf"
click node_ecs "https://github.com/rodriguecyber/shopnow/blob/main/.infra/modules/ecs/backend.tf"
click node_eks "https://github.com/rodriguecyber/shopnow/blob/main/.infra/modules/eks/main.tf"
click node_ingress "https://github.com/rodriguecyber/shopnow/blob/main/.k8s/ingress.yaml"
click node_ci "https://github.com/rodriguecyber/shopnow/blob/main/.github/workflows/ci-cd.yml"
click node_oidc "https://github.com/rodriguecyber/shopnow/blob/main/.infra/modules/github-oidc/main.tf"

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_storefront,node_api_client,node_cart,node_orders_page toneBlue
class node_api,node_api_composition,node_product_routes,node_order_controller toneAmber
class node_postgres,node_migrations,node_redis,node_cache_logic toneMint
class node_compose,node_backend_image,node_frontend_image toneRose
class node_terraform,node_ecs,node_eks,node_ingress toneIndigo
class node_ci,node_oidc toneTeal
```

## Components

### Frontend

- [Next.js storefront](https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/page.tsx): Next.js app · SSR product/order pages and client cart checkout. · `frontend/app/page.tsx`
- [API client](https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/api/client.ts): frontend boundary · Uses internal SSR or browser-facing API URLs. · `frontend/app/api/client.ts`
- [Cart state](https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/cart-context.tsx): React context · `frontend/app/cart-context.tsx`
- [Order page](https://github.com/rodriguecyber/shopnow/blob/main/frontend/app/orders/%5Bid%5D/page.tsx): SSR route · `frontend/app/orders/[id]/page.tsx`

### Backend

- [Express API](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/index.ts): Node.js service · Sole application boundary to PostgreSQL and Redis. · `backend/src/index.ts`
- [Middleware and routes](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/app.ts): Express composition · `backend/src/app.ts`
- [Product routes](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/routes/productRoutes.ts): HTTP routes · `backend/src/routes/productRoutes.ts`
- [Order controller](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/controllers/orderController.ts): commerce logic · `backend/src/controllers/orderController.ts`

### Data

- [PostgreSQL](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/connection.ts): relational store · Products, users, orders, and order items. · `backend/src/db/connection.ts`
- [Migrations and seeds](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/migrations.ts): schema lifecycle · `backend/src/db/migrations.ts`
- [Redis product cache](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/db/redis.ts): cache · Caches product list and item reads for one hour. · `backend/src/db/redis.ts`
- [Cache invalidation](https://github.com/rodriguecyber/shopnow/blob/main/backend/src/utils/cache.ts): cache utility · Product mutations invalidate relevant cache keys. · `backend/src/utils/cache.ts`

### Local runtime

- [Docker Compose](https://github.com/rodriguecyber/shopnow/blob/main/docker-compose.yml): local topology · Runs frontend, backend, PostgreSQL, and Redis. · `docker-compose.yml`
- [Backend image](https://github.com/rodriguecyber/shopnow/blob/main/backend/Dockerfile): Docker image · `backend/Dockerfile`
- [Frontend image](https://github.com/rodriguecyber/shopnow/blob/main/frontend/Dockerfile): Docker image · `frontend/Dockerfile`

### AWS deployment

- [Terraform foundation](https://github.com/rodriguecyber/shopnow/blob/main/.infra/main.tf): AWS infrastructure · Provisions VPC, ECR, ALB, RDS, ElastiCache, and compute foundations. · `.infra/main.tf`
- [ECS Fargate services](https://github.com/rodriguecyber/shopnow/blob/main/.infra/modules/ecs/backend.tf): ECS deployment · Frontend SSR resolves backend through Cloud Map; ALB sends /api to backend. · `.infra/modules/ecs/backend.tf`
- [EKS cluster](https://github.com/rodriguecyber/shopnow/blob/main/.infra/modules/eks/main.tf): Kubernetes deployment · Runs frontend and backend in the shopnow namespace. · `.infra/modules/eks/main.tf`
- [ALB Ingress](https://github.com/rodriguecyber/shopnow/blob/main/.k8s/ingress.yaml): Kubernetes ingress · Routes /api to backend and other paths to frontend. · `.k8s/ingress.yaml`

### Delivery

- [GitHub Actions](https://github.com/rodriguecyber/shopnow/blob/main/.github/workflows/ci-cd.yml): CI image publisher · Validates builds and pushes versioned/latest images to ECR; does not deploy. · `.github/workflows/ci-cd.yml`
- [GitHub OIDC role](https://github.com/rodriguecyber/shopnow/blob/main/.infra/modules/github-oidc/main.tf): AWS trust boundary · Narrowly scoped IAM role for CI authentication. · `.infra/modules/github-oidc/main.tf`

## Connections

- 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
