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/v1namespace - 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:
- DecisionServiceProvider - Business rule engine
- ShippingServiceProvider - Shipping calculations
- OrderServiceProvider - Order processing
- SettingsServiceProvider - Application settings
- 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 conditionstax_profile- Tax profile matchingdestination_region- Geographic conditionscart_weight- Weight-based rulescart_subtotal- Subtotal-based rulesshipping_profile- Shipping profile matchingproduct_categories- Category-based conditions
Actions (8 types):
set_shipping_cost- Set fixed shipping costadd_shipping_cost- Add to shipping costmultiply_shipping_cost- Multiply shipping costset_free_shipping- Enable free shippingdisable_shipping_method- Disable shipping methodset_product_tax_rate- Set product tax rateset_shipping_tax_rate- Set shipping tax rateset_product_tax_exempt- Exempt product from tax
WordPress Hooks (config/hooks.php)
Actions:
RegisterAdminMenu- Register WordPress admin menuEnqueueAdminScripts- Load admin assetsRemoveDuplicateSubmenu- Clean up menu structureRegisterRestApi- Register REST API routesSMTPConfig- 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:
| Resource | Endpoints | Bulk Actions |
|---|---|---|
| Tags | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Brands | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Categories | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Collections | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Attributes | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Customers | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Currencies | GET, GET/{id}, POST, PUT, DELETE/{id} | POST /bulk |
| Coupons | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Products | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Tax Profiles | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Shipping Boxes | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Shipping Profiles | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Product Schemas | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Orders | GET, GET/{id}, POST, PUT/{id}, DELETE/{id} | POST /bulk |
| Payment Gateways | GET, GET/{id}, PUT/{id}, GET /installable, POST /install | - |
| Payment Methods | GET, 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 catalogvariants- Product variationsproduct_schemas- Product templatesbrands- Product brandscategories- Product categoriestags- Product tagscollections- Product collectionsattributes- Product attributes (size, color, etc.)attribute_values- Attribute options
Order Management:
orders- Customer ordersorder_items- Line itemsorder_activities- Order history/logsrefunds- Order refunds
Cart Management:
carts- Shopping cartscart_items- Cart line items
Customer Management:
customers- Customer accountsaddresses- Customer addresses
Pricing & Promotions:
coupons- Discount couponscoupon_usage- Coupon redemption trackingcurrencies- Multi-currency support
Shipping & Tax:
shipping_profiles- Shipping configurationsshipping_boxes- Package definitionstax_profiles- Tax rules
Localization:
languages- Supported languagesproduct_translations- Product translationscollection_translations- Collection translationsattribute_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,AttributeValueRepositoryBrandRepository,CategoryRepository,TagRepository,CollectionRepositoryOrderRepository,CustomerRepository,AddressRepositoryCartRepository,CouponRepository,CurrencyRepositoryShippingProfileRepository,ShippingBoxRepository,TaxProfileRepositoryProductSchemaRepository,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 managementSchemaManager- Schema operationsQueryBuilder- Fluent query interfaceMigration- Database migrationsSeeder- Data seeding
Console Commands
Available Commands:
make:migration- Create migrationmake:model- Create modelmake:controller- Create controllermake:request- Create request validatormake:seeder- Create seedermake:provider- Create service providermake:class- Create generic classmigrate- Run migrationsmigrate:fresh- Drop and recreate databasedb: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 gatewaysPOST /payment-gateways/install- Install gatewayGET /payment-gateways- List installed gatewaysGET /payment-gateways/{id}- Get gateway detailsPUT /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
backenddirectory
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 handlingnesbot/carbon(^2.0) - Date/time manipulation
Development:
phpunit/phpunit(^9.0) - Testing frameworkphp-stubs/wp-cli-stubs(^2.12) - WP-CLI type hintsfakerphp/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
- Clean Architecture: Clear separation of concerns with Repository-Service-Controller pattern
- Dependency Injection: Automatic dependency resolution reduces boilerplate
- Extensibility: Service provider system allows modular extensions
- Type Safety: DTOs provide type-safe data transfer
- Business Rules: Decision engine enables flexible business logic
- Testing: Comprehensive test structure with PHPUnit
- API Design: RESTful API with consistent patterns
- WordPress Integration: Seamless integration while maintaining framework independence
Areas for Consideration
- Framework Coupling: Custom framework creates learning curve for new developers
- Documentation: Code documentation could be enhanced with PHPDoc blocks
- Error Handling: Centralized error handling could be more explicit
- Caching: No obvious caching layer for frequently accessed data
- Queue System: Background job processing appears basic
- API Versioning: Single API version may complicate future changes
- Logging: Logging strategy not immediately apparent
- Performance: Database query optimization opportunities (N+1 queries)
Recommended Next Steps
- Add API Documentation: Generate OpenAPI/Swagger documentation
- Implement Caching: Add Redis/Memcached for performance
- Enhance Logging: Implement structured logging with context
- Add Monitoring: Integrate application performance monitoring
- Write Integration Tests: Expand test coverage for critical flows
- Document Business Rules: Create decision engine documentation
- Add Code Quality Tools: Integrate PHPStan/Psalm for static analysis
- 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 lifecycleframework/Container.php- Dependency injectionframework/Route.php- Routing systemapp/Providers/- Service provider implementationsapp/Services/- Business logic implementationsdatabase/migrations/- Database schema definitions