@polymorphism-tech/morph-spec 4.17.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 (40) hide show
  1. package/CLAUDE.md +36 -0
  2. package/README.md +2 -2
  3. package/claude-plugin.json +1 -1
  4. package/docs/CHEATSHEET.md +1 -1
  5. package/docs/QUICKSTART.md +1 -1
  6. package/framework/agents/backend/neon-expert.md +9 -27
  7. package/framework/agents/integrations/neon-auth.md +151 -0
  8. package/framework/agents.json +21 -13
  9. package/framework/rules/neon-auth-standards.md +13 -0
  10. package/framework/rules/neon-standards.md +1 -0
  11. package/framework/skills/level-0-meta/morph-agent-teams/SKILL.md +3 -3
  12. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +1 -1
  13. package/framework/skills/level-0-meta/morph-init/SKILL.md +4 -4
  14. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +1 -1
  15. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +1 -1
  16. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +1 -1
  17. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +1 -1
  18. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +1 -1
  19. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +1 -1
  20. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +1 -1
  21. package/framework/standards/STANDARDS.json +13 -9
  22. package/framework/standards/backend/database/postgresql/database.md +5 -5
  23. package/framework/standards/backend/integrations/asaas/asaas-api.md +1 -1
  24. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +364 -0
  25. package/framework/standards/frontend/nextjs/nextjs-patterns.md +9 -9
  26. package/framework/templates/README.md +2 -2
  27. package/framework/templates/REGISTRY.json +5 -5
  28. package/framework/templates/code/sql/postgresql-migration.sql +10 -10
  29. package/framework/templates/code/sql/postgresql-migration.template.sql +12 -14
  30. package/framework/templates/code/sql/postgresql-rls-policy.sql +6 -9
  31. package/framework/templates/feature/decisions.md +8 -7
  32. package/framework/templates/integrations/neon-auth-config.cs +133 -0
  33. package/framework/workflows/docs/full-morph.md +1 -1
  34. package/package.json +1 -1
  35. package/src/lib/detectors/index.js +2 -2
  36. package/src/lib/generators/architecture-scanner.js +2 -3
  37. package/framework/agents/integrations/clerk-auth.md +0 -109
  38. package/framework/rules/clerk-standards.md +0 -13
  39. package/framework/standards/backend/integrations/clerk/clerk-auth.md +0 -292
  40. package/framework/templates/integrations/clerk-config.cs +0 -217
package/CLAUDE.md CHANGED
@@ -99,6 +99,42 @@ State lives in `.morph/state.json` in target projects. Phase and outputs are **d
99
99
  - **Template helpers** — Handlebars v2.0 helpers: pascalCase, camelCase, snakeCase, kebabCase, pluralize, plus comparison/logic helpers
100
100
  - **CLI structure** — Commands are thin wrappers that delegate to `src/core/` or `src/lib/` modules. Keep business logic out of command files.
101
101
 
