# Getting started

> Install the Sneferu CLI, create a theme with init, preview it with dev, check it with validate and compile it with build.

Source: https://hekana.dev/guide/getting-started

Sneferu is the language and SDK for Hekana store themes. A theme is a folder of
HTML-like `.snf` templates with `hk-*` tags, a `theme.json` manifest, locale
files and CSS. The CLI checks it, previews it with sample data and compiles it to
one JSON artifact that Hekana renders.

## Prerequisites

| Need | Version |
| - | - |
| Node.js | 20 or newer (`node -v`) |
| An editor | any; `.snf` files are HTML, so HTML highlighting works. [Format your theme](https://hekana.dev/guide/format-your-theme) sets up Prettier and format on save |

## Create a theme

```bash
npx sneferu init my-theme
cd my-theme
```

`init` copies the starter theme into `my-theme/` and sets `theme.json` `id` from
the folder name (`my-theme`) and `name` to its title case (`My Theme`). It refuses a non-empty folder unless you pass
`--force`.

> To skip `npx`, install the CLI once: `npm i -g sneferu`. It is then
> available as `sneferu` (or the short `snf`), for example `sneferu dev my-theme`.
> `npm create sneferu my-theme` does the same as `npx sneferu init my-theme`.
> `sneferu` is a short name for the `@hekana/sneferu` package; both install the same tool.

## Start from a template

`init` takes a template name. The default, `starter`, is the SDK's own complete
store; the others are finished example themes, each with its own design on every
page.

```bash
npx sneferu init my-shop --template arcade
npx sneferu init --list
```

| Template | What you get |
| - | - |
| `starter` | A neutral complete store: header, footer, every page type, tokens to edit. The default |
| `arcade` | Gaming: neon cyan and lime on near-black, for game gift cards and top-ups |
| `console` | Gaming: clean and light, for console games and subscriptions |
| `esports` | Gaming: bold and loud, for tournaments, teams and gear |
| `creator` | Digital: minimal, for a creator selling files, courses and presets |
| `license` | Digital: dark SaaS look, for software licenses and plans |
| `bento` | Digital: soft bento tiles, for apps and templates |

A template is a normal theme folder. It has a template for every page type
(home, product, collection, search, cart, 404, content page), header, footer and
announcement bar as section groups, theme settings, and Arabic and English
locale files, so nothing falls back to the SDK's default store. `init` sets the
theme `id` and `name` from the folder name and leaves everything else yours to
change. `sneferu validate`, `format --check` and `build` pass on a fresh copy.
A name that is not in the list prints the list and exits with an error.

## Preview: `dev`

```bash
npx sneferu dev            # current folder
npx sneferu dev ./my-theme --port 4200
```

![The starter theme in the dev preview: a dark hero with a heading and button, then the first sample product cards](https://hekana.dev/developers/examples/starter-dev@2x.webp "The top of the dev preview straight after init, 1080 px wide. The products and prices are the preview's sample data.")

Open `http://127.0.0.1:4100`. A new theme looks like the picture: the starter's
hero section and a grid of sample products, in English, left to right.

| What | Detail |
| - | - |
| Address | `http://127.0.0.1:4100` (local only; `--port` changes the port) |
| Language | The theme's `defaultLocale`. `?locale=<code>` shows another locale the theme lists in `locales` |
| Other templates | `http://127.0.0.1:4100/__template/<name>` renders `templates/<name>.snf` |
| Live reload | Saving any file recompiles and reloads the open page |
| Errors | A theme that does not compile shows the diagnostics list instead of the page |
| CSS | Every `assets/*.css` file (top level of `assets/`) is inlined after the token variables |
| Assets | `asset_url('logo.svg')` points at `/__assets/logo.svg` |

The preview uses sample data, not a real store:

| Data | Sample value |
| - | - |
| `store.name` | `Sample store` |
| Currency | EGP, so `money` prints `EGP 520.00` |
| `collection('featured')`, `'new'`, `'gift-cards'`, `'subscriptions'` | 4 to 6 products each, with `title`, `url` (`/products/<handle>`, or `/en/products/<handle>` in English), `price` (piastres), `compare_at`, `image.url` |
| `product('sample-1')` | the first of those products |
| Theme settings | every setting at its `default` |
| Sections | the default sections listed in the template's `<hk-schema>` (see [chapter 3](https://hekana.dev/guide/sections-and-blocks)) |

Any other collection is empty and any other product is nothing, which is a good
way to check your empty states.

### Your own sample data

To preview with products like your store's, put a `.sneferu-dev/data.json` in
the theme folder (or pass `--data <file>`). Folders starting with a dot are never
part of the theme and are never pushed.

```json title=".sneferu-dev/data.json"
{
  "store": { "name": "Pages" },
  "collections": {
    "ebooks": {
      "title": "E-books",
      "products": [
        { "title": "Notes on design", "url": "/products/notes", "price": 9900,
          "compare_at": null, "image": { "url": "https://example.com/notes.png" } }
      ]
    }
  }
}
```

| Key | Effect |
| - | - |
| `store` | merged over the sample store, e.g. `store.name` |
| `collections` | added to the sample collections; a handle you list (even `featured`) replaces the sample one |
| `products` | added to the `product('handle')` lookups, keyed by handle; a product has a page at `/products/<handle>` only when it is listed here |
| `menus` | menus by handle, `{ "handle", "title", "items": [{ "title", "url", "children"? }] }`; they replace the sample `main` and `footer` |

#### Local images in sample data

`hk-image` renders only `https://` and store-relative (`/…`) URLs, in `sneferu dev`
and on a store alike. So that sample data can use pictures you have on disk, the
dev server also accepts a **relative file path** in any image value of
`data.json`:

```json title=".sneferu-dev/data.json"
{ "products": { "notes": { "title": "Notes", "price": 9900, "image": { "url": "images/notes.webp" } } } }
```

The path is looked up next to `data.json` first (so put pictures in
`.sneferu-dev/images/`), then from the theme folder. A file found inside the theme
folder is served under `/__dev-images/<path>` and shown. Only `.png`, `.jpg`,
`.jpeg`, `.webp`, `.gif`, `.avif` and `.svg` files inside the theme folder are
served, and only by `sneferu dev`: nothing about `hk-image` or a published theme
changes, and these files are not part of the package.

A value that would be dropped (an `http://` URL, a `//host/…` URL, a path with no
file behind it, a path outside the theme folder) is not hidden: `sneferu dev`
prints a warning naming it, once per value.

For different text per language, split the file by locale:
`{ "ar": { "store": … }, "en": { "store": … } }`. The file is read on every
request: save it and reload the page. A file that is not valid JSON shows an
error page naming the file.

`init` writes a complete store: a layout with header, footer and announcement
groups, a template for every page type (home, product, collection, search,
cart, page, 404), the sections, blocks and snippets they use, tokens in
`theme.json` and `assets/theme.css`. `npx sneferu init --template starter`
is the same thing. Everything in it
is editable by the merchant: see [Make everything editable](https://hekana.dev/guide/make-everything-editable).

## Check: `validate`

```bash
npx sneferu validate
```

```
✔ theme my-theme@0.1.0 is valid
```

or, with problems, one line per diagnostic and a non-zero exit code:

```
sections/hero.snf:3:5 error SN2004 unknown property "colour" on <hk-heading>. Did you mean "color"?
✖ 1 error, 0 warnings
```

Format: `file:line:col severity CODE message`. Every code is listed in
[diagnostics.md](https://hekana.dev/reference/diagnostics). `validate` exits `0` when valid and `1` when
not, so it can gate CI.

## Compile: `build`

```bash
npx sneferu build            # → dist/my-theme-0.1.0.sneferu.json
npx sneferu build --out out  # another output folder
```

`build` runs the same checks as `validate`, writes
`<out>/<id>-<version>.sneferu.json` (the artifact) and copies `assets/` to
`<out>/assets/`. It prints the artifact hash. You do not upload this file:
`sneferu push` sends the source and Hekana compiles it itself (see
[chapter 7](https://hekana.dev/guide/publishing)).

## Commands

| Command | Arguments | Options |
| - | - | - |
| `init [dir]` | folder to create, default `my-theme` | `--force` write into a non-empty folder; `--template <name>` what to scaffold (default `starter`); `--list` list the templates. Also writes an `AGENTS.md` for AI coding agents (see [Build themes with AI agents](https://hekana.dev/guide/ai-agents)) |
| `dev [dir]` | theme folder, default `.` | `--port <n>` default `4100`; `--data <file>` sample data JSON, default `.sneferu-dev/data.json` when it exists |
| `validate [dir]` | theme folder, default `.` | |
| `build [dir]` | theme folder, default `.` | `--out <dir>` default `dist` |
| `format [dir]` | theme folder, default `.` | `--check` only report files that are not formatted and exit `1` (for CI). Formats `.snf` files, `theme.json` and `locales/` with Prettier and the Sneferu plugin; see [Format your theme](https://hekana.dev/guide/format-your-theme) |
| `login` | | `--api-url <url>` API to sign in to, default `https://api.hekana.com/api/v1`. Signs in through the browser and saves a developer key to `~/.config/sneferu/credentials.json`; revokes the previously saved key for the same API |
| `logout` | | revokes the saved key on Hekana and deletes the file |
| `whoami` | | prints the account, key prefix and dev store the CLI uses |
| `push [dir]` | theme folder, default `.` | `--package <slug>` required, must equal `theme.json` `id`, and not a reserved slug (`starter`, `hekana`, `default`, `admin`, `official`, `theme`, `themes`, `test`, `demo`, `preview`, and anything starting with `hekana-`); `--dev-store` also installs and publishes the version on your dev store and prints its URL. Uses the key saved by `login`, or env `HEKANA_TOKEN`; env `HEKANA_API_URL` |

`login`, `logout`, `whoami` and `push` are covered in
[Get an API key](https://hekana.dev/guide/get-an-api-key) and [Push and publish](https://hekana.dev/guide/publishing).

## Next

1. [Theme structure](https://hekana.dev/guide/theme-structure): what every file does.
2. [Sections and blocks](https://hekana.dev/guide/sections-and-blocks): the parts merchants edit.
3. [Data and expressions](https://hekana.dev/guide/data-and-expressions): `{{ }}`, filters, loops.
4. [Styling and responsive](https://hekana.dev/guide/styling-and-responsive): tokens, CSS, RTL.
5. [Security and limits](https://hekana.dev/guide/security-and-limits): what a theme cannot do.
6. [Get an API key](https://hekana.dev/guide/get-an-api-key): developer access, `sneferu login`, CI.
   [Push and publish](https://hekana.dev/guide/publishing): `sneferu push`, your dev store, review.
7. [Cookbook](https://hekana.dev/guide/cookbook): five complete store sections, with pictures.
   [Format your theme](https://hekana.dev/guide/format-your-theme): `sneferu format`, Prettier and VS Code.
8. [Tutorial: build a digital products store theme](https://hekana.dev/guide/tutorial-digital-store): a whole theme, from mockup to live store.
   [Tutorial: build a gaming store theme](https://hekana.dev/guide/tutorial-gaming-store): another whole theme, a dark gaming top-up store.
9. [Tag reference](https://hekana.dev/reference/tags): every `hk-*` tag and prop.
