- Add Superforms + Zod 4 for all admin form validation - Replace address isDefault with three separate boolean defaults (Mailing, Billing, Shipping) - Update profiles page with three-checkbox address form and toast improvements - Convert all admin page server actions to pass request directly to crud - Export superFormErrorsToFieldErrors helper for profiles server actions - Regenerate Prisma client for new schema fields
53 lines
2.8 KiB
Markdown
53 lines
2.8 KiB
Markdown
# portal.Rhemawavetech.com
|
|
|
|
SvelteKit 2 + Svelte 5 (runes) + Tailwind CSS v4 + Prisma 7 + PostgreSQL + Better-Auth.
|
|
|
|
## Quick start
|
|
|
|
```sh
|
|
npm install # engine-strict=true in .npmrc
|
|
npm run prepare # svelte-kit sync (generate types)
|
|
npm run dev # vite dev on :5173
|
|
```
|
|
|
|
Requires `.env` with at least `DATABASE_URL`, `BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`.
|
|
|
|
## Commands
|
|
|
|
| npm run ... | What it does |
|
|
| -------------------------- | ------------------------------------------------ |
|
|
| `check` | `svelte-kit sync && svelte-check` (typecheck) |
|
|
| `lint` | `prettier --check . && eslint .` (order matters) |
|
|
| `format` | `prettier --write .` |
|
|
| `test` | `vitest --run` (single run) |
|
|
| `test:unit` | `vitest` (watch mode) |
|
|
| `migrate -- --name <name>` | Create a Prisma migration |
|
|
| `deploy` | Apply pending migrations |
|
|
| `build` | Production build (adapter-node) |
|
|
|
|
## Testing quirks
|
|
|
|
- **Two Vitest projects**: `client` (Playwright/Chromium headless, `src/**/*.svelte.{test,spec}.{js,ts}`) and `server` (node env, everything else). Tests co-located beside source files.
|
|
- **`expect: { requireAssertions: true }`** — every test must assert something.
|
|
- **All route tests mock `$lib/db`** (Prisma client) and `$lib/auth-client`/`$lib/auth` via `vi.mock()`. Stub factories in `src/lib/test-utils.ts`.
|
|
- **No `.env.test`** — mocking `$lib/db` makes real DB unnecessary.
|
|
|
|
## Architecture notes
|
|
|
|
- **Route groups**: `(protected)/` requires auth + profile; `(user)/` is user-facing; `admin/` requires roleId <= 3 (STAFF+).
|
|
- **Svelte-Admin**: custom config-driven CRUD in `src/lib/svelte-admin/`. Models registered in `registry.ts`. Dynamic routes `[model]/[id]`.
|
|
- **Prisma client** generated to `src/lib/generated/prisma/` (not `node_modules/.prisma/client`). Lazy singleton via Proxy in `src/lib/db.ts`.
|
|
- **Better-Auth** server instance in `src/lib/auth.ts`, browser client in `src/lib/auth-client.ts`. Session fetched in `src/hooks.server.ts`.
|
|
- **Roles**: integer hierarchy (SUPER=1, ADMIN=2, STAFF=3, USER=4). `canAccessAdmin` checks roleId <= 3.
|
|
- **Payments are stubbed** (`src/lib/payments.ts` — setTimeout + console.log).
|
|
|
|
## Formatting conventions
|
|
|
|
- Tabs, single quotes, no trailing commas, 100 print width (enforced by Prettier).
|
|
- Svelte 5 runes only (`$state`, `$derived`, `$effect`, `$props`). No legacy stores.
|
|
|
|
## Generated / build artifacts
|
|
|
|
- `.svelte-kit/` — SvelteKit generated types (gitignored)
|
|
- `src/lib/generated/prisma/` — Prisma client output (not gitignored; regenerate with `npx prisma generate`)
|