102
+ ## Framework Development Guardrails
103
+
104
+ When modifying framework components, always verify the full scope of related files. A PostToolUse hook (`.claude/hooks/post-tool-use/framework-consistency-guard.js`) will remind you, but you should also proactively check.
105
+
106
+ ### Dependency Matrix
107
+
108
+ | When you modify... | Also verify... |
109
+ |---------------------|----------------|
110
+ | `framework/agents.json` | squad-templates/*.json, agents-installer.js (tier defaults), advance-phase.js (hardcoded agent lists), doctor.js (REQUIRED_AGENTS), agents-manager.js (validation rules), total_agents/tier counts |
111
+ | `framework/standards/**` | STANDARDS.json (entry exists), agents.json (agents reference the standard), .md file exists at declared path |
112
+ | `framework/hooks/claude-code/**` | hooks-installer.js (MORPH_HOOKS array + MORPH_PERMISSIONS), hook follows fail-open pattern |
113
+ | `framework/skills/**` | phases.json (requiredSkills if phase-bound), skills-installer.js, SKILL.md frontmatter |
114
+ | `framework/phases.json` | advance-phase.js, dispatch-agents.js, output-schema.js (phase mappings) |
115
+ | `framework/templates/**` | REGISTRY.json (template registered) |
116
+ | `src/core/paths/output-schema.js` | Run `npm run generate` to update phase-utils.js and skill markdown blocks |
117
+
118
+ ### Per-Domain Checklists
119
+
120
+ **Agents** — required fields: tier, title, group, active_phases, reports_to, domains, keywords, validators, standards. If tier 3+: teammate.spawn_prompt. If stack-specific: stacks[]. Update total_agents/tier counts.
121
+
122
+ **Standards** — STANDARDS.json entry needs: id, name, path, category, subcategory, tags, digest. At least one agent must reference it. If stack-specific: stacks[].
123
+
124
+ **Hooks** — must be in MORPH_HOOKS array in hooks-installer.js. Must follow fail-open pattern. If needs permissions: add to MORPH_PERMISSIONS.
125
+
126
+ **Skills** — SKILL.md with valid frontmatter. If phase-bound: in phases.json requiredSkills. If stack-specific: stacks[] frontmatter.
127
+
128
+ **Phases** — index/folder consistent. requiredSkills reference existing dirs. advance-phase.js handles transitions.
129
+
130
+ **Templates** — registered in REGISTRY.json. Uses only available Handlebars helpers.
131
+
132
+ **Output Schema** — always run `npm run generate` after changes.
133
+
134
+ ### Test Coverage
135
+
136
+ Every `src/**/*.js` file should have a corresponding `test/**/*.test.js`. The consistency hook will warn when a test file is missing.
137
+
102
138
  ## Framework vs Runtime Distinction
103
139
 
104
140
  - **This repo** (`morph-spec-framework/`) = the CLI tool source code
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > Spec-driven development framework for multi-stack projects. Turns feature requests into implementation-ready code through structured, AI-orchestrated phases.
4
4
 
5
5
  **Package:** `@polymorphism-tech/morph-spec`
6
- **Version:** 4.17.0
6
+ **Version:** 4.18.0
7
7
  **Requires:** Node.js 18+, Claude Code
8
8
 
9
9
  ---
@@ -364,4 +364,4 @@ Code generated by morph-spec (contracts, templates, implementation output) belon
364
364
 
365
365
  ---
366
366
 
367
- *morph-spec v4.17.0 by [Polymorphism Tech](https://polymorphism.tech)*
367
+ *morph-spec v4.18.0 by [Polymorphism Tech](https://polymorphism.tech)*
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morph-spec",
3
- "version": "4.17.0",
3
+ "version": "4.18.0",
4
4
  "displayName": "MORPH-SPEC Framework",
5
5
  "description": "Spec-driven development with 38 agents and 8-phase workflow for .NET/Blazor/Next.js/Azure",
6
6
  "publisher": "polymorphism-tech",
@@ -196,4 +196,4 @@ These files are never edited directly. Use CLI commands or `morph-spec update` i
196
196
 
197
197
  ---
198
198
 
199
- *morph-spec v4.17.0 by Polymorphism Tech*
199
+ *morph-spec v4.18.0 by Polymorphism Tech*
@@ -197,4 +197,4 @@ morph-spec doctor
197
197
 
198
198
  ---
199
199
 
200
- *morph-spec v4.17.0 by Polymorphism Tech*
200
+ *morph-spec v4.18.0 by Polymorphism Tech*
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neon-expert
3
- description: Neon PostgreSQL & AI Data specialist for connection pooling, RLS policies with Clerk 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.
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
4
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep
5
5
  stacks:
6
6
  - neon
@@ -10,7 +10,7 @@ effort: medium
10
10
 
11
11
  # Neon PostgreSQL & AI Data Specialist
12
12
 
13
- Expert in Neon serverless Postgres: connection pooling, RLS with Clerk JWT, EF Core migrations, pgvector, pgrag, database branching, and scale-to-zero.
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
14
 
15
15
  > **Ref:** `framework/standards/infrastructure/neon/` — connection pooling, RLS, pgvector, pgrag standards
16
16
 
@@ -59,51 +59,33 @@ Transaction mode restricts: `SET`/`RESET`, `LISTEN`/`NOTIFY`, SQL-level prepared
59
59
  ALTER TABLE public.documents ENABLE ROW LEVEL SECURITY;
60
60
  ```
61
61
 
62
- ### RLS with Clerk JWT (Neon Authorize)
62
+ ### RLS with Neon Auth JWT
63
63
 
64
- Neon provides `auth.user_id()` via the `pg_session_jwt` extension. It extracts the `sub` claim from the validated JWT automatically.
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
65
 
