# abdalrhman-mostafa/payops-ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/abdalrhman-mostafa/payops-ecommerce
- Repository: https://github.com/abdalrhman-mostafa/payops-ecommerce

## Overview

PayOps Ecommerce is a learning commerce system: customers browse and purchase through a Next.js storefront, while staff use its console; a same-origin BFF routes requests to independently deployed services. Commerce owns the transactional order, stock, payment, refund, ledger, and webhook domain; Identity separately manages customer accounts and carts. The gateway authorizes payment API requests, processes simulated connector payments, and dispatches signed webhooks. The README documents these service boundaries and the worker’s maintenance call. Several internal service connections are documented rather than shown in sampled call sites, so those edges cite the README; internal gateway calls cite sampled source.

Main entry points: [`services/gateway/src/server.js`](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/server.js) (Gateway API), [`services/commerce/src/app/api`](https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/commerce/src/app/api) (Commerce API), [`services/gateway/src/payments.js`](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/payments.js) (Payment processing), [`services/web/src/app/api/[...path]/route.ts`](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/web/src/app/api/%5B...path%5D/route.ts) (Web API and BFF)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Storefront and BFF"]
  node_storefront["Storefront"]
  node_staff["Staff console"]
  node_bff["Web API and BFF<br/>[route.ts]"]
  node_customer_api["Customer API"]
  node_invoice["Invoice proxy<br/>[route.ts]"]
end

subgraph group_commerce["Commerce domain"]
  node_commerce_api["Commerce API"]
  node_commerce_domain["Orders and finance"]
  node_commerce_db[("Commerce database<br/>[db.ts]")]
  node_commerce_hooks["Webhook inbox<br/>[webhooks.ts]"]
end

subgraph group_identity["Customer identity"]
  node_identity_service["Identity service<br/>[server.mjs]"]
  node_identity_db[("Identity database<br/>[server.mjs]")]
end

subgraph group_gateway["Payment gateway"]
  node_gateway_api["Gateway API<br/>[server.js]"]
  node_gateway_auth["API key auth<br/>[auth.js]"]
  node_gateway_payments["Payment processing<br/>[payments.js]"]
  node_connectors["Simulated connectors<br/>[connectors.js]"]
  node_hosted_page["Hosted checkout<br/>[pay-page.js]"]
  node_gateway_hooks["Webhook delivery<br/>[webhooks.js]"]
  node_gateway_db[("Gateway database<br/>[db.js]")]
end

subgraph group_ops["Maintenance"]
  node_worker["Maintenance worker"]
end

node_shopper(("Shopper"))
node_payops["External PayOps"]

node_shopper -->|"browses"| node_storefront
node_staff -->|"manages"| node_bff
node_shopper -->|"submits requests"| node_bff
node_storefront -->|"uses API"| node_bff
node_bff -->|"routes requests"| node_commerce_api
node_customer_api -->|"proxies customer actions"| node_identity_service
node_commerce_api -->|"handles domain requests"| node_commerce_domain
node_commerce_domain -->|"reads and writes"| node_commerce_db
node_commerce_api -->|"accepts webhooks"| node_commerce_hooks
node_commerce_hooks -->|"settles payments"| node_commerce_domain
node_identity_service -->|"stores accounts and carts"| node_identity_db
node_gateway_api -->|"authenticates requests"| node_gateway_auth
node_gateway_api -->|"dispatches payment calls"| node_gateway_payments
node_gateway_api -->|"serves checkout"| node_hosted_page
node_gateway_api -->|"initializes store"| node_gateway_db
node_gateway_payments -->|"routes transactions"| node_connectors
node_gateway_payments -->|"emits events"| node_gateway_hooks
node_hosted_page -->|"confirms payment"| node_gateway_payments
node_gateway_hooks -.->|"posts signed events"| node_commerce_hooks
node_commerce_api -.->|"requests payment"| node_gateway_api
node_invoice -->|"fetches invoice"| node_payops
node_worker -->|"calls maintenance"| node_commerce_api

