Skip to main content

Application Complete Overview

Entry Point: wp-content/droip-apps-dev/apps/Ecommerce
Type: WordPress Plugin - E-commerce Application
Framework: Custom Laravel-inspired Framework Language: PHP 7.4+


Overview​

The Droip Ecommerce application is a comprehensive e-commerce solution built as a WordPress plugin. It features a custom Laravel-inspired framework with dependency injection, service providers, and a clean architecture pattern. The application provides a complete REST API for managing products, orders, customers, payments, shipping, and more.

Key Characteristics​

  • Architecture: Clean Architecture with Repository-Service-Controller pattern
  • Framework: Custom dependency injection container with autowiring
  • Database: Custom migration system with 38 tables
  • API: RESTful API with 200+ endpoints under droip/ecommerce/v1 namespace
  • Integration: Deep WordPress integration via hooks and custom admin menu
  • Testing: PHPUnit test suite with Unit, Feature, and Support test categories
  • Payment: Extensible payment gateway system (Stripe integration included)

Directory Structure​

Ecommerce/
├── index.php # Application entry point
├── composer.json # Dependencies and autoloading
├── bootstrap/ # Application bootstrap files
│ ├── app.php # Application configuration
│ ├── providers.php # Service provider registration
│ └── aliases.php # Service aliases
├── config/ # Configuration files
│ ├── decisions.php # Business rule conditions/actions
│ ├── hooks.php # WordPress hook registrations
│ ├── menu.php # Admin menu structure
│ ├── migrations.php # Database migration registry
│ └── tax-strategies.php # Tax calculation strategies
├── framework/ # Custom framework (213 files)
│ ├── Application.php # Core application class
│ ├── Container.php # Dependency injection container
│ ├── Route.php # Routing system
│ ├── Database/ # Database abstraction layer
│ ├── Http/ # HTTP request/response handling
│ ├── Console/ # CLI command system
│ ├── Validation/ # Input validation
│ └── Wordpress/ # WordPress integration layer
├── app/ # Application logic (347 files)
│ ├── Actions/ # Action classes (20 files)
│ ├── Constants/ # Application constants (32 files)
│ ├── DTO/ # Data Transfer Objects (59 files)
│ ├── Decisions/ # Business rule engine (19 files)
│ ├── Events/ # Event classes
│ ├── Facades/ # Facade pattern implementations
│ ├── Http/ # Controllers, Middleware, Requests (65 files)
│ ├── Jobs/ # Background jobs
│ ├── Listeners/ # Event listeners
│ ├── Managers/ # Manager classes
│ ├── Menu/ # Admin menu pages (16 files)
│ ├── Models/ # Eloquent-style models (25 files)
│ ├── Payment/ # Payment gateway abstractions (6 files)
│ ├── Policies/ # Authorization policies
│ ├── Providers/ # Service providers (6 files)
│ ├── Repositories/ # Data access layer (20 files)
│ ├── Resources/ # API resource transformers (31 files)
│ ├── Services/ # Business logic layer (27 files)
│ ├── Settings/ # Settings management (9 files)
│ └── Tax/ # Tax calculation system (4 files)
├── database/ # Database files
│ ├── migrations/ # Database migrations (38 files)
│ └── seeders/ # Database seeders (15 files)
├── routes/ # Route definitions
│ └── api.php # API route definitions
├── resources/ # Frontend resources
│ └── data/ # Static data files (countries, etc.)
├── payments/ # Payment gateway integrations
│ └── droip-stripe/ # Stripe payment gateway
├── tests/ # Test suite
│ ├── Unit/ # Unit tests
│ ├── Feature/ # Feature tests
│ └── Support/ # Test support files
└── vendor/ # Composer dependencies

Application Bootstrap Process​

Entry Point Flow​

1. Entry Point (index.php)​

The application starts by defining critical constants:

