# infinitegithub/autoit-dealer-tools architecture

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

- Interactive diagram: https://gitdiagram.com/infinitegithub/autoit-dealer-tools
- Repository: https://github.com/infinitegithub/autoit-dealer-tools

## Overview

##### Project type and purpose
- This is a WordPress plugin (“autoit-dealer-tools”) that integrates with AutoIT A/S’s proprietary JSON/REST API (“api-v1.biltorvet.as”) to provide vehicle search, listing and detail pages, lead submission, and widgets via shortcodes and AJAX.
- The plugin ships with two maintained major versions (root / version-1 legacy code and the modern PSR-4–structured v2 folder) plus a small v3 script set for enhanced frontend behavior.

##### File structure
- Top level:
- ajax/ – custom AJAX endpoint
- api/ – custom WP REST API routes
- classes/, enums/, objects/ – domain logic pre-v2
- includes/, scripts/, templates/, css/, languages/, log/
- v2/ – fully namespaced PSR-4 plugin core
- v3/ – minor script additions
- v2/src:
- Controller layer (ApiController, DebugController, PluginController, PriceController, TemplateController)
- Factory layer (EquipmentFactory, LabelFactory, etc.)
- Helper & Utility layer (DataHelper, MailFormatter, WordPressHelper, Callbacks, PrivatePluginUpdater)
- Model layer (ApiResponse, Company, Vehicle, VehicleLead, etc.)
- v2/templates: view layer
- vendor/: third-party dependencies (HTTP clients, autoloader)
- Configuration: v2/.env, .gitignore, readme.md

##### README for additional insights
- Confirms WordPress hooks, shortcodes, REST API usage
- Emphasizes external JSON/REST API as the system of record
- Mentions caching requirements and social-sharing metadata
- Describes shortcode-driven MVC: controllers collect data → factories/models map → templates render HTML → assets (CSS/JS) on frontend

##### Main components
a. Client (Browser/SPA)
b. WordPress Core (Hook dispatcher, REST API, Shortcode parser, DB access)
c. Plugin Core
- Bootstrap & Settings (includes/PluginSettings)
- Controller Layer (v2/src/Controller + ajax/Ajax.php + api/CustomApiRoutes.php)
- Service Layer: HTTP client adapter → BiltorvetAPI (classes/BiltorvetAPI.php or v2/src/Helper/DataHelper)
- Domain Layer: Factories → Models → Templates
- Utility Layer: Caching, Logging (log/errors.log), MailFormatter, PrivatePluginUpdater
- Assets: CSS (css/biltorvet.css), JS (v3/scripts/vehiclesearchmultiselect.js), Images
d. WordPress Database (wp_posts, wp_options for storing plugin settings, transient cache)
e. External AutoIT JSON/REST API (api-v1.biltorvet.as)
f. Third-party services (mapping tiles, SEO plugins, contact-form plugin for lead forms)

##### Relationships and data flow
- Browser issues an HTTP request to a WordPress–powered page containing shortcodes.
- WP shortcode dispatcher calls PluginController → invokes appropriate Controller action.
- Controller calls Service Layer (BiltorvetAPI) to fetch JSON from external API.
- JSON response passed to Factory to build Model objects.
- TemplateController renders HTML via template files and returns to WordPress.
- Response delivered to browser; assets (CSS/JS) load separately.
- For forms/AJAX, Browser posts to ajax/Ajax.php or custom REST endpoints (api/CustomApiRoutes.php) → Plugin processes lead data → posts JSON to external API → returns status to Browser.
- PluginSettings persist API key + branding in wp_options; logs written to log/errors.log.

##### Architectural patterns and design principles
- MVC-style separation within the plugin: Controllers (request handling), Factories/Models (business/data), Templates (views).
- PSR-4 autoloading for version-2 code.
- Single Responsibility: each Factory builds one model; Helpers do one job (mail formatting, WP wrappers).
- Dependency Injection via constructor or service locator in controllers.
- Caching / environment configuration via .env in v2.
- Fallback: legacy code in root for backward compatibility.

