bsmnt 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.changeset/2026-02-11-test-patch-bump.md +5 -0
  2. package/.changeset/README.md +10 -0
  3. package/.changeset/config.json +16 -0
  4. package/.cursor/rules/README.md +184 -0
  5. package/.cursor/rules/architecture.mdc +437 -0
  6. package/.cursor/rules/components.mdc +436 -0
  7. package/.cursor/rules/integrations.mdc +447 -0
  8. package/.cursor/rules/main.mdc +278 -0
  9. package/.cursor/rules/styling.mdc +433 -0
  10. package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  11. package/.github/workflows/.gitkeep +0 -0
  12. package/.github/workflows/ci.yml +37 -0
  13. package/.github/workflows/release.yml +54 -0
  14. package/.tldr/cache/call_graph.json +7 -0
  15. package/.tldr/languages.json +6 -0
  16. package/.tldr/status +1 -0
  17. package/.tldrignore +84 -0
  18. package/.vscode/extensions.json +20 -0
  19. package/.vscode/settings.json +98 -0
  20. package/CHANGELOG.md +13 -0
  21. package/CLAUDE.md +138 -0
  22. package/README.md +176 -0
  23. package/bin/index.js +262 -0
  24. package/biome.json +44 -0
  25. package/bun.lock +496 -0
  26. package/changelog/04-02-26.md +86 -0
  27. package/changelog/05-02-26.md +101 -0
  28. package/changelog/09-02-26.md +83 -0
  29. package/docs/fix-studio-hydration.md +46 -0
  30. package/docs/plans/2026-01-29-sanity-smart-merge-design.md +196 -0
  31. package/docs/plans/2026-01-29-sanity-smart-merge-implementation.md +695 -0
  32. package/docs/sanity-setup-steps.md +199 -0
  33. package/integrations/basehub/README.md +3 -0
  34. package/integrations/sanity/app/api/draft-mode/disable/route.ts +7 -0
  35. package/integrations/sanity/app/api/draft-mode/enable/route.ts +21 -0
  36. package/integrations/sanity/app/api/revalidate/route.ts +37 -0
  37. package/integrations/sanity/app/layout.tsx +111 -0
  38. package/integrations/sanity/app/sitemap.ts +80 -0
  39. package/integrations/sanity/app/studio/[[...tool]]/page.tsx +8 -0
  40. package/integrations/sanity/app/studio/layout.tsx +7 -0
  41. package/integrations/sanity/components/ui/sanity-image/index.tsx +37 -0
  42. package/integrations/sanity/lib/integrations/README.md +58 -0
  43. package/integrations/sanity/lib/integrations/check-integration.ts +62 -0
  44. package/integrations/sanity/lib/integrations/sanity/README.md +144 -0
  45. package/integrations/sanity/lib/integrations/sanity/client.ts +30 -0
  46. package/integrations/sanity/lib/integrations/sanity/components/disable-draft-mode.tsx +29 -0
  47. package/integrations/sanity/lib/integrations/sanity/components/rich-text.tsx +73 -0
  48. package/integrations/sanity/lib/integrations/sanity/env.ts +38 -0
  49. package/integrations/sanity/lib/integrations/sanity/live/index.tsx +34 -0
  50. package/integrations/sanity/lib/integrations/sanity/queries.ts +99 -0
  51. package/integrations/sanity/lib/integrations/sanity/sanity.cli.ts +20 -0
  52. package/integrations/sanity/lib/integrations/sanity/sanity.config.ts +94 -0
  53. package/integrations/sanity/lib/integrations/sanity/sanity.types.ts +337 -0
  54. package/integrations/sanity/lib/integrations/sanity/schema.json +1850 -0
  55. package/integrations/sanity/lib/integrations/sanity/schemas/article.ts +132 -0
  56. package/integrations/sanity/lib/integrations/sanity/schemas/example.ts +203 -0
  57. package/integrations/sanity/lib/integrations/sanity/schemas/index.ts +37 -0
  58. package/integrations/sanity/lib/integrations/sanity/schemas/link.ts +127 -0
  59. package/integrations/sanity/lib/integrations/sanity/schemas/metadata.ts +68 -0
  60. package/integrations/sanity/lib/integrations/sanity/schemas/navigation.ts +39 -0
  61. package/integrations/sanity/lib/integrations/sanity/schemas/page.ts +77 -0
  62. package/integrations/sanity/lib/integrations/sanity/schemas/richText.ts +59 -0
  63. package/integrations/sanity/lib/integrations/sanity/structure.ts +5 -0
  64. package/integrations/sanity/lib/integrations/sanity/utils/image.ts +11 -0
  65. package/integrations/sanity/lib/integrations/sanity/utils/link.ts +61 -0
  66. package/integrations/sanity/lib/scripts/copy-sanity-mcp.ts +23 -0
  67. package/integrations/sanity/lib/scripts/generate-page.ts +310 -0
  68. package/integrations/sanity/lib/utils/metadata.ts +190 -0
  69. package/layers/experiment/components/layout/header/index.tsx +58 -0
  70. package/layers/experiment/components/layout/navigation-menu.tsx +127 -0
  71. package/layers/experiment/lib/constants.ts +12 -0
  72. package/layers/webgl/app/page.tsx +10 -0
  73. package/layers/webgl/components/webgl/canvas/dynamic.tsx +34 -0
  74. package/layers/webgl/components/webgl/canvas/index.tsx +43 -0
  75. package/layers/webgl/components/webgl/components/scene/index.tsx +21 -0
  76. package/layers/webgpu/.gitkeep +0 -0
  77. package/package.json +44 -0
  78. package/plugins/README.md +21 -0
  79. package/plugins/no-anchor-element.grit +11 -0
  80. package/plugins/no-relative-parent-imports.grit +6 -0
  81. package/plugins/no-unnecessary-forwardref.grit +5 -0
  82. package/src/commands/add-integration.js +325 -0
  83. package/src/commands/create.js +415 -0
  84. package/src/commands/setup-sanity.js +426 -0
  85. package/src/commands/worktree.js +805 -0
  86. package/src/mergers/check-integration-merger.js +105 -0
  87. package/src/mergers/config.js +137 -0
  88. package/src/mergers/index.js +355 -0
  89. package/src/mergers/layout-merger.js +223 -0
  90. package/src/mergers/next-config-merger.js +63 -0
  91. package/src/mergers/sitemap-merger.js +121 -0
  92. package/tasks/prd-next-starter-dynamic-layers.md +184 -0
  93. package/tasks/prd.json +153 -0
  94. package/tasks/progress.txt +115 -0
  95. package/template-hooks/use-battery.ts +126 -0
  96. package/template-hooks/use-device-perf.ts +184 -0
  97. package/template-hooks/use-intersection-observer.ts +32 -0
  98. package/template-hooks/use-media.ts +33 -0
