Cart Database
PostgreSQL database that is the system of record for shopping carts and their items.
What is this?
The Cart Database is the authoritative store for shopping carts at Acme Inc. The Cart APICart APIServicev1.0.0The public-facing API for shopping carts. Handles commands to add and remove items and to check out, and publishes an ev...Publishescart-checked-out, calculate-discountSubscribesadd-item-to-cart, remove-item-from-cart +1APIsOpenAPIOwnershopping-platformMapRepoView docs reads from and writes to it as customers add, remove and check out items.
What does it store?
- Carts — one row per cart: id, customer, status and timestamps.
- Cart Items — one row per item in a cart: product, quantity and unit price.
Schema
-- Cart Database — system of record for shopping carts
CREATE TABLE carts ( cart_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), customer_id UUID, status TEXT NOT NULL DEFAULT 'OPEN' CHECK (status IN ('OPEN', 'CHECKED_OUT', 'ABANDONED')), currency CHAR(3) NOT NULL DEFAULT 'USD', created_at TIMESTAMPTZ NOT NULL DEFAULT now(), updated_at TIMESTAMPTZ NOT NULL DEFAULT now());
CREATE TABLE cart_items ( cart_id UUID NOT NULL REFERENCES carts (cart_id) ON DELETE CASCADE, product_id UUID NOT NULL, quantity INTEGER NOT NULL CHECK (quantity > 0), unit_price_cents INTEGER NOT NULL CHECK (unit_price_cents >= 0), PRIMARY KEY (cart_id, product_id));
CREATE INDEX idx_carts_customer ON carts (customer_id);CREATE INDEX idx_carts_status ON carts (status);Retention
Carts are transient. Abandoned carts are pruned after 90 days (see frontmatter). A checked-out cart’s contents live on in the Cart Checked OutCart Checked OutEventv1.0.0Published when a customer has checked out their cart. Ownershopping-platformSchemaMapView docs event and downstream order records.