66
66
  ```sql
67
67
  -- User owns the row
68
68
  CREATE POLICY "Users can view own documents"
69
- ON public.documents FOR SELECT
69
+ ON public.documents FOR SELECT TO authenticated
70
70
  USING (auth.user_id() = user_id);
71
71
 
72
72
  -- User can insert own rows
73
73
  CREATE POLICY "Users can insert own documents"
74
- ON public.documents FOR INSERT
74
+ ON public.documents FOR INSERT TO authenticated
75
75
  WITH CHECK (auth.user_id() = user_id);
76
76
 
77
77
  -- User can update own rows
78
78
  CREATE POLICY "Users can update own documents"
79
- ON public.documents FOR UPDATE
79
+ ON public.documents FOR UPDATE TO authenticated
80
80
  USING (auth.user_id() = user_id)
81
81
  WITH CHECK (auth.user_id() = user_id);
82
82
 
83
83
  -- User can delete own rows
84
84
  CREATE POLICY "Users can delete own documents"
85
- ON public.documents FOR DELETE
85
+ ON public.documents FOR DELETE TO authenticated
86
86
  USING (auth.user_id() = user_id);
87
87
  ```
88
88
 
89
- ### Manual JWT extraction (without Neon Authorize)
90
-
91
- ```sql
92
- -- Extract Clerk user ID from JWT claims manually
93
- CREATE OR REPLACE FUNCTION public.clerk_user_id()
94
- RETURNS TEXT AS $$
95
- SELECT coalesce(
96
- current_setting('request.jwt.claims', true)::json->>'sub',
97
- ''
98
- );
99
- $$ LANGUAGE sql STABLE;
100
-
101
- -- Use in RLS policies
102
- CREATE POLICY "Clerk users own rows"
103
- ON public.documents FOR ALL
104
- USING (clerk_user_id = public.clerk_user_id());
105
- ```
106
-
107
89
  ### Team-based access
108
90
 
