# getdokan/dokan architecture

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

- Interactive diagram: https://gitdiagram.com/getdokan/dokan
- Repository: https://github.com/getdokan/dokan

## Overview

##### Major subsystems/components
- WordPress Plugin Core – The entry point (dokan.php, dokan-class.php) and the overall “glue” that integrates with WordPress and WooCommerce.
- PHP Backend & Business Logic – Organized into “includes”, “deprecated” (legacy code), and “lib” directories. This section hosts most of the core functionalities:
- Abstract classes and core controllers (for REST endpoints, dependency management, upgrade processes, etc.).
- Specific modules for commission calculations, vendor management, orders, withdrawals, emails, and reports. For instance, the various “includes/Commission”, “includes/Vendor”, “includes/Order”, “includes/Withdraw”, and “includes/REST” directories show a separation of responsibilities.
- Utility classes, cache management, dependency container (using League’s Container), and service providers offering dependency injection.
- UI Components – Divided by frontend and admin:
- Frontend UI: Under “src/frontend”, there is another Vue application that invokes vendor dashboard and store-front interactions.
- Templates: The “templates” directory holds PHP template files to render various parts of the plugin’s user interface. This includes account pages, admin pages, emails (both HTML and plain versions), and widgets.
- REST API & AJAX Endpoints – The “includes/REST” directory encapsulates various controllers that expose endpoints for admin, vendor, and customer interactions. Additionally, “includes/Ajax.php” and similar hooks let the plugin interact asynchronously.
- External Integrations & Modules – The README lists many integrations (payment gateways, shipping, Stripe, etc.) and additional modules. Elements like “includes/Emails”, “includes/Analytics”, and configuration files indicate that the plugin communicates with multiple external services and maintains compliance with standards enforced by WooCommerce.

##### Relationships & data flow between these components
- WordPress Core calls the Dokan plugin’s main file which then loads the PHP backend components (controllers, hooks, dependency injection container).
- The backend components execute business logic (handling commission calculations, vendor registrations, order processing, and so on) and expose REST endpoints.
- The UI layer (both admin and frontend Vue apps) communicates with these backend controllers via AJAX calls or REST API endpoints.
- Template files act as the glue between WordPress’s theming system and Dokan’s PHP output, ensuring that vendor dashboards, email templates, and various UI elements are correctly rendered.
- External integrations (payment gateways, shipping apps, analytics tools) are managed here as either separate modules or injected into the dependency container.
- The testing suite validates both backend (PHP unit tests under tests/php) and frontend (Playwright, API tests under tests/pw) components, ensuring robust interactions.

##### Notable architectural patterns & design principles
- Modular Design – The project is broken into many discrete modules (commissions, orders, vendor management, REST APIs, etc.) to keep responsibilities isolated.
- Dependency Injection – Use of League’s Container and service provider patterns can be shown to emphasize loose coupling and extendability.
- MV* Patterns in UI – The separation between Vue components (view layer) for admin and frontend applications and their corresponding business logic.
- WordPress Hooks – Since it’s a WordPress plugin, actions and filters are central to how components interact.
- Layering – The separation between frontend (templates and Vue apps), middle layer (REST API controllers and backend business logic) and external modules/integrations.

