Commerce training features¶
The shop has two layers of training features, both live on every profile and
on awesome.byst.re and aitesters.byst.re (current images:
CONTAINER_RELEASES.md):
- Shop features in the backend. Coupons, reviews, wishlist, product CSV,
idempotent checkout, conditional product updates, and the
warehousedemo user withROLE_WAREHOUSE. - Warehouse fulfilment, returns and purchasing in
warehouse-service. Shipments and the pick/pack/ship/deliver workflow, returns (RMA), suppliers, purchase orders and reorder suggestions, served by a separate Rust service (see below).
The business rules were written down for the original Java backend in
test-secure-backend/docs/COMMERCE_AND_FULFILMENT.md
(archived); backend-rs implements them unchanged.
What students can test¶
| Area | Screens | API | Good exercises |
|---|---|---|---|
| Coupons | Cart coupon panel, checkout summary, /admin/coupons |
PUT/DELETE /api/v1/cart/coupon, /api/v1/admin/coupons |
Boundary values (minimum subtotal, validity window, usage limits), decision tables, a coupon that stops qualifying between cart and checkout |
| Reviews | Product page reviews, /admin/reviews |
/api/v1/products/{id}/reviews, /api/v1/admin/reviews |
Eligibility (only after delivery), moderation states, average rounding |
| Wishlist | Product page toggle, /wishlist |
/api/v1/wishlist |
Create vs update status codes (201/200), back-in-stock email after a 0 → n stock change |
| Product CSV | /admin/products CSV panel |
/api/v1/admin/products/export, /api/v1/admin/products/import |
File upload and download, all-or-nothing validation, dry run, CSV formula injection |
| Idempotent checkout | Checkout | POST /api/v1/orders with Idempotency-Key |
Safe retries, replay header, conflicting reuse, per-user scope |
| Conditional updates | Admin product form | GET/PUT /api/v1/products/{id} with ETag, If-None-Match, If-Match |
304, 412 lost-update protection |
| Warehouse role | Sign-in as warehouse |
POST /api/v1/users/signin |
Role claims in the access token; admin-only endpoints return 403 for the warehouse role |
A typical end-to-end scenario:
clientadds products, appliesWELCOME10and checks out with anIdempotency-Key, then retries the same request safely.adminmarks the orderPAID, thenDELIVEREDthrough the existing status endpoint.clientreviews the product and adds an out-of-stock item to the wishlist.adminmoderates the review and restocks the wishlisted product; the back-in-stock email arrives.warehousepicks, packs and ships the order;clientfollows the shipment and requests a return, whichadminapproves and refunds.
Demo data¶
Profiles that seed demo data (local in the lightweight profile, demo in
the full profile) add:
- user
warehouse/warehousewithROLE_WAREHOUSE; - coupons
WELCOME10(10 % from 50.00),SAVE50(50.00 off from 300.00, 100 uses),EXPIRED20(expired) andSPRING25(starts in a week).
warehouse-service seeds the demo suppliers "Nordic Electronics" and "Baltic Gadgets" in the same profiles.
The server profile does not seed demo data.
Compatibility¶
- Existing request bodies, paths, status codes and enum values are unchanged,
including
OrderStatus. New response fields are additive and new request headers are optional, so the AI Testers API course suite keeps passing. - Database migration
V7adds tables and widens existing check constraints; it does not rewrite existing rows except to backfillorders.subtotal_amount. - The backend renders the subject and body of every customer email (since
backend 3.14.0 also for warehouse shipment and return emails, from template
properties). Consumer 3.6.0 delivers that text unchanged and maps unknown
template names to
GENERIC, so the local outbox and Mailpit show the same email. - Browser CORS now allows
Idempotency-Key,If-MatchandIf-None-Matchand exposesETag,Idempotent-ReplayedandContent-Disposition; requests through the gateway are same-origin and unaffected.
warehouse-service¶
warehouse-service hosts the Tier 2 features: shipments and the
pick/pack/ship/deliver workflow, returns (RMA) with proportional refunds,
suppliers, purchase orders and reorder suggestions. The backend keeps users,
JWT issuance, products, stock, cart, coupons, reviews, wishlist and orders, and
mirrors the shipment state in orders.fulfilment_state. The boundary is
specified in WAREHOUSE_SERVICE_CONTRACT.md.
| Area | Screens | API (through the gateway) | Good exercises |
|---|---|---|---|
| Warehouse | /warehouse (warehouse or admin role) |
/api/v1/warehouse/**, GET /api/v1/orders/{id}/shipment |
State machine, carrier-specific tracking formats, role-based access, cancellation rules |
| Returns | Order page return form, /returns, /admin/returns |
/api/v1/orders/{id}/returns, /api/v1/returns, /api/v1/admin/returns |
30-day window, returnable quantities, restocking, proportional refunds with coupons |
| Purchasing | /admin/purchasing |
/api/v1/admin/suppliers, /api/v1/admin/purchase-orders, /api/v1/admin/inventory/reorder-suggestions |
Partial receipts, over-receipt, receipt idempotency, reorder arithmetic |
Paths and bodies are unchanged for the frontend: the gateway routes them to
warehouse-service. Two services and a service-to-service call add exercises in
distributed failure: what a customer sees when warehouse-service is down (the
gateway returns 502) or when the backend is down (warehouse-service returns 503
Backend unavailable).
Deployment¶
- Profiles. lightweight, full and server all run
warehouse-serviceon internal port 4003 (never published on the host). - lightweight:
docker,demoprofiles, tmpfs PostgreSQLtestdbshared with the backend (?currentSchema=warehouse); - full:
dockerprofile, PostgreSQLtestdbwith?currentSchema=warehouse; - server:
dockerprofile, same database and schema,mem_limit: 160m(Rust binary, about 7–10 MiB measured); - server sandbox:
aitesters-warehouse-service, paired withaitesters-backendand using thewarehouseschema ofaitesters-postgres. - Secrets and database role. The backend signs access tokens with RS256
(
JWT_SIGNING_KEY, a base64 PKCS#8 RSA key; local profiles leave it empty, so the backend generates an ephemeral key per start). warehouse-service holds no signing secret: it verifies tokens with the backend's/internal/v1/jwks.json.WAREHOUSE_SERVICE_TOKENauthenticates warehouse-service to the backend/internal/v1API. warehouse-service connects as its ownwarehousedatabase role, which owns only thewarehouseschema; the one-shotpostgres-rolesservice (postgres/service-roles.sh, which runspostgres/service-role.shfor thewarehouseandpaymentroles) creates or updates that role before every warehouse-service start (WAREHOUSE_DB_PASSWORD, defaultlocal-warehouse-db-passwordlocally). The server takes the values from Ansible Vault (jwt_signing_key,warehouse_service_token,warehouse_postgres_passwordand theiraitesters_counterparts). - Gateway. Warehouse locations precede the generic
/api/v1/route,/warehouse/v3/api-docsexposes the warehouse OpenAPI document, and/internal/returns 404. The upstream is resolved at request time, so the gateway still starts without warehouse-service. Theaitesters.byst.rehost routes the same paths toaitesters-warehouse-service. - Monitoring. The host watchdog reports a missing, exited or unhealthy
warehouse-service; the deploy's verify role requests
https://awesome.byst.re/warehouse/v3/api-docs. - Memory. Container limits and measured usage are listed in PRODUCTION_MONITORING_PLAN.md.
- Image. Every profile pins a published
tag@sha256reference; the server deployment refuses an unpinned image. - Payments and tracking. Card payments run in
payment-service(port 4004, schema and rolepayment), deployed the same way; see PAYMENT_SERVICE_CONTRACT.md. Shipment tracking is part of warehouse-service 1.2.0; see the tracking addendum in WAREHOUSE_SERVICE_CONTRACT.md.