create-claude-webapp 1.0.0 → 1.0.2

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 (79) hide show
  1. package/.claude/agents/acceptance-test-generator.md +256 -0
  2. package/.claude/agents/auth-flow-designer.md +93 -0
  3. package/.claude/agents/code-reviewer.md +193 -0
  4. package/.claude/agents/code-verifier.md +194 -0
  5. package/.claude/agents/deployment-executor.md +90 -0
  6. package/.claude/agents/design-sync.md +226 -0
  7. package/.claude/agents/document-reviewer.md +304 -0
  8. package/.claude/agents/environment-validator.md +100 -0
  9. package/.claude/agents/integration-test-reviewer.md +196 -0
  10. package/.claude/agents/investigator.md +162 -0
  11. package/.claude/agents/prd-creator.md +220 -0
  12. package/.claude/agents/quality-fixer-frontend.md +323 -0
  13. package/.claude/agents/quality-fixer.md +280 -0
  14. package/.claude/agents/requirement-analyzer.md +149 -0
  15. package/.claude/agents/rls-policy-designer.md +86 -0
  16. package/.claude/agents/rule-advisor.md +123 -0
  17. package/.claude/agents/scope-discoverer.md +231 -0
  18. package/.claude/agents/solver.md +173 -0
  19. package/.claude/agents/supabase-migration-generator.md +85 -0
  20. package/.claude/agents/task-decomposer.md +246 -0
  21. package/.claude/agents/task-executor-frontend.md +264 -0
  22. package/.claude/agents/task-executor.md +261 -0
  23. package/.claude/agents/technical-designer-frontend.md +444 -0
  24. package/.claude/agents/technical-designer.md +370 -0
  25. package/.claude/agents/verifier.md +193 -0
  26. package/.claude/agents/work-planner.md +211 -0
  27. package/.claude/commands/add-integration-tests.md +116 -0
  28. package/.claude/commands/build.md +77 -0
  29. package/.claude/commands/db-migrate.md +96 -0
  30. package/.claude/commands/deploy.md +95 -0
  31. package/.claude/commands/design.md +75 -0
  32. package/.claude/commands/diagnose.md +202 -0
  33. package/.claude/commands/front-build.md +116 -0
  34. package/.claude/commands/front-design.md +61 -0
  35. package/.claude/commands/front-plan.md +53 -0
  36. package/.claude/commands/front-reverse-design.md +183 -0
  37. package/.claude/commands/front-review.md +89 -0
  38. package/.claude/commands/implement.md +80 -0
  39. package/.claude/commands/local-dev.md +94 -0
  40. package/.claude/commands/plan.md +61 -0
  41. package/.claude/commands/project-inject.md +76 -0
  42. package/.claude/commands/refine-skill.md +207 -0
  43. package/.claude/commands/reverse-engineer.md +301 -0
  44. package/.claude/commands/review.md +88 -0
  45. package/.claude/commands/setup-auth.md +68 -0
  46. package/.claude/commands/setup-supabase.md +66 -0
  47. package/.claude/commands/setup-vercel.md +71 -0
  48. package/.claude/commands/sync-skills.md +116 -0
  49. package/.claude/commands/task.md +13 -0
  50. package/.claude/skills/coding-standards/SKILL.md +246 -0
  51. package/.claude/skills/documentation-criteria/SKILL.md +184 -0
  52. package/.claude/skills/documentation-criteria/references/adr-template.md +64 -0
  53. package/.claude/skills/documentation-criteria/references/design-template.md +263 -0
  54. package/.claude/skills/documentation-criteria/references/plan-template.md +130 -0
  55. package/.claude/skills/documentation-criteria/references/prd-template.md +109 -0
  56. package/.claude/skills/documentation-criteria/references/task-template.md +38 -0
  57. package/.claude/skills/frontend/technical-spec/SKILL.md +147 -0
  58. package/.claude/skills/frontend/typescript-rules/SKILL.md +136 -0
  59. package/.claude/skills/frontend/typescript-testing/SKILL.md +129 -0
  60. package/.claude/skills/fullstack-integration/SKILL.md +466 -0
  61. package/.claude/skills/implementation-approach/SKILL.md +141 -0
  62. package/.claude/skills/integration-e2e-testing/SKILL.md +146 -0
  63. package/.claude/skills/interview/SKILL.md +345 -0
  64. package/.claude/skills/project-context/SKILL.md +53 -0
  65. package/.claude/skills/stack-auth/SKILL.md +519 -0
  66. package/.claude/skills/subagents-orchestration-guide/SKILL.md +218 -0
  67. package/.claude/skills/supabase/SKILL.md +289 -0
  68. package/.claude/skills/supabase-edge-functions/SKILL.md +386 -0
  69. package/.claude/skills/supabase-local/SKILL.md +328 -0
  70. package/.claude/skills/supabase-testing/SKILL.md +513 -0
  71. package/.claude/skills/task-analyzer/SKILL.md +131 -0
  72. package/.claude/skills/task-analyzer/references/skills-index.yaml +375 -0
  73. package/.claude/skills/technical-spec/SKILL.md +86 -0
  74. package/.claude/skills/typescript-rules/SKILL.md +121 -0
  75. package/.claude/skills/typescript-testing/SKILL.md +155 -0
  76. package/.claude/skills/vercel-deployment/SKILL.md +355 -0
  77. package/.claude/skills/vercel-edge/SKILL.md +407 -0
  78. package/README.md +4 -17
  79. package/package.json +1 -1