##### Final advice
- Start at a high level by visualizing the entire plugin as an integration layer that transforms a standard WooCommerce installation into a multivendor marketplace.
- Drill down to show the layered architecture: from WordPress hooks (entry points) to backend modules (business logic, REST APIs, dependency management), and then to the user-facing components (admin dashboards, vendor storefronts, email templates).
- Use annotations to highlight key design patterns (e.g., dependency injection, modular separation, MVC/MVVM in the Vue apps) that are critical for understanding the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "WordPress Plugin Core"
        WP1["Dokan Main Plugin"]:::core
        WP2["Dokan Class"]:::core
    end

    subgraph "PHP Backend & Business Logic"
        subgraph "Modules"
            M1["Core Modules (includes/)"]:::backend
            M2["Legacy Code (deprecated/)"]:::backend
            M3["Libraries & DI (lib/)"]:::backend
        end
        subgraph "Endpoint Interfaces"
            R1["REST API Controllers (includes/REST/)"]:::backend
            A1["AJAX Endpoints (includes/Ajax.php)"]:::backend
        end
    end

    subgraph "UI Components"
        subgraph "Admin UI"
            AU1["Admin Vue App (src/admin)"]:::ui
            AU2["Admin Assets (assets/src)"]:::ui
            AU3["Admin Setup Wizard Template (templates/admin-setup-wizard)"]:::ui
            AU4["Admin Header Template (templates/admin-header.php)"]:::ui
        end
        subgraph "Frontend UI"
            FU1["Frontend Vue App (src/frontend)"]:::ui
        end
        UT["Template Files (templates/)"]:::template
    end

    subgraph "External Integrations"
        EI1["Emails Module (includes/Emails)"]:::external
        EI2["Analytics Module (includes/Analytics)"]:::external
        EI3["Shipping Module (includes/Shipping)"]:::external
        EI4["Theme Support Module (includes/ThemeSupport)"]:::external
    end

    subgraph "Testing & Build Infrastructure"
        T1["PHP Tests (tests/php)"]:::testing
        T2["PW Tests (tests/pw)"]:::testing
        T3["Package.json (package.json)"]:::testing
        T4["Webpack Config (webpack.config.js)"]:::testing
        T5["Composer.json (composer.json)"]:::testing
    end

    %% Connections between layers
    WP1 --> M1
    WP2 --> M1
    M2 --> M1
    M3 --> M1
    M1 --> R1
    M1 --> A1
    M1 --> UT
    M1 --> EI1
    M1 --> EI2
    M1 --> EI3
    M1 --> EI4
    R1 --> AU1
    R1 --> FU1
    A1 --> AU1
    A1 --> FU1
    AU1 --> AU3
    AU1 --> AU4
    AU1 --- AU2
    FU1 --> UT

    %% Testing & Build support connections (for context)
    T1 --- M1
    T2 --- AU1
    T3 --- WP1
    T4 --- WP1
    T5 --- WP1

    %% Click Events
    click WP1 "https://github.com/getdokan/dokan/blob/develop/dokan.php"
    click WP2 "https://github.com/getdokan/dokan/blob/develop/dokan-class.php"
    click M1 "https://github.com/getdokan/dokan/tree/develop/includes/"
    click M2 "https://github.com/getdokan/dokan/tree/develop/deprecated/"
    click M3 "https://github.com/getdokan/dokan/tree/develop/lib/"
    click R1 "https://github.com/getdokan/dokan/tree/develop/includes/REST/"
    click A1 "https://github.com/getdokan/dokan/blob/develop/includes/Ajax.php"
    click AU1 "https://github.com/getdokan/dokan/tree/develop/src/admin"
    click AU2 "https://github.com/getdokan/dokan/tree/develop/assets/src"
    click AU3 "https://github.com/getdokan/dokan/tree/develop/templates/admin-setup-wizard"
    click AU4 "https://github.com/getdokan/dokan/blob/develop/templates/admin-header.php"
    click FU1 "https://github.com/getdokan/dokan/tree/develop/src/frontend"
    click UT "https://github.com/getdokan/dokan/tree/develop/templates/"
    click EI1 "https://github.com/getdokan/dokan/tree/develop/includes/Emails"
    click EI2 "https://github.com/getdokan/dokan/tree/develop/includes/Analytics"
    click EI3 "https://github.com/getdokan/dokan/tree/develop/includes/Shipping"
    click EI4 "https://github.com/getdokan/dokan/tree/develop/includes/ThemeSupport"
    click T1 "https://github.com/getdokan/dokan/tree/develop/tests/php"
    click T2 "https://github.com/getdokan/dokan/tree/develop/tests/pw"
    click T3 "https://github.com/getdokan/dokan/blob/develop/package.json"
    click T4 "https://github.com/getdokan/dokan/blob/develop/webpack.config.js"
    click T5 "https://github.com/getdokan/dokan/blob/develop/composer.json"

    %% Styles
    classDef core fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef backend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef ui fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef template fill:#ffddaa,stroke:#333,stroke-width:2px;
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef testing fill:#dda0dd,stroke:#333,stroke-width:2px;
```