109
91
  ```sql
@@ -381,7 +363,7 @@ builder.Services.AddDbContext<AppDbContext>(options =>
381
363
  - [ ] Pooled connection (`-pooler` endpoint) used for all application connections
382
364
  - [ ] Direct connection used only for migrations and schema changes
383
365
  - [ ] RLS enabled on ALL public tables
384
- - [ ] RLS policies use `auth.user_id()` (Neon Authorize) or manual `clerk_user_id()` function
366
+ - [ ] RLS policies use `auth.user_id()` via `pg_session_jwt` extension
385
367
  - [ ] RLS policies cover SELECT, INSERT, UPDATE, DELETE
386
368
  - [ ] EF Core migrations use direct connection string
387
369
  - [ ] Indexes on all frequently filtered columns
@@ -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*
@@ -162,7 +162,7 @@
162
162
  "role": "Backend Squad Leader",
163
163
  "icon": "⚙️",
164
164
  "triggers": ".NET/C# backend, VSA architecture, EF Core, API design, backend squad coordination",
165
- "spawn_prompt": "You are the Backend Squad Leader. Coordinate backend specialists and own VSA architecture, API design, and .NET/C# standards.\n\nWorkflow:\n1. Read `.morph/state.json` and spec.md for backend requirements\n2. Produce VSA Blueprint: entity fields, operations (slices), routes, error types, validation rules\n3. Delegate to squad: ef-modeler, hangfire-orchestrator, ms-agent-expert, neon-expert, vector-search-expert, asaas-financial, clerk-auth, resend-email\n\nRefer to the Domain Knowledge section below for IHandler, Result<T>, Scrutor, IApiEndpoint patterns and code templates."
165
+ "spawn_prompt": "You are the Backend Squad Leader. Coordinate backend specialists and own VSA architecture, API design, and .NET/C# standards.\n\nWorkflow:\n1. Read `.morph/state.json` and spec.md for backend requirements\n2. Produce VSA Blueprint: entity fields, operations (slices), routes, error types, validation rules\n3. Delegate to squad: ef-modeler, hangfire-orchestrator, ms-agent-expert, neon-expert, vector-search-expert, asaas-financial, neon-auth, resend-email\n\nRefer to the Domain Knowledge section below for IHandler, Result<T>, Scrutor, IApiEndpoint patterns and code templates."
166
166
  }
167
167
  },
168
168
  "infra-architect": {
@@ -441,7 +441,7 @@
441
441
  "role": "Neon PostgreSQL & AI Data Specialist",
442
442
  "icon": "\uD83D\uDC18",
443
443
  "triggers": "database setup, pgvector, pgrag, vector search, embeddings, Neon branching, RAG pipeline, Semantic Kernel vector store, neonctl",
444
- "spawn_prompt": "You are the Neon PostgreSQL & AI Data Specialist. Implement database schemas, RLS policies, pgvector embeddings, pgrag RAG pipelines, and manage Neon branches.\n\nWorkflow:\n1. Read spec.md for database, vector search, and RAG requirements\n2. Review architecture from dotnet-senior for entity and schema design\n3. ALWAYS use the pooled connection (-pooler endpoint) for application code — direct connections only for EF Core migrations\n4. Implement RLS policies using auth.user_id() (Neon Authorize) with Clerk JWT\n5. Set up pgvector with HNSW indexes and tune maintenance_work_mem before index creation\n6. For RAG pipelines, use pgrag extensions (rag, rag_bge_small_en_v15, rag_jina_reranker_v1_tiny_en) for chunking, embedding, search, and reranking entirely in SQL\n7. Create database branches for PR previews (--schema-only) and run schema-diff before merging\n8. Configure connection retry logic for scale-to-zero cold starts\n\nCRITICAL: Two connection strings — pooled for application, direct for migrations. Never use direct connections in application code.\n\nRefer to the Domain Knowledge section below for connection pooling, RLS patterns, pgvector setup, pgrag pipeline, branching strategy, and scale-to-zero configuration."
444
+ "spawn_prompt": "You are the Neon PostgreSQL & AI Data Specialist. Implement database schemas, RLS policies, pgvector embeddings, pgrag RAG pipelines, and manage Neon branches.\n\nWorkflow:\n1. Read spec.md for database, vector search, and RAG requirements\n2. Review architecture from dotnet-senior for entity and schema design\n3. ALWAYS use the pooled connection (-pooler endpoint) for application code — direct connections only for EF Core migrations\n4. Implement RLS policies using auth.user_id() via pg_session_jwt with Neon Auth JWT\n5. Set up pgvector with HNSW indexes and tune maintenance_work_mem before index creation\n6. For RAG pipelines, use pgrag extensions (rag, rag_bge_small_en_v15, rag_jina_reranker_v1_tiny_en) for chunking, embedding, search, and reranking entirely in SQL\n7. Create database branches for PR previews (--schema-only) and run schema-diff before merging\n8. Configure connection retry logic for scale-to-zero cold starts\n\nCRITICAL: Two connection strings — pooled for application, direct for migrations. Never use direct connections in application code.\n\nRefer to the Domain Knowledge section below for connection pooling, RLS patterns, pgvector setup, pgrag pipeline, branching strategy, and scale-to-zero configuration."
445
445
  }
446
446
  },
447
447
  "vector-search-expert": {
@@ -521,11 +521,11 @@
521
521
  "spawn_prompt": "You are the Payment Integration Specialist (Asaas/Brazil). Implement PIX, Boleto, Credit Card, and subscription billing.\n\nNever hardcode API keys. Follow contract-compliance patterns.\n\nRefer to the Domain Knowledge section below for Asaas SDK patterns, webhook handling, and payment flow examples."
522
522
  }
523
523
  },
524
- "clerk-auth": {
524
+ "neon-auth": {
525
525
  "color": "teal",
526
526
  "tier": 3,
527
- "title": "Auth SaaS Integration Specialist",
528
- "stacks": ["clerk"],
527
+ "title": "Neon Auth Integration Specialist",
528
+ "stacks": ["neon"],
529
529
  "group": "backend",
530
530
  "active_phases": [
531
531
  "design",
@@ -536,21 +536,29 @@
536
536
  "integration-auth"
537
537
  ],
538
538
  "keywords": [
539
- "clerk",
540
- "clerk auth",
539
+ "neon auth",
540
+ "better auth",
541
+ "authentication",
541
542
  "add auth",
542
543
  "implement auth",
543
544
  "login",
544
545
  "signup",
545
- "oauth"
546
+ "oauth",
547
+ "session management",
548
+ "neon_auth schema"
546
549
  ],
547
550
  "validators": [],
548
- "standards": [],
551
+ "standards": [
552
+ {
553
+ "id": "neon-auth",
554
+ "scope": "neon"
555
+ }
556
+ ],
549
557
  "teammate": {
550
- "role": "Auth SaaS Integration Specialist",
558
+ "role": "Neon Auth Integration Specialist",
551
559
  "icon": "🔐",
552
- "triggers": "Clerk authentication, login/signup flows, OAuth, session management",
553
- "spawn_prompt": "You are the Auth SaaS Integration Specialist (Clerk). Implement authentication flows and session management with Next.js App Router.\n\nRefer to the Domain Knowledge section below for Clerk SDK patterns, middleware configuration, and webhook handling."
560
+ "triggers": "Neon Auth, authentication, login/signup flows, OAuth, session management, Better Auth",
561
+ "spawn_prompt": "You are the Neon Auth Integration Specialist. Implement authentication flows using Neon Auth (Better Auth) with @neondatabase/auth SDK for Next.js and JWT Bearer validation for .NET.\n\nRefer to the Domain Knowledge section below for SDK setup, auth pages, middleware protection, RLS integration, and .NET JWT configuration."
554
562
  }
555
563
  },
556
564
  "resend-email": {
@@ -1101,7 +1109,7 @@
1101
1109
  "neon-expert",
1102
1110
  "vector-search-expert",
1103
1111
  "asaas-financial",
1104
- "clerk-auth",
1112
+ "neon-auth",
1105
1113
  "resend-email"
1106
1114
  ],
1107
1115
  "domains": [
@@ -0,0 +1,13 @@
1
+ ---
2
+ paths:
3
+ - "**/Auth/**"
4
+ - "**/auth/**"
5
+ - "**/Identity/**"
6
+ - "**/neon-auth/**"
7
+ stacks:
8
+ - neon
9
+ ---
10
+
11
+ # Neon Auth Standards
12
+
13
+ @.morph/framework/standards/backend/integrations/neon-auth/neon-auth.md
@@ -14,6 +14,7 @@ stacks:
14
14
  @.morph/framework/standards/infrastructure/neon/neon-pgvector.md
15
15
  @.morph/framework/standards/infrastructure/neon/neon-pgrag.md
16
16
  @.morph/framework/standards/infrastructure/neon/neon-semantic-kernel.md
17
+ @.morph/framework/standards/backend/integrations/neon-auth/neon-auth.md
17
18
 
18
19
  ## SQL Templates
19
20
 
@@ -67,7 +67,7 @@ allowed-tools: Read, Bash, Glob, Grep, Edit, Write, AskUserQuestion
67
67
  - Testing teammate (unit + integration)
68
68
 
69
69
  4. **Research & Standards Validation (Phases 0-3)**
70
- - Investigate multiple integration options (Clerk vs Neon Auth vs custom)
70
+ - Investigate multiple integration options (Neon Auth vs custom JWT vs Passkeys)
71
71
  - Compare UI patterns (shadcn/ui component composition strategies)
72
72
  - Validate architecture patterns (CQRS vs simple Repository)
73
73
 
@@ -195,8 +195,8 @@ morph-spec state set scheduled-reports phase implement
195
195
  ```
