Spree Commerce

On this page 7

Spree Commerce is an open-source e-commerce platform written in Ruby on Rails that provides the core of an online store, including catalog, cart, checkout, orders, payments, shipping, taxes and an administration panel, as a set of Rails components that developers extend in code. Among store platforms in e-commerce, it belongs to the group of developer-oriented, self-hosted frameworks rather than ready-made hosted services.

The project started in 2007 and has gone through several major versions. Its design favors API-first and headless use: the same commerce engine can serve a classic server-rendered storefront, a separate JavaScript front end, a mobile app or a marketplace with many vendors.

How Spree Commerce is built

Spree Commerce is built as a collection of Rails engines packaged as Ruby gems, which a developer adds to a Rails application. The engines share one relational database, usually PostgreSQL or MySQL, and expose models, controllers and views that the host application can reuse or override.

The main parts are listed below. Recent versions have reorganized the packages, so names differ slightly between releases, but the division of responsibilities has stayed similar.

ComponentResponsibilityTypical consumer
CoreData models and business logicAll other components
Storefront APIShopper-facing endpoints for cart and checkoutHeadless front ends, mobile apps
Platform APIAdministrative endpoints for catalog and ordersIntegrations, back-office tools
AdminWeb dashboard for merchantsStore staff and operators
StorefrontServer-rendered shop templatesMerchants without a separate front end
Main components of Spree Commerce

The APIs follow the JSON:API specification for request and response formats, and the administrative API uses OAuth 2.0 tokens for authorization. This makes Spree suitable as the commerce layer in a headless commerce or composable commerce architecture.

The Spree data model and checkout flow

The Spree data model separates products from variants: a product holds shared information such as name and description, while each variant represents a purchasable combination of options, such as size and color, with its own SKU and price. Categories are organized as taxonomies and taxons, which form trees for navigation and filtering.

Stock is tracked per variant in stock locations, which allows one store to fulfill from several warehouses or shops. An order contains line items, shipments, payments and adjustments, the general mechanism for taxes, promotions and other price changes.

Checkout is driven by an order state machine. The default sequence is shown in the table; developers can add, remove or reorder steps in code.

StateWhat happensData recorded
CartShopper adds or removes itemsLine items, quantities
AddressBilling and shipping addresses enteredAddress records
DeliveryShipping method selected per shipmentShipments, shipping rates
PaymentPayment method chosen and authorizedPayment records, gateway response
ConfirmOptional review step before placingFinal totals
CompleteOrder placed and stock allocatedOrder number, completion time
Default order states in Spree checkout

Because state transitions trigger callbacks, the state machine is also the main extension point for custom logic, such as fraud checks before payment or extra validation for business customers.

Spree compared with other store platforms

Spree is best understood as a framework for building a store, not as a finished hosted product. Merchants trade setup speed for control over code, data and hosting, which places it closer to Solidus, Sylius, Saleor and Medusa than to Shopify or Wix eCommerce.

The comparison below summarizes how Spree differs from several neighbors in the store platforms topic.

PlatformLanguage or stackHosting modelTypical buyer
Spree CommerceRuby on RailsSelf-hosted or managedTeams with Rails developers
SolidusRuby on RailsSelf-hostedRails teams wanting a conservative fork
SyliusPHP, SymfonySelf-hostedTeams with Symfony developers
MedusaNode.js, TypeScriptSelf-hosted or cloudJavaScript-focused teams
ShopifyProprietaryHosted software as a serviceMerchants wanting speed over control
Spree Commerce and related platforms

Solidus deserves special mention: it began in 2015 as a fork of Spree and still shares much of its original data model, so experience and some extensions transfer between the two, although the projects have diverged considerably.

Customization, extensions and licensing

Spree is customized mainly through Ruby code in the host application. Developers override views, add models and attach behavior to core classes, traditionally through decorators that reopen Spree classes with additional methods. Shared functionality is distributed as extension gems, for example for payment gateways, product reviews or multi-vendor marketplaces.

The flexibility has a cost. Heavy use of decorators couples the store to internal implementation details, which makes major version upgrades difficult. Recent versions encourage events, dependency injection and API-level integration to reduce that coupling.

Licensing should be checked for each major version. Older releases were distributed under the permissive BSD 3-Clause license, while newer releases introduced different terms for parts of the code base, including a commercial option for some features. A merchant planning a closed-source deployment should review the license of the exact version before committing.

When Spree is a good fit and when it is not

Spree suits organizations whose requirements do not fit a standard hosted platform and that can maintain a Rails application over several years. Native support for multiple stores, currencies and languages from one installation makes it common in cross-border retail and B2B portals.

Project situationFitReason
Complex B2B pricing and approval rulesGood fitLogic can be coded directly in the core
Multi-vendor marketplaceGood fitMarketplace extensions and flexible data model
In-house Rails team already in placeGood fitReuses existing skills and infrastructure
Small shop without developersPoor fitHosting, security and upgrades need engineers
Need for a large app marketplacePoor fitExtension ecosystem is far smaller than Shopify’s
Deciding whether Spree fits a project

The most common mistakes are underestimating operating costs, such as hosting, PCI DSS scope for payment handling and security patching, and over-customizing the core so that later upgrades require a near rewrite.

In everyday language

Spree Commerce is like a professional kit for building an online shop. It already contains the hard parts, such as the shopping cart, checkout, product list and order tracking, but a programmer has to assemble them, decide how the shop looks and keep it running.

Services such as Shopify are more like renting a furnished store: quick to open, but with limited changes. Spree is closer to owning the building. You get full control, but you also take responsibility for maintenance.

Seen in the real world

A European distributor of industrial fasteners wanted an online portal where about 2,000 business customers could see negotiated price lists, order by SKU and request approval for orders above a set limit. Standard hosted platforms required costly workarounds for these rules.

Its four-person Rails team built the portal on Spree Commerce, using separate stores for three countries with local currencies and languages. They added an approval step to the order state machine and synchronized prices and stock with the company’s ERP system through the Platform API every few minutes.

Within a year, most repeat orders moved online from email and phone, and the sales team spent more time on new accounts. The company also budgeted one developer for upgrades and security patches, because ownership of the code meant ownership of its maintenance.