@polymorphism-tech/morph-spec 4.16.0 → 4.18.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 (107) hide show
  1. package/CLAUDE.md +36 -0
  2. package/README.md +2 -2
  3. package/bin/morph-spec.js +3 -0
  4. package/bin/task-manager.js +999 -962
  5. package/claude-plugin.json +1 -1
  6. package/docs/CHEATSHEET.md +1 -1
  7. package/docs/QUICKSTART.md +1 -1
  8. package/framework/agents/ai-agents/vector-search-expert.md +247 -233
  9. package/framework/agents/backend/ms-agent-expert.md +1 -1
  10. package/framework/agents/backend/neon-expert.md +379 -0
  11. package/framework/agents/frontend/gsap-animator.md +131 -0
  12. package/framework/agents/integrations/neon-auth.md +151 -0
  13. package/framework/agents.json +1183 -1085
  14. package/framework/commands/morph-preflight.md +200 -192
  15. package/framework/hooks/claude-code/session-start/inject-morph-context.js +1 -1
  16. package/framework/rules/gsap-standards.md +13 -0
  17. package/framework/rules/neon-auth-standards.md +13 -0
  18. package/framework/rules/neon-standards.md +26 -0
  19. package/framework/skills/level-0-meta/mcp-registry.json +1 -1
  20. package/framework/skills/level-0-meta/morph-agent-teams/SKILL.md +472 -472
  21. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +1 -1
  22. package/framework/skills/level-0-meta/morph-init/SKILL.md +12 -12
  23. package/framework/skills/level-0-meta/morph-post-implementation/SKILL.md +5 -5
  24. package/framework/skills/level-0-meta/morph-tool-usage-guide/SKILL.md +5 -5
  25. package/framework/skills/level-0-meta/morph-tool-usage-guide/references/tools-per-phase.md +7 -7
  26. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +24 -24
  27. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +12 -12
  28. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +9 -9
  29. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +1 -1
  30. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +1 -1
  31. package/framework/skills/level-1-workflows/morph-phase-tasks/references/task-planning-patterns.md +143 -143
  32. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +1 -1
  33. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +1 -1
  34. package/framework/standards/STANDARDS.json +197 -116
  35. package/framework/standards/ai-agents/production.md +1 -0
  36. package/framework/standards/ai-agents/setup.md +3 -2
  37. package/framework/standards/ai-agents/workflows.md +1 -0
  38. package/framework/standards/architecture/vertical-slice/vertical-slice.md +4 -4
  39. package/framework/standards/backend/database/postgresql/database.md +63 -83
  40. package/framework/standards/backend/dotnet/scalar-ui.md +172 -172
  41. package/framework/standards/backend/dotnet/vsa-handler-patterns.md +274 -274
  42. package/framework/standards/backend/integrations/asaas/asaas-api.md +2 -2
  43. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +364 -0
  44. package/framework/standards/frontend/design-system/animations.md +9 -0
  45. package/framework/standards/frontend/gsap/gsap-core.md +463 -0
  46. package/framework/standards/frontend/gsap/gsap-plugins.md +294 -0
  47. package/framework/standards/frontend/gsap/gsap-scrolltrigger.md +318 -0
  48. package/framework/standards/frontend/nextjs/motion-patterns.md +1 -0
  49. package/framework/standards/frontend/nextjs/nextjs-patterns.md +47 -37
  50. package/framework/standards/infrastructure/docker/easypanel-deploy.md +4 -8
  51. package/framework/standards/infrastructure/neon/neon-pgrag.md +239 -0
  52. package/framework/standards/infrastructure/neon/neon-pgvector.md +236 -0
  53. package/framework/standards/infrastructure/neon/neon-semantic-kernel.md +310 -0
  54. package/framework/standards/infrastructure/neon/neon-setup.md +186 -0
  55. package/framework/standards/integration/mcp/mcp-tools.md +32 -34
  56. package/framework/templates/README.md +20 -20
  57. package/framework/templates/REGISTRY.json +54 -101
  58. package/framework/templates/code/dotnet/abstractions/api-endpoint.cs +7 -7
  59. package/framework/templates/code/dotnet/backend/repository.cs +148 -148
  60. package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +2 -2
  61. package/framework/templates/code/dotnet/database/vector-entity.cs +93 -0
  62. package/framework/templates/code/dotnet/feature/endpoint.cs.hbs +1 -1
  63. package/framework/templates/code/sql/{supabase-migration.sql → postgresql-migration.sql} +12 -21
  64. package/framework/templates/code/sql/{supabase-migration.template.sql → postgresql-migration.template.sql} +13 -18
  65. package/framework/templates/code/sql/{rls-policy.sql → postgresql-rls-policy.sql} +6 -9
  66. package/framework/templates/code/typescript/contracts.ts +167 -168
  67. package/framework/templates/context/CONTEXT.md +3 -3
  68. package/framework/templates/docs/proposal.md +6 -6
  69. package/framework/templates/docs/ui-components.md +1 -1
  70. package/framework/templates/feature/decisions.md +122 -121
  71. package/framework/templates/feature/recap.md +145 -145
  72. package/framework/templates/feature/tasks.md +199 -199
  73. package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +44 -0
  74. package/framework/templates/infrastructure/docker/docker-compose.template.yml +50 -67
  75. package/framework/templates/infrastructure/docker/dockerfile-api.dockerfile +38 -38
  76. package/framework/templates/infrastructure/docker/dockerfile-web.dockerfile +48 -48
  77. package/framework/templates/infrastructure/docker/easypanel.template.json +46 -54
  78. package/framework/templates/infrastructure/github/README.md +56 -56
  79. package/framework/templates/integrations/neon-auth-config.cs +133 -0
  80. package/framework/templates/integrations/semantic-kernel-neon.cs +125 -0
  81. package/framework/workflows/README.md +1 -1
  82. package/framework/workflows/docs/full-morph.md +69 -69
  83. package/package.json +1 -1
  84. package/src/commands/agents/dispatch-agents.js +19 -15
  85. package/src/commands/state/advance-phase.js +5 -0
  86. package/src/commands/tasks/task.js +3 -0
  87. package/src/core/state/state-manager.js +45 -1
  88. package/src/core/templates/template-registry.js +1 -66
  89. package/src/lib/detectors/index.js +4 -4
  90. package/src/lib/generators/architecture-scanner.js +639 -640
  91. package/src/lib/installers/mcp-installer.js +1 -1
  92. package/src/lib/tasks/task-classifier.js +15 -1
  93. package/src/lib/tasks/test-runner.js +5 -1
  94. package/src/lib/validators/content/content-validator.js +9 -10
  95. package/src/lib/validators/validation-runner.js +7 -5
  96. package/framework/agents/backend/supabase-expert.md +0 -256
  97. package/framework/agents/integrations/clerk-auth.md +0 -109
  98. package/framework/rules/clerk-standards.md +0 -13
  99. package/framework/rules/supabase-standards.md +0 -29
  100. package/framework/standards/backend/integrations/clerk/clerk-auth.md +0 -290
  101. package/framework/standards/infrastructure/supabase/mcp-setup.md +0 -142
  102. package/framework/standards/infrastructure/supabase/supabase-auth.md +0 -176
  103. package/framework/standards/infrastructure/supabase/supabase-custom-jwt.md +0 -206
  104. package/framework/standards/infrastructure/supabase/supabase-pgvector.md +0 -169
  105. package/framework/standards/infrastructure/supabase/supabase-rls.md +0 -184
  106. package/framework/standards/infrastructure/supabase/supabase-storage.md +0 -153
  107. package/framework/templates/integrations/clerk-config.cs +0 -217