define('DROIP_APPS_ECOMMERCE_VERSION', '1.0.0');
define('DROIP_ECOMMERCE_IS_DEV', true);
define('DROIP_APPS_ECOMMERCE_APP_SLUG', 'droip');
define('DROIP_APPS_ECOMMERCE_ROOT_PATH', plugin_dir_path(__FILE__));
define('DROIP_APPS_ECOMMERCE_ASSETS_URL', WP_CONTENT_URL . $relative_path . 'assets');
define('DROIP_APPS_ECOMMERCE_PREFIX', 'droip_ecommerce_');
define('DROIP_APPS_ECOMMERCE_MODE', 'development');

2. Application Configuration (bootstrap/app.php)​

Application::configure(DROIP_APPS_ECOMMERCE_ROOT_PATH)
->use_routing(DROIP_APPS_ECOMMERCE_ROOT_PATH . '/routes/api.php')
->use_prefix(DROIP_APPS_ECOMMERCE_PREFIX)
->boot();

3. Service Provider Registration​

Five core service providers are registered:

  1. DecisionServiceProvider - Business rule engine
  2. ShippingServiceProvider - Shipping calculations
  3. OrderServiceProvider - Order processing
  4. SettingsServiceProvider - Application settings
  5. PaymentServiceProvider - Payment gateway management

Configuration System​

Decision Engine (config/decisions.php)​

The application uses a rule-based decision engine for dynamic business logic:

Conditions (7 types):

  • product_profile - Product-based conditions
  • tax_profile - Tax profile matching
  • destination_region - Geographic conditions
  • cart_weight - Weight-based rules
  • cart_subtotal - Subtotal-based rules
  • shipping_profile - Shipping profile matching
  • product_categories - Category-based conditions

Actions (8 types):

  • set_shipping_cost - Set fixed shipping cost
  • add_shipping_cost - Add to shipping cost
  • multiply_shipping_cost - Multiply shipping cost
  • set_free_shipping - Enable free shipping
  • disable_shipping_method - Disable shipping method
  • set_product_tax_rate - Set product tax rate
  • set_shipping_tax_rate - Set shipping tax rate
  • set_product_tax_exempt - Exempt product from tax

WordPress Hooks (config/hooks.php)​

Actions:

  • RegisterAdminMenu - Register WordPress admin menu
  • EnqueueAdminScripts - Load admin assets
  • RemoveDuplicateSubmenu - Clean up menu structure
  • RegisterRestApi - Register REST API routes
  • SMTPConfig - Configure email settings

Admin Menu (config/menu.php)​

15 menu items organized hierarchically:

  • Root, Home, Orders
  • Products, Inventory, Collections, Categories, Tags, Brands
  • Analytics, Report
  • Customers, Coupons, Settings, Tools

Routing System​

API Namespace​

All routes are registered under droip/ecommerce/v1 namespace.

Route Structure​

Route::set_namespace('droip/ecommerce/v1');

// Public webhook endpoint
Route::post('/payment/webhook/{gateway_id}', [WebhookController::class, 'handle']);

// Protected routes (require authentication)
Route::group(['middleware' => AuthMiddleware::class], function () {
// 200+ endpoints defined here
});

Resource Endpoints​

The API follows RESTful conventions with standard CRUD operations:

ResourceEndpointsBulk Actions
TagsGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
BrandsGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
CategoriesGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
CollectionsGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
AttributesGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
CustomersGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
CurrenciesGET, GET/{id}, POST, PUT, DELETE/{id}POST /bulk
CouponsGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
ProductsGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
Tax ProfilesGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
Shipping BoxesGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
Shipping ProfilesGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
Product SchemasGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
OrdersGET, GET/{id}, POST, PUT/{id}, DELETE/{id}POST /bulk
Payment GatewaysGET, GET/{id}, PUT/{id}, GET /installable, POST /install-
Payment MethodsGET, GET/{id}, POST, PUT/{id}, DELETE/{id}-

