by Kai

A self-contained TypeScript/Express commerce backend covering the full shopping lifecycle — product catalog with variants and tags, cart management, atomic checkout with stock gating, order creation, and payment records stored in SQLite via `better-sqlite3`. Designed for AI outfit commerce demos, it exposes 25 pure service functions that can be called directly in-process or consumed over HTTP by frontend, recommendation, and payment blocks. Ships with 67 passing integration tests, 12 seeded demo products, and a clear extension point for swapping in a real payment provider via `payment_provider` and `provider_payment_id` columns.
Backend 7SND is a production-ready commerce backend block built for TypeScript/Node.js environments. Designed as the data and logic layer for an AI Outfit Commerce SaaS demo, it covers the full commerce lifecycle: product catalog with variants and tags, cart management, checkout sessions, mock payment processing, order creation, and inventory control — all exposed over a clean HTTP API.
This is a backend-only block. Frontend screens, real payment gateway integration, and marketplace logic are explicitly out of scope. Internal API routes are included as part of backend delivery.
style_tags, season_tags, occasion_tags, fit_tags, color_family) used for filtering and recommendation feedssrc/services/*.ts) with no HTTP dependency, enabling in-process consumption by co-located blocks| Layer | Technology |
|---|---|
| Runtime | Node.js + TypeScript |
| HTTP Framework | Express 4 |
| Database | SQLite via better-sqlite3 (synchronous) |
| Auth (demo) | X-Admin-Token header (admin), X-User-Id header (end user) |
| Test Runner | Custom HTTP integration suite (src/tests/run.ts) |
npm install
# Optional: compile TypeScript
npm run build
# Seed 12 demo products into commerce.db
npm run seed
# Start development server on :3000
npm run dev
# Run 67 HTTP-level integration tests
npm test
All variables are optional with sensible defaults.
| Variable | Default | Description |
|---|---|---|
PORT | 3000 | HTTP port |
DB_PATH | ./commerce.db | SQLite file path; use :memory: for ephemeral |
ADMIN_TOKEN | dev-admin-token | Required value for X-Admin-Token on admin routes |
DEFAULT_CURRENCY | USD | Fallback currency when a product omits it |
FLAT_SHIPPING_FEE | 10.00 | Added to subtotal at checkout |
ENABLE_SEED | true | Auto-seeds on boot if the products table is empty |
All routes are mounted under /api. All responses are JSON. Error shape:
{ "error": { "code": "validation_error", "message": "quantity must be >= 1" } }
Status codes: 400 validation · 401 unauthorized · 404 not found · 409 conflict · 500 server fault
GET /api/health
GET /api/products # List active products (paginated)
GET /api/products?limit=5&offset=0&category=tops
GET /api/products/:idOrSlug # Get single product by ID or slug
GET /api/products/search?q=blazer # Full-text-style search
GET /api/products/filter?style_tag=minimalist&color_family=white&in_stock=true
GET /api/recommendations/feed?style_tags=minimalist,classic&season_tags=spring&limit=6
Requires X-User-Id header on all requests.
GET /api/cart # View cart (auto-created on first read)
POST /api/cart/items # Add item (price_snapshot in body is ignored)
PATCH /api/cart/items/:cart_item_id # Update quantity (0 = remove)
DELETE /api/cart/items/:cart_item_id # Remove item
POST /api/cart/clear # Clear all items
Add item body:
{ "product_id": "<pid>", "variant_id": "<vid>", "quantity": 2 }
POST /api/checkout/sessions # Open checkout session (requires X-User-Id)
POST /api/payments/mock-confirm # Confirm or simulate-fail a mock payment
POST /api/orders # Create order from session (atomic)
GET /api/orders # List user's orders (requires X-User-Id)
GET /api/orders/:order_id # Order detail (requires X-User-Id)
Mock confirm body:
{ "checkout_session_id": "<sid>" }
Simulate failure:
{ "checkout_session_id": "<sid>", "simulate": "fail", "failed_reason": "card_declined" }
Create order body:
{
"checkout_session_id": "<sid>",
"shipping_address": {
"recipient": "Ada Lovelace",
"line1": "1 Analytical Way",
"city": "London",
"postal_code": "WC1",
"country": "UK"
}
}
All admin routes require X-Admin-Token: <ADMIN_TOKEN>.
GET /api/admin/products # List all products (any status)
POST /api/admin/products # Create product with variants and tags
PATCH /api/admin/products/:id # Update product fields
POST /api/admin/products/:id/archive # Soft-delete (archive) a product
POST /api/admin/products/:id/inventory # Set absolute stock on a variant
PUT /api/admin/products/:id/tags # Replace product tags
POST /api/admin/seed # Re-run seed (idempotent)
Create product body:
{
"name": "Linen Camp Shirt",
"price": 78,
"category": "tops",
"brand": "Atelier",
"variants": [{ "size": "M", "color": "sand", "stock_quantity": 12 }],
"tags": { "style_tags": ["minimalist"], "season_tags": ["summer"], "color_family": "beige" }
}
GET /api/admin/orders # List orders (filterable by order_status, payment_status)
GET /api/admin/orders/:order_id # Order detail
PATCH /api/admin/orders/:order_id/status # Advance fulfillment status
GET /api/admin/payments # List payments (filterable by status)
Order status values: pending → confirmed → preparing → shipped → delivered · canceled
Payment status values: pending · paid · failed · refunded
10 tables with the following relationships:
products ──┬── product_images
├── product_variants
└── product_tags
carts ──── cart_items ──── product_variants
checkout_sessions ── carts
orders ──── order_items ──── product_variants
└────── payments
UPDATE … WHERE stock_quantity >= ? inside the order transactionprice_snapshot values on cart items and order items are always read from the database; client-submitted prices are discardedAll 25 service functions are pure (no HTTP dependency) and importable directly for in-process use by co-located blocks.
| # | Function | File |
|---|---|---|
| 1–11 | listProducts, getProduct, searchProducts, filterProducts, listProductsForAdmin, createProduct, updateProduct, archiveProduct, updateInventory, updateProductTags, getRecommendationProductFeed | services/catalog.ts |
| 12–16 | getCart, addCartItem, updateCartItem, removeCartItem, clearCart | services/cart.ts |
| 17–21 | createCheckoutSession, confirmMockPayment, createOrderFromCheckout, getUserOrders, getOrderDetail | services/checkout.ts |
| 22–25 | listOrdersForAdmin, getOrderDetailForAdmin, updateOrderStatus, listPaymentsForAdmin | services/admin.ts |
Consumes catalog, cart, checkout, and order endpoints over HTTP. Must never submit price_snapshot values — the server reprices on every mutation.
Calls GET /api/recommendations/feed (or imports getRecommendationProductFeed in-process) to hydrate tag-matched products with current price, stock, images, and variants. The recommendation block remains stateless with respect to commerce data.
The payments table has payment_provider (free-form text, currently 'mock') and provider_payment_id columns ready for a real provider. A Stripe plugin would skip confirmMockPayment and pass its own provider_payment_id directly to createOrderFromCheckout. Webhook handling is the plugin's responsibility.
src/
app.ts # Express app factory
index.ts # Bootstrap: migrations, auto-seed, listen
config.ts # Environment-driven configuration
db.ts # better-sqlite3 + idempotent migrations
errors.ts # Typed error classes (HttpError, NotFound, Conflict, etc.)
types.ts # Shared row types and status unions
validators.ts # Zero-dependency input validators
seed.ts # 12 demo products
scripts/run-seed.ts # npm run seed entrypoint
tests/run.ts # npm test — HTTP integration suite (67 tests)
services/
catalog.ts # 11 catalog and admin product functions
cart.ts # 5 cart functions
checkout.ts # 5 checkout and order functions
admin.ts # 4 admin order and payment functions
routes/
catalog.ts # Public catalog endpoints
cart.ts # Cart endpoints
checkout.ts # Checkout, mock payment, user order endpoints
Tetrees License
Spin up an isolated sandbox and run it server-side — no local setup.
The sandbox audition completed and the detected runnable path passed.
This Express backend / api completed archive review with strong static results. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Pipeline avcp-2026-08-04.1 · SHA-256 89a5be0d1d3c2972…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Reviewed Aug 4, 2026
The full install guide and integration prompts unlock after purchase.
Push this product straight into your AI IDE, web builder or cloud IDE.
Connect Tetrees to a compatible AI IDE, list products you own, and request the verified ZIP without exposing seller upload controls.
21 ratings
Dropped it into my stack and it just worked. Used this store / POS to sell my storefront and it cut days off the build. Exactly as described.
Dropped it into my stack and it just worked. Setup was a single command and it ran first try, and examples matched the actual API, which is rare. Docking half a star only because I wanted a couple more examples.
Genuinely impressed. Used this store / POS to sell my storefront and it cut days off the build. No regrets.
Saved me a ton of time. Picked up "Commerce Backend Block Kit" for a client storefront — Handles the edge cases I usually have to patch myself. Minor tweaks needed for my use case but nothing broke.
Exactly what I needed. Picked up this store / POS for a client storefront — Components are cleanly separated and easy to extend. Minor tweaks needed for my use case but nothing broke.
Exactly what I needed. As someone who sells these all day, typeScript types are actually accurate, no fighting the compiler. Will definitely check their other products.
Better than I expected. As someone who sells these all day, the abstractions are sensible and easy to swap out. Highly recommend.
Clean and well thought out. Components are cleanly separated and easy to extend, and the walkthrough got me running in minutes. Already using it in production.
This is a keeper. As someone who sells these all day, zero mystery dependencies, everything is documented.
Better than I expected. Used "Commerce Backend Block Kit" to sell my storefront and it cut days off the build. Docking half a star only because I wanted a couple more examples.
Sign in to join the discussion
Loading discussion…