# chapa-et/chapa-woocommerce architecture

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

- Interactive diagram: https://gitdiagram.com/chapa-et/chapa-woocommerce
- Repository: https://github.com/chapa-et/chapa-woocommerce

## Overview

##### Project type and purpose
- This is a WordPress plugin that implements a WooCommerce payment gateway for “Chapa” (an Ethiopian payment provider).
- It extends WooCommerce at checkout to accept telebirr, CBE Birr, PayPal, Visa, Mastercard, Amex, bank transfers, etc.

##### File structure
- Top-level plugin bootstrap: woo-chapa.php (WordPress plugin header, init hooks).
- includes/
- class-waf-wc-chapa-gateway.php – PHP class that registers the gateway with WooCommerce, handles payment requests, callbacks, order status updates.
- blocks/
– class-wc-chapa-payments-blocks.php – PHP class to register Gutenberg blocks for payment UI.
- assets/js/blocks.js + blocks.asset.php – compiled block script and metadata loaded in the WP admin/editor.
- src/*.js + webpack.config.js – source for any custom JS (e.g., button.js, index.js) that get bundled into assets/js.
- uninstall.php – cleanup logic on plugin removal.
- package.json/package-lock.json – JS build dependencies (e.g. webpack, Babel).
- assets/images – static assets for UI or block previews.
- README.md/readme.txt – user-facing documentation and changelog.

##### README for additional insights
- Describes supported payment methods and features.
- Outlines installation, settings (Secret/Public Key), enabling/disabling the gateway.
- Mentions Gutenberg block support since v1.0.2.

- Core components (WP + WooCommerce)
- Plugin modules (PHP classes, JS bundles)
- External services (Chapa API)
- Actors (Admin, Customer)
- Hook registration (plugin → WP/WC)
- Data flow (Checkout UI → Plugin → Chapa API → Plugin → Order DB)
- Build flow (src → webpack → assets/js)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    subgraph "Actors"
        Admin["Admin Browser"]:::actor
        Customer["Customer Browser"]:::actor
    end

    %% Core
    subgraph "WordPress Core" 
        WP["WordPress Core"]:::core
        WC["WooCommerce Core"]:::core
        DB["Database (WP Options & Orders)"]:::core
    end

    %% Plugin
    subgraph "Chapa Plugin"
        Boot["woo-chapa.php"]:::plugin
        subgraph "Includes"
            Gateway["class-waf-wc-chapa-gateway.php"]:::plugin
            BlockReg["class-wc-chapa-payments-blocks.php"]:::plugin
        end
        Settings["Settings UI"]:::plugin
        CheckoutUI["Chapa Checkout UI"]:::plugin
        subgraph "Build Pipeline"
            IDX["src/index.js"]:::js
            BTN["src/button.js"]:::js
            WPConfig["webpack.config.js"]:::js
            Bundle["assets/js/blocks.js"]:::js
            Meta["assets/js/blocks.asset.php"]:::js
        end
        Images["assets/images"]:::plugin
        Clean["uninstall.php"]:::plugin
        Doc1["README.md"]:::doc
        Doc2["readme.txt"]:::doc
        PKG["package.json"]:::doc
        PKGLock["package-lock.json"]:::doc
    end

    %% External
    ChapaAPI["Chapa External API"]:::external

    %% Hook Registrations
    Boot -->|"registers hooks"| WP
    Boot -->|"registers gateway"| WC
    Boot --> Gateway
    Boot --> BlockReg

    %% Block Enqueue
    BlockReg -->|"enqueues"| Bundle
    BlockReg --> Meta

    %% Checkout Flow
    Customer -->|"visits checkout"| CheckoutUI
    CheckoutUI -->|"processPayment()"| Gateway
    Gateway -->|"calls API"| ChapaAPI
    ChapaAPI -->|"response"| Gateway
    Gateway -->|"update order"| DB

    %% Admin Flow
    Admin -->|"configure"| Settings
    Settings -->|"stores keys"| DB

    %% Build Flow
    IDX --> WPConfig
    BTN --> WPConfig
    WPConfig --> Bundle
    WPConfig --> Meta

    %% Cleanup
    Clean -->|"cleanup options"| DB

    %% Click Events
    click Boot "https://github.com/chapa-et/chapa-woocommerce/blob/main/woo-chapa.php"
    click Gateway "https://github.com/chapa-et/chapa-woocommerce/blob/main/includes/class-waf-wc-chapa-gateway.php"
    click BlockReg "https://github.com/chapa-et/chapa-woocommerce/blob/main/includes/blocks/class-wc-chapa-payments-blocks.php"
    click Bundle "https://github.com/chapa-et/chapa-woocommerce/blob/main/assets/js/blocks.js"
    click Meta "https://github.com/chapa-et/chapa-woocommerce/blob/main/assets/js/blocks.asset.php"
    click IDX "https://github.com/chapa-et/chapa-woocommerce/blob/main/src/index.js"
    click BTN "https://github.com/chapa-et/chapa-woocommerce/blob/main/src/button.js"
    click WPConfig "https://github.com/chapa-et/chapa-woocommerce/blob/main/webpack.config.js"
    click Clean "https://github.com/chapa-et/chapa-woocommerce/blob/main/uninstall.php"
    click Images "https://github.com/chapa-et/chapa-woocommerce/tree/main/assets/images"
    click Doc1 "https://github.com/chapa-et/chapa-woocommerce/blob/main/README.md"
    click Doc2 "https://github.com/chapa-et/chapa-woocommerce/blob/main/readme.txt"
    click PKG "https://github.com/chapa-et/chapa-woocommerce/blob/main/package.json"
    click PKGLock "https://github.com/chapa-et/chapa-woocommerce/blob/main/package-lock.json"

    %% Styles
    classDef actor fill:#AEDFF7,stroke:#000,stroke-width:1px
    classDef core fill:#DDDDDD,stroke:#000,stroke-width:1px
    classDef plugin fill:#C8E6C9,stroke:#000,stroke-width:1px
    classDef js fill:#FFF59D,stroke:#000,stroke-width:1px
    classDef external fill:#FFCDD2,stroke:#000,stroke-width:1px
    classDef doc fill:#FFE082,stroke:#000,stroke-width:1px
```
