Back to Arky

Arky Docs

Implementation docs for using Arky as the backend under custom websites.

Arky is a backend for a custom website. The frontend can be Astro, Svelte, React, Vue, plain TypeScript, or an agent-generated storefront. Arky provides the Admin, the records, the storefront APIs, the SDK helpers, and the modules behind the website.

Build From This Mental Model

Keep the website custom. Put repeat backend work in Arky: Content, commerce, bookings, forms, customers, actions, store email, newsletters, support, Admin, API, and SDK.

The Storefront Contract

import { initialize } from "arky-sdk/storefront";
import { createOrderToken } from "arky-sdk/utils";

export const arky = initialize("arky_pk_...", {
	locale: "en",
	market: "eu",
	createVisitorIdentity: () => ({
		customer_id: crypto.randomUUID(),
		session_id: crypto.randomUUID(),
	}),
	createSessionId: () => crypto.randomUUID(),
	createId: () => crypto.randomUUID(),
	createOrderToken,
});

arky.pageViews.send({ path: location.pathname, referrer: document.referrer });

const { items: packages } = await arky.eshop.package.find();
const shopPackage = packages.find((candidate) => candidate.key === "public");
if (!shopPackage) throw new Error("This buyer can't shop here");
const cart = arky.eshop.cart({ buyer: { type: "customer" }, package_id: shopPackage.id });
await cart.load();

After initialize, use only the modules the website needs. A content site might use content, forms, actions and pageViews. A storefront adds eshop.cart, products, promotions and checkout. A service business adds bookings through the cart. A newsletter is a free package people join.

Three rules hold everywhere:

  1. The app picks every id. Creates carry a UUID v4 from your createId, or one you pass. The SDK keeps a pending id until its answer and sends the same request again under it, so a retry never makes a duplicate.
  2. Changes carry what they read. Updates and actions send the expected_updated_at they read; a stale one is refused. Stock actions and two conversation actions name the value they read instead, and a package’s access row, which has no version, is deleted by its id alone.
  3. Language and market are explicit, and the key decides the channel. The storefront sends its language, and its market on every commercial call; its publishable key belongs to one sales channel. Every product read and cart names its package. Arky never falls back to a default.

Build Order

Build on a free test store, and go live on a second store set up by the same script.

  1. Call initialize once when the page or app starts.
  2. Read editable copy from Content collections and entries.
  3. Add commerce or bookings when the flow needs products, carts, availability, quotes or checkout.
  4. Track important moments with action keys such as lead.submitted or checkout.started, and count page views with pageViews.send.
  5. Create the webhook at Arky’s address in the store’s own Resend account and connect the account with its signing secret, verify its domain there, add a sending address and select a complete email for each purpose the store sends, so receipts, sign-in codes and the other emails go out from the store’s own address.
  6. Add a chat flow, support email on the store’s receiving domain, and a newsletter when the client needs them.

Core Modules

ModuleUse it for
ContentCollections, entries, blocks, media and localization
CommerceProducts, variants, carts, promotions, orders, payments, checkout
PackagesShops, price lists, memberships, renewals, club prices and newsletters: one set of things to buy, get or rent
BookingsBooking services, resources, offerings, availability, booking lines
FormsLead capture, intake, quote requests, applications
CustomersVisitor and signed-in customers, sign-in codes, email changes
ActionsFirst-party facts for timelines and experiment goals
Page viewsPage views, pages, countries, referrers and unique visitors, counted from a beacon that stores nothing
EmailThe store’s own Resend accounts, sending and receiving addresses, templates with layouts, a complete email per purpose, broadcasts
SupportFixed-step chat flows, team replies, support email on the store’s own domain
API & SDKFramework-agnostic storefront and Admin access

Common Starting Points

Content website

const website = await arky.content.load({ collection: { key: "website" } });
const post = await arky.content.load({ entry: { collection_id: blogId, slug: "launch" } });

Product storefront

const { items: [shopPackage] } = await arky.eshop.package.find();
const { items: products } = await arky.eshop.packageItem.find({
	package_id: shopPackage.id,
	include_price: true,
	selection: { types: ["product"] },
	limit: 20,
});
await arky.eshop.cart({ buyer: { type: "customer" }, package_id: shopPackage.id }).ensure();

Service booking

const { items: [service] } = await arky.eshop.packageItem.find({
	package_id: shopPackage.id,
	selection: { types: ["booking_service"] },
});
const calendar = arky.eshop.bookingCalendar({ buyer: { type: "customer" }, package_id: shopPackage.id });
if (service?.item.type === "booking_service")
	await calendar.select({ booking_service_id: service.item.booking_service_id });
calendar.selectFirstAvailableDate();

Support chat

const chat = await arky.support.conversation.start({ language: "en", flow_key: "default" });

Next

  • Quick Start for the minimal setup.
  • Core Concepts for the rules every record follows.
  • Store Email for the store’s Resend account, sending addresses and a complete email for each purpose.
  • E-commerce Store for products, carts, quotes and checkout.
  • Packages for what a store sells, to whom and at what price.
  • Support for chat flows and support email.