196
196
  Create an agent team to decide on the authentication architecture.
197
197
  Spawn 3 debate teammates:
198
- - Pro-Clerk: Argue for Clerk.com (ease of use, modern UI, MFA built-in)
199
- - Pro-Neon-Auth: Argue for PostgreSQL RLS with Neon (integrated with existing DB, Row Level Security)
198
+ - Pro-Neon-Auth: Argue for Neon Auth (database-native, no external deps, branch isolation, Better Auth)
199
+ - Pro-NextAuth: Argue for NextAuth.js (flexible providers, community ecosystem, self-hosted)
200
200
  - Pro-Custom: Argue for custom JWT + Passkeys (full control, no vendor lock-in)
201
201
 
202
202
  Have them debate, challenge each other's assumptions, and document pros/cons.
@@ -10,7 +10,7 @@ allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion,
10
10
  mcp__playwright__browser_navigate, mcp__playwright__browser_resize,
11
11
  mcp__playwright__browser_take_screenshot, mcp__playwright__browser_snapshot,
12
12
  mcp__playwright__browser_evaluate, mcp__playwright__browser_console_messages
13
- cliVersion: "4.8.19"
13
+ cliVersion: "4.18.0"
14
14
  stacks:
15
15
  - nextjs
16
16
  ---
@@ -101,7 +101,7 @@ Gather evidence to build a stack map. Run these in parallel:
101
101
 
