Zid's TanStack Start boilerplate -- a modern, production-ready foundation for building Zid frontend applications.
- Runtime: Bun 1.4.4
- Framework: TanStack Start + TanStack Router
- UI: MUI v7 + @zidsa/zidmui
- Styling: Emotion (CSS-in-JS) -- no Tailwind; plain CSS only for the global reset and fonts
- State: TanStack Query v5 + react-query-kit
- Forms: react-hook-form + zod v4
- HTTP: ky (API wrapper)
- i18n: react-i18next -- Arabic-first, RTL support
- Testing: Vitest + Testing Library
MUI Material and Lab stay on their newest stable v7 releases because ZidMUI 3.4.2 requires MUI v7. All other direct dependencies use their latest published releases.
# Install the pinned runtime
curl -fsSL https://bun.sh/install | bash -s "bun-v$(cat .bun-version)"
# Install dependencies
bun install
# Copy environment file
cp .env.example .env.local
# Start development server
bun run devThe app starts at http://localhost:3000.
| Script | Description |
|---|---|
bun run dev |
Start development server (port 3000) |
bun run build |
Build for production (SPA) |
bun run start |
Serve production build locally |
bun run build:ssr |
Build for production (SSR) |
bun run start:ssr |
Start SSR server |
bun run build:ssg |
Prerender static HTML for Pages |
bun run test |
Run tests |
bun run test:watch |
Run tests in watch mode |
bun run lint |
Lint with oxlint |
bun run lint:fix |
Lint and auto-fix |
bun run fmt |
Check formatting |
bun run fmt:fix |
Fix formatting |
bun run doctor |
Require a complete 100/100 scan |
bun run tscheck |
TypeScript type checking |
If you use Task, copy taskfile.dist.yml to Taskfile.yml and use task dev, task lint, etc.
Copy .env.example to .env.local and configure:
| Variable | Description | Required |
|---|---|---|
VITE_API_URL |
Hermod API proxy URL | Yes |
VITE_SENTRY_DSN |
Server-side Sentry error tracking | No |
VITE_POSTHOG_KEY |
PostHog analytics | No |
VITE_POSTHOG_HOST |
PostHog API host (default us.i.posthog.com) |
No |
src/
├── routes/ # TanStack Router file-based routes
│ ├── __root.tsx # Root layout (providers, theme)
│ ├── index.tsx # / → redirects to /$lang/
│ └── $lang/ # Language-scoped routes
│ ├── route.tsx # Language layout (validates locale, sets dir)
│ ├── index.tsx # Home page
│ └── example/ # Example route
├── modules/ # Feature modules
│ └── example/ # Example module
│ ├── components/ # Module-specific components
│ ├── pages/ # Page components
│ └── schemas/ # Zod validation schemas
├── global/ # Shared utilities
│ ├── components/ # Shared components (I18nLink, PageContainer)
│ ├── hooks/ # Shared hooks (useI18nNavigate)
│ └── utils/ # Utility functions
├── api/ # HTTP client (ky wrapper)
│ ├── client/ # Main ky client + interceptors
│ ├── errors/ # Error classes
│ ├── hooks/ # react-query-kit query/mutation hooks
│ ├── resources/ # API endpoint definitions
│ ├── types/ # Request/response types
│ └── utils/ # HTTP utilities
├── ui/ # MUI theme + Emotion
│ ├── libraries/
│ │ ├── emotion/ # Emotion cache + RTL
│ │ └── theme/ # Theme configuration
│ └── styles/ # Font declarations
├── libraries/ # Third-party library setup
│ └── i18next/ # i18n configuration
└── integrations/ # PostHog provider, TanStack devtools
- Arabic (ar-sa): Default language, RTL
- English (en-sa): LTR
All routes are prefixed with the locale: /{locale}/path
/ar-sa/-- Arabic home/en-sa/example-- English example page/-- Redirects to/ar-sa/
Always use the i18n-aware navigation utilities:
// Programmatic navigation
import { useI18nNavigate } from '~/global/hooks/use-i18n-navigate';
const navigate = useI18nNavigate();
void navigate({ to: '/$lang/example' }); // preserves the current lang parameter
// Link component
import { I18nLink } from '~/global/components/i18n-link';
<I18nLink to="/$lang/example">Go to Example</I18nLink>;These are TanStack navigation functions bound to /$lang. Use them inside localized routes; route params, search, hash, and link props retain native typing. Pass params: { lang: 'en-sa' } to switch locale. Paths use route templates, not string prefixes.
Translations are bundled inline in src/libraries/i18next/locales.ts (not loaded via HTTP). Add your strings directly to the i18nResources object under the appropriate locale and namespace:
// src/libraries/i18next/locales.ts
export const i18nResources: Resource = {
'ar-sa': {
common: {/* ... */},
'your-namespace': {
key: 'القيمة',
},
},
'en-sa': {
common: {/* ... */},
'your-namespace': {
key: 'Value',
},
},
};If you add a new namespace, register it in src/libraries/i18next/options.ts under the ns array.
Spark supports three rendering modes:
SPA (default) — static shell, client renders everything:
- Build with
bun run build, then serve locally withbun run start. - The default build enables SPA mode and disables SSR on the root route.
- Deploy
dist/clientwith/index.htmlas the SPA fallback (automatic on Cloudflare Pages).
SSR — server renders full HTML per request:
- Build with
bun run build:ssr, then runbun run start:ssr. - The
ssrbuild mode disables SPA mode and enables SSR on the root route. - Both start commands use srvx on Bun to serve the built app and its static assets.
SSG — HTML generated at build time:
- Run
bun run build:ssgand deploy onlydist/client; no request-time server is needed. vite.config.tsseeds both localized home URLs; prerendering follows their example links. Add seeds for other dynamic paths.- Router-owned caches and locales are isolated per server render and retained during browser navigation; app and tests share providers. See runtime and data flow.
- Create module directory:
src/modules/your-module/ - Add only the subdirectories it needs:
components/,hooks/,pages/,schemas/,types/ - Create route:
src/routes/$lang/your-route/index.tsx - Add translations to
src/libraries/i18next/locales.ts
The example uses one query/resource path with validated local fixtures, including during prerendering. Its form validates only; it does not persist. Follow runtime and data flow and code splitting.
Route UI splits automatically; defer optional heavy code and run bun run check:bundle after building.
- Use MUI components and
sxprop orstyledfrom@mui/material/styles - Colors must come from
theme.palette.*-- never hardcode colors - No Tailwind CSS and no new CSS/SCSS files (
src/styles.cssandsrc/ui/styles/fonts.csshold the global reset and fonts) - Use
Boxinstead of rawdiv/spanfor MUI theme access
- Imports: Absolute with
~/prefix. No relative imports. - File names: kebab-case (e.g.,
example-card.tsx) - Components: PascalCase named exports. No default exports.
- Commits: Conventional commits (
feat:,fix:,chore:, etc.) - Max file size: 250 lines
- No console.log: Error in oxlint
wrangler.jsonc is the source of truth for the project name,
output directory (dist/client), compatibility date/flags and build variables.
BUN_VERSION pins Bun to 1.4.4; keep it aligned with .bun-version and package.json.
SKIP_DEPENDENCY_INSTALL=1 lets the build command enforce the frozen lockfile.
Set the Pages Build command to bun install --frozen-lockfile && bun run build.
TanStack emits index.html directly. Pages supplies SPA fallback when there is no
top-level 404.html, so no shell script, file rename or _redirects is needed.
Pages does not support Wrangler's build.command. Git repository connection,
root directory, build system version (v3), production branch (master), preview
branch controls, build watch paths, build caching, build comments and custom
domains remain Pages project settings, managed through the dashboard or API.
For a repo created from Spark, set name to its Pages project name. Add non-secret
VITE_* values and resource bindings to Wrangler as needed. Keep secrets in Pages
secrets; never commit credentials. Use env.production and env.preview for
overrides, repeating all variables/bindings when overriding non-inheritable keys.
develop and feature branches both use preview settings; a separate staging
configuration requires a separate Pages project or explicit build-time logic.
When migrating an existing project, compare its current settings before deploying.
While older branches still need the script, use this temporary Pages build command:
if [ -f cloudflare-pages-build.sh ]; then bash cloudflare-pages-build.sh; else bun install --frozen-lockfile && bun run build; fi.
After migrating those branches, replace it with the build command above.
References: Pages configuration, build settings, SPA fallback.
MIT. Bundled fonts are under the SIL Open Font License 1.1: IBM Plex Sans Arabic and Saudi Riyal Font.