Rethinking Oscar's architecture: extensibility, modularity, and a path forward

Author: joeyjurjensCreated Mar 4, 2026Updated Jul 15, 2026
Labelsrefactor

This builds on discussions from #2972 (2019) about splitting Oscar into core/storefront/dashboard and extracting business logic from views. Those ideas were never fully realized. This issue goes further and proposes rethinking Oscar's fundamental extensibility model.

See also #4540 for related discussion about modernizing Oscar's communication layer using Django's new tasks API.

Oscar describes itself as "an e-commerce framework for building domain-driven applications" — not a turnkey shop, but a framework you build on top of. Its customisation docs promise that "the behaviour of all Oscar apps can heavily be altered by injecting your own code." In practice, that injection mechanism is forking apps and subclassing classes — which works for individual projects but doesn't support an ecosystem of composable modules. If Oscar wants to truly be a framework that others build on, the extensibility model needs to match that ambition.

The more modular Oscar becomes, the easier it is for third parties to build and distribute extensions — payment providers, shipping integrations, tax engines, marketplace features — without forking or conflicting with each other. A healthy extension ecosystem drives adoption, which in turn attracts more contributors and extensions. This flywheel effect is what made platforms like WooCommerce and Shopware successful, and it's what Oscar is currently missing.

Note: This document is primarily intended to start a discussion, not a final blueprint. It's based on my experience working with Oscar and other commerce systems. Not everything here is a fully formed proposal — some points are observations, some are directions, and some are open questions. The goal is to get the conversation going about where Oscar should head next. AI was used to assist with writing and researching documentation of other platforms.

Current pain points

1. Forking as the primary extensibility mechanism

Oscar's customization model is built around forking apps. You copy an app into your project, subclass its models/views, and replace it in INSTALLED_APPS. This works for single-project customization but fundamentally prevents an ecosystem of distributable modules:

  • An app label can only be registered once — two packages can't both customize catalogue
  • Migrations are tied to the forked app, making package distribution impractical
  • You can't compose customizations from multiple sources

2. Inheritance is the wrong model for extensibility

All extensibility in Oscar is via class inheritance. If 5 modules all want to modify BasketView, they need to form a linear inheritance chain where each module must know about and inherit from the previous one. This doesn't scale and makes modules interdependent. The same applies to models — Product can only be made concrete once.

This isn't just a theoretical concern. The most successful extension ecosystems in software — WordPress/WooCommerce, Shopware, Spree Commerce — are all built on hooks and events, not inheritance. WooCommerce's hook-based architecture has enabled hundreds of extensions to coexist and compose without knowing about each other. Shopware, built on Symfony, uses an event-driven architecture where modules subscribe to events rather than subclassing core classes. Spree Commerce recently moved to an Events & Subscribers engine specifically so that customizations survive upgrades without forking core code.

In the Django ecosystem, Wagtail uses a hook system that allows modules to both extend behavior and replace built-in implementations — apps register functions via @hooks.register in a wagtail_hooks.py file. While Wagtail still relies on inheritance in many places, its hook system shows that the pattern works well within Django's architecture.

The pattern is clear: hook/event-based extensibility scales to ecosystems. Inheritance-based extensibility does not.

3. Hooks make deprecation and evolution easier

With inheritance, changing a method signature or removing a method breaks every subclass. You're locked into your API surface because you don't know who's overriding what. And because Python is dynamically typed and Oscar has virtually no type annotations, these breaks are invisible — no compiler catches them, and tools like mypy can't help either. You only find out at runtime, potentially in production.

With hooks, you control the contract explicitly: you can deprecate a hookspec, introduce a new one alongside it, and give module authors a clear migration path. The core can evolve without silently breaking downstream code.

4. Business logic lives in views

Core business processes like checkout, order placement, basket manipulation, and voucher handling are implemented directly in view methods (CheckoutSessionMixin, OrderPlacementMixin, etc.). This means:

  • Logic cannot be reused outside of an HTTP request context
  • Building an API or alternative frontend requires reimplementing business logic
  • Testing business rules requires simulating HTTP requests
  • Dashboard views duplicate logic from storefront views

CheckoutSessionMixin and OrderPlacementMixin together contain hundreds of lines of orchestration: order number generation, basket freezing, payment handling, error recovery, email sending, stock allocation — all in view mixins.

5. Storefront is embedded in the package

Oscar ships with a full storefront (templates, static assets, views) as part of the core package. This creates problems:

  • Template updates in new Oscar versions can break sites that depend on specific template structure
  • Projects that override templates must carefully track upstream changes across releases
  • There's no clear boundary between "Oscar core" and "Oscar's default storefront"
  • Projects that don't use Oscar's storefront (API-only, headless, custom frontend) still carry all the template/view baggage

Other platforms have already made this separation. Medusa is core-only with no default storefront. Spree Commerce splits into core, storefront, admin, and API as separate components. The storefront should be a separate, optional layer on top of core business logic — not intertwined with it.