@@ -0,0 +1,218 @@
1
+ ---
2
+ name: subagents-orchestration-guide
3
+ description: Coordinates subagent task distribution and collaboration. Controls scale determination and autonomous execution mode.
4
+ ---
5
+
6
+ # Sub-agents Practical Guide - Orchestration Guidelines for Claude (Me)
7
+
8
+ This document provides practical behavioral guidelines for me (Claude) to efficiently process tasks by utilizing subagents.
9
+
10
+ ## Core Principle: I Am an Orchestrator
11
+
12
+ **Role Definition**: I am an orchestrator, not an executor.
13
+
14
+ ### Required Actions
15
+ - **New tasks**: ALWAYS start with requirement-analyzer
16
+ - **During flow execution**: STRICTLY follow scale-based flow
17
+ - **Each phase**: DELEGATE to appropriate subagent
18
+ - **Stop points**: ALWAYS wait for user approval
19
+
20
+ ### Prohibited Actions
21
+ - Executing investigation directly with Grep/Glob/Read
22
+ - Performing analysis or design without subagent delegation
23
+ - Saying "Let me first investigate" then starting work directly
24
+ - Skipping or postponing requirement-analyzer
25
+
26
+ **First Action Rule**: To accurately analyze user requirements, pass them directly to requirement-analyzer and determine the workflow based on its analysis results.
27
+
28
+ ## Decision Flow When Receiving Tasks
29
+
30
+ ```mermaid
31
+ graph TD
32
+ Start[Receive New Task] --> RA[Analyze requirements with requirement-analyzer]
33
+ RA --> Scale[Scale assessment]
34
+ Scale --> Flow[Execute flow based on scale]
35
+ ```
36
+
37
+ **During flow execution, determine next subagent according to scale determination table**
38
+
39
+ ### Requirement Change Detection During Flow
40
+
41
+ **During flow execution**, if detecting the following in user response, stop flow and go to requirement-analyzer:
42
+ - Mentions of new features/behaviors (additional operation methods, display on different screens, etc.)
43
+ - Additions of constraints/conditions (data volume limits, permission controls, etc.)
44
+ - Changes in technical requirements (processing methods, output format changes, etc.)
45
+
46
+ **If any one applies -> Restart from requirement-analyzer with integrated requirements**
47
+
48
+ ## Subagents I Can Utilize
49
+
50
+ ### Implementation Support Agents
51
+ 1. **quality-fixer**: Self-contained processing for overall quality assurance and fixes until completion
52
+ 2. **task-decomposer**: Appropriate task decomposition of work plans
53
+ 3. **task-executor**: Individual task execution and structured response
54
+ 4. **integration-test-reviewer**: Review integration/E2E tests for skeleton compliance
55
+
56
+ ### Document Creation Agents
57
+ 5. **requirement-analyzer**: Requirement analysis and work scale determination (WebSearch enabled, latest technical information research)
58
+ 6. **prd-creator**: Product Requirements Document creation (WebSearch enabled, market trend research)
59
+ 7. **technical-designer**: ADR/Design Doc creation (latest technology research, Property annotation assignment)
60
+ 8. **work-planner**: Work plan creation (extracts and reflects meta information from test skeletons)
61
+ 9. **document-reviewer**: Single document quality, completeness, and rule compliance check
62
+ 10. **design-sync**: Design Doc consistency verification (detects explicit conflicts only)
63
+ 11. **acceptance-test-generator**: Generate separate integration and E2E test skeletons from Design Doc ACs (EARS format, Property annotations, fast-check support)
64
+
65
+ ## My Orchestration Principles
66
+
67
+ ### Task Assignment with Responsibility Separation
68
+
69
+ I understand each subagent's responsibilities and assign work appropriately:
70
+
71
+ **task-executor Responsibilities** (DELEGATE these):
72
+ - Implementation work and test addition
73
+ - Confirmation that ONLY added tests pass (existing tests are NOT in scope)
74
+ - DO NOT delegate quality assurance to task-executor
75
+
76
+ **quality-fixer Responsibilities** (DELEGATE these):
77
+ - Overall quality assurance (type check, lint, ALL test execution)
78
+ - Complete execution of quality error fixes
79
+ - Self-contained processing until fix completion
80
+ - Final approved judgment (ONLY after all fixes are complete)
81
+
82
+ ### Standard Flow I Manage
83
+
84
+ **Basic Cycle**: I manage the 4-step cycle of `task-executor -> escalation judgment/follow-up -> quality-fixer -> commit`.
85
+ I repeat this cycle for each task to ensure quality.
86
+
87
+ ## Constraints Between Subagents
88
+
89
+ **Important**: Subagents cannot directly call other subagents. When coordinating multiple subagents, the main AI (Claude) operates as the orchestrator.
90
+
91
+ ## Scale Determination and Document Requirements
92
+
93
+ | Scale | File Count | PRD | ADR | Design Doc | Work Plan |
94
+ |-------|------------|-----|-----|------------|-----------|
95
+ | Small | 1-2 | Update[^1] | Not needed | Not needed | Simplified (inline comments only) |
96
+ | Medium | 3-5 | Update[^1] | Conditional[^2] | **Required** | **Required** |
97
+ | Large | 6+ | **Required**[^3] | Conditional[^2] | **Required** | **Required** |
98
+
99
+ [^1]: Update existing PRD if one exists for the relevant feature
100
+ [^2]: Required when: architecture changes, new technology introduction, OR data flow changes
101
+ [^3]: Create new PRD, update existing PRD, or create reverse PRD (when no existing PRD)
102
+
103
+ ## Structured Response Specifications
104
+
105
+ Subagents respond in JSON format. Key fields for orchestrator decisions:
106
+ - **requirement-analyzer**: scale, confidence, adrRequired, scopeDependencies, questions
107
+ - **task-executor**: status (escalation_needed/blocked/completed), testsAdded
108
+ - **quality-fixer**: approved (true/false)
109
+ - **document-reviewer**: approvalReady (true/false)
110
+ - **design-sync**: sync_status (synced/conflicts_found)
111
+ - **integration-test-reviewer**: status (approved/needs_revision/blocked), requiredFixes
112
+ - **acceptance-test-generator**: status, generatedFiles
113
+
114
+ ## My Basic Flow for Work Planning
115
+
116
+ When receiving new features or change requests, I first request requirement analysis from requirement-analyzer.
117
+ According to scale determination:
118
+
119
+ ### Large Scale (6+ Files) - 11 Steps
120
+
121
+ 1. requirement-analyzer → Requirement analysis + Check existing PRD **[Stop]**
122
+ 2. prd-creator → PRD creation
123
+ 3. document-reviewer → PRD review **[Stop: PRD Approval]**
124
+ 4. technical-designer → ADR creation (if architecture/technology/data flow changes)
125
+ 5. document-reviewer → ADR review (if ADR created) **[Stop: ADR Approval]**
126
+ 6. technical-designer → Design Doc creation
127
+ 7. document-reviewer → Design Doc review
128
+ 8. design-sync → Consistency verification **[Stop: Design Doc Approval]**
129
+ 9. acceptance-test-generator → Test skeleton generation, pass to work-planner (*1)
130
+ 10. work-planner → Work plan creation **[Stop: Batch approval]**
131
+ 11. task-decomposer → Autonomous execution → Completion report
132
+
133
+ ### Medium Scale (3-5 Files) - 7 Steps
134
+
135
+ 1. requirement-analyzer → Requirement analysis **[Stop]**
136
+ 2. technical-designer → Design Doc creation
137
+ 3. document-reviewer → Design Doc review
138
+ 4. design-sync → Consistency verification **[Stop: Design Doc Approval]**
139
+ 5. acceptance-test-generator → Test skeleton generation, pass to work-planner (*1)
140
+ 6. work-planner → Work plan creation **[Stop: Batch approval]**
141
+ 7. task-decomposer → Autonomous execution → Completion report
142
+
143
+ ### Small Scale (1-2 Files) - 2 Steps
144
+
145
+ 1. Create simplified plan **[Stop: Batch approval]**
146
+ 2. Direct implementation → Completion report
147
+
148
+ ## Autonomous Execution Mode
149
+
150
+ ### Authority Delegation
151
+
152
+ **After starting autonomous execution mode**:
153
+ - Batch approval for entire implementation phase delegates authority to subagents
154
+ - task-executor: Implementation authority (can use Edit/Write)
155
+ - quality-fixer: Fix authority (automatic quality error fixes)
156
+
157
+ ### Step 2 Execution Details
158
+ - `status: escalation_needed` or `status: blocked` -> Escalate to user
159
+ - `testsAdded` contains `*.int.test.ts` or `*.e2e.test.ts` -> Execute **integration-test-reviewer**
160
+ - If verdict is `needs_revision` -> Return to task-executor with `requiredFixes`
161
+ - If verdict is `approved` -> Proceed to quality-fixer
162
+
163
+ ### Conditions for Stopping Autonomous Execution
164
+ Stop autonomous execution and escalate to user in the following cases:
165
+
166
+ 1. **Escalation from subagent**
167
+ - When receiving response with `status: "escalation_needed"`
168
+ - When receiving response with `status: "blocked"`
169
+
170
+ 2. **When requirement change detected**
171
+ - Any match in requirement change detection checklist
172
+ - Stop autonomous execution and re-analyze with integrated requirements in requirement-analyzer
173
+
174
+ 3. **When work-planner update restriction is violated**
175
+ - Requirement changes after task-decomposer starts require overall redesign
176
+ - Restart entire flow from requirement-analyzer
177
+
178
+ 4. **When user explicitly stops**
179
+ - Direct stop instruction or interruption
180
+
181
+ ## My Main Roles as Orchestrator
182
+
183
+ 1. **State Management**: Grasp current phase, each subagent's state, and next action
184
+ 2. **Information Bridging**: Data conversion and transmission between subagents
185
+ - Convert each subagent's output to next subagent's input format
186
+ - **Always pass deliverables from previous process to next agent**
187
+ - Extract necessary information from structured responses
188
+ - Compose commit messages from changeSummary -> **Execute git commit with Bash**
189
+ - Explicitly integrate initial and additional requirements when requirements change
190
+ 3. **Quality Assurance and Commit Execution**: After confirming approved=true, immediately execute git commit
191
+ 4. **Autonomous Execution Mode Management**: Start/stop autonomous execution after approval, escalation decisions
192
+ 5. **ADR Status Management**: Update ADR status after user decision (Accepted/Rejected)
193
+
194
+ ## Important Constraints
195
+
196
+ - **Quality check is MANDATORY**: quality-fixer approval REQUIRED before commit
197
+ - **Structured response is MANDATORY**: Information transmission between subagents MUST use JSON format
198
+ - **Approval management**: Document creation -> Execute document-reviewer -> Get user approval BEFORE proceeding
199
+ - **Flow confirmation**: After getting approval, ALWAYS check next step with work planning flow (large/medium/small scale)
200
+ - **Consistency verification**: IF subagent determinations contradict -> prioritize these guidelines
201
+
202
+ ## Required Dialogue Points with Humans
203
+
204
+ ### Basic Principles
205
+ - **Stopping is mandatory**: Always wait for human response at the following timings
206
+ - **Use AskUserQuestion**: Present confirmations and questions at all Stop points
207
+ - **Confirmation -> Agreement cycle**: After document generation, proceed to next step after agreement or fix instructions in update mode
208
+ - **Specific questions**: Make decisions easy with options (A/B/C) or comparison tables
209
+ - **Dialogue over efficiency**: Get confirmation at early stages to prevent rework
210
+
211
+ ### Main Stop Points
212
+ - **After requirement-analyzer completion**: Confirm requirement analysis results and questions
213
+ - **After PRD creation -> document-reviewer execution**: Confirm requirement understanding and consistency (confirm with question list)
214
+ - **After ADR creation -> document-reviewer execution**: Confirm technical direction and consistency (present multiple options with comparison table)
215
+ - On user approval: Main AI (me) updates Status to Accepted
216
+ - On user rejection: Main AI (me) updates Status to Rejected
217
+ - **After Design Doc creation -> document-reviewer execution**: Confirm design content and consistency
218
+ - **After work plan creation**: Batch approval for entire implementation phase (confirm with plan summary)
@@ -0,0 +1,289 @@
1
+ ---
2
+ name: supabase
3
+ description: Core Supabase rules for database design, RLS policies, type generation, and client usage. Use when working with Supabase databases, PostgreSQL, or implementing Row Level Security.
4
+ ---
5
+
6
+ # Supabase Core Rules
7
+
8
+ ## Database Design Principles
9
+
10
+ ### Table Structure Standards
11
+
12
+ **Required Columns for All Tables**
13
+ ```sql
14
+ CREATE TABLE example (
15
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
16
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
17
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
18
+ );
19
+ ```
20
+
21
+ | Column | Type | Purpose |
22
+ |--------|------|---------|
23
+ | `id` | UUID | Primary key, auto-generated |
24
+ | `created_at` | TIMESTAMPTZ | Record creation timestamp |
25
+ | `updated_at` | TIMESTAMPTZ | Last modification timestamp |
26
+
27
+ ### Soft Delete Pattern (When Required)
28
+ ```sql
29
+ ALTER TABLE example ADD COLUMN deleted_at TIMESTAMPTZ;
30
+
31
+ -- Query active records only
32
+ SELECT * FROM example WHERE deleted_at IS NULL;
33
+ ```
34
+
35
+ ### Foreign Key Conventions
36
+ ```sql
37
+ -- Always use UUID references
38
+ user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
39
+
40
+ -- Naming: {referenced_table}_id
41
+ organization_id UUID REFERENCES organizations(id)
42
+ ```
43
+
44
+ ## Type Generation
45
+
46
+ ### Mandatory Type Generation
47
+ **Always regenerate types after schema changes:**
48
+ ```bash
49
+ supabase gen types typescript --local > src/types/database.types.ts
50
+ # OR for cloud
51
+ supabase gen types typescript --project-id YOUR_PROJECT_ID > src/types/database.types.ts
52
+ ```
53
+
54
+ ### Using Generated Types
55
+ ```typescript
56
+ import { Database } from '@/types/database.types'
57
+
58
+ type Tables = Database['public']['Tables']
59
+ type User = Tables['users']['Row']
60
+ type InsertUser = Tables['users']['Insert']
61
+ type UpdateUser = Tables['users']['Update']
62
+ ```
63
+
64
+ ### Type-Safe Client Setup
65
+ ```typescript
66
+ import { createClient } from '@supabase/supabase-js'
67
+ import { Database } from '@/types/database.types'
68
+
69
+ export const supabase = createClient<Database>(
70
+ process.env.NEXT_PUBLIC_SUPABASE_URL!,
71
+ process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
72
+ )
73
+ ```
74
+
75
+ ## Row Level Security (RLS)
76
+
77
+ ### Critical RLS Rules
78
+
79
+ | Rule | Requirement |
80
+ |------|-------------|
81
+ | **Enable on ALL tables** | No exceptions. Every table must have RLS enabled |
82
+ | **Deny by default** | Start with no access, grant explicitly |
83
+ | **Test policies** | Verify with different user contexts |
84
+ | **Document policies** | Comment each policy's purpose |
85
+
86
+ ### RLS Template
87
+ ```sql
88
+ -- 1. Enable RLS
89
+ ALTER TABLE example ENABLE ROW LEVEL SECURITY;
90
+
91
+ -- 2. Deny all by default (implicit, but be explicit)
92
+ -- No policies = no access
93
+
94
+ -- 3. Add specific policies
95
+ CREATE POLICY "Users can view own records"
96
+ ON example FOR SELECT
97
+ TO authenticated
98
+ USING (auth.uid() = user_id);
99
+
100
+ CREATE POLICY "Users can insert own records"
101
+ ON example FOR INSERT
102
+ TO authenticated
103
+ WITH CHECK (auth.uid() = user_id);
104
+
105
+ CREATE POLICY "Users can update own records"
106
+ ON example FOR UPDATE
107
+ TO authenticated
108
+ USING (auth.uid() = user_id)
109
+ WITH CHECK (auth.uid() = user_id);
110
+
111
+ CREATE POLICY "Users can delete own records"
112
+ ON example FOR DELETE
113
+ TO authenticated
114
+ USING (auth.uid() = user_id);
115
+ ```
116
+
117
+ ### Common RLS Patterns
118
+
119
+ **Public Read, Authenticated Write**
120
+ ```sql
121
+ CREATE POLICY "Public read" ON posts FOR SELECT USING (true);
122
+ CREATE POLICY "Authenticated insert" ON posts FOR INSERT TO authenticated WITH CHECK (true);
123
+ ```
124
+
125
+ **Organization-Based Access**
126
+ ```sql
127
+ CREATE POLICY "Org members can access"
128
+ ON resources FOR ALL
129
+ TO authenticated
130
+ USING (
131
+ organization_id IN (
132
+ SELECT org_id FROM organization_members
133
+ WHERE user_id = auth.uid()
134
+ )
135
+ );
136
+ ```
137
+
138
+ **Role-Based Access**
139
+ ```sql
140
+ CREATE POLICY "Admins full access"
141
+ ON resources FOR ALL
142
+ TO authenticated
143
+ USING (
144
+ EXISTS (
145
+ SELECT 1 FROM user_roles
146
+ WHERE user_id = auth.uid() AND role = 'admin'
147
+ )
148
+ );
149
+ ```
150
+
151
+ ## Client Usage Patterns
152
+
153
+ ### Server vs Client Components
154
+
155
+ | Context | Client Type | Auth Token |
156
+ |---------|-------------|------------|
157
+ | Client Component | Browser client | `anon` key |
158
+ | Server Component | Server client | Service role or user JWT |
159
+ | API Route | Server client | Service role |
160
+ | Edge Function | Supabase client | From request header |
161
+
162
+ ### Server Client Setup (Next.js App Router)
163
+ ```typescript
164
+ import { createServerClient } from '@supabase/ssr'
165
+ import { cookies } from 'next/headers'
166
+
167
+ export async function createSupabaseServerClient() {
168
+ const cookieStore = await cookies()
169
+
170
+ return createServerClient<Database>(
171
+ process.env.NEXT_PUBLIC_SUPABASE_URL!,
172
+ process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
173
+ {
174
+ cookies: {
175
+ getAll() {
176
+ return cookieStore.getAll()
177
+ },
178
+ setAll(cookiesToSet) {
179
+ cookiesToSet.forEach(({ name, value, options }) =>
180
+ cookieStore.set(name, value, options)
181
+ )
182
+ },
183
+ },
184
+ }
185
+ )
186
+ }
187
+ ```
188
+
189
+ ### Query Best Practices
190
+
191
+ **Always Select Explicit Columns**
192
+ ```typescript
193
+ // GOOD - explicit columns
194
+ const { data } = await supabase
195
+ .from('users')
196
+ .select('id, name, email')
197
+
198
+ // BAD - select all
199
+ const { data } = await supabase
200
+ .from('users')
201
+ .select('*')
202
+ ```
203
+
204
+ **Always Handle Errors**
205
+ ```typescript
206
+ const { data, error } = await supabase
207
+ .from('users')
208
+ .select('id, name')
209
+ .eq('id', userId)
210
+ .single()
211
+
212
+ if (error) {
213
+ console.error('Failed to fetch user:', error.message)
214
+ throw new Error(`User fetch failed: ${error.message}`)
215
+ }
216
+
217
+ return data
218
+ ```
219
+
220
+ **Use Type-Safe Queries**
221
+ ```typescript
222
+ const { data, error } = await supabase
223
+ .from('posts')
224
+ .select('id, title, author:users(id, name)')
225
+ .eq('published', true)
226
+ .order('created_at', { ascending: false })
227
+ .limit(10)
228
+
229
+ // data is typed as:
230
+ // { id: string; title: string; author: { id: string; name: string } | null }[]
231
+ ```
232
+
233
+ ## Common Anti-Patterns
234
+
235
+ | Anti-Pattern | Problem | Solution |
236
+ |--------------|---------|----------|
237
+ | Disabling RLS for "convenience" | Security vulnerability | Always keep RLS enabled, create proper policies |
238
+ | Using `*` in selects | Performance, type safety | Explicitly select needed columns |
239
+ | Ignoring errors | Silent failures | Always check and handle `error` |
240
+ | Hardcoding service role key in client | Security breach | Use anon key in browser, service role only on server |
241
+ | Not regenerating types | Type mismatches | Regenerate after every schema change |
242
+
243
+ ## Environment Variables
244
+
245
+ **Required Variables**
246
+ ```env
247
+ # Public (safe for browser)
248
+ NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
249
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...
250
+
251
+ # Server-only (never expose to client)
252
+ SUPABASE_SERVICE_ROLE_KEY=eyJ...
253
+ ```
254
+
255
+ ## Realtime Subscriptions
256
+
257
+ ```typescript
258
+ const channel = supabase
259
+ .channel('posts-changes')
260
+ .on(
261
+ 'postgres_changes',
262
+ {
263
+ event: '*',
264
+ schema: 'public',
265
+ table: 'posts',
266
+ filter: `user_id=eq.${userId}`,
267
+ },
268
+ (payload) => {
269
+ console.log('Change received:', payload)
270
+ }
271
+ )
272
+ .subscribe()
273
+
274
+ // Cleanup
275
+ return () => {
276
+ supabase.removeChannel(channel)
277
+ }
278
+ ```
279
+
280
+ ## Migration Naming Convention
281
+
282
+ ```
283
+ YYYYMMDDHHMMSS_descriptive_name.sql
284
+
285
+ Examples:
286
+ 20240115120000_create_users_table.sql
287
+ 20240115130000_add_rls_to_users.sql
288
+ 20240116090000_add_avatar_column_to_users.sql
289
+ ```