Special Endpoints​

  • Cart Management: /cart, /cart/items, /cart/coupon
  • Variants: /variants, /variants/bulk/{ids}, /variants/bulk (PUT)
  • Attribute Values: /attributes/{attribute_id}/values/*
  • Order Refunds: /orders/{order_id}/refunds/*
  • Countries: /countries, /countries/{code}
  • Settings: /settings/{key}, /settings (PUT)
  • App Config: /app-config
  • Pages: /pages

Database Schema​

Migration System​

38 database tables managed through migration classes:

Core Tables​

Product Management:

  • products - Product catalog
  • variants - Product variations
  • product_schemas - Product templates
  • brands - Product brands
  • categories - Product categories
  • tags - Product tags
  • collections - Product collections
  • attributes - Product attributes (size, color, etc.)
  • attribute_values - Attribute options

Order Management:

  • orders - Customer orders
  • order_items - Line items
  • order_activities - Order history/logs
  • refunds - Order refunds

Cart Management:

  • carts - Shopping carts
  • cart_items - Cart line items

Customer Management:

  • customers - Customer accounts
  • addresses - Customer addresses

Pricing & Promotions:

  • coupons - Discount coupons
  • coupon_usage - Coupon redemption tracking
  • currencies - Multi-currency support

Shipping & Tax:

  • shipping_profiles - Shipping configurations
  • shipping_boxes - Package definitions
  • tax_profiles - Tax rules

Localization:

  • languages - Supported languages
  • product_translations - Product translations
  • collection_translations - Collection translations
  • attribute_translations - Attribute translations

System:

  • scheduler_jobs - Background job queue

Application Architecture​

Layered Architecture Pattern​

Core Modules​

1. Models (25 files)​

Eloquent-style ORM models for database interaction:

  • Product Domain: Product, Variant, ProductSchema, Brand, Category, Tag, Collection, Attribute, AttributeValue
  • Order Domain: Order, OrderItem, Refund
  • Cart Domain: Cart, CartItem
  • Customer Domain: Customer, Address
  • Pricing Domain: Coupon, CouponUsage, Currency
  • Shipping/Tax: ShippingProfile, ShippingBox, TaxProfile
  • WordPress Integration: Post, PostMeta, Page

2. Services (27 files)​

Business logic layer implementing core functionality:

  • Product Services: ProductService, VariantService, AttributeService, AttributeValueService, BrandService, CategoryService, TagService, CollectionService, ProductSchemaService
  • Order Services: OrderService, InventoryService
  • Cart Services: CartService, DiscountService
  • Customer Services: CustomerService, AddressService
  • Pricing Services: CouponService, CurrencyService
  • Shipping/Tax Services: ShippingService, ShippingBoxService, ShippingProfileService, TaxProfileService
  • Payment Services: PaymentGatewayService, ManualPaymentMethodService
  • Utility Services: AppConfigService, SettingsService, PageService, CountryService

3. Repositories (20 files)​

Data access layer abstracting database operations:

  • ProductRepository, VariantRepository, AttributeRepository, AttributeValueRepository
  • BrandRepository, CategoryRepository, TagRepository, CollectionRepository
  • OrderRepository, CustomerRepository, AddressRepository
  • CartRepository, CouponRepository, CurrencyRepository
  • ShippingProfileRepository, ShippingBoxRepository, TaxProfileRepository
  • ProductSchemaRepository, PageRepository, CountryRepository

4. Controllers (HTTP Layer)​

RESTful API controllers in app/Http/Controllers/Api/:

  • Resource controllers for all entities
  • Consistent CRUD operations
  • Bulk action support
  • Input validation via Request classes
  • Response transformation via Resource classes

5. DTOs (59 files)​

Data Transfer Objects for type-safe data passing between layers.

6. Actions (20 files)​

Single-responsibility action classes for specific operations.

7. Decisions (19 files)​

Business rule engine components:

  • Conditions: Evaluate business rules
  • Actions: Execute business logic based on conditions

8. Resources (31 files)​

API response transformers for consistent JSON output.


Custom Framework​

Dependency Injection Container​

File: framework/Container.php

Features:

  • Automatic dependency resolution via reflection
  • Singleton and transient bindings
  • Service aliasing
  • Tagged services
  • Circular dependency detection
  • Constructor autowiring

Key Methods:

$container->bind(string $name, ?Closure $resolver = null)
$container->singleton(string $name, ?Closure $resolver = null)
$container->instance(string $abstract, $instance)
$container->make(string $name, array $parameters = [])
$container->alias(string $alias, string $abstract)
$container->tag(array $services, string $tag)

Application Class​

File: framework/Application.php

Responsibilities:

  • Container management
  • Service provider registration
  • Path management
  • Boot lifecycle
  • CLI command registration
  • WordPress integration

Lifecycle Hooks:

$app->booting(callable $callback)  // Before boot
$app->booted(callable $callback) // After boot

Path Helpers:

$app->base_path($path = '')
$app->path($path = '') // app directory
$app->bootstrap_path($path = '')
$app->config_path($path = '')
$app->database_path($path = '')
$app->resource_path($path = '')

Routing System​

File: framework/Route.php

Features:

  • RESTful route definitions
  • Route groups with middleware
  • Parameter binding
  • Namespace management

Usage:

Route::set_namespace('droip/ecommerce/v1');
Route::get('/products', [ProductController::class, 'get']);
Route::post('/products', [ProductController::class, 'create']);
Route::group(['middleware' => AuthMiddleware::class], function () {
// Protected routes
});

Database Layer​

Components:

  • DatabaseManager - Database connection management
  • SchemaManager - Schema operations
  • QueryBuilder - Fluent query interface
  • Migration - Database migrations
  • Seeder - Data seeding

Console Commands​

Available Commands:

  • make:migration - Create migration
  • make:model - Create model
  • make:controller - Create controller
  • make:request - Create request validator
  • make:seeder - Create seeder
  • make:provider - Create service provider
  • make:class - Create generic class
  • migrate - Run migrations
  • migrate:fresh - Drop and recreate database
  • db:seed - Run seeders

Payment System​

Architecture​

Payment Gateway Structure​

Location: payments/droip-stripe/

Components:

  • Gateway implementation
  • Webhook handling
  • Configuration management
  • Transaction processing

Gateway Management​

Endpoints:

  • GET /payment-gateways/installable - List available gateways
  • POST /payment-gateways/install - Install gateway
  • GET /payment-gateways - List installed gateways
  • GET /payment-gateways/{id} - Get gateway details
  • PUT /payment-gateways/{id} - Update gateway settings

Webhook:

  • POST /payment/webhook/{gateway_id} - Handle payment webhooks (public endpoint)

Testing Setup​

Test Structure​

tests/
├── Unit/ # Unit tests for individual classes
├── Feature/ # Feature/integration tests
└── Support/ # Test helpers and utilities

PHPUnit Configuration​

File: phpunit.xml

Configuration:

  • Bootstrap: backend/Tests/bootstrap.php
  • Test Suite: Unit tests in backend/Tests/Unit
  • Coverage: Includes backend directory

Running Tests​

# Run all tests
composer test

# Or directly
vendor/bin/phpunit

Key Design Patterns​

1. Repository Pattern​

Abstracts data access logic from business logic:

// Repository handles data access
class ProductRepository {
public function find($id) { /* ... */ }
public function all() { /* ... */ }
public function create(array $data) { /* ... */ }
}

