How infinitegithub/autoit-dealer-tools works
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”).