@@ -0,0 +1,379 @@
1
+ ---
2
+ name: neon-expert
3
+ description: Neon PostgreSQL & AI Data specialist for connection pooling, RLS policies with Neon Auth JWT, EF Core migrations, pgvector embeddings, pgrag RAG pipelines, database branching, and scale-to-zero configuration. Use when designing database schemas, implementing Row Level Security, setting up vector search, or managing Neon branches.
4
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep
5
+ stacks:
6
+ - neon
7
+ color: green
8
+ effort: medium
9
+ ---
10
+
11
+ # Neon PostgreSQL & AI Data Specialist
12
+
13
+ Expert in Neon serverless Postgres: connection pooling, RLS with Neon Auth JWT, EF Core migrations, pgvector, pgrag, database branching, and scale-to-zero.
14
+
15
+ > **Ref:** `framework/standards/infrastructure/neon/` — connection pooling, RLS, pgvector, pgrag standards
16
+
17
+ ## Connection Pooling
18
+
19
+ ```
20
+ # Direct connection (migrations, pg_dump, schema changes only)
21
+ postgresql://user:password@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname?sslmode=require
22
+
23
+ # Pooled connection (application — ALWAYS use this)
24
+ postgresql://user:password@ep-cool-darkness-123456-pooler.us-east-2.aws.neon.tech/dbname?sslmode=require
25
+ ```
26
+
27
+ **Rule:** Application code ALWAYS connects via the `-pooler` endpoint. Direct connections only for migrations and schema changes.
28
+
29
+ ### Get connection strings via CLI
30
+
31
+ ```bash
32
+ # Direct (default)
33
+ neonctl connection-string
34
+
35
+ # Pooled (for application use)
36
+ neonctl connection-string --pooled
37
+
38
+ # Specific branch
39
+ neonctl connection-string feature/user-auth --pooled
40
+ ```
41
+
42
+ ### PgBouncer settings (Neon-managed, not configurable)
43
+
44
+ - `pool_mode=transaction` — connections returned after each transaction
45
+ - `max_client_conn=10000`
46
+ - `default_pool_size=0.9 * max_connections`
47
+
48
+ ### Pooled connection limitations
49
+
50
+ Transaction mode restricts: `SET`/`RESET`, `LISTEN`/`NOTIFY`, SQL-level prepared statements, persistent temp tables. Use explicit schema references instead of `SET search_path`.
51
+
52
+ ---
53
+
54
+ ## Row Level Security (RLS)
55
+
56
+ ### Enable RLS on every table
57
+
58
+ ```sql
59
+ ALTER TABLE public.documents ENABLE ROW LEVEL SECURITY;
60
+ ```
61
+
62
+ ### RLS with Neon Auth JWT
63
+
64
+ Neon provides `auth.user_id()` via the `pg_session_jwt` extension. It extracts the `sub` claim from the validated JWT automatically. Neon Auth issues these JWTs — no external provider needed.
65
+
66
+ ```sql
67
+ -- User owns the row
68
+ CREATE POLICY "Users can view own documents"
69
+ ON public.documents FOR SELECT TO authenticated
70
+ USING (auth.user_id() = user_id);
71
+
72
+ -- User can insert own rows
73
+ CREATE POLICY "Users can insert own documents"
74
+ ON public.documents FOR INSERT TO authenticated
75
+ WITH CHECK (auth.user_id() = user_id);
76
+
77
+ -- User can update own rows
78
+ CREATE POLICY "Users can update own documents"
79
+ ON public.documents FOR UPDATE TO authenticated
80
+ USING (auth.user_id() = user_id)
81
+ WITH CHECK (auth.user_id() = user_id);
82
+
83
+ -- User can delete own rows
84
+ CREATE POLICY "Users can delete own documents"
85
+ ON public.documents FOR DELETE TO authenticated
86
+ USING (auth.user_id() = user_id);
87
+ ```
88
+
89
+ ### Team-based access
90
+
91
+ ```sql
92
+ CREATE POLICY "Team members can view"
93
+ ON public.documents FOR SELECT
94
+ USING (
95
+ team_id IN (
96
+ SELECT team_id FROM public.team_members
97
+ WHERE user_id = auth.user_id()
98
+ )
99
+ );
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Migrations (EF Core)
105
+
106
+ Neon uses standard PostgreSQL — migrations are managed via EF Core, NOT a proprietary CLI.
107
+
108
+ ```bash
109
+ # Create migration
110
+ dotnet ef migrations add CreateDocumentsTable --project src/Infrastructure --startup-project src/Web
111
+
112
+ # Apply migration (use DIRECT connection string, not pooled)
113
+ dotnet ef database update --project src/Infrastructure --startup-project src/Web
114
+
115
+ # Review generated migration before applying — check Up() and Down()
116
+ ```
117
+
118
+ ### Connection string in appsettings
119
+
120
+ ```json
121
+ {
122
+ "ConnectionStrings": {
123
+ "DefaultConnection": "Host=ep-cool-darkness-123456-pooler.us-east-2.aws.neon.tech;Database=dbname;Username=user;Password=password;SSL Mode=Require",
124
+ "MigrationConnection": "Host=ep-cool-darkness-123456.us-east-2.aws.neon.tech;Database=dbname;Username=user;Password=password;SSL Mode=Require"
125
+ }
126
+ }
127
+ ```
128
+
129
+ **Rule:** Register two connection strings — pooled for application, direct for migrations. Configure `DbContext` to use `MigrationConnection` only in migration tooling.
130
+
131
+ ---
132
+
133
+ ## pgvector (Embeddings)
134
+
135
+ ### Setup
136
+
137
+ ```sql
138
+ CREATE EXTENSION IF NOT EXISTS vector;
139
+
140
+ CREATE TABLE public.embeddings (
141
+ id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
142
+ document_id UUID REFERENCES public.documents(id) ON DELETE CASCADE,
143
+ content TEXT NOT NULL,
144
+ embedding vector(1536) NOT NULL, -- OpenAI text-embedding-3-small
145
+ metadata JSONB DEFAULT '{}'::jsonb,
146
+ created_at TIMESTAMPTZ DEFAULT now() NOT NULL
147
+ );
148
+
149
+ -- Optimize memory before index creation
150
+ SET maintenance_work_mem = '2 GB'; -- max 50-60% of compute RAM
151
+ SET max_parallel_maintenance_workers = 7;
152
+
153
+ -- HNSW index for fast similarity search (cosine distance)
154
+ CREATE INDEX idx_embeddings_vector ON public.embeddings
155
+ USING hnsw (embedding vector_cosine_ops)
156
+ WITH (m = 16, ef_construction = 64);
157
+ ```
158
+
159
+ ### Similarity search function
160
+
161
+ ```sql
162
+ CREATE OR REPLACE FUNCTION match_embeddings(
163
+ query_embedding vector(1536),
164
+ match_threshold FLOAT DEFAULT 0.78,
165
+ match_count INT DEFAULT 5
166
+ )
167
+ RETURNS TABLE (
168
+ id UUID,
169
+ content TEXT,
170
+ metadata JSONB,
171
+ similarity FLOAT
172
+ )
173
+ LANGUAGE plpgsql AS $$
174
+ BEGIN
175
+ RETURN QUERY
176
+ SELECT
177
+ e.id,
178
+ e.content,
179
+ e.metadata,
180
+ 1 - (e.embedding <=> query_embedding) AS similarity
181
+ FROM public.embeddings e
182
+ WHERE 1 - (e.embedding <=> query_embedding) > match_threshold
183
+ ORDER BY e.embedding <=> query_embedding
184
+ LIMIT match_count;
185
+ END;
186
+ $$;
187
+ ```
188
+
189
+ ### C# — Semantic Kernel vector store with Neon
190
+
191
+ ```csharp
192
+ // NuGet: Microsoft.SemanticKernel, Npgsql.EntityFrameworkCore.PostgreSQL, pgvector
193
+ using Microsoft.SemanticKernel;
194
+ using Microsoft.SemanticKernel.Connectors.Postgres;
195
+ using Npgsql;
196
+
197
+ // Register the Postgres vector store
198
+ var dataSource = new NpgsqlDataSourceBuilder(connectionString)
199
+ .UseVector()
200
+ .Build();
201
+
202
+ builder.Services.AddPostgresVectorStore(dataSource);
203
+ ```
204
+
205
+ ---
206
+
207
+ ## pgrag (SQL-Native RAG Pipeline)
208
+
209
+ pgrag is an experimental Neon extension for building end-to-end RAG pipelines entirely in SQL.
210
+
211
+ ### Setup
212
+
213
+ ```sql
214
+ SET neon.allow_unstable_extensions = 'true';
215
+
216
+ CREATE EXTENSION IF NOT EXISTS rag CASCADE;
217
+ CREATE EXTENSION IF NOT EXISTS rag_bge_small_en_v15 CASCADE; -- local embeddings
218
+ CREATE EXTENSION IF NOT EXISTS rag_jina_reranker_v1_tiny_en CASCADE; -- local reranker
219
+ ```
220
+
221
+ ### Text extraction
222
+
223
+ ```sql
224
+ -- Extract text from PDF, DOCX, or HTML
225
+ SELECT rag.text_from_pdf(pdf_bytea);
226
+ SELECT rag.text_from_docx(docx_bytea);
227
+ SELECT rag.markdown_from_html(html_text);
228
+ ```
229
+
230
+ ### Chunking
231
+
232
+ ```sql
233
+ -- Character-based chunking
234
+ SELECT unnest(rag.chunks_by_character_count(fulltext, 1000, 200)) AS chunk
235
+ FROM documents;
236
+
237
+ -- Token-based chunking (model-aware)
238
+ SELECT unnest(rag_bge_small_en_v15.chunks_by_token_count(fulltext, 192, 8)) AS chunk
239
+ FROM documents;
240
+ ```
241
+
242
+ ### Embedding generation
243
+
244
+ ```sql
245
+ -- Local embeddings (BGE small, 384 dimensions — no API key needed)
246
+ INSERT INTO embeddings (doc_id, chunk, embedding)
247
+ SELECT id, chunk, rag_bge_small_en_v15.embedding_for_passage(chunk)
248
+ FROM chunks;
249
+
250
+ -- OpenAI embeddings (1536 dimensions — requires OPENAI_API_KEY)
251
+ INSERT INTO embeddings (doc_id, chunk, embedding)
252
+ SELECT id, chunk, rag.openai_text_embedding_3_small(chunk)
253
+ FROM chunks;
254
+ ```
255
+
256
+ ### Search with reranking
257
+
258
+ ```sql
259
+ -- Step 1: Vector similarity search
260
+ WITH candidates AS (
261
+ SELECT chunk, embedding <=> rag_bge_small_en_v15.embedding_for_query('my question') AS distance
262
+ FROM embeddings
263
+ ORDER BY distance
264
+ LIMIT 20
265
+ ),
266
+ -- Step 2: Rerank for precision
267
+ ranked AS (
268
+ SELECT chunk, rag_jina_reranker_v1_tiny_en.rerank_distance('my question', chunk) AS rerank_distance
269
+ FROM candidates
270
+ ORDER BY rerank_distance
271
+ LIMIT 5
272
+ )
273
+ SELECT * FROM ranked;
274
+ ```
275
+
276
+ ### Chat completion (answer generation)
277
+
278
+ ```sql
279
+ SELECT rag.openai_chat_completion(json_object(
280
+ 'model': 'gpt-4o-mini',
281
+ 'messages': json_array(
282
+ json_object('role': 'system', 'content': 'Answer based on the provided context.'),
283
+ json_object('role': 'user', 'content': 'Context: ' || context_chunks || E'\n\nQuestion: ' || user_question)
284
+ )
285
+ )) -> 'choices' -> 0 -> 'message' -> 'content' AS answer;
286
+ ```
287
+
288
+ ---
289
+
290
+ ## Database Branching
291
+
292
+ Neon branches are copy-on-write clones of your database — instant, zero-cost until data diverges.
293
+
294
+ ### Branch workflow
295
+
296
+ ```bash
297
+ # Create a feature branch from main
298
+ neonctl branches create --name feature/user-auth
299
+
300
+ # Create a branch from a specific point in time
301
+ neonctl branches create --name data-recovery --parent 2024-07-11T10:00:00Z
302
+
303
+ # Create a schema-only branch (no data)
304
+ neonctl branches create --name preview/pr-42 --schema-only
305
+
306
+ # List all branches
307
+ neonctl branches list
308
+
309
+ # Compare schema differences
310
+ neonctl branches schema-diff production feature/user-auth
311
+
312
+ # Reset branch to parent (re-sync with main)
313
+ neonctl branches reset feature/user-auth --parent
314
+
315
+ # Delete branch
316
+ neonctl branches delete feature/user-auth
317
+ ```
318
+
319
+ ### Branch strategy
320
+
321
+ | Branch | Purpose | Lifecycle |
322
+ |--------|---------|-----------|
323
+ | `main` | Production database | Permanent |
324
+ | `dev` | Shared development | Permanent |
325
+ | `preview/pr-{n}` | PR preview environments | Ephemeral (delete on merge) |
326
+ | `staging` | Pre-production validation | Permanent |
327
+
328
+ **Rule:** Always create `--schema-only` branches for PR previews to avoid copying production data. Use `neonctl branches schema-diff` before merging migration branches.
329
+
330
+ ---
331
+
332
+ ## Scale-to-Zero
333
+
334
+ Neon auto-suspends inactive computes after 5 minutes of inactivity (Free plan, fixed). Reactivation takes ~200-500ms on first query.
335
+
336
+ ### Configuration
337
+
338
+ - **Free plan:** 5-minute suspend timeout (not configurable)
339
+ - **Paid plans:** Configurable timeout or disable scale-to-zero entirely
340
+ - **Computes > 16 CU:** Always active (no auto-suspend)
341
+
342
+ ### Cold start mitigation
343
+
344
+ ```csharp
345
+ // Use connection retry logic in .NET
346
+ builder.Services.AddDbContext<AppDbContext>(options =>
347
+ options.UseNpgsql(connectionString, npgsqlOptions =>
348
+ {
349
+ npgsqlOptions.EnableRetryOnFailure(
350
+ maxRetryCount: 3,
351
+ maxRetryDelay: TimeSpan.FromSeconds(5),
352
+ errorCodesToAdd: null);
353
+ npgsqlOptions.CommandTimeout(30);
354
+ }));
355
+ ```
356
+
357
+ **Rule:** Always configure retry logic in application code. The first connection after auto-suspend may take 200-500ms. For latency-sensitive production workloads on paid plans, disable scale-to-zero.
358
+
359
+ ---
360
+
361
+ ## Checklist
362
+
363
+ - [ ] Pooled connection (`-pooler` endpoint) used for all application connections
364
+ - [ ] Direct connection used only for migrations and schema changes
365
+ - [ ] RLS enabled on ALL public tables
366
+ - [ ] RLS policies use `auth.user_id()` via `pg_session_jwt` extension
367
+ - [ ] RLS policies cover SELECT, INSERT, UPDATE, DELETE
368
+ - [ ] EF Core migrations use direct connection string
369
+ - [ ] Indexes on all frequently filtered columns
370
+ - [ ] pgvector: HNSW index with `maintenance_work_mem` tuned before creation
371
+ - [ ] pgrag: extensions installed with `neon.allow_unstable_extensions = 'true'`
372
+ - [ ] Database branches created for PR previews (`--schema-only`)
373
+ - [ ] Branch cleanup automated on PR merge
374
+ - [ ] Connection retry logic configured for scale-to-zero cold starts
375
+ - [ ] `neonctl branches schema-diff` run before merging migration branches
376
+
377
+ ---
378
+
379
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: gsap-animator
3
+ description: GSAP animation specialist for complex scroll-driven animations, SVG morphing, timeline sequencing, and premium plugin integration (ScrollTrigger, SplitText, Flip, MorphSVG, DrawSVG, MotionPath). Use when animations need fine-grained control beyond Framer Motion.
4
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep
5
+ stacks:
6
+ - nextjs
7
+ color: green
8
+ effort: high
9
+ permissionMode: acceptEdits
10
+ ---
11
+
12
+ # GSAP Animation Specialist
13
+
14
+ Implements complex imperative animations using GSAP with ScrollTrigger, timelines, and premium plugins in Next.js projects. Complements Framer Motion — use GSAP for scroll-driven animations, SVG morphing, complex sequenced timelines, and SplitText effects.
15
+
16
+ ## Stack
17
+
18
+ | Layer | Technology |
19
+ |-------|-----------|
20
+ | Animation Engine | GSAP 3.12+ |
21
+ | React Hook | `@gsap/react` (`useGSAP()`) |
22
+ | Scroll Plugin | ScrollTrigger |
23
+ | Premium Plugins | SplitText, MorphSVG, DrawSVG, Flip, MotionPath, Draggable |
24
+
25
+ ## Critical Standards (Read FIRST)
26
+
27
+ | Standard | What |
28
+ |----------|------|
29
+ | `frontend/gsap/gsap-core.md` | **Core APIs, useGSAP hook, timeline, performance, accessibility** |
30
+ | `frontend/gsap/gsap-scrolltrigger.md` | **ScrollTrigger: pinning, scrubbing, batch, parallax** |
31
+ | `frontend/gsap/gsap-plugins.md` | **Flip, SplitText, MorphSVG, DrawSVG, MotionPath, Draggable** |
32
+
33
+ ## Mandatory Design System Protocol
34
+
35
+ **Before any animation implementation:**
36
+
37
+ 1. Read `.morph/context/design-system.md` — extract motion tokens (durations, easings)
38
+ 2. Import from `@/lib/design-tokens` — never hardcode duration or easing values
39
+ 3. Check if the animation is better suited for Framer Motion (see decision tree below)
40
+
41
+ ## Decision Tree: GSAP vs Framer Motion
42
+
43
+ | Need | Use |
44
+ |------|-----|
45
+ | ScrollTrigger (pin, scrub, parallax) | GSAP |
46
+ | SVG morphing, stroke drawing | GSAP |
47
+ | Complex multi-step timelines with labels | GSAP |
48
+ | SplitText, text scramble effects | GSAP |
49
+ | Drag with physics/inertia | GSAP |
50
+ | Simple enter/exit transitions | Framer Motion |
51
+ | Layout animations (AnimatePresence) | Framer Motion |
52
+ | Gesture responses (hover, tap) | Framer Motion |
53
+
54
+ **CRITICAL:** Never animate the same DOM element with both GSAP and Framer Motion. They fight for control of inline styles.
55
+
56
+ ## Canonical useGSAP Pattern
57
+
58
+ ```typescript
59
+ 'use client';
60
+ import { useRef } from 'react';
61
+ import { useGSAP } from '@gsap/react';
62
+ import gsap from 'gsap';
63
+ import { ScrollTrigger } from 'gsap/ScrollTrigger';
64
+
65
+ gsap.registerPlugin(ScrollTrigger);
66
+
67
+ function AnimatedSection() {
68
+ const containerRef = useRef<HTMLDivElement>(null);
69
+
70
+ useGSAP(() => {
71
+ const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
72
+ if (prefersReducedMotion) return;
73
+
74
+ gsap.from('.reveal-item', {
75
+ y: 40,
76
+ opacity: 0,
77
+ stagger: 0.1,
78
+ duration: 0.6,
79
+ ease: 'power2.out',
80
+ scrollTrigger: {
81
+ trigger: containerRef.current,
82
+ start: 'top 80%',
83
+ toggleActions: 'play none none none',
84
+ },
85
+ });
86
+ }, { scope: containerRef });
87
+
88
+ return (
89
+ <section ref={containerRef}>
90
+ <div className="reveal-item">Content</div>
91
+ </section>
92
+ );
93
+ }
94
+ ```
95
+
96
+ Key points:
97
+ - **Always** pass `{ scope: containerRef }` to limit selectors to this component
98
+ - **Always** check `prefers-reduced-motion` before animating
99
+ - **Always** use `'use client'` directive — GSAP cannot run server-side
100
+ - useGSAP handles cleanup automatically on unmount
101
+
102
+ ## WCAG Motion Compliance
103
+
104
+ Every animated component must respect `prefers-reduced-motion`:
105
+
106
+ ```typescript
107
+ // Recommended: gsap.matchMedia()
108
+ gsap.matchMedia().add('(prefers-reduced-motion: no-preference)', () => {
109
+ // Animations here — automatically reverted when media query stops matching
110
+ });
111
+ ```
112
+
113
+ When reduced motion is active:
114
+ - Skip all transform animations (x, y, scale, rotation)
115
+ - Keep opacity-only fades (they do not cause vestibular issues)
116
+ - Use `gsap.set()` to jump to final state instantly
117
+
118
+ ## Checklist
119
+
120
+ - [ ] All GSAP code in `'use client'` components
121
+ - [ ] `useGSAP()` hook with `{ scope: containerRef }`
122
+ - [ ] `prefers-reduced-motion` check before animations
123
+ - [ ] Design tokens imported from `@/lib/design-tokens`
124
+ - [ ] Plugins registered ONCE at app init
125
+ - [ ] No GSAP + Framer Motion on the same DOM element
126
+ - [ ] ScrollTrigger.refresh() called after dynamic content loads
127
+ - [ ] Naming: kebab-case files (`use-scroll-reveal.ts`, `gsap-providers.tsx`)
128
+
129
+ ---
130
+
131
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,151 @@
1
+ ---
2
+ name: neon-auth
3
+ description: Neon Auth (Better Auth) specialist for authentication flows, session management, Next.js App Router integration, .NET JWT validation, and RLS policy integration. Use when integrating Neon Auth, implementing social login flows, managing user sessions, or protecting routes with Neon Auth middleware.
4
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep
5
+ stacks:
6
+ - neon
7
+ color: teal
8
+ effort: medium
9
+ ---
10
+
11
+ # Neon Auth (Better Auth)
12
+
13
+ Authentication with Neon Auth for Next.js and .NET. SDK: `@neondatabase/auth` (Next.js) / JWT Bearer validation (.NET).
14
+
15
+ > **Ref:** `framework/standards/backend/integrations/neon-auth/neon-auth.md`
16
+
17
+ ## Setup (Next.js)
18
+
19
+ ```typescript
20
+ // lib/auth/client.ts
21
+ 'use client';
22
+ import { createAuthClient } from '@neondatabase/auth/next';
23
+ export const authClient = createAuthClient();
24
+
25
+ // lib/auth/server.ts
26
+ import { createNeonAuth } from '@neondatabase/auth/next/server';
27
+ export const auth = createNeonAuth({
28
+ baseUrl: process.env.NEON_AUTH_BASE_URL!,
29
+ cookies: { secret: process.env.NEON_AUTH_COOKIE_SECRET! },
30
+ });
31
+
32
+ // app/api/auth/[...path]/route.ts
33
+ import { auth } from '@/lib/auth/server';
34
+ export const { GET, POST } = auth.handler();
35
+ ```
36
+
37
+ ## Setup (.NET)
38
+
39
+ ```csharp
40
+ // Program.cs
41
+ builder.Services.AddAuthentication("NeonAuth")
42
+ .AddJwtBearer("NeonAuth", options =>
43
+ {
44
+ options.Authority = builder.Configuration["NeonAuth:BaseUrl"];
45
+ options.TokenValidationParameters = new()
46
+ {
47
+ ValidateIssuer = true,
48
+ ValidateAudience = false,
49
+ ValidateLifetime = true,
50
+ ValidateIssuerSigningKey = true,
51
+ NameClaimType = "sub"
52
+ };
53
+ });
54
+ builder.Services.AddAuthorization();
55
+ app.UseAuthentication();
56
+ app.UseAuthorization();
57
+ ```
58
+
59
+ ## Protected Endpoints
60
+
61
+ ```csharp
62
+ // Minimal API
63
+ app.MapGet("/api/profile", (ClaimsPrincipal user) =>
64
+ {
65
+ var userId = user.FindFirstValue("sub");
66
+ if (userId is null) return Results.Unauthorized();
67
+ return Results.Ok(new { UserId = userId });
68
+ }).RequireAuthorization();
69
+
70
+ // Controller: same pattern with [Authorize] + User.FindFirstValue("sub")
71
+ ```
72
+
73
+ ## Next.js Integration
74
+
75
+ ```tsx
76
+ // middleware.ts
77
+ import { auth } from '@/lib/auth/server';
78
+ export default auth.middleware({ loginUrl: '/auth/sign-in' });
79
+ export const config = { matcher: ['/((?!.*\\..*|_next|auth).*)', '/'] };
80
+
81
+ // Protected page (server)
82
+ import { auth } from '@/lib/auth/server';
83
+ export const dynamic = 'force-dynamic';
84
+ export default async function DashboardPage() {
85
+ const { data: session } = await auth.getSession();
86
+ if (!session?.user) redirect('/auth/sign-in');
87
+ return <Dashboard user={session.user} />;
88
+ }
89
+
90
+ // Client component
91
+ 'use client';
92
+ import { useSession } from '@/lib/auth/client';
93
+ const { data } = useSession();
94
+ const user = data?.user;
95
+ ```
96
+
97
+ ## Auth Pages
98
+
99
+ ```tsx
100
+ // Sign in / Sign up — single component
101
+ import { AuthView } from '@neondatabase/auth/react';
102
+ export default function SignInPage() {
103
+ return <AuthView pathname="sign-in" />;
104
+ }
105
+ ```
106
+
107
+ ## OAuth
108
+
109
+ ```typescript
110
+ await authClient.signIn.social({
111
+ provider: 'google',
112
+ callbackURL: '/auth/callback',
113
+ });
114
+ ```
115
+
116
+ ## RLS Integration
117
+
118
+ Neon Auth JWTs are validated by the Data API. Use `auth.user_id()` in RLS policies:
119
+
120
+ ```sql
121
+ CREATE POLICY "Users own rows"
122
+ ON public.documents FOR ALL TO authenticated
123
+ USING (user_id = auth.user_id());
124
+ ```
125
+
126
+ ## Database Schema
127
+
128
+ Auth data lives in `neon_auth` schema (managed automatically):
129
+ - `neon_auth.user` — profiles
130
+ - `neon_auth.session` — sessions
131
+ - `neon_auth.account` — credentials
132
+
133
+ Query directly — no webhook sync needed:
134
+ ```sql
135
+ SELECT id, email, name FROM neon_auth.user WHERE id = auth.user_id();
136
+ ```
137
+
138
+ ## Checklist
139
+
140
+ - [ ] `NEON_AUTH_BASE_URL` in environment variables
141
+ - [ ] `NEON_AUTH_COOKIE_SECRET` (32+ chars) in environment variables
142
+ - [ ] Auth API route at `app/api/auth/[...path]/route.ts`
143
+ - [ ] `NeonAuthUIProvider` wrapping app in root layout
144
+ - [ ] Middleware protecting private routes
145
+ - [ ] `.NET` JWT Bearer configured with Neon Auth authority
146
+ - [ ] RLS policies using `auth.user_id()`
147
+ - [ ] `force-dynamic` on pages using `auth.getSession()`
148
+
149
+ ---
150
+
151
+ *MORPH-SPEC by Polymorphism Tech*