@polymorphism-tech/morph-spec 7.0.0 → 7.1.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 (79) hide show
  1. package/README.md +367 -367
  2. package/framework/agents.json +132 -127
  3. package/framework/rubrics/backend.json +41 -36
  4. package/framework/rules/ai-agents-standards.md +45 -15
  5. package/framework/rules/neon-standards.md +25 -26
  6. package/framework/standards/STANDARDS.json +1729 -1133
  7. package/framework/standards/ai-agents/agent-session.md +160 -0
  8. package/framework/standards/ai-agents/batching.md +193 -0
  9. package/framework/standards/ai-agents/context-providers.md +188 -0
  10. package/framework/standards/ai-agents/mcp-server.md +250 -0
  11. package/framework/standards/ai-agents/mcp-tools.md +197 -0
  12. package/framework/standards/ai-agents/middleware-patterns.md +207 -0
  13. package/framework/standards/ai-agents/modalities-image-gen.md +173 -0
  14. package/framework/standards/ai-agents/modalities-speech-to-text.md +171 -0
  15. package/framework/standards/ai-agents/modalities-text-to-speech.md +181 -0
  16. package/framework/standards/ai-agents/modalities-vision.md +201 -0
  17. package/framework/standards/ai-agents/multi-agent-patterns.md +155 -0
  18. package/framework/standards/ai-agents/production.md +114 -258
  19. package/framework/standards/ai-agents/prompts-in-db.md +214 -0
  20. package/framework/standards/ai-agents/providers/model-registry.md +158 -0
  21. package/framework/standards/ai-agents/rag-custom-pgvector.md +243 -0
  22. package/framework/standards/ai-agents/service-tier-flex.md +135 -0
  23. package/framework/standards/ai-agents/setup.md +142 -316
  24. package/framework/standards/ai-agents/structured-output.md +249 -0
  25. package/framework/standards/ai-agents/sweet-spot.md +109 -0
  26. package/framework/standards/ai-agents/workflows.md +114 -284
  27. package/framework/standards/architecture/vertical-slice/vertical-slice.md +433 -429
  28. package/framework/standards/backend/api/validation.md +92 -88
  29. package/framework/standards/backend/database/postgresql/database.md +336 -332
  30. package/framework/standards/backend/database/vector-search-rag.md +599 -541
  31. package/framework/standards/backend/dotnet/fluent-validation-vsa.md +4 -0
  32. package/framework/standards/backend/dotnet/result-pattern.md +4 -0
  33. package/framework/standards/backend/dotnet/scalar-ui.md +176 -172
  34. package/framework/standards/backend/dotnet/scrutor.md +4 -0
  35. package/framework/standards/backend/dotnet/vsa-handler-patterns.md +278 -274
  36. package/framework/standards/backend/integrations/asaas/asaas-api.md +260 -216
  37. package/framework/standards/backend/integrations/hangfire/hangfire-jobs.md +354 -350
  38. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +30 -19
  39. package/framework/standards/backend/integrations/resend/resend-email.md +400 -385
  40. package/framework/standards/data/nosql/cache/redis.md +106 -97
  41. package/framework/standards/data/nosql/cosmos-db.md +127 -118
  42. package/framework/standards/data/vector-search/rag-chunking.md +113 -104
  43. package/framework/standards/frontend/design-system/ai-image-generation.md +4 -0
  44. package/framework/standards/frontend/design-system/animations.md +164 -160
  45. package/framework/standards/frontend/design-system/naming.md +68 -64
  46. package/framework/standards/frontend/gsap/gsap-core.md +14 -8
  47. package/framework/standards/frontend/gsap/gsap-plugins.md +26 -21
  48. package/framework/standards/frontend/gsap/gsap-scrolltrigger.md +9 -7
  49. package/framework/standards/frontend/nextjs/app-router.md +127 -123
  50. package/framework/standards/frontend/nextjs/components.md +136 -132
  51. package/framework/standards/frontend/nextjs/data-fetching.md +130 -126
  52. package/framework/standards/frontend/nextjs/forms.md +134 -128
  53. package/framework/standards/frontend/nextjs/motion-patterns.md +328 -322
  54. package/framework/standards/frontend/nextjs/naming-conventions.md +71 -67
  55. package/framework/standards/frontend/nextjs/nextjs-patterns.md +229 -225
  56. package/framework/standards/frontend/nextjs/project-structure.md +106 -102
  57. package/framework/standards/frontend/nextjs/state-management.md +76 -72
  58. package/framework/standards/frontend/nextjs/testing.md +115 -111
  59. package/framework/standards/infrastructure/docker/easypanel-deploy.md +196 -192
  60. package/framework/standards/infrastructure/neon/neon-pgrag.md +6 -2
  61. package/framework/standards/infrastructure/neon/neon-pgvector.md +4 -0
  62. package/framework/standards/infrastructure/neon/neon-setup.md +5 -1
  63. package/framework/standards/integration/mcp/mcp-tools.md +471 -462
  64. package/framework/templates/REGISTRY.json +1745 -1239
  65. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +39 -0
  66. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +68 -0
  67. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +117 -0
  68. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +95 -0
  69. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +61 -0
  70. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +107 -0
  71. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +58 -0
  72. package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +58 -0
  73. package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +91 -0
  74. package/package.json +89 -83
  75. package/src/core/templates/template-registry.js +289 -256
  76. package/src/lib/generators/context-generator.js +516 -518
  77. package/src/lib/generators/scaffold-generator.js +23 -26
  78. package/framework/standards/infrastructure/neon/neon-semantic-kernel.md +0 -310
  79. package/framework/templates/integrations/semantic-kernel-neon.cs +0 -125
