# phazerooman/thawani-for-woocommerce architecture

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

- Interactive diagram: https://gitdiagram.com/phazerooman/thawani-for-woocommerce
- Repository: https://github.com/phazerooman/thawani-for-woocommerce

## Overview

##### Project type and purpose
- This is a WordPress/WooCommerce plugin (“Thawani for WooCommerce”) that extends WooCommerce to accept Credit/Debit card payments via the Thawani payment gateway.
- The plugin provides both server-side PHP endpoints (to interact with WooCommerce orders and Thawani’s API) and client-side JavaScript (Vue components) to handle payment sessions and display status.

##### File structure
- Top-level plugin files (thawani-for-woocommerce.php, composer.json, package.json) register the plugin, declare dependencies, and bootstrap autoloaders.
- src/ holds core PHP classes:
– WC_Gateway_ThawaniGateway.php integrates into WooCommerce’s payment‐gateway hooks.
– Endpoint/*.php defines REST/AJAX endpoints (Customer, Session, Payment, Refund).
– RestAPI.php and ThawaniAjax.php orchestrate HTTP requests to Thawani and AJAX handlers.
– Statistics.php, AdminDashboard.php render the admin screens and session history.
- js/ contains Vue components for the checkout UI (CustomerList.vue, Sessions.vue, etc.), plus supporting CSS and language files.
- webpack.mix.js, tailwind.config.js, postcss.config.js drive asset compilation into dist/app.js and thawani-generate.js.
- template/ and static/ provide PHP view templates and static assets for README screenshots.
- languages/ holds translation files.
- vendor/ and composer.lock record PHP library dependencies.

##### Extract architecture hints from the README
- Plugin hooks into WooCommerce checkout page to inject “Pay with Thawani” option.
- On checkout, client-side code initiates a session via AJAX to a PHP endpoint, which calls Thawani’s Checkout API.
- A redirect or popup collects card details on Thawani’s side; Thawani sends webhook callbacks to wc-api/thawani-payment-status.
- Plugin verifies payment status via REST calls, updates WooCommerce order status, logs events, and stores session history for admin review.

a. Main components
- WordPress/WooCommerce Core (hooks & REST API)
- Thawani for WooCommerce Plugin
– PHP Layer: Gateway class, Endpoint controllers, REST/AJAX handlers, Logging subsystem
– JS Layer: Vue.js components, CSS, language translations
– Templates: Admin dashboard and session history views
- Database: WooCommerce orders, plugin’s session history, logs
- External Service: Thawani Checkout API & Webhook endpoint
- Browser/Client: Customer checkout frontend and Admin dashboard UI
b. Relationships & interactions
1. Customer → WooCommerce Checkout UI → Vue.js component (“Pay with Thawani”)
2. Vue.js → AJAX → PHP Endpoint → Thawani API (create session)
3. Thawani API → Customer’s Browser (redirect to payment page)
4. Thawani → Webhook → Plugin’s wc-api endpoint → PHP handler → validate & update order
5. Admin → WordPress Admin UI → PHP Dashboard class → reads DB → displays session logs
c. Architectural patterns & principles
- WordPress plugin hook/filter architecture (observer pattern)
- Separation of concerns: PHP backend vs. Vue.js frontend vs. template views
- RESTful/AJAX endpoints for asynchronous operations
- Build pipeline: Webpack (Laravel Mix) + Tailwind for asset bundling
- Internationalization via .mo/.pot files
d. Key technologies & frameworks
- PHP 7.x+, Composer, WordPress Plugin API, WooCommerce payment-gateway hooks
- JavaScript (ES6+), Vue.js single-file components, Axios for AJAX
- Laravel Mix (webpack.mix.js), Tailwind CSS, PostCSS
- Thawani Checkout REST API, Webhook mechanism
- MySQL (WordPress DB) for orders, plugin logs & session history

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browsers"
        CB["Customer Browser"]:::client
        AB["Admin Browser"]:::client
    end

    subgraph "Plugin Frontend (Vue.js)"
        APP["App.vue"]:::client
        CLS["CustomerList.vue"]:::client
        CSB["CustomerSidebar.vue"]:::client
        SES["Sessions.vue"]:::client
        SSB["SessionSidebar.vue"]:::client
        PST["PaymentStatus.vue"]:::client
        RFP["RefundPopup.vue"]:::client
        POP["popup.vue"]:::client
        ENTRY["app.js"]:::client
        CSS["style.css"]:::client
        LANG["lang.js"]:::client
        DIST1["dist/app.js"]:::client
        DIST2["dist/thawani-generate.js"]:::client
    end

    subgraph "Plugin PHP Layer"
        ENTRYFILE["thawani-for-woocommerce.php"]:::php
        COMPOSER["composer.json"]:::php
        NPM["package.json"]:::php
        GATEWAY["WC_Gateway_ThawaniGateway.php"]:::php
        REST["RestAPI.php"]:::php
        AJAX["ThawaniAjax.php"]:::php
        DASH["AdminDashboard.php"]:::php
        STATS["Statistics.php"]:::php
        subgraph "Endpoint Controllers"
            CUST["Customer.php"]:::php
            SESEND["Session.php"]:::php
            PAYEND["Payment.php"]:::php
            REFEND["Refund.php"]:::php
            PMEND["PaymentMethods.php"]:::php
        end
        TEMPLATE1["index.php"]:::php
        TEMPLATE2["statistics.php"]:::php
    end

    subgraph "WordPress / WooCommerce Core & DB"
        WP["WordPress/WooCommerce Core"]:::core
        DB["MySQL Database"]:::core
    end

    EXTERNAL["Thawani Checkout API & Webhook"]:::external

    CB -->|"renders Vue UI"| APP
    AB -->|"renders Admin UI"| APP
    APP -->|"AJAX create session"| AJAX
    AJAX -->|"calls Thawani API"| EXTERNAL
    EXTERNAL -->|"redirect to payment"| CB
    EXTERNAL -->|"webhook notify"| REST
    REST -->|"validate & update order"| GATEWAY
    GATEWAY -->|"updates order"| WP
    GATEWAY -->|"logs session"| STATS
    DASH -->|"reads session logs"| DB
    DASH -->|"renders admin dashboard"| AB
    COMPOSER --> ENTRYFILE
    NPM --> APP
    WP --> DB

    click APP "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/App.vue"
    click CLS "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/CustomerList.vue"
    click CSB "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/CustomerSidebar.vue"
    click SES "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/Sessions.vue"
    click SSB "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/SessionSidebar.vue"
    click PST "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/PaymentStatus.vue"
    click RFP "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/RefundPopup.vue"
    click POP "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/component/popup.vue"
    click ENTRY "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/app.js"
    click CSS "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/css/style.css"
    click LANG "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/js/language/lang.js"
    click DIST1 "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/dist/app.js"
    click DIST2 "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/dist/thawani-generate.js"
    click ENTRYFILE "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/thawani-for-woocommerce.php"
    click COMPOSER "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/composer.json"
    click NPM "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/package.json"
    click GATEWAY "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/WC_Gateway_ThawaniGateway.php"
    click REST "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/RestAPI.php"
    click AJAX "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/ThawaniAjax.php"
    click DASH "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/AdminDashboard.php"
    click STATS "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/Statistics.php"
    click CUST "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/Endpoint/Customer.php"
    click SESEND "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/Endpoint/Session.php"
    click PAYEND "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/Endpoint/Payment.php"
    click REFEND "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/Endpoint/Refund.php"
    click PMEND "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/src/Endpoint/PaymentMethods.php"
    click TEMPLATE1 "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/template/index.php"
    click TEMPLATE2 "https://github.com/phazerooman/thawani-for-woocommerce/blob/master/template/statistics.php"

    classDef client fill:#b7e4c7,stroke:#2d6a4f
    classDef php fill:#caf0f8,stroke:#0077b6
    classDef external fill:#ffd166,stroke:#ef476f
    classDef core fill:#e0e0e0,stroke:#6c757d
```
