Architecture Overview
Core design
Section titled “Core design”rCommerce is a single Rust binary with a PostgreSQL backend. Every request flows through the same typed core over the REST API.
Frontends (Next.js, Astro, iOS, Android, POS) ↓ REST + WebSocket API ↓ rCommerce Core (Rust) ┌───────────────────────┐ │ Catalog │ Cart │ Orders│ │ Payments│ Tax │ Auth │ │ Shipping│ Pricing│ Inventory│ └───────────────────────┘ ↓ PostgreSQLState changes → events
Section titled “State changes → events”Every state change in the core fans out as a signed event:
- Webhooks — HTTP POST to registered endpoints
- Email — transactional notifications (order confirmation, shipping, password reset)
- Analytics — event tracking
- OpenTelemetry — traces and metrics
Request lifecycle
Section titled “Request lifecycle”- Client sends REST request
- Axum router matches handler
- Middleware: JWT/API key auth, rate limiting, CORS
- Handler calls service layer
- Service validates, applies business logic
- Repository writes to PostgreSQL
- Events dispatched (webhooks, email, etc.)
- Response returned to client
Service layer
Section titled “Service layer”Each domain has a service:
ProductService— catalogue managementCartService— cart operations, bundle expansionCheckoutService— checkout flow, tax, shippingOrderService— order lifecycle, fulfillmentAuthService— JWT tokens, API keys, password resetNotificationService— email, SMS, webhooks
Services are injected into handlers via Axum state.
Repository layer
Section titled “Repository layer”Each entity has a repository trait:
#[async_trait]pub trait ProductRepository { async fn find_by_id(&self, id: Uuid) -> Result<Option<Product>>; async fn create(&self, product: CreateProduct) -> Result<Product>; async fn update(&self, id: Uuid, product: UpdateProduct) -> Result<Product>; async fn delete(&self, id: Uuid) -> Result<bool>; async fn list(&self, filter: ProductFilter) -> Result<Vec<Product>>;}PostgreSQL implementation uses SQLx with compile-time query checking.
Error handling
Section titled “Error handling”Custom Error enum with HTTP status code mapping:
pub enum Error { Validation(String), // 400 Unauthorized(String), // 401 Forbidden(String), // 403 NotFound(String), // 404 Conflict(String), // 409 RateLimited(String), // 429 Internal(String), // 500 // ...}Configuration
Section titled “Configuration”All configuration in one TOML file. Validated at boot — typos fail fast.
[server]host = "0.0.0.0"port = 8080
[database]db_type = "Postgres"# ...Deployment
Section titled “Deployment”Single binary, no runtime dependencies:
rcommerce serve -c config.tomlOr via systemd, Docker, or any process manager. Migrations run automatically on startup.