# Payment Gateway Architecture

Task: ARCH-PAYMENT-GATEWAY-DIAGRAM

## Source Mode

`source-free`

No visual source reference was provided. This diagram is validated against its
own architecture contract and the current diagram quality rules.

## Architecture Contract

- Audience: architect, security, developer, QA, and release reviewers.
- Required systems:
  - Web interface for merchants, admins, and customers.
  - APIs / middleware layer for payment orchestration.
  - Payment gateway core service.
  - Transaction database.
  - Security layer.
- Added supporting elements:
  - Identity provider for authentication.
  - WAF / API gateway for edge protection.
  - Token vault / KMS for card tokenization and key management.
  - Fraud/risk engine for transaction scoring.
  - Audit log / monitoring for compliance and operations.
  - External payment processor / card network.
- Required relationships:
  - Users access the web interface through edge security.
  - Web interface calls APIs through the API gateway.
  - Middleware orchestrates payment requests and routes them to the payment
    gateway core.
  - Gateway core stores transaction state in the database.
  - Gateway core tokenizes sensitive payment data through token vault / KMS.
  - Gateway core requests fraud/risk scoring before authorization.
  - Gateway core sends authorization/capture/refund messages to the external
    processor.
  - Middleware and gateway core emit audit and operational events.
- Visual requirements:
  - Security controls are visually distinct and readable.
  - API/middleware and core payment responsibilities are separated.
  - Connectors are orthogonal, visibly attached, and do not cover text.
  - Parent containers leave visible padding around child nodes.
  - Empty whitespace is intentional and supports scan order.

## Validation Notes

- All requested systems are present.
- The security layer is shown as a distinct trust/control band.
- Connector labels sit in whitespace or on readable label backgrounds.
- The first render was reviewed and adjusted for label lanes and connector
  endpoint clarity before acceptance.
- Preview `output/diagram-experiments/payment-gateway/preview-v6.png` is the
  current visual candidate for review after applying prompt v14. The pass moved
  competing labels into separate lanes, split and repositioned the long
  application note, terminated `user traffic` at the Security Edge boundary, and
  resized Security Controls so Audit / Monitoring remains fully contained.