// Service uses repository
class ProductService {
public function __construct(ProductRepository $repository) {
$this->repository = $repository;
}
}

2. Service Layer Pattern​

Encapsulates business logic:

class OrderService {
public function createOrder(CreateOrderDTO $dto) {
// Business logic
// Inventory checks
// Price calculations
// Tax calculations
// Order creation
}
}

3. Resource Pattern​

Transforms models to API responses:

class ProductResource extends Resource {
public function to_array() {
return [
'id' => $this->id,
'name' => $this->name,
'price' => $this->price,
// ... transformed data
];
}
}

4. DTO Pattern​

Type-safe data transfer between layers:

class CreateProductDTO extends DTO {
public string $name;
public float $price;
public ?string $description;
// ... validated properties
}

5. Decision Pattern​

Rule-based business logic:

// Condition checks if rule applies
class CartWeightCondition {
public function evaluate($context) { /* ... */ }
}

// Action executes if condition passes
class SetFreeShippingAction {
public function execute($context) { /* ... */ }
}

6. Service Provider Pattern​

Modular service registration:

class ShippingServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton(ShippingService::class);
}

public function boot() {
// Bootstrap logic
}
}

WordPress Integration​

Hook System​

The application integrates with WordPress through a custom hook system:

Registration: config/hooks.php

