# pdg-global/rcommerce-core architecture

> Architecture diagram of the GitHub repository pdg-global/rcommerce-core, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pdg-global/rcommerce-core
- Repository: https://github.com/pdg-global/rcommerce-core

## Overview

#### 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: [`crates/rcommerce-core/src/services/checkout_service.rs`](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/services/checkout_service.rs) (Checkout service), [`crates/rcommerce-api/src/server.rs`](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/server.rs) (Axum API server), [`crates/rcommerce-core/src/repository/traits.rs`](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/repository/traits.rs) (Repository boundary), [`Cargo.toml`](https://github.com/pdg-global/rcommerce-core/blob/main/Cargo.toml) (Rust workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_workspace["Rust workspace<br/>[Cargo.toml]"]
  node_app["Management binary<br/>[main.rs]"]
  node_cli["Admin CLI<br/>binary<br/>[main.rs]"]
end

subgraph group_api["HTTP API"]
  node_api_server["Axum API server<br/>HTTP server<br/>[server.rs]"]
  node_routes["Commerce routes<br/>route layer"]
  node_api_auth["API auth and scopes<br/>middleware<br/>[api_key_auth.rs]"]
  node_tls["TLS boundary<br/>[server_tls.rs]"]
end

subgraph group_core["Commerce Core"]
  node_core_models["Commerce models<br/>domain models"]
  node_checkout["Checkout service<br/>application service"]
  node_order["Order pricing and lifecycle<br/>order domain<br/>[calculation.rs]"]
  node_inventory["Inventory reservation<br/>consistency service<br/>[reservation.rs]"]
  node_tax_shipping["Tax and shipping calculation<br/>calculation services<br/>[service.rs]"]
  node_repositories["Repository boundary<br/>repository traits<br/>[traits.rs]"]
end

subgraph group_infra["Infrastructure"]
  node_postgres[("PostgreSQL<br/>primary database<br/>[db.rs]")]
  node_redis[("Optional Redis<br/>cache/session broker")]
  node_jobs["Background jobs and dunning<br/>async workers"]
  node_websocket["WebSocket delivery<br/>real-time subsystem"]
end

subgraph group_external["External Adapters"]
  node_payments{{"Payment gateway adapters<br/>payment integration<br/>[agnostic.rs]"}}
  node_shipping_providers{{"Shipping providers<br/>shipping integration"}}
  node_notifications{{"Email notifications<br/>notification service<br/>[service.rs]"}}
  node_imports{{"Platform imports<br/>import adapters"}}
end

node_workspace -->|"builds"| node_app
node_workspace -->|"builds"| node_cli
node_workspace -->|"includes"| node_api_server
node_app -->|"runs"| node_api_server
node_cli -->|"admin operations"| node_repositories
node_api_server -->|"secures with"| node_tls
node_api_server -->|"applies"| node_api_auth
node_api_server -->|"serves"| node_routes
node_api_auth -.->|"sessions and rate limits"| node_redis
node_routes -->|"cart and checkout requests"| node_checkout
node_routes -->|"catalog and account requests"| node_core_models
node_checkout -->|"prices and transitions"| node_order
node_checkout -->|"reserves stock"| node_inventory
node_checkout -->|"calculates totals"| node_tax_shipping
node_checkout -->|"authorizes and captures"| node_payments
node_checkout -->|"persists commerce state"| node_repositories
node_repositories -->|"PostgreSQL implementations"| node_postgres
node_tax_shipping -->|"rates and fulfillment"| node_shipping_providers
node_jobs -->|"dunning and retries"| node_payments
node_jobs -->|"sends asynchronously"| node_notifications
node_jobs -.->|"queue/pub-sub support"| node_redis
node_websocket -.->|"pub/sub"| node_redis
node_imports -->|"writes imported data"| node_repositories