@@ -0,0 +1,5 @@
1
+ ---
2
+ "bsmnt": patch
3
+ ---
4
+
5
+ Rename package to bsmnt and trigger first patch release to 0.0.1.
@@ -0,0 +1,10 @@
1
+ # Changesets
2
+
3
+ Create a changeset in feature branches before merging:
4
+
5
+ ```bash
6
+ bun run changeset
7
+ ```
8
+
9
+ On merge to `main`, GitHub Actions opens or updates a release PR with version/changelog changes.
10
+ Merging that release PR publishes to npm via Trusted Publishing.
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
+ "changelog": [
4
+ "@changesets/changelog-github",
5
+ {
6
+ "repo": "basementstudio/basement-cli"
7
+ }
8
+ ],
9
+ "commit": false,
10
+ "fixed": [],
11
+ "linked": [],
12
+ "access": "public",
13
+ "baseBranch": "main",
14
+ "updateInternalDependencies": "patch",
15
+ "ignore": []
16
+ }
@@ -0,0 +1,184 @@
1
+ # Cursor Rules Documentation
2
+
3
+ This directory contains consolidated Cursor AI rules for the Satus project. The rules are organized into 5 focused files for easy maintenance and efficient AI context loading.
4
+
5
+ ## 📁 File Structure
6
+
7
+ ### 1. `main.mdc` - Project Overview & Cross-Cutting Concerns
8
+ **Purpose**: High-level overview and concerns that apply across the entire project
9
+
10
+ **Contents**:
11
+ - Technology stack (Next.js 16+, React 19+, Tailwind v4, Biome, Bun)
12
+ - React 19+ new features (`<Activity />`, `useEffectEvent`, `cacheSignal`)
13
+ - Next.js 16 Cache Components gotchas and best practices
14
+ - File organization
15
+ - React Compiler & memoization guidelines (single source of truth)
16
+ - Image optimization guidelines (single source of truth)
17
+ - Development vs production guidelines (single source of truth)
18
+ - Core utility libraries (`@/utils`)
19
+
20
+ **When to reference**: Starting a new project, understanding the tech stack, cross-cutting concerns
21
+
22
+ ---
23
+
24
+ ### 2. `components.mdc` - React Component Patterns & WebGL
25
+ **Purpose**: All React component patterns including standard components and WebGL/Three.js
26
+
27
+ **Contents**:
28
+ - Component structure and imports
29
+ - Props interfaces and React 19 ref handling
30
+ - Forms and responsive design
31
+ - Performance best practices (code splitting)
32
+ - Error handling
33
+ - WebGL/Three.js setup and patterns
34
+ - React Three Fiber
35
+ - Drei components
36
+ - Custom shaders
37
+ - Animation and interaction
38
+ - Post-processing
39
+
40
+ **When to reference**: Building React components, creating WebGL experiences, working with Three.js
41
+
42
+ ---
43
+
44
+ ### 3. `styling.mdc` - CSS Modules & Tailwind CSS v4
45
+ **Purpose**: All styling approaches including CSS Modules and Tailwind CSS v4
46
+
47
+ **Contents**:
48
+ - CSS Modules (file naming, class naming, imports)
49
+ - Responsive design (viewport functions, breakpoints, grid system)
50
+ - Typography and colors
51
+ - Animations and transitions
52
+ - Tailwind CSS v4 (CSS-first configuration, theme variables, new features)
53
+ - 3D transforms, gradients, shadows
54
+ - New variants (composable, `starting`, `not-*`, `nth-*`)
55
+ - Custom extensions (`@utility`, `@variant`, `@plugin`)
56
+ - Breaking changes and migration
57
+ - Project-specific custom utilities (`b-*` classes)
58
+ - PostCSS functions
59
+
60
+ **When to reference**: Styling components, using Tailwind, creating responsive designs
61
+
62
+ ---
63
+
64
+ ### 4. `integrations.mdc` - Third-Party Integrations
65
+ **Purpose**: Guidelines for all third-party service integrations
66
+
67
+ **Contents**:
68
+ - **Sanity CMS**: Configuration, schema management, GROQ queries, visual editing, TypeScript generation, cacheSignal integration
69
+ - **Shopify**: API configuration, product management, cart operations, cacheSignal integration
70
+ - General best practices (environment variables, API resilience, error handling)
71
+ - Cache Components gotchas for integrations (user-specific data, real-time data)
72
+ - Type safety and performance
73
+ - Security and integration management
74
+ - Webhook handling
75
+
76
+ **When to reference**: Integrating with Sanity, Shopify, or other third-party services
77
+
78
+ ---
79
+
80
+ ### 5. `architecture.mdc` - Architecture Patterns & Best Practices
81
+ **Purpose**: Architectural patterns, state management, routing, and code quality guidelines
82
+
83
+ **Contents**:
84
+ - Type safety (TypeScript configuration)
85
+ - State management (React state, Zustand)
86
+ - Routing & navigation (Next.js App Router, Link component)
87
+ - Metadata & SEO
88
+ - Performance (server components, code splitting, caching)
89
+ - Cache Components (Next.js 16) - Suspense, invalidation, gotchas
90
+ - Security (environment variables, input validation, authentication)
91
+ - Testing & debugging (unit tests, debugging tools, error boundaries)
92
+ - Code quality (linting, formatting, code organization)
93
+ - Development workflow (package manager, git workflow, client/server boundaries)
94
+
95
+ **When to reference**: Architectural decisions, state management, routing patterns, code quality
96
+
97
+ ---
98
+
99
+ ## 🎯 Quick Reference Guide
100
+
101
+ ### I want to...
102
+
103
+ - **Start a new feature** → Read `main.mdc` for overview, then `architecture.mdc` for patterns
104
+ - **Build a React component** → `components.mdc`
105
+ - **Add WebGL/Three.js** → `components.mdc` § WebGL Components & Activity Integration
106
+ - **Style with CSS Modules** → `styling.mdc` § CSS Modules
107
+ - **Style with Tailwind** → `styling.mdc` § Tailwind CSS v4
108
+ - **Use custom utilities** → `styling.mdc` § Project-Specific Custom Utilities
109
+ - **Integrate Sanity CMS** → `integrations.mdc` § Sanity CMS Integration
110
+ - **Integrate Shopify** → `integrations.mdc` § Shopify Integration
111
+ - **Manage state** → `architecture.mdc` § State Management
112
+ - **Add routing** → `architecture.mdc` § Routing & Navigation
113
+ - **Optimize performance** → `architecture.mdc` § Performance
114
+ - **Handle security** → `architecture.mdc` § Security
115
+ - **Debug issues** → `architecture.mdc` § Testing & Debugging
116
+ - **Understand React Compiler** → `main.mdc` § React Compiler & Memoization
117
+ - **Handle images** → `main.mdc` § Image Optimization (`@/components/ui/image`)
118
+ - **Dev vs prod differences** → `main.mdc` § Development vs Production
119
+ - **Use utility functions** → `main.mdc` § Core Utility Libraries (`@/utils`)
120
+
121
+ ---
122
+
123
+ ## 📝 Maintenance Guidelines
124
+
125
+ ### When Editing Rules
126
+
127
+ 1. **Avoid Duplication**: If content applies to multiple areas, put it in `main.mdc` and reference it
128
+ 2. **Use Cross-References**: Link to other sections instead of duplicating content
129
+ 3. **Keep It Focused**: Each file should maintain its specific purpose
130
+ 4. **Update Dates**: Update the "Last updated" date when making changes
131
+ 5. **Check Dependencies**: When updating one file, check if related files need updates
132
+
133
+ ### Example Cross-Reference Pattern
134
+
135
+ ```markdown
136
+ <!-- In components.mdc -->
137
+ ## Performance Optimization
138
+ See main.mdc § React Compiler & Memoization for optimization guidelines.
139
+ ```
140
+
141
+ ### Adding New Content
142
+
143
+ **Ask yourself**:
144
+ - Is this component-specific? → `components.mdc`
145
+ - Is this styling-related? → `styling.mdc`
146
+ - Is this an integration? → `integrations.mdc`
147
+ - Is this architectural? → `architecture.mdc`
148
+ - Is this cross-cutting? → `main.mdc`
149
+
150
+ ---
151
+
152
+ ## 🚀 For Developers
153
+
154
+ ### Quick Setup
155
+ 1. These rules are automatically loaded by Cursor AI
156
+ 2. All files have `alwaysApply: true` in frontmatter
157
+ 3. Files apply to: `*.tsx, *.jsx, *.css, *.js, *.ts`
158
+
159
+ ### Contributing
160
+ When adding new guidelines:
161
+ 1. Choose the appropriate file
162
+ 2. Follow existing formatting patterns
163
+ 3. Add clear examples
164
+ 4. Update this README if needed
165
+ 5. Keep content focused and actionable
166
+
167
+ ---
168
+
169
+ ## 📊 File Statistics
170
+
171
+ | File | Purpose | Key Topics |
172
+ |------|---------|------------|
173
+ | `main.mdc` | Overview & Cross-cutting | Tech stack, React 19+ features, Cache Components, React Compiler, Images, Dev/Prod |
174
+ | `components.mdc` | React & WebGL | Components, Forms, WebGL, Three.js, Shaders, Activity |
175
+ | `styling.mdc` | All Styling | CSS Modules, Tailwind v4, Responsive, Custom utilities |
176
+ | `integrations.mdc` | Third-party Services | Sanity, Shopify, Cache Components, cacheSignal |
177
+ | `architecture.mdc` | Patterns & Quality | State, Routing, Performance, Cache Components, Security, Testing |
178
+
179
+ ---
180
+
181
+ Last updated: 2026-01-26
182
+
183
+ For questions or suggestions about these rules, contact the development team.
184
+
@@ -0,0 +1,437 @@
1
+ ---
2
+ alwaysApply: true
3
+ ---
4
+ ---
5
+ description: Architecture patterns, state management, routing, and best practices
6
+ globs: *.tsx, *.jsx, *.css, *.js, *.ts
7
+ ---
8
+
9
+ # Architecture Guidelines
10
+
11
+ ## Type Safety
12
+
13
+ ### TypeScript Configuration
14
+ - Use TypeScript for all new code
15
+ - Maintain strict type checking
16
+ - Avoid `any` types unless absolutely necessary
17
+ - Use proper type imports (`import type` when importing only types)
18
+
19
+ ```tsx
20
+ import type { ComponentProps } from 'react'
21
+
22
+ interface ButtonProps extends ComponentProps<'button'> {
23
+ variant?: 'primary' | 'secondary'
24
+ }
25
+ ```
26
+
27
+ ## State Management
28
+
29
+ ### React Built-in State
30
+ Prefer React's built-in state for component state. Keep state as close to where it's used as possible.
31
+
32
+ ```tsx
33
+ function Component() {
34
+ const [count, setCount] = useState(0)
35
+ return <button onClick={() => setCount(count + 1)}>{count}</button>
36
+ }
37
+ ```
38
+
39
+ ### Zustand for Global State
40
+ Use Zustand for global state when needed. Define stores in `@/lib/store.ts` or dedicated store files.
41
+
42
+ ```tsx
43
+ import { create } from 'zustand'
44
+
45
+ interface CartStore {
46
+ items: CartItem[]
47
+ addItem: (item: CartItem) => void
48
+ removeItem: (id: string) => void
49
+ }
50
+
51
+ export const useCartStore = create<CartStore>((set) => ({
52
+ items: [],
53
+ addItem: (item) => set((state) => ({ items: [...state.items, item] })),
54
+ removeItem: (id) => set((state) => ({
55
+ items: state.items.filter(item => item.id !== id)
56
+ })),
57
+ }))
58
+ ```
59
+
60
+ ### State Management Best Practices
61
+ - Keep state minimal and derived values computed
62
+ - Use context for shared UI state (theme, modals)
63
+ - Use Zustand for complex global state (cart, user)
64
+ - Avoid prop drilling with composition patterns
65
+
66
+ ## Routing & Navigation
67
+
68
+ ### Next.js App Router
69
+ Use Next.js App Router conventions. Follow the file-based routing structure.
70
+
71
+ ```
72
+ app/
73
+ (pages)/
74
+ home/
75
+ page.tsx
76
+ about/
77
+ page.tsx
78
+ ```
79
+
80
+ ### Navigation
81
+ Use the custom Link component for internal navigation. It automatically handles external links.
82
+
83
+ ```tsx
84
+ import { Link } from '@/components/ui'
85
+
86
+ function Navigation() {
87
+ return (
88
+ <>
89
+ {/* Internal link - uses next/link */}
90
+ <Link href="/about">About</Link>
91
+
92
+ {/* External link - uses <a> with target="_blank" */}
93
+ <Link href="https://example.com">External</Link>
94
+ </>
95
+ )
96
+ }
97
+ ```
98
+
99
+ ### Metadata & SEO
100
+ Use `@/utils/metadata` for SEO optimization. Generate metadata for all pages.
101
+
102
+ ```tsx
103
+ import { generatePageMetadata } from '@/utils/metadata'
104
+
105
+ export async function generateMetadata({ params }) {
106
+ const page = await fetchPage(params.slug)
107
+
108
+ return generatePageMetadata({
109
+ title: page.title,
110
+ description: page.description,
111
+ image: { url: page.image },
112
+ url: `/pages/${params.slug}`,
113
+ })
114
+ }
115
+ ```
116
+
117
+ ### Loading and Error States
118
+ Implement proper loading and error states for all routes.
119
+
120
+ ```tsx
121
+ // loading.tsx
122
+ export default function Loading() {
123
+ return <div>Loading...</div>
124
+ }
125
+
126
+ // error.tsx
127
+ 'use client'
128
+
129
+ export default function Error({ error, reset }) {
130
+ return (
131
+ <div>
132
+ <h2>Something went wrong!</h2>
133
+ <button onClick={() => reset()}>Try again</button>
134
+ </div>
135
+ )
136
+ }
137
+ ```
138
+
139
+ ## Performance
140
+
141
+ ### Server Components
142
+ Use React Server Components by default. Only add 'use client' when needed.
143
+
144
+ ```tsx
145
+ // Server Component (default)
146
+ async function ServerComponent() {
147
+ const data = await fetchData()
148
+ return <div>{data.title}</div>
149
+ }
150
+
151
+ // Client Component (when needed)
152
+ 'use client'
153
+
154
+ function ClientComponent() {
155
+ const [state, setState] = useState(0)
156
+ return <button onClick={() => setState(state + 1)}>{state}</button>
157
+ }
158
+ ```
159
+
160
+ ### Code Splitting
161
+ Use `next/dynamic` for heavy components. Implement proper loading states.
162
+
163
+ ```tsx
164
+ import dynamic from 'next/dynamic'
165
+
166
+ const HeavyComponent = dynamic(() => import('./HeavyComponent'), {
167
+ loading: () => <div>Loading...</div>,
168
+ ssr: false // if needed
169
+ })
170
+ ```
171
+
172
+ ### Caching Strategies
173
+ Follow Next.js 16 recommended caching strategies. Use appropriate revalidation times.
174
+
175
+ ```tsx
176
+ // Static generation with revalidation
177
+ export const revalidate = 3600 // 1 hour
178
+
179
+ // Dynamic with specific cache tags
180
+ export async function fetchData() {
181
+ const res = await fetch('https://api.example.com/data', {
182
+ next: {
183
+ revalidate: 3600,
184
+ tags: ['data']
185
+ }
186
+ })
187
+ return res.json()
188
+ }
189
+
190
+ // User-specific data - NEVER cache
191
+ export async function fetchUserCart(userId: string) {
192
+ const res = await fetch(`https://api.example.com/cart/${userId}`, {
193
+ cache: 'no-store' // Required for user-specific data
194
+ })
195
+ return res.json()
196
+ }
197
+ ```
198
+
199
+ ### Cache Components (Next.js 16)
200
+
201
+ Cache Components are enabled globally (`cacheComponents: true`). Key considerations:
202
+
203
+ **Suspense Boundaries:**
204
+ ```tsx
205
+ import { Suspense } from 'react'
206
+
207
+ export default async function Page() {
208
+ return (
209
+ <Suspense fallback={<Loading />}>
210
+ <DataComponent />
211
+ </Suspense>
212
+ )
213
+ }
214
+ ```
215
+
216
+ **Cache Invalidation:**
217
+ ```tsx
218
+ import { revalidateTag, revalidatePath } from 'next/cache'
219
+
220
+ // In webhook handlers
221
+ export async function POST(request: Request) {
222
+ revalidateTag('products')
223
+ // or
224
+ revalidatePath('/products/[slug]', 'page')
225
+ return Response.json({ revalidated: true })
226
+ }
227
+ ```
228
+
229
+ **⚠️ Critical Rules:**
230
+ - User-specific data: Always use `cache: 'no-store'`
231
+ - Real-time data: Always use `cache: 'no-store'`
232
+ - Test with hard refresh AND navigation
233
+ - Wrap data fetching in Suspense boundaries
234
+
235
+ ### Asset Optimization
236
+ - Always use the custom `Image` component (`@/components/ui/image`)
237
+ - Optimize bundles with tree-shaking
238
+ - Check bundle size impact of new dependencies
239
+ - Use `bun lint` to check for linting issues
240
+
241
+ ## Security
242
+
243
+ ### Environment Variables
244
+ - Never commit API keys
245
+ - Use `.env.local` for development
246
+ - Document required variables in `.env.example`
247
+ - Validate environment variables are set before use
248
+
249
+ ```typescript
250
+ // Check required env vars at module load
251
+ const requiredEnvVars = [
252
+ 'NEXT_PUBLIC_API_KEY',
253
+ 'DATABASE_URL',
254
+ 'SANITY_API_TOKEN'
255
+ ] as const
256
+
257
+ for (const envVar of requiredEnvVars) {
258
+ if (!process.env[envVar]) {
259
+ throw new Error(`Missing required environment variable: ${envVar}`)
260
+ }
261
+ }
262
+ ```
263
+
264
+ ### Input Validation
265
+ Validate all user inputs. Use server-side validation for forms.
266
+
267
+ ```tsx
268
+ async function submitForm(formData: FormData) {
269
+ 'use server'
270
+
271
+ const email = formData.get('email')
272
+
273
+ // Validate
274
+ if (!email || typeof email !== 'string') {
275
+ return { error: 'Invalid email' }
276
+ }
277
+
278
+ // Process
279
+ // ...
280
+ }
281
+ ```
282
+
283
+ ### Authentication & Authorization
284
+ - Implement proper authentication
285
+ - Use server-side API calls for sensitive operations
286
+ - Implement rate limiting where necessary
287
+ - Follow CSP guidelines
288
+
289
+ ## Testing & Debugging
290
+
291
+ ### Unit Testing
292
+ Write unit tests for critical functionality.
293
+
294
+ ```tsx
295
+ import { render, screen } from '@testing-library/react'
296
+ import Button from './Button'
297
+
298
+ test('renders button with text', () => {
299
+ render(<Button>Click me</Button>)
300
+ expect(screen.getByText('Click me')).toBeInTheDocument()
301
+ })
302
+ ```
303
+
304
+ ### Debugging Tools
305
+ - Use React DevTools for component inspection
306
+
307
+ ### Error Boundaries
308
+ Implement error boundaries for critical sections. Provide meaningful fallback UI.
309
+
310
+ ```tsx
311
+ 'use client'
312
+
313
+ import { Component } from 'react'
314
+
315
+ class ErrorBoundary extends Component {
316
+ state = { hasError: false }
317
+
318
+ static getDerivedStateFromError(error) {
319
+ return { hasError: true }
320
+ }
321
+
322
+ componentDidCatch(error, errorInfo) {
323
+ console.error('ErrorBoundary caught:', error, errorInfo)
324
+ }
325
+
326
+ render() {
327
+ if (this.state.hasError) {
328
+ return <div>Something went wrong.</div>
329
+ }
330
+
331
+ return this.props.children
332
+ }
333
+ }
334
+ ```
335
+
336
+ ### Logging Best Practices
337
+ - Use console.log for simple debugging (auto-stripped in production)
338
+ - Use console.error and console.warn for important issues (kept in production)
339
+ - Gate expensive debug operations with `process.env.NODE_ENV === 'development'`
340
+ - Log errors with context for better debugging
341
+
342
+ ## Code Quality
343
+
344
+ ### Linting & Formatting
345
+ - Follow Biome linting rules
346
+ - Run `bun lint` before committing
347
+ - Maintain consistent code style
348
+ - Fix linting errors immediately
349
+
350
+ ### Code Organization
351
+ - Follow the defined project structure
352
+ - Maintain separation of concerns
353
+ - Use meaningful variable and function names
354
+ - Write meaningful comments and documentation
355
+ - Prefer named exports for utilities
356
+
357
+ ### Component Composition
358
+ Follow component composition patterns. Keep components focused and reusable.
359
+
360
+ ```tsx
361
+ // Good: Composable components
362
+ function Card({ children, className }) {
363
+ return <div className={cn(s.card, className)}>{children}</div>
364
+ }
365
+
366
+ function CardHeader({ children }) {
367
+ return <div className={s.header}>{children}</div>
368
+ }
369
+
370
+ function CardBody({ children }) {
371
+ return <div className={s.body}>{children}</div>
372
+ }
373
+
374
+ // Usage
375
+ <Card>
376
+ <CardHeader>Title</CardHeader>
377
+ <CardBody>Content</CardBody>
378
+ </Card>
379
+ ```
380
+
381
+ ## Development Workflow
382
+
383
+ ### Package Manager
384
+ Use Bun as the JavaScript runtime and package manager.
385
+
386
+ ```bash
387
+ # Install dependencies
388
+ bun install
389
+
390
+ # Run development server (with Turbopack)
391
+ bun dev
392
+
393
+ # Build for production
394
+ bun run build
395
+
396
+ # Run linting
397
+ bun lint
398
+ ```
399
+
400
+ ### Git Workflow
401
+ - Write meaningful commit messages
402
+ - Use conventional commits when possible
403
+ - Review changes before committing
404
+ - DO NOT use `git push --force` without permission
405
+ - DO NOT skip hooks (--no-verify) unless explicitly requested
406
+
407
+ ### Client/Server Boundaries
408
+ Keep client/server boundaries clear. Understand when code runs where.
409
+
410
+ ```tsx
411
+ // Server Component
412
+ async function ServerComponent() {
413
+ 'use server' // Optional annotation
414
+ const data = await fetchData() // Runs on server
415
+ return <ClientComponent data={data} />
416
+ }
417
+
418
+ // Client Component
419
+ 'use client'
420
+
421
+ function ClientComponent({ data }) {
422
+ const [state, setState] = useState(data) // Runs on client
423
+ return <div>{state}</div>
424
+ }
425
+ ```
426
+
427
+ ## Best Practices Summary
428
+
429
+ 1. **Type Safety**: Use TypeScript everywhere, avoid `any`
430
+ 2. **State Management**: React state first, Zustand for global needs
431
+ 3. **Performance**: Server components by default, code splitting for heavy components
432
+ 4. **Security**: Validate inputs, secure environment variables, server-side sensitive operations
433
+ 5. **Testing**: Write tests for critical paths, use debugging tools effectively
434
+ 6. **Code Quality**: Follow linting rules, maintain consistent style, write meaningful documentation
435
+ 7. **Development**: Use Bun, follow git best practices, understand client/server boundaries
436
+
437
+ Last updated: 2026-01-26