| name | sfnext-project-setup |
| description | Create and configure Storefront Next projects. Use when creating a new storefront, understanding project structure, setting up environment variables, or running the sfnext CLI for the first time. Covers project creation, directory layout, .env configuration, and sfnext CLI basics. |
Project Setup Skill
This skill guides you through creating and configuring a Storefront Next project โ a server-rendered SPA built on React 19, React Router 7, Vite, and Tailwind CSS v4.
Overview
Storefront Next storefronts run on Managed Runtime (MRT) with all SCAPI requests executing server-side. Projects are created with create-storefront from @salesforce/storefront-next-dev and use TypeScript exclusively (.ts/.tsx files only โ .js/.jsx/.mjs/.cjs are forbidden).
Creating a Project
Via CLI (local development)
pnpm dlx @salesforce/storefront-next-dev create-storefront
pnpm dlx @salesforce/storefront-next-dev create-storefront --name my-storefront
cd my-storefront
pnpm install
pnpm dev
Via Business Manager
Projects can also be created from Business Manager, which sets up the storefront with Commerce Cloud credentials pre-configured.
Project Structure
my-storefront/
โโโ .env.default # Default environment variables (template)
โโโ .env # Local overrides (git-ignored)
โโโ config.server.ts # Centralized configuration with defaults
โโโ vite.config.ts # Vite build configuration
โโโ package.json # Dependencies and scripts
โโโ src/
โ โโโ app.css # Global styles and Tailwind theme
โ โโโ root.tsx # Root layout component
โ โโโ routes/ # File-based routes (React Router 7)
โ โ โโโ _app.tsx # App layout (authenticated shell)
โ โ โโโ _app._index.tsx # Home page
โ โ โโโ _app.product.$productId.tsx
โ โโโ components/ # Reusable UI components
โ โ โโโ ui/ # shadcn/ui base components (customizable)
โ โ โโโ ... # Custom components
โ โโโ config/ # Configuration schema and context
โ โ โโโ schema.ts # Config type definitions
โ โโโ lib/ # Utilities and API client setup
โ โ โโโ api-clients.ts # createApiClients() factory
โ โ โโโ utils.ts # cn() utility and helpers
โ โ โโโ registry.ts # Page Designer component registry
โ โโโ locales/ # Translation files
โ โ โโโ en-US/
โ โ โโโ translations.json
โ โโโ middlewares/ # Server middleware
โ โ โโโ auth.server.ts # Authentication middleware
โ โ โโโ basket.server.ts # Basket middleware
โ โโโ providers/ # React context providers
โ โโโ hooks/ # Custom React hooks
โ โโโ extensions/ # Extension modules
โ โโโ test-utils/ # Shared test utilities
โโโ public/ # Static assets
โโโ cartridges/ # Page Designer cartridge metadata
See Project Structure Reference for detailed directory explanations.
Environment Setup
Copy .env.default to .env and configure required Commerce Cloud credentials:
cp .env.default .env
Required Variables
PUBLIC__app__commerce__api__clientId=your-client-id
PUBLIC__app__commerce__api__organizationId=your-org-id
PUBLIC__app__commerce__api__siteId=your-site-id
PUBLIC__app__commerce__api__shortCode=your-short-code
PUBLIC__app__defaultSiteId=your-site-id
PUBLIC__app__commerce__sites='[{"id":"your-site-id","defaultLocale":"en-US","defaultCurrency":"USD","supportedLocales":[{"id":"en-US","preferredCurrency":"USD"}],"supportedCurrencies":["USD"]}]'
See Environment Variables Reference for the complete variable list and naming rules.
Development Commands
pnpm dev
pnpm build
pnpm test
pnpm storybook
pnpm bundlesize:test
Non-Negotiable Rules
- TypeScript only โ
.ts and .tsx files; JavaScript files are blocked by ESLint
- Server-only data loading โ Use
loader functions; never use client loaders
- Synchronous loaders โ Return promises, do not use
async/await (enables streaming)
- Tailwind CSS 4 only โ No inline styles, CSS modules, or separate CSS files
- Use
createPage() HOC โ Standardizes page patterns with Suspense
Troubleshooting
| Issue | Cause | Solution |
|---|
| SCAPI 401 errors | Missing or invalid credentials | Verify .env variables match your Commerce Cloud org |
| JavaScript file errors | .js/.jsx files in source | Rename to .ts/.tsx; ESLint blocks JS files |
| Dev server not starting | Missing dependencies | Run pnpm install |
| Config not loading | Missing config.server.ts defaults | Define defaults before using environment overrides |
Related Skills
storefront-next:sfnext-configuration - Ongoing configuration management and multi-site setup
storefront-next:sfnext-routing - File-based routing conventions
storefront-next:sfnext-data-fetching - Server-side data loading patterns
storefront-next:sfnext-deployment - Building and deploying to MRT
Reference Documentation