# agorapay/node-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/agorapay/node-sdk
- Repository: https://github.com/agorapay/node-sdk

## Overview

##### Project type and purpose
- This is an open-source Node.js SDK (client library) for interacting with the CAPSPayment REST API.
- Its goal is to provide a strongly-typed TypeScript interface (and compiled JavaScript) so that downstream applications can easily call CAPSPayment services (Payin, Payout, Transfer, Operation, AccountHolder, etc.).

##### File structure
- Top-level:
- src/ – all TypeScript source, organized per API module (e.g., src/PayinApi, src/TransferApi, src/models, src/utils)
- lib/ – compiled JS + declaration files, mirroring src/ structure
- index.ts – SDK entry point (“CAPSPaymentAPI” class)
- tsconfig.json, ESLint/Prettier configs, package.json – build, lint, publish config
- Patterns:
- Modular API clients: each directory under src/*Api exports a class with methods for that endpoint group
- Shared models under src/models
- Shared HTTP transport & helpers under src/utils (apiRest, enums, Utils)

##### README for additional insights
- The README shows instantiation of CAPSPaymentAPI with credentials and URLs, then retrieving module clients (e.g., operationApi = capsPaymentApi.operationApi()).
- It lists out each endpoint, SDK function, and HTTP method, confirming that each module class wraps one or more REST endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Components
    ConsumerApp["Consumer Application"]:::consumer
    CAPSPaymentAPI["CAPSPaymentAPI (Core)"]:::core
    subgraph "API Modules"
        direction TB
        PayinApi["PayinApi Module"]:::module
        PayoutApi["PayoutApi Module"]:::module
        TransferApi["TransferApi Module"]:::module
        OperationApi["OperationApi Module"]:::module
        AccountHolderApi["AccountHolderApi Module"]:::module
        MandateApi["MandateApi Module"]:::module
        PaymentAccountApi["PaymentAccountApi Module"]:::module
        PaymentMethodApi["PaymentMethodApi Module"]:::module
        SelfcareApi["SelfcareApi Module"]:::module
    end
    subgraph "Utils Layer"
        direction TB
        ApiRest["apiRest (HTTP Client)"]:::utils
        Enums["enums"]:::utils
        UtilsFn["Utils"]:::utils
    end
    Models["Shared Models"]:::models
    ExternalAPI["CAPSPayment REST API"]:::external
    BuildPipeline["Build & Distribution Pipeline"]:::pipeline

    %% Relationships
    ConsumerApp -->|"instantiate"| CAPSPaymentAPI
    CAPSPaymentAPI -->|".payinApi() etc."| PayinApi
    CAPSPaymentAPI -->|".payoutApi() etc."| PayoutApi
    CAPSPaymentAPI -->|".transferApi() etc."| TransferApi
    CAPSPaymentAPI -->|".operationApi() etc."| OperationApi
    CAPSPaymentAPI -->|".accountHolderApi() etc."| AccountHolderApi
    CAPSPaymentAPI -->|".mandateApi() etc."| MandateApi
    CAPSPaymentAPI -->|".paymentAccountApi() etc."| PaymentAccountApi
    CAPSPaymentAPI -->|".paymentMethodApi() etc."| PaymentMethodApi
    CAPSPaymentAPI -->|".selfcareApi() etc."| SelfcareApi

    %% Module to utils to external
    PayinApi -->|calls| ApiRest
    PayoutApi -->|calls| ApiRest
    TransferApi -->|calls| ApiRest
    OperationApi -->|calls| ApiRest
    AccountHolderApi -->|calls| ApiRest
    MandateApi -->|calls| ApiRest
    PaymentAccountApi -->|calls| ApiRest
    PaymentMethodApi -->|calls| ApiRest
    SelfcareApi -->|calls| ApiRest

    ApiRest -->|sends HTTP| ExternalAPI
    ExternalAPI -->|returns JSON| ApiRest
    ApiRest -->|deserializes| Models
    Models -->|payload objects| ConsumerApp

    %% Build pipeline
    subgraph "Build"
        direction TB
        SourceTS["src/ (TypeScript)"]:::pipeline
        Compile["tsc compile"]:::process
        Lib["lib/ (Compiled .js & .d.ts)"]:::pipeline
    end
    SourceTS --> Compile --> Lib
    Compile -->|publish| BuildPipeline

    %% Click Events
    click CAPSPaymentAPI "https://github.com/agorapay/node-sdk/blob/main/src/CAPSPaymentAPI.ts"
    click CAPSPaymentAPI "https://github.com/agorapay/node-sdk/blob/main/index.ts"
    click PayinApi "https://github.com/agorapay/node-sdk/blob/main/src/PayinApi/PayinApi.ts"
    click PayoutApi "https://github.com/agorapay/node-sdk/blob/main/src/PayoutApi/PayoutApi.ts"
    click TransferApi "https://github.com/agorapay/node-sdk/blob/main/src/TransferApi/TransferApi.ts"
    click OperationApi "https://github.com/agorapay/node-sdk/blob/main/src/OperationApi/OperationApi.ts"
    click AccountHolderApi "https://github.com/agorapay/node-sdk/blob/main/src/AccountHolderApi/AccountHolderApi.ts"
    click MandateApi "https://github.com/agorapay/node-sdk/blob/main/src/MandateApi/MandateApi.ts"
    click PaymentAccountApi "https://github.com/agorapay/node-sdk/blob/main/src/PaymentAccountApi/PaymentAccountApi.ts"
    click PaymentMethodApi "https://github.com/agorapay/node-sdk/blob/main/src/PaymentMethodApi/PaymentMethodApi.ts"
    click SelfcareApi "https://github.com/agorapay/node-sdk/blob/main/src/SelfcareApi/SelfcareApi.ts"
    click Models "https://github.com/agorapay/node-sdk/tree/main/src/models"
    click ApiRest "https://github.com/agorapay/node-sdk/blob/main/src/utils/apiRest.ts"
    click Enums "https://github.com/agorapay/node-sdk/blob/main/src/utils/enums.ts"
    click UtilsFn "https://github.com/agorapay/node-sdk/blob/main/src/utils/Utils.ts"

    %% Styles
    classDef consumer fill:#e0f7e9,stroke:#2e7d32,stroke-width:2px
    classDef core fill:#bbdefb,stroke:#1565c0,stroke-width:2px
    classDef module fill:#e3f2fd,stroke:#1e88e5,stroke-width:1.5px
    classDef utils fill:#f3e5f5,stroke:#6a1b9a,stroke-width:1.5px
    classDef models fill:#e0f2f1,stroke:#00796b,stroke-width:1.5px,shape:cylinder
    classDef external fill:#eeeeee,stroke:#424242,stroke-width:2px
    classDef pipeline fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
    classDef process fill:#ffe0b2,stroke:#ff8f00,stroke-width:2px,shape:parallelogram
```
