# Start with the Next.js starter

Source: https://snizu.dev/docs/storefronts/nextjs-starter

## Create it [#create-it]

```shellsession title="Terminal"
$ npm create snizu-storefront@latest my-shop
$ cd my-shop
$ npm install
$ npm run dev
```

It asks for what it needs, or takes it as flags:

<Fields>
<Field name="--key" type="pk_…">
The store's publishable key, from the admin under **Settings → API keys**.
</Field>

<Field name="--name" type="text">
The store's name, shown in the header.
</Field>

<Field name="--api" type="url">
Where the API answers. `https://api.snizu.com` unless you put a proxy in front of it.
</Field>
</Fields>

It never takes a secret key: anyone can read what's in a storefront.

## What you get [#what-you-get]

Home, collection, product, search, cart and account pages on the App Router, rendered on the server. Adding to the cart and signing in are server actions, so they work before scripts load; once scripts run, an add shows in a cart drawer at once. Paying happens on the store's hosted checkout.

<Fields>
<Field name="app/[locale]/">
The pages. The language comes from the address, and `proxy.ts` sends `/` to the shopper's, Arabic when they have no preference.
</Field>

<Field name="lib/storefront.ts">
`catalog()` for what's the same for everyone, cached under tags. `shopper()` for a cart and account, from cookies, never cached.
</Field>

<Field name="lib/actions/">
Cart and account changes as server actions.
</Field>

<Field name="components/shop-provider.tsx, cart-drawer.tsx, add-to-cart.tsx">
One `@snizu/react` client for the page, a cart drawer whose changes show at once, and the product form that adds through it. They read the same cookies as the server, so the drawer and the cart page are one cart.
</Field>

<Field name="lib/i18n.ts">
Every word in both languages. Add a language here and it has a path.
</Field>

<Field name="lib/seo.ts">
Metadata, hreflang, Open Graph and product structured data, with `app/sitemap.ts` and `app/robots.ts`.
</Field>

<Field name="app/api/revalidate/">
Refreshes what changed when the store's webhooks say so.
</Field>

<Field name="components/funnel.tsx">
Tells the store what shoppers see and add, for its analytics.
</Field>

<Field name="app/globals.css">
Plain CSS with custom properties and logical properties, which is all right to left needs.
</Field>
</Fields>

## Its settings [#its-settings]

```sh title=".env.local"
NEXT_PUBLIC_SNIZU_API_URL=https://api.snizu.com
NEXT_PUBLIC_SNIZU_PUBLISHABLE_KEY=pk_…
NEXT_PUBLIC_SITE_URL=http://localhost:3000
NEXT_PUBLIC_STORE_NAME=Siwa Grove
SNIZU_WEBHOOK_SECRET=
SNIZU_SECRET_KEY=
SNIZU_SHOPPER_IP_HEADER=
```

<Fields>
<Field name="NEXT_PUBLIC_SNIZU_API_URL" type="url" required>
Where the API answers.
</Field>

<Field name="NEXT_PUBLIC_SNIZU_PUBLISHABLE_KEY" type="pk_…" required>
The store's publishable key. Safe in browsers.
</Field>

<Field name="NEXT_PUBLIC_SITE_URL" type="url">
Your shop's own address, for sitemaps, canonical links and Open Graph.
</Field>

<Field name="NEXT_PUBLIC_STORE_NAME" type="text">
The name in the header.
</Field>

<Field name="SNIZU_WEBHOOK_SECRET" type="secret">
The signing secret of the webhook pointed at `/api/revalidate`. Private.
</Field>

<Field name="SNIZU_SECRET_KEY" type="secret">
Optional and private: a secret key with no permissions, so each shopper gets their own allowance. Never prefix it with `NEXT_PUBLIC_`.
</Field>

<Field name="SNIZU_SHOPPER_IP_HEADER" type="header">
With `SNIZU_SECRET_KEY`: the one header holding the shopper's address on your host, which visitors can't set. Vercel and Netlify are known without it.
</Field>
</Fields>

## A change shows without a rebuild [#a-change-shows-without-a-rebuild]

Catalog reads are cached and tagged. In the admin, add a webhook pointing at `https://your-shop/api/revalidate`, subscribed to `product.*`, `collection.*` and `inventory_level.updated`, and put its signing secret in `SNIZU_WEBHOOK_SECRET`. The route checks the signature on the raw body, then refreshes only the tags the event names. [Caching and revalidation](/docs/storefronts/caching-and-revalidation) has the details.

## Pages the store moved [#pages-the-store-moved]

When a product, a collection or any other address has nothing to show, the shop asks the store whether it moved that page (**Online store → URL redirects** in the admin) and answers with a permanent redirect to where it lives now. Only then does it show the not-found page.

## Many shoppers, one server [#many-shoppers-one-server]

Every shopper's cart and account calls leave from your server, so to the API they come from one address and share its allowance. Put a secret key made with no permissions in `SNIZU_SECRET_KEY`: those calls then carry the shopper's own address, and each shopper gets their own allowance.

The address comes from one header only, one your host sets and a visitor can't. On Vercel and Netlify that's known. Elsewhere, name it in `SNIZU_SHOPPER_IP_HEADER`: `cf-connecting-ip` behind Cloudflare, or `x-real-ip` behind a proxy of yours that sets it. A header a visitor can write, like a plain `x-forwarded-for`, would let them name a new address on every request and get around per-shopper limits such as sign-in's. With nothing named, no address is sent: safe, just slower for a busy shop.

## Deploy it [#deploy-it]

It runs anywhere Next.js does: Vercel, or `npm run build && npm start` on any Node 22 host. Set the same variables there, with `NEXT_PUBLIC_SITE_URL` as your real address.

```shellsession title="Terminal"
$ npm test
$ npm run typecheck
$ npm run build
```

`npm test` checks the webhook signature and the language handling.