# zz30maxzz/niubiz-pay architecture

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

- Interactive diagram: https://gitdiagram.com/zz30maxzz/niubiz-pay
- Repository: https://github.com/zz30maxzz/niubiz-pay

## Overview

##### Main Components
- Hooks: Located in src/hooks, hooks like useNiubiz, useNiubizPay, and their App variants encapsulate application logic, state management, and side effects. They abstract away the communication with Niubiz endpoints.
- Helper Functions: Found in src/helper, these functions (e.g., GetNiubizToken, PostNiubizAuthorize) deal with network requests and integration with Niubiz’s external services.
- Storybook Setup: Although not part of production code, the .storybook directory is used for component development and visualization, which is important for testing UI interactions.
- Type Declarations and Global Definitions: Files like src/components/types.ts and src/global.d.ts ensure type safety and clear contracts between components.

##### Out the Component Interactions
- The entry point (src/index.ts) initializes or exports the necessary hooks and components. This serves as the library’s facade.
- In real-world usage, client applications import hooks (useNiubiz or useNiubizPay) from niubiz-pay. These hooks internally coordinate:
- The initiation of payment or tokenization flows.
- Triggering helper functions to fetch tokens or send data to Niubiz’s APIs.
- Returning the associated FormComponent (built from components like CustomForm or CustomPayForm) for rendering.
- The UI components, when rendered in client applications, display the form and may allow user interaction (like button clicks) to trigger state changes via hooks.

##### Architectural Patterns and Design Principles
- Component-Based Design: Emphasize modularization through distinct components for different forms and controls.
- Separation of Concerns: Clearly separate view layers (components), business logic/state (hooks), and network integration (helper functions).
- External Dependency Integration: Highlight the client’s interaction with external Niubiz APIs, which are critical to the functionality (token fetch, authorize, etc.).

##### Final Touches
- Use clear labels and annotations to indicate important configurations (such as the parameters for API endpoints and external asset URLs, which are passed to hooks).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client Application"):::client
    Facade("Library Facade"):::facade

    subgraph "UI Components"
        card["Card: Payment Card UI"]:::components
        customForm["CustomForm: Reusable Form"]:::components
        customPayForm["CustomPayForm: Payment Form"]:::components
        icons["Icons: Brand icons"]:::components
        inputGroup["InputGroup: Grouped Inputs"]:::components
        loader["Loader: Loading Indicator"]:::components
    end

    subgraph "Hooks (Business Logic)"
        hookNiubiz["useNiubiz: Tokenization Flow"]:::hooks
        hookNiubizPay["useNiubizPay: Payment Processing Hook"]:::hooks
        hookNiubizApp["useNiubizApp: App Tokenization Hook"]:::hooks
        hookNiubizPayApp["useNiubizPayApp: App Payment Hook"]:::hooks
    end

    subgraph "Helper Functions (API Calls)"
        helperToken["GetNiubizToken: Token API Call"]:::helpers
        helperTokenSession["GetNiubizTokenSession: Token Session API Call"]:::helpers
        helperTokenizerCard["GetNiubizTokenizerCard: Card Tokenization API"]:::helpers
        helperAuthorize["PostNiubizAuthorize: Payment Authorization API"]:::helpers
        helperCard["card: Card Utility"]:::helpers
        helperFetcher["fetcher: Network Utility"]:::helpers
    end

    subgraph "Type Declarations"
        types["Type Definitions"]:::types
    end

    subgraph "Storybook Setup"
        storybook["Storybook: Component Dev Setup"]:::storybook
    end

    subgraph "External Niubiz Services"
        externalAPIToken["Niubiz Token API"]:::external
        externalAPIPayment["Niubiz Payment API"]:::external
    end

    %% Connections
    Client -->|"initiates"| Facade
    Facade -->|"calls"| hookNiubiz
    Facade -->|"calls"| hookNiubizPay
    Facade -->|"delivers"| customForm
    Facade -->|"delivers"| customPayForm

    hookNiubiz -->|"triggers"| helperToken
    hookNiubiz -->|"triggers"| helperTokenSession
    hookNiubiz -->|"triggers"| helperTokenizerCard
    hookNiubizPay -->|"triggers"| helperAuthorize

    helperToken -->|"requests"| externalAPIToken
    helperTokenSession -->|"requests"| externalAPIToken
    helperTokenizerCard -->|"requests"| externalAPIToken
    helperAuthorize -->|"requests"| externalAPIPayment

    hookNiubiz -->|"renders"| customForm
    hookNiubizPay -->|"renders"| customPayForm

    customForm -->|"displayedIn"| Client
    customPayForm -->|"displayedIn"| Client

    storybook -->|"visualizes"| customForm

    types -.->|"typeSafe"| card
    types -.->|"typeSafe"| hookNiubiz

    %% Click Events
    click card "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/components/Card/Card.tsx"
    click customForm "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/components/CustomForm/CustomForm.tsx"
    click customPayForm "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/components/CustomPayForm/CustomPayForm.tsx"
    click icons "https://github.com/zz30maxzz/niubiz-pay/tree/main/src/components/Icons"
    click inputGroup "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/components/InputGroup/InputGroup.tsx"
    click loader "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/components/Loader/Loader.tsx"
    click hookNiubiz "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/hooks/useNiubiz.tsx"
    click hookNiubizPay "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/hooks/useNiubizPay.tsx"
    click hookNiubizApp "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/hooks/useNiubizApp.tsx"
    click hookNiubizPayApp "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/hooks/useNiubizPayApp.tsx"
    click helperToken "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/helper/GetNiubizToken.tsx"
    click helperTokenSession "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/helper/GetNiubizTokenSession.tsx"
    click helperTokenizerCard "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/helper/GetNiubizTokenizerCard.tsx"
    click helperAuthorize "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/helper/PostNiubizAuthorize.tsx"
    click helperCard "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/helper/card.tsx"
    click helperFetcher "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/helper/fetcher.tsx"
    click types "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/components/types.ts"
    click storybook "https://github.com/zz30maxzz/niubiz-pay/blob/main/.storybook"
    click Facade "https://github.com/zz30maxzz/niubiz-pay/blob/main/src/index.ts"

    %% Styles
    classDef client fill:#B0C4DE,stroke:#000,stroke-width:2px;
    classDef facade fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef components fill:#ffcccc,stroke:#000,stroke-width:2px;
    classDef hooks fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef helpers fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef types fill:#AFEEEE,stroke:#000,stroke-width:2px;
    classDef storybook fill:#dda0dd,stroke:#000,stroke-width:2px;
```
