# emagombe/mpesa-api architecture

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

- Interactive diagram: https://gitdiagram.com/emagombe/mpesa-api
- Repository: https://github.com/emagombe/mpesa-api

## Overview

This PHP library wraps M-PESA Mozambique operations. Callers initialize credentials and an environment through Mpesa, then invoke a Transaction operation; that operation maps inputs to the provider API and delegates HTTP transport to Request. Request obtains an encrypted bearer token from Cryptor and returns the provider response. README capabilities are represented as separate operation nodes. Source excerpts show these internal calls; the provider relationship is also explicit in the README and transaction URLs.

Main entry points: [`src/Transaction.php`](https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php) (Transaction facade), [`src/Request.php`](https://github.com/emagombe/mpesa-api/blob/master/src/Request.php) (HTTP request), [`src/Mpesa.php`](https://github.com/emagombe/mpesa-api/blob/master/src/Mpesa.php) (Initialize client), [`src/Cryptor.php`](https://github.com/emagombe/mpesa-api/blob/master/src/Cryptor.php) (Token encryption)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Library entry"]
  node_mpesa["Initialize client<br/>[Mpesa.php]"]
  node_transaction["Transaction facade<br/>[Transaction.php]"]
end

subgraph group_operations["Payment operations"]
  node_payments["C2B / B2C / B2B<br/>[Transaction.php]"]
  node_reversal["Reversal<br/>[Transaction.php]"]
  node_status["Status query<br/>[Transaction.php]"]
  node_customer["Customer name<br/>[Transaction.php]"]
end

subgraph group_transport["API transport and security"]
  node_request["HTTP request<br/>[Request.php]"]
  node_cryptor["Token encryption<br/>[Cryptor.php]"]
end

node_caller(("PHP caller"))
node_provider["M-PESA API"]

node_caller -->|"initializes"| node_mpesa
node_mpesa -->|"creates"| node_transaction
node_caller -->|"invokes"| node_transaction
node_transaction -->|"dispatches"| node_payments
node_transaction -->|"dispatches"| node_reversal
node_transaction -->|"dispatches"| node_status
node_transaction -->|"dispatches"| node_customer
node_payments -->|"calls"| node_request
node_reversal -->|"calls"| node_request
node_status -->|"calls"| node_request
node_customer -->|"calls"| node_request
node_request -->|"generates token"| node_cryptor
node_request -->|"sends HTTP request"| node_provider

click node_mpesa "https://github.com/emagombe/mpesa-api/blob/master/src/Mpesa.php"
click node_transaction "https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php"
click node_payments "https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php"
click node_reversal "https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php"
click node_status "https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php"
click node_customer "https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php"
click node_request "https://github.com/emagombe/mpesa-api/blob/master/src/Request.php"
click node_cryptor "https://github.com/emagombe/mpesa-api/blob/master/src/Cryptor.php"

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_mpesa,node_transaction toneBlue
class node_payments,node_reversal,node_status,node_customer toneAmber
class node_request,node_cryptor,node_provider toneMint
class node_caller toneIndigo
```

## Components

### Library entry

- [Initialize client](https://github.com/emagombe/mpesa-api/blob/master/src/Mpesa.php): `src/Mpesa.php`
- [Transaction facade](https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php): `src/Transaction.php`

### Payment operations

- [C2B / B2C / B2B](https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php): `src/Transaction.php`
- [Reversal](https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php): `src/Transaction.php`
- [Status query](https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php): `src/Transaction.php`
- [Customer name](https://github.com/emagombe/mpesa-api/blob/master/src/Transaction.php): `src/Transaction.php`

### API transport and security

- [HTTP request](https://github.com/emagombe/mpesa-api/blob/master/src/Request.php): `src/Request.php`
- [Token encryption](https://github.com/emagombe/mpesa-api/blob/master/src/Cryptor.php): `src/Cryptor.php`

### Other components

- **PHP caller**
- **M-PESA API**

## Connections

- PHP caller → Initialize client: initializes (evidence: `README.md`)
- Initialize client → Transaction facade: creates (evidence: `src/Mpesa.php`)
- PHP caller → Transaction facade: invokes (evidence: `README.md`)
- Transaction facade → C2B / B2C / B2B: dispatches (evidence: `src/Transaction.php`)
- Transaction facade → Reversal: dispatches (evidence: `src/Transaction.php`)
- Transaction facade → Status query: dispatches (evidence: `src/Transaction.php`)
- Transaction facade → Customer name: dispatches (evidence: `src/Transaction.php`)
- C2B / B2C / B2B → HTTP request: calls (evidence: `src/Transaction.php`)
- Reversal → HTTP request: calls (evidence: `src/Transaction.php`)
- Status query → HTTP request: calls (evidence: `src/Transaction.php`)
- Customer name → HTTP request: calls (evidence: `src/Transaction.php`)
- HTTP request → Token encryption: generates token (evidence: `src/Request.php`)
- HTTP request → M-PESA API: sends HTTP request