102
102
  | Tool | Pattern | Signal |
103
103
  |------|---------|--------|
104
- | `Glob` | `**/package.json` | Detect next, neon, clerk, stripe in deps |
104
+ | `Glob` | `**/package.json` | Detect next, neon, @neondatabase/auth, stripe in deps |
105
105
  | `Glob` | `**/*.csproj` | .NET projects at any depth |
106
106
  | `Glob` | `**/next.config.{js,ts,mjs}` | Next.js in any subdirectory |
107
107
  | `Glob` | `**/components.json` | shadcn/ui |
@@ -115,14 +115,14 @@ Gather evidence to build a stack map. Run these in parallel:
115
115
  | `Read` | `.env.example` | Env vars reveal integrations |
116
116
  | `Read` | `README.md` | Existing project description |
117
117
  | `Grep` | `@neondatabase/serverless` | Neon dep in any package.json |
118
- | `Grep` | `clerk\|auth0\|nextauth` | Auth provider |
118
+ | `Grep` | `@neondatabase/auth\|auth0\|nextauth` | Auth provider |
119
119
  | `Grep` | `stripe\|asaas` | Payment provider |
120
120
 
121
121
  Read each found `package.json` for dependency names. Build an **evidence map**:
122
122
 
123
123
  ```
124
124
  stack: [nextjs, dotnet, ...]
125
- integrations: [neon, docker, clerk, ...]
125
+ integrations: [neon, docker, neon-auth, ...]
126
126
  uiLibrary: shadcn | null
127
127
  monorepo: true | false
128
128
  frontendPath: src/frontend (if monorepo)
@@ -326,7 +326,7 @@ Read `.morph/config/config.json` and merge into `project`:
326
326
  "stack": "[stacks joined with +, e.g. nextjs+dotnet]",
327
327
  "architecture": "[monorepo | single-stack | detected pattern]",
328
328
  "uiLibrary": "[detected or null]",
329
- "integrations": ["neon", "docker", "clerk"],
329
+ "integrations": ["neon", "docker", "neon-auth"],
330
330
  "frontendPath": "[path if monorepo, else omit]",
331
331
  "backendPath": "[path if monorepo, else omit]"
332
332
  }
@@ -3,7 +3,7 @@ name: morph-phase-codebase-analysis
3
3
  description: MORPH-SPEC Design sub-phase that analyzes existing codebase and database schema, producing schema-analysis.md with real column names, types, relationships, and field mismatches. Use at the start of Design phase before generating contracts.cs to prevent incorrect field names or types.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
- cliVersion: "4.17.0"
6
+ cliVersion: "4.18.0"
7
7
  ---
8
8
 
9
9
  # MORPH Codebase Analysis - Design Sub-phase
@@ -4,7 +4,7 @@ description: MORPH-SPEC Phase 2 (Design). Schema-first interactive design: reads
4
4
  argument-hint: "[feature-name]"
5
5
  user-invocable: false
6
6
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion, Agent
7
- cliVersion: "4.17.0"
7
+ cliVersion: "4.18.0"
8
8
  ---
9
9
 
10
10
  # MORPH Design — Phase 2
@@ -5,7 +5,7 @@ argument-hint: "[feature-name]"
5
5
  context: fork
6
6
  agent: general-purpose
7
7
  user-invocable: false
8
- cliVersion: "4.17.0"
8
+ cliVersion: "4.18.0"
9
9
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion, Agent
10
10
  ---
11
11
 
@@ -4,7 +4,7 @@ description: MORPH-SPEC Phase 3 (Plan). Generates a detailed implementation plan
4
4
  argument-hint: "[feature-name]"
5
5
  user-invocable: false
6
6
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
7
- cliVersion: "4.17.0"
7
+ cliVersion: "4.18.0"
8
8
  ---
9
9
 
10
10
  # MORPH Plan — Phase 3
@@ -4,7 +4,7 @@ description: MORPH-SPEC Phase 4 (Tasks). Breaks approved spec into bottom-up ord
4
4
  argument-hint: "[feature-name]"
5
5
  user-invocable: false
6
6
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
7
- cliVersion: "4.17.0"
7
+ cliVersion: "4.18.0"
8
8
  ---
9
9
 
10
10
  # MORPH Tasks — Phase 4
@@ -4,7 +4,7 @@ description: MORPH-SPEC Phase 2 (UI/UX). Creates design-system.md, mockups.md, c
4
4
  argument-hint: "[feature-name]"
5
5
  user-invocable: false
6
6
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
7
- cliVersion: "4.17.0"
7
+ cliVersion: "4.18.0"
8
8
  ---
9
9
 
10
10
  # MORPH UI/UX Design - Phase 2
@@ -4,7 +4,7 @@ description: Guided workflow for mid-implementation scope escalation — analyze
4
4
  user-invocable: true
5
5
  argument-hint: "[feature-name]"
6
6
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
7
- cliVersion: "4.17.0"
7
+ cliVersion: "4.18.0"
8
8
  ---
9
9
 
10
10
  # Scope Escalation Workflow
@@ -356,30 +356,34 @@
356
356
  ]
357
357
  },
358
358
  {
359
- "id": "backend-integrations-clerk-clerk-auth",
360
- "name": "clerk auth",
361
- "path": "backend/integrations/clerk/clerk-auth.md",
359
+ "id": "backend-integrations-neon-auth-neon-auth",
360
+ "name": "neon auth",
361
+ "path": "backend/integrations/neon-auth/neon-auth.md",
362
362
  "category": "backend",
363
363
  "subcategory": "integrations",
364
364
  "tags": [
365
365
  "backend",
366
366
  "integrations",
367
- "clerk"
367
+ "neon-auth",
368
+ "better-auth"
368
369
  ],
369
370
  "aliases": [
370
- "clerk",
371
+ "neon auth",
372
+ "better auth",
371
373
  "authentication",
372
374
  "OAuth",
373
375
  "JWT",
374
376
  "session management"
375
377
  ],
376
378
  "anchors": {
377
- "setup": "#clerk-setup",
378
- "middleware": "#auth-middleware"
379
+ "setup": "#installation--setup",
380
+ "middleware": "#route-protection-middleware",
381
+ "dotnet": "#net-backend-integration",
382
+ "rls": "#row-level-security-integration"
379
383
  },
380
- "digest": "Add ClerkMiddleware to ASP.NET pipeline. Access userId via User.GetClerkUserId(). Configure allowed redirect URLs in Clerk dashboard. Use [Authorize] for protected endpoints. Never store passwords — Clerk manages credentials. Sync Clerk users to local DB on first login.",
384
+ "digest": "Use @neondatabase/auth SDK for Next.js. Auth data lives in neon_auth schema — no external provider, no webhooks. Server: createNeonAuth() with NEON_AUTH_BASE_URL + NEON_AUTH_COOKIE_SECRET. Client: createAuthClient(). Pages: AuthView component. Protection: auth.middleware(). .NET: JWT Bearer with Neon Auth authority, NameClaimType=sub. RLS: auth.user_id() via pg_session_jwt.",
381
385
  "stacks": [
382
- "dotnet"
386
+ "neon"
383
387
  ]
384
388
  },
385
389
  {
@@ -68,7 +68,7 @@ alter table public.profiles enable row level security;
68
68
  ```sql
