# thatfiredev/mpesa-node-api architecture

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

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

## Overview

This small Node.js library exposes configuration plus C2B and B2C payment methods. Each method initializes configuration, creates an RSA-encrypted bearer token, sends a request to the corresponding M-Pesa endpoint, and returns the response data or throws an error. The README documents environment-based and custom configuration. Both transaction methods share one implementation file; the graph shows their separate request paths without assuming any additional stages.

Main entry points: [`index.js`](https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js) (C2B payment)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("API caller"))
node_configuration["Configuration<br/>[index.js]"]
node_c2b["C2B payment<br/>[index.js]"]
node_b2c["B2C payment<br/>[index.js]"]
node_token["Bearer token<br/>[index.js]"]
node_http["Axios client"]
node_mpesa["M-Pesa API"]

node_caller -->|"configures API"| node_configuration
node_caller -->|"initiates C2B"| node_c2b
node_caller -->|"initiates B2C"| node_b2c
node_c2b -->|"initializes config"| node_configuration
node_b2c -->|"initializes config"| node_configuration
node_c2b -->|"creates token"| node_token
node_b2c -->|"creates token"| node_token
node_c2b -->|"posts request"| node_http
node_b2c -->|"posts request"| node_http
node_http -->|"sends request"| node_mpesa
node_mpesa -->|"returns response"| node_http
node_http -->|"returns data"| node_c2b
node_http -->|"returns data"| node_b2c

click node_configuration "https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js"
click node_c2b "https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js"
click node_b2c "https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js"
click node_token "https://github.com/thatfiredev/mpesa-node-api/blob/master/index.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_caller,node_mpesa toneMint
class node_configuration,node_c2b,node_b2c,node_token toneTeal
class node_http toneBlue
```

## Components

### Other components

- **API caller**
- [Configuration](https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js): `index.js`
- [C2B payment](https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js): `index.js`
- [B2C payment](https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js): `index.js`
- [Bearer token](https://github.com/thatfiredev/mpesa-node-api/blob/master/index.js): `index.js`
- **Axios client**
- **M-Pesa API**

## Connections

- API caller → Configuration: configures API (evidence: `README.md`)
- API caller → C2B payment: initiates C2B (evidence: `README.md`)
- API caller → B2C payment: initiates B2C (evidence: `README.md`)
- C2B payment → Configuration: initializes config (evidence: `index.js`)
- B2C payment → Configuration: initializes config (evidence: `index.js`)
- C2B payment → Bearer token: creates token (evidence: `index.js`)
- B2C payment → Bearer token: creates token (evidence: `index.js`)
- C2B payment → Axios client: posts request (evidence: `index.js`)
- B2C payment → Axios client: posts request (evidence: `index.js`)
- Axios client → M-Pesa API: sends request
- M-Pesa API → Axios client: returns response
- Axios client → C2B payment: returns data (evidence: `index.js`)
- Axios client → B2C payment: returns data (evidence: `index.js`)