@@ -1,128 +1,134 @@
1
- # Next.js Forms Standard
2
-
3
- > **Scope:** frontend/nextjs/forms
4
- > **Layer:** 2 (on keyword)
5
- > **Keywords:** form, react-hook-form, zod, validation, input, submit, zodResolver
6
- > **Load When:** implementing any form in Next.js
7
-
8
- react-hook-form + Zod + shadcn Form components. Schema defines both validation rules and TypeScript types.
9
-
10
- ## Core Rules
11
-
12
- - ALWAYS define the Zod schema first — derive the TypeScript type from it with `z.infer<>`
13
- - ALWAYS use `zodResolver` to connect schema to react-hook-form
14
- - ALWAYS use shadcn `<Form>`, `<FormField>`, `<FormItem>`, `<FormMessage>` for consistent UI
15
- - NEVER use `useState` for form field values — react-hook-form handles this
16
- - ALWAYS use `useMutation` from TanStack Query for form submission
17
-
18
- ## Complete Form Pattern
19
-
20
- ```tsx
21
- // features/users/types/user.schemas.ts
22
- import { z } from 'zod';
23
-
24
- export const createUserSchema = z.object({
25
- name: z.string().min(2, 'Name must be at least 2 characters'),
26
- email: z.string().email('Invalid email address'),
27
- role: z.enum(['admin', 'user'], { required_error: 'Role is required' }),
28
- });
29
-
30
- export type CreateUserInput = z.infer<typeof createUserSchema>;
31
- ```
32
-
33
- ```tsx
34
- // features/users/components/create-user-form.tsx
35
- 'use client';
36
-
37
- import { useForm } from 'react-hook-form';
38
- import { zodResolver } from '@hookform/resolvers/zod';
39
- import {
40
- Form, FormControl, FormField, FormItem, FormLabel, FormMessage
41
- } from '@/components/ui/form';
42
- import { Input } from '@/components/ui/input';
43
- import { Button } from '@/components/ui/button';
44
- import { useCreateUser } from '@/features/users/hooks/use-create-user';
45
- import { createUserSchema, type CreateUserInput } from '@/features/users/types/user.schemas';
46
-
47
- export function CreateUserForm({ onSuccess }: { onSuccess?: () => void }) {
48
- const form = useForm<CreateUserInput>({
49
- resolver: zodResolver(createUserSchema),
50
- defaultValues: { name: '', email: '', role: 'user' },
51
- });
52
-
53
- const { mutate: createUser, isPending } = useCreateUser();
54
-
55
- function onSubmit(values: CreateUserInput) {
56
- createUser(values, {
57
- onSuccess: () => { form.reset(); onSuccess?.(); },
58
- onError: (error) => form.setError('root', { message: error.message }),
59
- });
60
- }
61
-
62
- return (
63
- <Form {...form}>
64
- <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
65
- <FormField
66
- control={form.control}
67
- name="name"
68
- render={({ field }) => (
69
- <FormItem>
70
- <FormLabel>Name</FormLabel>
71
- <FormControl><Input placeholder="John Doe" {...field} /></FormControl>
72
- <FormMessage />
73
- </FormItem>
74
- )}
75
- />
76
- <FormField
77
- control={form.control}
78
- name="email"
79
- render={({ field }) => (
80
- <FormItem>
81
- <FormLabel>Email</FormLabel>
82
- <FormControl><Input type="email" {...field} /></FormControl>
83
- <FormMessage />
84
- </FormItem>
85
- )}
86
- />
87
- {form.formState.errors.root && (
88
- <p className="text-sm text-destructive">{form.formState.errors.root.message}</p>
89
- )}
90
- <Button type="submit" disabled={isPending}>
91
- {isPending ? 'Creating...' : 'Create User'}
92
- </Button>
93
- </form>
94
- </Form>
95
- );
96
- }
97
- ```
98
-
99
- ## Edit Form Pattern
100
-
101
- ```tsx
102
- // Edit forms reuse the same schema with partial()
103
- const form = useForm<UpdateUserInput>({
104
- resolver: zodResolver(updateUserSchema),
105
- defaultValues: { name: user.name, email: user.email },
106
- });
107
- ```
108
-
109
- ## Schema Composition
110
-
111
- ```ts
112
- export const userSchema = z.object({ id: z.string(), name: z.string(), email: z.string() });
113
- export const createUserSchema = userSchema.omit({ id: true });
114
- export const updateUserSchema = createUserSchema.partial();
115
- ```
116
-
117
- ## Common Mistakes
118
-
119
- | Wrong | Right | Why |
120
- |-------|-------|-----|
121
- | `useState` for each field | `useForm` | Unnecessary re-renders on every keystroke |
122
- | Manual error display | `<FormMessage />` | Consistent UI, auto-connects to field errors |
123
- | `fetch` in submit handler | `useMutation` | Loading state, error handling, cache invalidation |
124
- | Type written manually | `z.infer<typeof schema>` | Single source of truth |
125
-
126
- ---
127
-
128
- *MORPH-SPEC by Polymorphism Tech*
1
+ # Next.js Forms Standard
2
+
3
+ > **Scope:** frontend/nextjs/forms
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** form, react-hook-form, zod, validation, input, submit, zodResolver
6
+ > **Load When:** implementing any form in Next.js
7
+
8
+ **Verified against:** Next.js 15 + react-hook-form 7 + Zod 4 + @hookform/resolvers 3. Last-verified: 2026-05-20.
9
+
10
+ ---
11
+
12
+ react-hook-form + Zod + shadcn Form components. Schema defines both validation rules and TypeScript types.
13
+
14
+ ## Core Rules
15
+
16
+ - ALWAYS define the Zod schema first — derive the TypeScript type from it with `z.infer<>`
17
+ - ALWAYS use `zodResolver` to connect schema to react-hook-form
18
+ - ALWAYS use shadcn `<Form>`, `<FormField>`, `<FormItem>`, `<FormMessage>` for consistent UI
19
+ - NEVER use `useState` for form field values — react-hook-form handles this
20
+ - ALWAYS use `useMutation` from TanStack Query for form submission
21
+
22
+ ## Complete Form Pattern
23
+
24
+ ```tsx
25
+ // features/users/types/user.schemas.ts
26
+ import { z } from 'zod';
27
+
28
+ export const createUserSchema = z.object({
29
+ name: z.string().min(2, 'Name must be at least 2 characters'),
30
+ email: z.email('Invalid email address'),
31
+ role: z.enum(['admin', 'user'], { error: 'Role is required' }),
32
+ });
33
+
34
+ export type CreateUserInput = z.infer<typeof createUserSchema>;
35
+ ```
36
+
37
+ ```tsx
38
+ // features/users/components/create-user-form.tsx
39
+ 'use client';
40
+
41
+ import { useForm } from 'react-hook-form';
42
+ import { zodResolver } from '@hookform/resolvers/zod';
43
+ import {
44
+ Form, FormControl, FormField, FormItem, FormLabel, FormMessage
45
+ } from '@/components/ui/form';
46
+ import { Input } from '@/components/ui/input';
47
+ import { Button } from '@/components/ui/button';
48
+ import { useCreateUser } from '@/features/users/hooks/use-create-user';
49
+ import { createUserSchema, type CreateUserInput } from '@/features/users/types/user.schemas';
50
+
51
+ export function CreateUserForm({ onSuccess }: { onSuccess?: () => void }) {
52
+ const form = useForm<CreateUserInput>({
53
+ resolver: zodResolver(createUserSchema),
54
+ defaultValues: { name: '', email: '', role: 'user' },
55
+ });
56
+
57
+ const { mutate: createUser, isPending } = useCreateUser();
58
+
59
+ function onSubmit(values: CreateUserInput) {
60
+ createUser(values, {
61
+ onSuccess: () => { form.reset(); onSuccess?.(); },
62
+ onError: (error) => form.setError('root', { message: error.message }),
63
+ });
64
+ }
65
+
66
+ return (
67
+ <Form {...form}>
68
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
69
+ <FormField
70
+ control={form.control}
71
+ name="name"
72
+ render={({ field }) => (
73
+ <FormItem>
74
+ <FormLabel>Name</FormLabel>
75
+ <FormControl><Input placeholder="John Doe" {...field} /></FormControl>
76
+ <FormMessage />
77
+ </FormItem>
78
+ )}
79
+ />
80
+ <FormField
81
+ control={form.control}
82
+ name="email"
83
+ render={({ field }) => (
84
+ <FormItem>
85
+ <FormLabel>Email</FormLabel>
86
+ <FormControl><Input type="email" {...field} /></FormControl>
87
+ <FormMessage />
88
+ </FormItem>
89
+ )}
90
+ />
91
+ {form.formState.errors.root && (
92
+ <p className="text-sm text-destructive">{form.formState.errors.root.message}</p>
93
+ )}
94
+ <Button type="submit" disabled={isPending}>
95
+ {isPending ? 'Creating...' : 'Create User'}
96
+ </Button>
97
+ </form>
98
+ </Form>
99
+ );
100
+ }
101
+ ```
102
+
103
+ ## Edit Form Pattern
104
+
105
+ ```tsx
106
+ // Edit forms reuse the same schema with partial()
107
+ const form = useForm<UpdateUserInput>({
108
+ resolver: zodResolver(updateUserSchema),
109
+ defaultValues: { name: user.name, email: user.email },
110
+ });
111
+ ```
112
+
113
+ ## Schema Composition
114
+
115
+ ```ts
116
+ export const userSchema = z.object({ id: z.string(), name: z.string(), email: z.string() });
117
+ export const createUserSchema = userSchema.omit({ id: true });
118
+ export const updateUserSchema = createUserSchema.partial();
119
+ ```
120
+
121
+ ## Common Mistakes
122
+
123
+ | Wrong | Right | Why |
124
+ |-------|-------|-----|
125
+ | `useState` for each field | `useForm` | Unnecessary re-renders on every keystroke |
126
+ | Manual error display | `<FormMessage />` | Consistent UI, auto-connects to field errors |
127
+ | `fetch` in submit handler | `useMutation` | Loading state, error handling, cache invalidation |
128
+ | Type written manually | `z.infer<typeof schema>` | Single source of truth |
129
+ | `z.string().email()` | `z.email()` | Zod 4 moved format checks to top-level functions |
130
+ | `{ required_error: '...' }` | `{ error: '...' }` | Zod 4 unified error customization on one `error` param |
131
+
132
+ ---
133
+
134
+ *MORPH-SPEC by Polymorphism Tech*