6. Dashboard is monolithic

Dashboard views contain their own business logic rather than delegating to shared services. The dashboard catalogue view alone is 1000+ lines, handling product creation, image ordering, category management, and stockrecord manipulation all within view methods. A dashboard rewrite (whether with a modern frontend framework or otherwise) would require reimplementing all that logic.

7. Data modeling has accumulated debt

Several core models combine responsibilities that most modern e-commerce platforms separate:

  • StockRecord combines pricing, inventory, and partner information in a single model. This makes it difficult to implement multiple warehouses, per-region pricing, price lists, or separate inventory tracking. Most platforms (Medusa, Spree, Sylius) treat pricing and inventory as independent domains.
  • Oscar has no concept of tax. There are incl_tax / excl_tax fields scattered across models, but no tax rules, tax rates, or tax calculation engine. Projects must build this entirely themselves. Platforms like Sylius ship a dedicated taxation component.
  • Product/variant modeling uses a parent-child product relationship. This pattern itself is not unusual — many platforms model variants as product-like entities. The issue is that Oscar has no concept of "variant-defining attributes." ProductAttribute and ProductAttributeValue exist, and child products can have their own attribute values, but there's no metadata saying "color and size define the variants." The building blocks are there, but without that layer the frontend can't render proper option selectors (the default template just lists links to child products), there's no validation that attribute combinations are unique, and there's no way to auto-generate variants from option combinations. Platforms like Spree and Sylius solve this with explicit OptionType/OptionValue models that define the variant axes.
  • The offer system uses a complex proxy pattern with runtime class loading (proxy_class string imports, field dict copying) that is fragile and hard to extend with custom benefit/condition types.

These are areas worth rethinking, but we want to be upfront: none of these have been fully designed yet. Each one has implications and trade-offs that need to be worked out — splitting StockRecord affects how partners work, adding a tax engine has scope implications, changing the variant model affects the dashboard, templates, and every project's data. These are directions, not blueprints.

8. Communication is coupled to views

