How pdg-global/rcommerce-core works
Purpose and workspace entry points
R Commerce is a Rust headless e-commerce engine: API-first commerce capabilities backed by PostgreSQL, with optional Redis and pluggable external integrations. The workspace is defined by Cargo.toml. Operational entry points are the management/application binary at crates/rcommerce/src/main.rs, CLI commands in crates/rcommerce-cli/src/main.rs, and the Axum API library/server in crates/rcommerce-api/src/lib.rs and crates/rcommerce-api/src/server.rs. Demo-facing executables are separate: crates/rcommerce-demo/src/main.rs and crates/rcommerce-demo-server/src/main.rs.
HTTP edge and access control
The API crate owns HTTP serving, route assembly, request state, TLS, and auth boundaries. Domain routes cover authentication, products, carts, checkout, orders, payments, subscriptions, webhooks, and administration under crates/rcommerce-api/src/routes/. API-key validation and authorization scopes are middleware concerns in crates/rcommerce-api/src/middleware/api_key_auth.rs and crates/rcommerce-api/src/middleware/scopes.rs. TLS is implemented as a server boundary with configurable/Let’s Encrypt support in crates/rcommerce-api/src/server_tls.rs and crates/rcommerce-api/src/tls/letsencrypt.rs.
Core domain and persistence boundary
rcommerce-core is the shared business library. It defines commerce entities—products, customers, carts, orders, coupons, subscriptions—in crates/rcommerce-core/src/models/. Services coordinate use cases while repositories isolate persistence: crates/rcommerce-core/src/services/checkout_service.rs, crates/rcommerce-core/src/repository/traits.rs, and PostgreSQL implementations under crates/rcommerce-core/src/repository/postgres/. PostgreSQL is required; connection/migration responsibilities reside in crates/rcommerce-core/src/db.rs, crates/rcommerce-core/src/db/migrate.rs, and schema evolution in crates/rcommerce-core/migrations/.
Commerce transaction flow
A typical purchase flows from cart operations through checkout into pricing/order/payment orchestration: API routes (crates/rcommerce-api/src/routes/cart.rs, crates/rcommerce-api/src/routes/checkout.rs) invoke core services, which calculate/order transitions in crates/rcommerce-core/src/order/calculation.rs, crates/rcommerce-core/src/order/lifecycle.rs, and persist through repositories. Inventory reservation/tracking is a distinct consistency concern in crates/rcommerce-core/src/inventory/reservation.rs and crates/rcommerce-core/src/inventory/service.rs. Taxes and shipping calculations are separable subsystems in crates/rcommerce-core/src/tax/service.rs and crates/rcommerce-core/src/shipping/calculation.rs.
External integration adapters
Payments use a gateway-agnostic abstraction with provider adapters, keeping gateway-specific protocols outside checkout/order logic: crates/rcommerce-core/src/payment/agnostic.rs, crates/rcommerce-core/src/payment/gateways/stripe.rs, and crates/rcommerce-core/src/payment/gateways/wechatpay.rs. Shipping follows an equivalent provider/carrier split, including EasyPost and ShipStation: crates/rcommerce-core/src/shipping/providers/, crates/rcommerce-core/src/shipping/carriers/, and crates/rcommerce-core/src/shipping/mod.rs. Notifications have channel/service/template boundaries, principally email: crates/rcommerce-core/src/notification/service.rs, crates/rcommerce-core/src/notification/channels/email.rs, and crates/rcommerce-core/src/notification/templates/.
Async, cache, and real-time infrastructure
Redis is optional infrastructure for cache, sessions/tokens, pub/sub, and rate limiting, behind modules in crates/rcommerce-core/src/cache/. Background work—including scheduled jobs, retries, dead-letter handling, workers, and payment dunning—is organized in crates/rcommerce-core/src/jobs/ and crates/rcommerce-core/src/payment/dunning.rs. Real-time delivery is a separate WebSocket subsystem with authenticated connections, broadcast, and pub/sub in crates/rcommerce-core/src/websocket/.
Configuration and administration
Runtime configuration centralizes database, server, cache, media, and integration settings in crates/rcommerce-core/src/config.rs, with an example at config.example.toml. The CLI is the administrative control plane for setup and email/shell operations (crates/rcommerce-cli/src/commands/setup.rs, crates/rcommerce-cli/src/commands/email.rs). Import adapters support migration from Shopify, WooCommerce, Magento, and Medusa through crates/rcommerce-core/src/import/platforms/.
Main entry points: checkout_service.rs Checkout service · server.rs Axum API server · traits.rs Repository boundary · Cargo.toml Rust workspace
Components 21
Entry Points
- Rust workspace
Cargo.toml - Management binary
crates/rcommerce/src/main.rs - Admin CLI · Setup and operational commands.
crates/rcommerce-cli/src/main.rs
HTTP API
- Axum API server · Owns serving, route assembly, and request state.
crates/rcommerce-api/src/server.rs - Commerce routes · Auth, catalog, cart, checkout, orders, and admin endpoints.
- API auth and scopes
crates/rcommerce-api/src/middleware/api_key_auth.rs - TLS boundary · Configurable TLS including Let's Encrypt.
crates/rcommerce-api/src/server_tls.rs
Commerce Core
- Commerce models · Products, customers, carts, orders, coupons, and subscriptions.
- Checkout service · Coordinates purchase use cases.
crates/rcommerce-core/src/services/checkout_service.rs - Order pricing and lifecycle
crates/rcommerce-core/src/order/calculation.rs - Inventory reservation
crates/rcommerce-core/src/inventory/reservation.rs - Tax and shipping calculation
crates/rcommerce-core/src/tax/service.rs - Repository boundary · Isolates domain services from persistence.
crates/rcommerce-core/src/repository/traits.rs
Infrastructure
- PostgreSQL · Required persistence store and migration target.
crates/rcommerce-core/src/db.rs - Optional Redis · Supports cache, tokens, pub/sub, and rate limits.
- Background jobs and dunning · Scheduled work, retries, dead letters, and payment dunning.
- WebSocket delivery · Authenticated broadcast and pub/sub connections.
External Adapters
- Payment gateway adapters · Gateway-agnostic interface with Stripe and WeChat Pay adapters.
crates/rcommerce-core/src/payment/agnostic.rs - Shipping providers · Carrier/provider adapters including EasyPost and ShipStation.
- Email notifications · Channel, service, and template boundary.
crates/rcommerce-core/src/notification/service.rs - Platform imports · Imports Shopify, WooCommerce, Magento, and Medusa data.
Connections 23
- Rust workspace → Management binary: builds
- Rust workspace → Admin CLI: builds
- Rust workspace → Axum API server: includes
- Management binary → Axum API server: runs
- Admin CLI → Repository boundary: admin operations
- Axum API server → TLS boundary: secures with
- Axum API server → API auth and scopes: applies
- Axum API server → Commerce routes: serves
- API auth and scopes → Optional Redis: sessions and rate limits
- Commerce routes → Checkout service: cart and checkout requests
- Commerce routes → Commerce models: catalog and account requests
- Checkout service → Order pricing and lifecycle: prices and transitions
- Checkout service → Inventory reservation: reserves stock
- Checkout service → Tax and shipping calculation: calculates totals
- Checkout service → Payment gateway adapters: authorizes and captures
- Checkout service → Repository boundary: persists commerce state
- Repository boundary → PostgreSQL: PostgreSQL implementations
- Tax and shipping calculation → Shipping providers: rates and fulfillment
- Background jobs and dunning → Payment gateway adapters: dunning and retries
- Background jobs and dunning → Email notifications: sends asynchronously
- Background jobs and dunning → Optional Redis: queue/pub-sub support
- WebSocket delivery → Optional Redis: pub/sub
- Platform imports → Repository boundary: writes imported data