Essential rules and conventions. Detailed guides in
.claude/directory.
Next.js 16 dashboard with locale/RTL direction support (en/vi/ar locales are
detected and drive dir; a translation layer is NOT yet wired — UI strings are
currently English), Zustand auth, and shadcn/ui.
Status: Production-ready | TypeScript strict | Turbopack (React Compiler is NOT currently enabled — see Tech Stack)
Multi-tenant: Backend enforces WHERE tenant_id = ? on all queries. JWT includes tenant context automatically. Never attempt cross-tenant API access.
- Next.js 16 (App Router, Turbopack, Server Components,
proxy.tsreplacesmiddleware.ts) - React 19 with Server Components. NOTE: the React Compiler is not enabled
yet (
next.config.tsleaves it off;babel-plugin-react-compileris an unused devDependency). Manual memoization (useMemo/useCallback) is therefore load-bearing — do not strip it. To enable the compiler, wirereactCompilerinnext.config.tsand verify the build, then memoization becomes optional. - TypeScript strict mode, no
any(useunknown) - shadcn/ui + Tailwind CSS + CVA +
cn()utility - Zustand for global state (auth), React Context for UI state (theme, direction, layout)
- React Hook Form + Zod for forms, SWR for API caching
- ESLint + Prettier, path alias
@/*→./src/*
src/
├── app/ # App Router (route groups: (auth), (dashboard))
├── config/ # App-level config (sidebar, etc.)
├── features/[name]/ # Business logic (components/, actions/, schemas/, types/, hooks/, lib/)
├── components/ # Shared components (ui/ = shadcn, layout/)
├── context/ # React Context providers
├── stores/ # Zustand stores
├── lib/ # Utilities
├── hooks/ # Global hooks
├── types/ # Global types
└── assets/ # Static assets
proxy.ts # Next.js 16 Proxy (locale detection, routing)
See architecture.md for details.
CRITICAL: For new features: Research → Write tests first (all edge cases) → Implement → All tests pass.
- Component tests, integration tests, E2E tests, accessibility tests
npm test,npm test -- --watch,npm test -- --coverage
npm run validate # type-check + lint (run before every commit) npm run build # Full build to catch remaining issues
Pre-commit hooks (Husky + lint-staged) run automatically on staged files.
import { Button } from '@/components/ui/button' // GOOD import { Button } from '../../components/ui/button' // BAD
Components: user-card.tsx Actions: user-actions.ts Schemas: user.schema.ts
Types: user.types.ts Hooks: use-user.ts
- Server Component (default) — no directive, can
awaitdata - Client Component —
"use client"for hooks, events, browser APIs - Server Action —
"use server"for mutations, callrevalidatePathafter
Create a src/features/[name]/ folder when: 2+ related components, distinct business domain, could be independent module.
cn()for conditional classes, shadcn/ui variants, Tailwind utilities- Mobile-first, CSS variables for theming
- NO emoji in code/JSX — use text or icon components (lucide-react)
- Zustand → global (auth):
useAuthStore() - Context → UI (theme, direction, layout, search):
useTheme(),useDirection()
- Locales:
en,vi,ar| RTL:ar,he,fa,ur - Server:
(await headers()).get('x-locale') || 'en' - See i18n.md for complete guide
- Server Components for reads (default), Server Actions for mutations
- SWR for client-side fetching,
mutate()to invalidate after mutations - Always use pagination params (
page,limit) on list endpoints
- Zod schemas for all server-side validation
- Server Actions return
{ success: boolean, error?: string, data?: T } - Every route group needs
error.tsx - Toast via
sonner
Unauthenticated → /login → No Tenant → /onboarding/create-team → Dashboard
After auth changes, use window.location.href (not router.push) to pick up cookies.
See auth.md for details.
All state-changing requests from the browser must carry an X-CSRF-Token header matching the csrf_token cookie. src/lib/api/client.ts does this automatically (reads cookie, attaches header on POST/PUT/PATCH/DELETE). The Next.js proxy route src/app/api/v1/[...path]/route.ts forwards both refresh_token and csrf_token cookies to the backend. If you bypass the shared client (raw fetch) on a mutating endpoint, you MUST add the header yourself — otherwise the backend returns 403 csrf_token_missing_header.
Rendered markdown (notes, finding descriptions, etc.) goes through src/lib/sanitize-markdown.ts wired as a rehypeRewrite plugin on the markdown editor. It strips <script>/<iframe>/<object>/<embed>/<style>/<link>/<meta>/<base>/<form>, on* handlers, inline style, and javascript:/data:/vbscript: URLs. Do not disable it. If you need to render a new dangerous-looking tag, extend the allowlist in that file and add a test case in sanitize-markdown.test.ts.
User → Membership (owner | member) → Roles → Permissions (DO) → Groups → Data Scope (SEE)
const { hasPermission } = useMyPermissions() <PermissionGate permission="assets:write"><EditButton /></PermissionGate>
Permissions sync in real-time via X-Permission-Stale header. See access-control.md.
middleware.ts → proxy.ts, export function middleware() → export function proxy(). Node.js runtime (not Edge). Keep proxy lightweight — no DB calls or JWT verification.
npm run dev # Dev server (Turbopack) npm run build # Production build npm run lint # ESLint npm run lint:fix # ESLint auto-fix npm run type-check # TypeScript check npm run validate # type-check + lint
feat: fix: docs: style: refactor: perf: test: chore: — No Co-Authored-By lines.
- architecture.md — Structure deep dive
- auth.md — Authentication & multi-tenant flow
- access-control.md — RBAC & permissions
- account.md — Account settings
- patterns.md — Code patterns & examples
- i18n.md — Internationalization
- troubleshooting.md — Common issues
Last Updated: 2026-03-17