Implementation: framework/Wordpress/Hooks/

Key Integrations:

  • Admin menu registration
  • Asset enqueuing
  • REST API registration
  • SMTP configuration

Admin Interface​

Menu Structure: Defined in config/menu.php

Menu Classes: app/Menu/

Each menu item is a class implementing menu registration logic.

Database Integration​

Uses WordPress $wpdb global for database operations while maintaining framework abstraction.


Dependencies​

Composer Packages​

Production:

  • brick/money (0.7) - Money and currency handling
  • nesbot/carbon (^2.0) - Date/time manipulation

Development:

  • phpunit/phpunit (^9.0) - Testing framework
  • php-stubs/wp-cli-stubs (^2.12) - WP-CLI type hints
  • fakerphp/faker (^1.24) - Test data generation

Autoloading​

PSR-4 Namespaces:

  • Ecommerce\ → framework/
  • Ecommerce\App\ → app/
  • Ecommerce\Database\Migrations\ → database/migrations/
  • Ecommerce\Database\Seeders\ → database/seeders/
  • Ecommerce\Tests\ → tests/ (dev only)

Files:

  • framework/helpers.php - Global helper functions

Visual Architecture​

Request Flow​

Service Provider Boot Process​


Additional Insights​

Strengths​

  1. Clean Architecture: Clear separation of concerns with Repository-Service-Controller pattern
  2. Dependency Injection: Automatic dependency resolution reduces boilerplate
  3. Extensibility: Service provider system allows modular extensions
  4. Type Safety: DTOs provide type-safe data transfer
  5. Business Rules: Decision engine enables flexible business logic
  6. Testing: Comprehensive test structure with PHPUnit
  7. API Design: RESTful API with consistent patterns
  8. WordPress Integration: Seamless integration while maintaining framework independence

Areas for Consideration​

  1. Framework Coupling: Custom framework creates learning curve for new developers
  2. Documentation: Code documentation could be enhanced with PHPDoc blocks
  3. Error Handling: Centralized error handling could be more explicit
  4. Caching: No obvious caching layer for frequently accessed data
  5. Queue System: Background job processing appears basic
  6. API Versioning: Single API version may complicate future changes
  7. Logging: Logging strategy not immediately apparent
  8. Performance: Database query optimization opportunities (N+1 queries)
  1. Add API Documentation: Generate OpenAPI/Swagger documentation
  2. Implement Caching: Add Redis/Memcached for performance
  3. Enhance Logging: Implement structured logging with context
  4. Add Monitoring: Integrate application performance monitoring
  5. Write Integration Tests: Expand test coverage for critical flows
  6. Document Business Rules: Create decision engine documentation
  7. Add Code Quality Tools: Integrate PHPStan/Psalm for static analysis
  8. Create Developer Guide: Write onboarding documentation for new developers

Metadata​

Analysis Date: 2026-02-08
Analysis Depth: Full application structure (excluding src directory)
Files Analyzed: 600+ files across framework, app, config, database, and routes
Database Tables: 38 tables
API Endpoints: 200+ endpoints
Service Providers: 5 core providers
Models: 25 models
Services: 27 services
Repositories: 20 repositories

Related Documentation:

  • Composer configuration: composer.json
  • Bootstrap configuration: bootstrap/app.php
  • Route definitions: routes/api.php
  • Migration registry: config/migrations.php
  • Service providers: bootstrap/providers.php

Entry Points for Further Investigation:

  • framework/Application.php - Application lifecycle
  • framework/Container.php - Dependency injection
  • framework/Route.php - Routing system
  • app/Providers/ - Service provider implementations
  • app/Services/ - Business logic implementations
  • database/migrations/ - Database schema definitions