##### Essential elements
- Clear labels for each layer and component (e.g., “ApiController”, “VehicleFactory”, “BiltorvetAPI Service”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Browser Layer"
        Browser["Browser/SPA"]:::external
    end

    subgraph "WordPress Core"
        WPShortcode["Shortcode Dispatcher"]:::internal
        WPREST["WP REST API"]:::internal
        WPHooks["Hook Dispatcher"]:::internal
    end

    subgraph "Plugin Core"
        subgraph "Bootstrap & Settings"
            Bootstrap["autoit-dealer-tools.php"]:::internal
            Settings["PluginSettings"]:::internal
        end

        subgraph "Controller Layer"
            ApiCtrl["ApiController"]:::internal
            DebugCtrl["DebugController"]:::internal
            PluginCtrl["PluginController"]:::internal
            PriceCtrl["PriceController"]:::internal
            TemplateCtrl["TemplateController"]:::internal
            AjaxEp["Ajax Endpoint"]:::internal
            CustomAPI["Custom REST API Routes"]:::internal
            LegacySC["BiltorvetShortcodes"]:::internal
        end

        subgraph "Service Layer"
            LegacyAPI["BiltorvetAPI Service"]:::internal
            DataHelper["DataHelper"]:::internal
        end

        subgraph "Domain Layer"
            subgraph Factories
                EqFactory["EquipmentFactory"]:::internal
                LFactory["LabelFactory"]:::internal
                PFactory["PriceFactory"]:::internal
                PropFactory["PropertyFactory"]:::internal
                SDFactory["StructuredDataFactory"]:::internal
                VehFactory["VehicleFactory"]:::internal
                VLFactory["VehicleLeadFactory"]:::internal
            end
            subgraph Models
                ApiResp["ApiResponse"]:::internal
                Company["Company"]:::internal
                Equipment["Equipment"]:::internal
                Label["Label"]:::internal
                Price["Price"]:::internal
                Property["Property"]:::internal
                SearchFilter["SearchFilter"]:::internal
                Vehicle["Vehicle"]:::internal
                VehicleLead["VehicleLead"]:::internal
            end
            subgraph Templates
                LegacyTemplates["Legacy templates"]:::internal
                V2Templates["v2 templates"]:::internal
            end
        end

        subgraph "Utility Layer"
            MailFmt1["MailFormatter (legacy)"]:::internal
            MailFmt2["MailFormatter (v2)"]:::internal
            WPHelper["WordPressHelper"]:::internal
            Callbacks["Callbacks"]:::internal
            Updater["PrivatePluginUpdater"]:::internal
            LogFile["errors.log"]:::datastore
        end

        subgraph Assets
            CSS["biltorvet.css"]:::asset
            JS["vehiclesearchmultiselect.js"]:::asset
            Images["images"]:::asset
        end
    end

    subgraph "Data Stores"
        WPDB["WordPress DB (wp_posts, wp_options, transients)"]:::datastore
    end

    subgraph "External Services"
        BiltorvetAPI["AutoIT JSON/REST API"]:::external
        MapTiles["Mapping Tiles Service"]:::external
        SEOPlugin["SEO Plugin"]:::external
        ContactForm["Contact-Form Plugin"]:::external
    end

    %% Connections
    Browser -->|renders page with shortcode| WPShortcode
    Browser -->|AJAX/REST call| WPREST
    WPShortcode -->|invokes| LegacySC
    WPShortcode -->|invokes| PluginCtrl
    WPREST -->|routes to| CustomAPI
    LegacySC -->|calls| PluginCtrl
    PluginCtrl -->|calls| DataHelper
    ApiCtrl -->|calls| DataHelper
    CustomAPI -->|invokes| ApiCtrl
    AjaxEp -->|posts| ApiCtrl
    AjaxEp -->|posts| DataHelper
    DataHelper -->|fetches| BiltorvetAPI
    LegacyAPI -->|fetches| BiltorvetAPI
    DataHelper -->|produces| EqFactory
    DataHelper -->|produces| LFactory
    DataHelper -->|produces| PFactory
    DataHelper -->|produces| PropFactory
    DataHelper -->|produces| SDFactory
    DataHelper -->|produces| VehFactory
    DataHelper -->|produces| VLFactory
    EqFactory --> Equipment
    LFactory --> Label
    PFactory --> Price
    PropFactory --> Property
    SDFactory --> SearchFilter
    VehFactory --> Vehicle
    VLFactory --> VehicleLead
    Vehicle --> V2Templates
    VehicleLead --> V2Templates
    LegacyTemplates --> Browser
    V2Templates --> Browser
    PluginCtrl -->|reads/writes| WPDB
    CustomAPI -->|reads/writes| WPDB
    PluginCtrl -->|logs to| LogFile
    Updater -->|updates plugin| WPDB
    Browser -->|loads| CSS
    Browser -->|loads| JS
    Browser -->|loads| Images
    DataHelper -->|caches in| WPDB
    SEOPlugin -->|integrates| V2Templates
    ContactForm -->|used by| AjaxEp
    MapTiles -->|used by| V2Templates

    %% Click Events
    click Bootstrap "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/autoit-dealer-tools.php"
    click Settings "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/includes/PluginSettings.php"
    click ApiCtrl "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Controller/ApiController.php"
    click DebugCtrl "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Controller/DebugController.php"
    click PluginCtrl "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Controller/PluginController.php"
    click PriceCtrl "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Controller/PriceController.php"
    click TemplateCtrl "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Controller/TemplateController.php"
    click AjaxEp "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/ajax/Ajax.php"
    click CustomAPI "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/api/CustomApiRoutes.php"
    click LegacySC "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/classes/BiltorvetShortcodes.php"
    click LegacyAPI "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/classes/BiltorvetAPI.php"
    click DataHelper "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Helper/DataHelper.php"
    click EqFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/EquipmentFactory.php"
    click LFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/LabelFactory.php"
    click PFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/PriceFactory.php"
    click PropFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/PropertyFactory.php"
    click SDFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/StructuredDataFactory.php"
    click VehFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/VehicleFactory.php"
    click VLFactory "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Factory/VehicleLeadFactory.php"
    click ApiResp "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/ApiResponse.php"
    click Company "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/Company.php"
    click Equipment "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/Equipment.php"
    click Label "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/Label.php"
    click Price "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/Price.php"
    click Property "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/Property.php"
    click SearchFilter "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/SearchFilter.php"
    click Vehicle "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/Vehicle.php"
    click VehicleLead "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Model/VehicleLead.php"
    click LegacyTemplates "https://github.com/infinitegithub/autoit-dealer-tools/tree/master/templates/"
    click V2Templates "https://github.com/infinitegithub/autoit-dealer-tools/tree/master/v2/templates/"
    click MailFmt1 "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/classes/helpers/MailFormatter.php"
    click MailFmt2 "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Helper/MailFormatter.php"
    click WPHelper "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Helper/WordpressHelper.php"
    click Callbacks "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Utility/Callbacks.php"
    click Updater "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v2/src/Utility/PrivatePluginUpdater.php"
    click LogFile "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/log/errors.log"
    click CSS "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/css/biltorvet.css"
    click JS "https://github.com/infinitegithub/autoit-dealer-tools/blob/master/v3/scripts/vehiclesearchmultiselect.js"
    click Images "https://github.com/infinitegithub/autoit-dealer-tools/tree/master/includes/img/"

    %% Styles
    classDef internal fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef external fill:#E6FFEA,stroke:#28a745,color:#28a745
    classDef datastore fill:#FFF4D6,stroke:#d18600,color:#d18600
    classDef asset fill:#E7E7E7,stroke:#888888,color:#555555
```