click node_workspace "https://github.com/pdg-global/rcommerce-core/blob/main/Cargo.toml"
click node_app "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce/src/main.rs"
click node_cli "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-cli/src/main.rs"
click node_api_server "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/server.rs"
click node_api_auth "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/middleware/api_key_auth.rs"
click node_tls "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/server_tls.rs"
click node_checkout "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/services/checkout_service.rs"
click node_order "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/order/calculation.rs"
click node_inventory "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/inventory/reservation.rs"
click node_tax_shipping "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/tax/service.rs"
click node_repositories "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/repository/traits.rs"
click node_postgres "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/db.rs"
click node_payments "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/payment/agnostic.rs"
click node_notifications "https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/notification/service.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_workspace,node_app,node_cli toneBlue
class node_api_server,node_routes,node_api_auth,node_tls toneAmber
class node_core_models,node_checkout,node_order,node_inventory,node_tax_shipping,node_repositories toneMint
class node_postgres,node_redis,node_jobs,node_websocket toneRose
class node_payments,node_shipping_providers,node_notifications,node_imports toneIndigo
```

## Components

### Entry Points

- [Rust workspace](https://github.com/pdg-global/rcommerce-core/blob/main/Cargo.toml): workspace · `Cargo.toml`
- [Management binary](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce/src/main.rs): binary · `crates/rcommerce/src/main.rs`
- [Admin CLI](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-cli/src/main.rs): binary · Setup and operational commands. · `crates/rcommerce-cli/src/main.rs`

### HTTP API

- [Axum API server](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/server.rs): HTTP server · Owns serving, route assembly, and request state. · `crates/rcommerce-api/src/server.rs`
- **Commerce routes**: route layer · Auth, catalog, cart, checkout, orders, and admin endpoints.
- [API auth and scopes](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/middleware/api_key_auth.rs): middleware · `crates/rcommerce-api/src/middleware/api_key_auth.rs`
- [TLS boundary](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-api/src/server_tls.rs): TLS · Configurable TLS including Let's Encrypt. · `crates/rcommerce-api/src/server_tls.rs`

### Commerce Core

- **Commerce models**: domain models · Products, customers, carts, orders, coupons, and subscriptions.
- [Checkout service](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/services/checkout_service.rs): application service · Coordinates purchase use cases. · `crates/rcommerce-core/src/services/checkout_service.rs`
- [Order pricing and lifecycle](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/order/calculation.rs): order domain · `crates/rcommerce-core/src/order/calculation.rs`
- [Inventory reservation](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/inventory/reservation.rs): consistency service · `crates/rcommerce-core/src/inventory/reservation.rs`
- [Tax and shipping calculation](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/tax/service.rs): calculation services · `crates/rcommerce-core/src/tax/service.rs`
- [Repository boundary](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/repository/traits.rs): repository traits · Isolates domain services from persistence. · `crates/rcommerce-core/src/repository/traits.rs`

### Infrastructure

- [PostgreSQL](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/db.rs): primary database · Required persistence store and migration target. · `crates/rcommerce-core/src/db.rs`
- **Optional Redis**: cache/session broker · Supports cache, tokens, pub/sub, and rate limits.
- **Background jobs and dunning**: async workers · Scheduled work, retries, dead letters, and payment dunning.
- **WebSocket delivery**: real-time subsystem · Authenticated broadcast and pub/sub connections.

### External Adapters

- [Payment gateway adapters](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/payment/agnostic.rs): payment integration · Gateway-agnostic interface with Stripe and WeChat Pay adapters. · `crates/rcommerce-core/src/payment/agnostic.rs`
- **Shipping providers**: shipping integration · Carrier/provider adapters including EasyPost and ShipStation.
- [Email notifications](https://github.com/pdg-global/rcommerce-core/blob/main/crates/rcommerce-core/src/notification/service.rs): notification service · Channel, service, and template boundary. · `crates/rcommerce-core/src/notification/service.rs`
- **Platform imports**: import adapters · Imports Shopify, WooCommerce, Magento, and Medusa data.

## Connections

- 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
