Overview
OpenCart 4.x follows a custom MVC-A (Model-View-Controller-Action) pattern built on modern PHP 8.0+ with namespaced classes. The framework emphasizes modularity, extensibility through events, and a clean separation of concerns.Directory Structure
Core Architecture Components
1. Registry Pattern
The Registry (system/engine/registry.php:15) is the heart of OpenCart’s architecture, providing dependency injection and service location.
system/engine/registry.php
The registry stores all system objects (db, config, session, cart, etc.) and makes them accessible throughout the application via magic methods.
2. Base Classes
All controllers and models extend base classes that provide access to the registry: Controller Base Class (system/engine/controller.php:17)
system/engine/model.php:21)
3. Loader System
The Loader (system/engine/loader.php:17) handles dynamic loading of MVC components:
4. Namespacing Convention
OpenCart 4.x uses PHP namespaces following this pattern:- Catalog Controllers:
Opencart\Catalog\Controller\{Path} - Admin Controllers:
Opencart\Admin\Controller\{Path} - Models:
Opencart\{Application}\Model\{Path} - System Classes:
Opencart\System\Engine\{Class} - Libraries:
Opencart\System\Library\{Class} - Extensions:
Opencart\{Application}\Controller\Extension\{Vendor}\{Type}\{Name}
Application Flow
Bootstrap
The
index.php file initializes the framework, loads configuration, and creates the registry with core services (database, session, cache, etc.).Routing
The router parses the URL and determines which controller and method to execute based on the
route parameter.Controller Execution
The loader instantiates the controller, injects the registry, and calls the appropriate method.
Key Registry Objects
When you access$this-> properties in controllers and models, you’re accessing registry objects:
| Property | Type | Purpose |
|---|---|---|
$this->db | Database | Query execution and database operations |
$this->config | Config | Configuration values and settings |
$this->session | Session | Session data management |
$this->request | Request | HTTP request data (GET, POST, etc.) |
$this->response | Response | HTTP response handling |
$this->cache | Cache | Caching operations |
$this->url | URL | URL generation |
$this->load | Loader | Dynamic loading of components |
$this->cart | Cart | Shopping cart operations (catalog only) |
$this->customer | Customer | Customer session data (catalog only) |
$this->user | User | Admin user data (admin only) |
Extension Architecture
Extensions are organized by vendor and type:payment, shipping, module, total, theme, fraud, captcha, currency, etc.
PHP 8.0+ Features
OpenCart 4.x leverages modern PHP features:- Typed Properties: All class properties use type declarations
- Return Types: Methods specify return types
- Named Arguments: Support for named parameters
- Nullsafe Operator: Used for optional chaining
- Constructor Property Promotion: Simplified syntax
Next Steps
Development Setup
Configure your local development environment
MVC Pattern
Learn how MVC works in OpenCart
Coding Standards
Follow OpenCart coding conventions
Event System
Extend functionality with events