click node_storefront "https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/web/src/app"
click node_staff "https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/web/src/app/admin"
click node_bff "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/web/src/app/api/%5B...path%5D/route.ts"
click node_customer_api "https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/web/src/app/api/customer"
click node_invoice "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/web/src/app/api/invoice/route.ts"
click node_commerce_api "https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/commerce/src/app/api"
click node_commerce_domain "https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/commerce/src/lib"
click node_commerce_db "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/commerce/src/lib/db.ts"
click node_commerce_hooks "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/commerce/src/lib/webhooks.ts"
click node_identity_service "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/identity/server.mjs"
click node_identity_db "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/identity/server.mjs"
click node_gateway_api "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/server.js"
click node_gateway_auth "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/auth.js"
click node_gateway_payments "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/payments.js"
click node_connectors "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/connectors.js"
click node_hosted_page "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/pay-page.js"
click node_gateway_hooks "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/webhooks.js"
click node_gateway_db "https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/db.js"

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_staff,node_bff,node_customer_api,node_invoice toneBlue
class node_commerce_api,node_commerce_domain,node_commerce_db,node_commerce_hooks toneAmber
class node_identity_service,node_identity_db toneMint
class node_gateway_api,node_gateway_auth,node_gateway_payments,node_connectors,node_hosted_page,node_gateway_hooks,node_gateway_db toneRose
class node_worker,node_shopper,node_payops toneIndigo
```

## Components

### Storefront and BFF

- [Storefront](https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/web/src/app): `services/web/src/app`
- [Staff console](https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/web/src/app/admin): `services/web/src/app/admin`
- [Web API and BFF](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/web/src/app/api/%5B...path%5D/route.ts): `services/web/src/app/api/[...path]/route.ts`
- [Customer API](https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/web/src/app/api/customer): `services/web/src/app/api/customer`
- [Invoice proxy](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/web/src/app/api/invoice/route.ts): `services/web/src/app/api/invoice/route.ts`

### Commerce domain

- [Commerce API](https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/commerce/src/app/api): `services/commerce/src/app/api`
- [Orders and finance](https://github.com/abdalrhman-mostafa/payops-ecommerce/tree/master/services/commerce/src/lib): `services/commerce/src/lib`
- [Commerce database](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/commerce/src/lib/db.ts): `services/commerce/src/lib/db.ts`
- [Webhook inbox](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/commerce/src/lib/webhooks.ts): `services/commerce/src/lib/webhooks.ts`

### Customer identity

- [Identity service](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/identity/server.mjs): `services/identity/server.mjs`
- [Identity database](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/identity/server.mjs): `services/identity/server.mjs`

### Payment gateway

- [Gateway API](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/server.js): `services/gateway/src/server.js`
- [API key auth](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/auth.js): `services/gateway/src/auth.js`
- [Payment processing](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/payments.js): `services/gateway/src/payments.js`
- [Simulated connectors](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/connectors.js): `services/gateway/src/connectors.js`
- [Hosted checkout](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/pay-page.js): `services/gateway/src/pay-page.js`
- [Webhook delivery](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/webhooks.js): `services/gateway/src/webhooks.js`
- [Gateway database](https://github.com/abdalrhman-mostafa/payops-ecommerce/blob/master/services/gateway/src/db.js): `services/gateway/src/db.js`

### Maintenance

- **Maintenance worker**

### Other components

- **Shopper**
- **External PayOps**

## Connections

- Shopper → Storefront: browses (evidence: `README.md`)
- Staff console → Web API and BFF: manages (evidence: `README.md`)
- Shopper → Web API and BFF: submits requests (evidence: `README.md`)
- Storefront → Web API and BFF: uses API (evidence: `README.md`)
- Web API and BFF → Commerce API: routes requests (evidence: `README.md`)
- Customer API → Identity service: proxies customer actions (evidence: `README.md`)
- Commerce API → Orders and finance: handles domain requests (evidence: `README.md`)
- Orders and finance → Commerce database: reads and writes (evidence: `README.md`)
- Commerce API → Webhook inbox: accepts webhooks (evidence: `services/commerce/src/app/api/webhooks/payops/route.ts`)
- Webhook inbox → Orders and finance: settles payments (evidence: `services/commerce/src/lib/webhooks.ts`)
- Identity service → Identity database: stores accounts and carts (evidence: `services/identity/server.mjs`)
- Gateway API → API key auth: authenticates requests (evidence: `services/gateway/src/server.js`)
- Gateway API → Payment processing: dispatches payment calls (evidence: `services/gateway/src/server.js`)
- Gateway API → Hosted checkout: serves checkout (evidence: `services/gateway/src/server.js`)
- Gateway API → Gateway database: initializes store (evidence: `services/gateway/src/server.js`)
- Payment processing → Simulated connectors: routes transactions (evidence: `services/gateway/src/payments.js`)
- Payment processing → Webhook delivery: emits events (evidence: `services/gateway/src/payments.js`)
- Hosted checkout → Payment processing: confirms payment (evidence: `services/gateway/src/pay-page.js`)
- Webhook delivery → Webhook inbox: posts signed events (evidence: `README.md`)
- Commerce API → Gateway API: requests payment (evidence: `README.md`)
- Invoice proxy → External PayOps: fetches invoice (evidence: `services/web/src/app/api/invoice/route.ts`)
- Maintenance worker → Commerce API: calls maintenance (evidence: `README.md`)
