# arif98741/nagadapi architecture

> Architecture diagram of the GitHub repository arif98741/nagadapi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arif98741/nagadapi
- Repository: https://github.com/arif98741/nagadapi

## Overview

##### Main Components

a) Core Components:
- Payment Processing Layer
- Exception Handling Layer
- Helper Utilities
- Configuration Management
- Request Handler

b) External Systems:
- Nagad Payment Gateway (Sandbox/Production)
- Merchant Application
- Client Browser/Application

**┌─ Merchant Application ─────────────────┐**

- Client Browser/Application           │
- ┬───────────────────────┘
- ↓
**┌─ Xenon/NagadApi Library ──────────────┐**
- ┌─────────────┐    ┌──────────────┐  │
- Base     │←→  │    Helper    │  │
- ┘    └──────────────┘  │
- ↓                  ↓           │
- ┌─────────────┐    ┌──────────────┐  │
- Request    │    │  Exception    │  │
- Handler    │    │   Handler     │  │
- ┘    └──────────────┘  │
- ↓                              │
- ┬──────────────────────────────┘
- ↓
**┌─ Nagad Payment Gateway ───────────────┐**

- Sandbox / Production Environment     │
- ┘

##### Component Descriptions

a) Base Component:
- Primary entry point for payment processing
- Handles configuration management
- Initiates payment flows

b) Helper Component:
- Utility functions
- Invoice generation
- Response parsing
- Payment verification

c) Request Handler:
- Manages HTTP communications
- Handles API endpoints
- Processes payment requests

d) Exception Handler:
- Custom exception management
- Error reporting
- Payment-specific exceptions

##### Payment Initiation Flow
**Merchant App → Base → RequestHandler → Nagad Gateway**

##### Payment Verification Flow
**Merchant App → Helper → RequestHandler → Nagad Gateway**

##### Callback Processing Flow
**Nagad Gateway → Merchant Callback URL → Helper**

##### Additional Elements

- Configuration nodes showing environment options (development/production)
- Security elements (merchant keys, encryption)
- Callback URL handling
- Sandbox vs. production pathways

##### Notes

- Separation between the library and external systems
- Clear boundaries between merchant implementation and library code
- Where configuration is required
- Security-critical paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Client Browser/Application"]:::client
    end

    subgraph MerchantApp["Merchant Application"]
        MA["Merchant Implementation"]:::merchant
        CB["Callback Handler"]:::merchant
    end

    subgraph XenonLib["Xenon/NagadApi Library"]
        Base["Base Component"]:::core
        Helper["Helper Utilities"]:::core
        ReqHandler["Request Handler"]:::core
        ExHandler["Exception Handler"]:::core
        KeyMgmt["Key Management"]:::security
        Config["Configuration"]:::config
    end

    subgraph Gateway["Nagad Payment Gateway"]
        Sandbox["Sandbox Environment"]:::gateway
        Prod["Production Environment"]:::gateway
    end

    %% Connections
    Browser --> MA
    MA --> Base
    Base --> Helper
    Base --> ReqHandler
    Helper --> ReqHandler
    ReqHandler --> KeyMgmt
    Base --> ExHandler
    Helper --> ExHandler
    ReqHandler --> ExHandler
    ReqHandler --> Sandbox
    ReqHandler --> Prod
    Sandbox --> CB
    Prod --> CB
    CB --> Helper
    Config --> Base

    %% Click Events
    click Base "https://github.com/arif98741/nagadApi/blob/master/src/Base.php"
    click Helper "https://github.com/arif98741/nagadApi/blob/master/src/Helper.php"
    click ReqHandler "https://github.com/arif98741/nagadApi/blob/master/src/RequestHandler.php"
    click ExHandler "https://github.com/arif98741/nagadApi/tree/master/src/Exception"
    click KeyMgmt "https://github.com/arif98741/nagadApi/blob/master/src/lib/Key.php"
    click Config "https://github.com/arif98741/nagadApi/blob/master/.env.example"

    %% Styling
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef client fill:#95b8d1,stroke:#95b8d1,color:#333
    classDef merchant fill:#88d498,stroke:#88d498,color:#333
    classDef gateway fill:#f58549,stroke:#f58549,color:#fff
    classDef security fill:#b8336a,stroke:#b8336a,color:#fff
    classDef config fill:#726da8,stroke:#726da8,color:#fff

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Client Interface"]:::client
        L3["Merchant Components"]:::merchant
        L4["Payment Gateway"]:::gateway
        L5["Security Layer"]:::security
        L6["Configuration"]:::config
    end
```