69
69
  create policy "Users can view own profile"
70
70
  on public.profiles for select
71
- using (auth.uid() = user_id);
71
+ using (auth.user_id() = user_id);
72
72
  ```
73
73
 
74
74
  #### User can update own profile
@@ -76,8 +76,8 @@ create policy "Users can view own profile"
76
76
  ```sql
77
77
  create policy "Users can update own profile"
78
78
  on public.profiles for update
79
- using (auth.uid() = user_id)
80
- with check (auth.uid() = user_id);
79
+ using (auth.user_id() = user_id)
80
+ with check (auth.user_id() = user_id);
81
81
  ```
82
82
 
83
83
  #### User can insert own profile
@@ -85,7 +85,7 @@ create policy "Users can update own profile"
85
85
  ```sql
86
86
  create policy "Users can insert own profile"
87
87
  on public.profiles for insert
88
- with check (auth.uid() = user_id);
88
+ with check (auth.user_id() = user_id);
89
89
  ```
90
90
 
91
91
  #### Admin can do anything
@@ -96,7 +96,7 @@ create policy "Admins have full access"
96
96
  using (
97
97
  exists (
98
98
  select 1 from public.user_roles
99
- where user_id = auth.uid() and role = 'admin'
99
+ where user_id = auth.user_id() and role = 'admin'
100
100
  )
101
101
  );
102
102
  ```