Email sending is directly called from view methods and order placement mixins. There's no unified notification interface — different dispatchers handle different email types with different patterns. This makes it hard to:

  • Switch to async email sending (see #4540)
  • Add alternative notification channels (webhooks, push notifications)
  • Test business logic without triggering emails

9. Other observations from the codebase

  • God classes: AbstractProduct (1700+ lines) handles validation, caching, child product logic, recommendations, attributes, and review stats. AbstractOrder (1400+ lines) mixes financial calculations, status management, shipping events, and discount tracking. AbstractBasket (1100+ lines) handles validation, offers, caching, serialization, merging, and pricing. ConditionalOffer (1350+ lines) uses a complex proxy pattern with runtime class loading. These are hard to understand, test, and extend.
  • Inconsistent signal usage: Only 6 of Oscar's 15+ apps use Django signals. Some apps emit signals, others handle the same kind of events directly in business logic. StockRecord even manually dispatches pre_save/post_save signals from its allocate(), consume_allocation(), and cancel_allocation() methods — mixing concerns in a confusing way.
  • Duplicated logic: Price calculations (total_incl_tax, total_excl_tax, discount totals) are implemented separately on Basket, Order, and OrderLine with similar but subtly different logic. If you need to change how totals are computed, you need to update multiple places.
  • Order, payment, and shipping lack proper abstractions: These three domains interact in confusing ways. Order numbers are generated before the order exists (needed for payment gateways), but if order creation fails after payment succeeds there's no built-in reconciliation. Payment happens in handle_payment() (a view method you override), but payment sources and events are saved after order creation — there's no atomic coupling. The payment module provides data models for tracking amounts but no payment gateway interface — no standard way to authorize, capture, refund, or handle webhooks. Every project reinvents this. The shipping module is similar: stateless calculate() methods with no hooks for tax, no handling time, no tracking URL support. Shipping methods are fetched fresh on every request with no validation that a selected method still exists between checkout steps. Status pipelines (order and line) are purely settings-based with no enforcement — you can bypass them entirely. These domains need better abstractions so that implementing payment providers, shipping carriers, and order fulfillment is straightforward rather than requiring each project to figure out the integration points from scratch.
  • Forms contain business logic: Dashboard forms like StockRecordForm filter partners based on user permissions during form initialization. ProductForm handles parent-child conversion logic. These are business rules that belong in a service, not in form __init__ methods.

Proposed direction

The ideas below are directions to explore, not final designs. Each comes with trade-offs and open questions that need to be worked out. The goal of this issue is to start the conversation and align on a vision, not to prescribe exact solutions.

Service layer

Extract all business logic from views into service classes. Views become thin wrappers that validate input, call services, and return responses. This is the foundation that enables everything else — API support, headless, alternative frontends, testability.

This was already proposed in #2972 and is a prerequisite for any further architectural changes.

Today, business logic is spread across view mixins, model methods, utility classes, and forms — often duplicated or split across multiple paths. A service layer gives each domain a single, clear entry point that can be called from views, API endpoints, management commands, or tests without requiring an HTTP request.

This also enables better abstractions for domains that currently lack them. For example, a payment service could define a clear interface for authorize/capture/refund that payment providers implement, instead of leaving every project to wire up handle_payment() from scratch. A shipping service could provide proper hooks for tax, handling time, and carrier integration. An order service could handle the full submission flow — including the payment-order coupling that is currently fragile — in one place.

Hook-based extensibility via pluggy

Replace inheritance-based extensibility with a pluggy-based hook system. Oscar defines hookspecs at key extension points, and modules register hookimpls.

Multiple modules can implement the same hook without knowing about each other. No inheritance, no forking, no conflicts. Pluggy is battle-tested (it powers pytest's plugin system) and is a natural fit for Python.

This is similar to how Wagtail uses hooks within Django — apps register functions in a discoverable file, and the core calls them at defined points. Pluggy adds more structure on top: typed hookspecs, firstresult semantics (first non-None result wins), ordering via tryfirst/trylast, and a well-defined module lifecycle.

Example: pricing becomes extensible without inheritance

Today, customizing pricing requires forking the partner app and subclassing the strategy. Only one customization can exist. With hooks, multiple modules can participate in pricing:

python
# Oscar defines the hookspec
@hookspec
def calculate_price(product, quantity, context):
    """Return a Price or None to defer to the next module."""

# Module A: B2B pricing
@hookimpl
def calculate_price(product, quantity, context):
    if context.customer_group == "wholesale":
        return get_wholesale_price(product, quantity)

# Module B: volume discounts
@hookimpl
def calculate_price(product, quantity, context):
    if quantity >= 100:
        return apply_bulk_discount(product, quantity)

Both modules work side by side — no inheritance chain, no forking, no conflicts.

Example: stock validation becomes pluggable

Today, stock validation is baked into the availability policy classes. With hooks, modules can add custom validation without subclassing:

python
@hookspec
def validate_stock(product, quantity, context):
    """Validate stock availability. Raise ValidationError to reject."""

# Module: per-warehouse availability
@hookimpl
def validate_stock(product, quantity, context):
    warehouse = get_nearest_warehouse(context.shipping_address)
    if not warehouse.has_stock(product, quantity):
        raise ValidationError("Out of stock in your region")

# Module: pre-order support
@hookimpl
def validate_stock(product, quantity, context):
    if product.is_preorder and quantity > product.max_preorder_qty:
        raise ValidationError("Exceeds pre-order limit")

Data extensibility via relations, not field additions

Modules extend data by creating their own models with relations to Oscar's core models. For example, a gift wrapping module creates a GiftWrap model with a FK to Line, rather than forking the order app to add gift wrap fields to the line model. A subscription module creates a Subscription model linked to Product, rather than adding subscription fields to the product model.

Forking remains available for projects that truly need to add fields to core models, but it should be a project-level decision — not something reusable modules depend on.

Core / Storefront / Dashboard split

As proposed in #2972: separate Oscar into packages where storefront and dashboard depend on core, but not on each other. Core exposes services, storefront and dashboard consume them. The storefront becomes optional — not a required part of every Oscar installation.

Workflow / saga pattern (worth exploring)

Multi-step business processes like checkout (validate → allocate stock → process payment → create order → send confirmation) currently live in monolithic view methods with manual try/except for rollback. A workflow pattern — where each step defines its own compensation/rollback action — could make these processes more robust and extensible.

Medusa uses this pattern with composable workflow steps. In the Python ecosystem, Temporal provides durable workflow execution, though it's a heavy dependency. A lighter approach could be a simple step/compensation pattern built on top of the service layer and hooks.

Whether this is worth the complexity for Oscar is an open question — it may be that a well-structured service layer with hooks at the right points is sufficient for most use cases.

Incremental migration: the "v2" approach

Rather than a big-bang rewrite, new implementations can be built alongside existing ones as "v2" versions. The existing code keeps working as-is, while the improved version is developed in parallel. Once the v2 is stable and battle-tested, it becomes the default — and the old implementation is deprecated and eventually removed.

Concretely:

  • Service layer: New service classes are added next to the existing views. Views are gradually refactored to delegate to services. Both paths work during the transition — the old views still function, but the services become the canonical entry point.
  • Hooks: Hookspecs are introduced domain by domain. For each domain, the default hookimpl provides the same behavior as the current code. Modules can register their own hookimpls immediately, while projects that don't use hooks see no change.
  • Models: Where data models need to change (e.g., splitting StockRecord into separate pricing and inventory models), the new models can coexist with the old ones during a transition period. Data migrations handle the conversion.
  • Forking: The forking mechanism continues to work throughout. Projects that have forked apps keep working. The new hook-based extensibility is an alternative, not a forced replacement — though it becomes the recommended approach.

This means there's no single release where everything breaks. Each domain migrates independently, and projects can

Source: django-oscar/django-oscar