# haddjs/payment-gateway-cip architecture

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

- Interactive diagram: https://gitdiagram.com/haddjs/payment-gateway-cip
- Repository: https://github.com/haddjs/payment-gateway-cip

## Overview

This Spring Boot payment gateway exposes token issuance and authenticated payment APIs to banking channels. Its main workflow validates a payment, creates a pending transaction, debits Core Banking, then pays the biller only after a successful debit; it persists the final state and returns a response. Separate capabilities include transaction lookup, JWT security, error formatting, and mock endpoints for the two external systems. Edges reflect the provided service/controller excerpts and README; mock implementation internals and some configuration wiring were not sampled.

Main entry points: [`src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java) (Payment orchestration), [`src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java`](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java) (Payment API), [`src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java`](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java) (Core Banking client), [`src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java`](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java) (Biller client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and security"]
  node_payment_api["Payment API"]
  node_auth_api["Token API"]
  node_security["JWT security"]
  node_request_dto["Payment request DTO"]
  node_token_dto["Token request DTO<br/>[TokenRequest.java]"]
  node_error_handler["API error handling"]
end

subgraph group_processing["Payment processing"]
  node_payment_service["Payment orchestration"]
  node_response_dto["Payment response DTO"]
  node_transaction_ids["Transaction ID codec"]
  node_status_types["Payment statuses"]
  node_channel_types["Channel types"]
end

subgraph group_persistence["Transaction persistence"]
  node_transaction["Transaction record<br/>[Transaction.java]"]
  node_repository["Transaction repository"]
  node_postgres[("PostgreSQL")]
end

subgraph group_integrations["Payment integrations"]
  node_core_client["Core Banking client"]
  node_core_dto["Debit DTOs<br/>[DebitRequest.java]"]
  node_core_system{{"Core Banking"}}
  node_biller_client["Biller client<br/>[BillerClient.java]"]
  node_biller_dto["Biller payment DTOs"]
  node_biller_system{{"Biller aggregator"}}
  node_mock_core["Core Banking mock"]
  node_mock_biller["Biller mock"]
end

node_channel(("Banking channel"))

node_channel -->|"submits payment"| node_payment_api
node_payment_api -->|"delegates"| node_payment_service
node_payment_api -->|"accepts"| node_request_dto
node_payment_service -->|"returns"| node_response_dto
node_payment_api -->|"parses ID"| node_transaction_ids
node_payment_service -->|"formats ID"| node_transaction_ids
node_payment_service -->|"reads and saves"| node_repository
node_repository -->|"persists"| node_transaction
node_transaction -.->|"stored in"| node_postgres
node_payment_service -->|"requests debit"| node_core_client
node_core_client -->|"uses"| node_core_dto
node_core_client -->|"calls debit"| node_core_system
node_payment_service -->|"requests payment"| node_biller_client
node_biller_client -->|"uses"| node_biller_dto
node_biller_client -->|"calls payment"| node_biller_system
node_payment_api -->|"protected by"| node_security
node_channel -->|"requests token"| node_auth_api
node_auth_api -->|"accepts"| node_token_dto
node_core_system -.->|"simulated by"| node_mock_core
node_biller_system -.->|"simulated by"| node_mock_biller
node_payment_service -->|"sets status"| node_status_types
node_request_dto -->|"validates channel"| node_channel_types

click node_payment_api "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java"
click node_auth_api "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/controller/AuthController.java"
click node_security "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/config/SecurityConfig.java"
click node_request_dto "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/PaymentRequest.java"
click node_token_dto "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/TokenRequest.java"
click node_payment_service "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java"
click node_response_dto "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/dto/response/PaymentResponse.java"
click node_transaction_ids "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/util/TransactionIds.java"
click node_status_types "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/enums/TransactionStatus.java"
click node_channel_types "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/enums/PaymentChannel.java"
click node_transaction "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/entity/Transaction.java"
click node_repository "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/repository/TransactionRepository.java"
click node_core_client "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java"
click node_core_dto "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/dto/DebitRequest.java"
click node_biller_client "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java"
click node_biller_dto "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/dto/BillerPayRequest.java"
click node_mock_core "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/mock/MockCoreBankController.java"
click node_mock_biller "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/mock/MockBillerController.java"
click node_error_handler "https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/exceptions/GlobalExceptionHandler.java"

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_payment_api,node_auth_api,node_security,node_request_dto,node_token_dto,node_error_handler toneBlue
class node_payment_service,node_response_dto,node_transaction_ids,node_status_types,node_channel_types toneAmber
class node_transaction,node_repository,node_postgres toneMint
class node_core_client,node_core_dto,node_core_system,node_biller_client,node_biller_dto,node_biller_system,node_mock_core,node_mock_biller toneRose
class node_channel toneIndigo
```

## Components

### API and security

- [Payment API](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java): `src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java`
- [Token API](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/controller/AuthController.java): `src/main/java/com/nadirhadd/payment_gateway_cip/controller/AuthController.java`
- [JWT security](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/config/SecurityConfig.java): `src/main/java/com/nadirhadd/payment_gateway_cip/config/SecurityConfig.java`
- [Payment request DTO](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/PaymentRequest.java): `src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/PaymentRequest.java`
- [Token request DTO](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/TokenRequest.java): `src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/TokenRequest.java`
- [API error handling](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/exceptions/GlobalExceptionHandler.java): `src/main/java/com/nadirhadd/payment_gateway_cip/exceptions/GlobalExceptionHandler.java`

### Payment processing

- [Payment orchestration](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java): `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`
- [Payment response DTO](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/dto/response/PaymentResponse.java): `src/main/java/com/nadirhadd/payment_gateway_cip/dto/response/PaymentResponse.java`
- [Transaction ID codec](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/util/TransactionIds.java): `src/main/java/com/nadirhadd/payment_gateway_cip/util/TransactionIds.java`
- [Payment statuses](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/enums/TransactionStatus.java): `src/main/java/com/nadirhadd/payment_gateway_cip/enums/TransactionStatus.java`
- [Channel types](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/enums/PaymentChannel.java): `src/main/java/com/nadirhadd/payment_gateway_cip/enums/PaymentChannel.java`

### Transaction persistence

- [Transaction record](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/entity/Transaction.java): `src/main/java/com/nadirhadd/payment_gateway_cip/entity/Transaction.java`
- [Transaction repository](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/repository/TransactionRepository.java): `src/main/java/com/nadirhadd/payment_gateway_cip/repository/TransactionRepository.java`
- **PostgreSQL**

### Payment integrations

- [Core Banking client](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java): `src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java`
- [Debit DTOs](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/dto/DebitRequest.java): `src/main/java/com/nadirhadd/payment_gateway_cip/client/dto/DebitRequest.java`
- **Core Banking**
- [Biller client](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java): `src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java`
- [Biller payment DTOs](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/client/dto/BillerPayRequest.java): `src/main/java/com/nadirhadd/payment_gateway_cip/client/dto/BillerPayRequest.java`
- **Biller aggregator**
- [Core Banking mock](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/mock/MockCoreBankController.java): `src/main/java/com/nadirhadd/payment_gateway_cip/mock/MockCoreBankController.java`
- [Biller mock](https://github.com/haddjs/payment-gateway-cip/blob/main/src/main/java/com/nadirhadd/payment_gateway_cip/mock/MockBillerController.java): `src/main/java/com/nadirhadd/payment_gateway_cip/mock/MockBillerController.java`

### Other components

- **Banking channel**

## Connections

- Banking channel → Payment API: submits payment (evidence: `README.md`)
- Payment API → Payment orchestration: delegates (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java`)
- Payment API → Payment request DTO: accepts (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java`)
- Payment orchestration → Payment response DTO: returns (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`)
- Payment API → Transaction ID codec: parses ID (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/controller/PaymentController.java`)
- Payment orchestration → Transaction ID codec: formats ID (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`)
- Payment orchestration → Transaction repository: reads and saves (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`)
- Transaction repository → Transaction record: persists (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/repository/TransactionRepository.java`)
- Transaction record → PostgreSQL: stored in (evidence: `README.md`)
- Payment orchestration → Core Banking client: requests debit (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`)
- Core Banking client → Debit DTOs: uses (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java`)
- Core Banking client → Core Banking: calls debit (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/client/CoreBankClient.java`)
- Payment orchestration → Biller client: requests payment (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`)
- Biller client → Biller payment DTOs: uses (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java`)
- Biller client → Biller aggregator: calls payment (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/client/BillerClient.java`)
- Payment API → JWT security: protected by (evidence: `README.md`)
- Banking channel → Token API: requests token (evidence: `README.md`)
- Token API → Token request DTO: accepts (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/controller/AuthController.java`)
- Core Banking → Core Banking mock: simulated by (evidence: `README.md`)
- Biller aggregator → Biller mock: simulated by (evidence: `README.md`)
- Payment orchestration → Payment statuses: sets status (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/service/PaymentService.java`)
- Payment request DTO → Channel types: validates channel (evidence: `src/main/java/com/nadirhadd/payment_gateway_cip/dto/request/PaymentRequest.java`)
