@polymorphism-tech/morph-spec 4.7.1 → 4.7.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 (232) hide show
  1. package/.morph/.morphversion +5 -0
  2. package/.morph/analytics/threads-log.jsonl +5 -0
  3. package/.morph/config/config.json +8 -0
  4. package/.morph/framework/agents.json +1815 -0
  5. package/.morph/framework/hooks/README.md +205 -0
  6. package/.morph/framework/hooks/claude-code/notification/approval-reminder.js +54 -0
  7. package/.morph/framework/hooks/claude-code/post-tool-use/dispatch.js +83 -0
  8. package/.morph/framework/hooks/claude-code/post-tool-use/handle-tool-failure.js +42 -0
  9. package/.morph/framework/hooks/claude-code/pre-compact/save-morph-context.js +61 -0
  10. package/.morph/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +71 -0
  11. package/.morph/framework/hooks/claude-code/pre-tool-use/protect-readonly-files.js +58 -0
  12. package/.morph/framework/hooks/claude-code/pre-tool-use/protect-spec-files.js +64 -0
  13. package/.morph/framework/hooks/claude-code/session-start/inject-morph-context.js +94 -0
  14. package/.morph/framework/hooks/claude-code/statusline.py +538 -0
  15. package/.morph/framework/hooks/claude-code/statusline.sh +7 -0
  16. package/.morph/framework/hooks/claude-code/stop/validate-completion.js +88 -0
  17. package/.morph/framework/hooks/claude-code/user-prompt/enrich-prompt.js +91 -0
  18. package/.morph/framework/hooks/git/commit-msg/conventional-commits.sh +33 -0
  19. package/.morph/framework/hooks/git/pre-commit/agents.sh +25 -0
  20. package/.morph/framework/hooks/git/pre-commit/orchestrator.sh +64 -0
  21. package/.morph/framework/hooks/git/pre-commit/specs.sh +50 -0
  22. package/.morph/framework/hooks/git/pre-push/run-tests.sh +44 -0
  23. package/.morph/framework/hooks/shared/hook-response.js +45 -0
  24. package/.morph/framework/hooks/shared/phase-utils.js +129 -0
  25. package/.morph/framework/hooks/shared/state-reader.js +138 -0
  26. package/.morph/framework/hooks/shared/stdin-reader.js +26 -0
  27. package/.morph/framework/standards/STANDARDS.json +933 -0
  28. package/.morph/framework/standards/ai-agents/blazor-ui.md +364 -0
  29. package/.morph/framework/standards/ai-agents/production.md +415 -0
  30. package/.morph/framework/standards/ai-agents/setup.md +418 -0
  31. package/.morph/framework/standards/ai-agents/team-orchestration.md +479 -0
  32. package/.morph/framework/standards/ai-agents/workflows.md +354 -0
  33. package/.morph/framework/standards/architecture/ddd/aggregates.md +120 -0
  34. package/.morph/framework/standards/architecture/ddd/bounded-contexts.md +105 -0
  35. package/.morph/framework/standards/architecture/ddd/complexity-levels.md +108 -0
  36. package/.morph/framework/standards/architecture/ddd/entities.md +99 -0
  37. package/.morph/framework/standards/architecture/ddd/ubiquitous-language.md +58 -0
  38. package/.morph/framework/standards/architecture/ddd/value-objects.md +124 -0
  39. package/.morph/framework/standards/backend/api/minimal-api.md +494 -0
  40. package/.morph/framework/standards/backend/api/rest.md +492 -0
  41. package/.morph/framework/standards/backend/api/validation.md +88 -0
  42. package/.morph/framework/standards/backend/authentication/passkeys.md +428 -0
  43. package/.morph/framework/standards/backend/database/ef-core.md +199 -0
  44. package/.morph/framework/standards/backend/database/migrations.md +393 -0
  45. package/.morph/framework/standards/backend/database/postgresql/database.md +352 -0
  46. package/.morph/framework/standards/backend/database/repository-patterns.md +528 -0
  47. package/.morph/framework/standards/backend/database/vector-search-rag.md +541 -0
  48. package/.morph/framework/standards/backend/dotnet/async.md +366 -0
  49. package/.morph/framework/standards/backend/dotnet/core.md +117 -0
  50. package/.morph/framework/standards/backend/dotnet/di.md +439 -0
  51. package/.morph/framework/standards/backend/dotnet/program-cs-checklist.md +92 -0
  52. package/.morph/framework/standards/backend/integrations/asaas/asaas-api.md +216 -0
  53. package/.morph/framework/standards/backend/integrations/clerk/clerk-auth.md +290 -0
  54. package/.morph/framework/standards/backend/integrations/hangfire/hangfire-jobs.md +350 -0
  55. package/.morph/framework/standards/backend/integrations/resend/resend-email.md +385 -0
  56. package/.morph/framework/standards/context/analytics.md +96 -0
  57. package/.morph/framework/standards/context/bundles.md +110 -0
  58. package/.morph/framework/standards/context/priming.md +78 -0
  59. package/.morph/framework/standards/core/architecture.md +185 -0
  60. package/.morph/framework/standards/core/coding.md +214 -0
  61. package/.morph/framework/standards/core/git-branching-strategy.md +403 -0
  62. package/.morph/framework/standards/core/git.md +185 -0
  63. package/.morph/framework/standards/core/testing.md +295 -0
  64. package/.morph/framework/standards/data/nosql/blob-storage.md +102 -0
  65. package/.morph/framework/standards/data/nosql/cache/redis.md +97 -0
  66. package/.morph/framework/standards/data/nosql/cosmos-db.md +118 -0
  67. package/.morph/framework/standards/data/vector-search/azure-ai-search.md +121 -0
  68. package/.morph/framework/standards/data/vector-search/rag-chunking.md +104 -0
  69. package/.morph/framework/standards/frontend/blazor/design-checklist.md +222 -0
  70. package/.morph/framework/standards/frontend/blazor/fluent-ui-setup.md +595 -0
  71. package/.morph/framework/standards/frontend/blazor/fluent-ui.md +137 -0
  72. package/.morph/framework/standards/frontend/blazor/html-conversion.md +184 -0
  73. package/.morph/framework/standards/frontend/blazor/lifecycle.md +195 -0
  74. package/.morph/framework/standards/frontend/blazor/pitfalls.md +198 -0
  75. package/.morph/framework/standards/frontend/blazor/state.md +191 -0
  76. package/.morph/framework/standards/frontend/design-system/animations.md +151 -0
  77. package/.morph/framework/standards/frontend/design-system/naming.md +64 -0
  78. package/.morph/framework/standards/frontend/nextjs/app-router.md +123 -0
  79. package/.morph/framework/standards/frontend/nextjs/components.md +132 -0
  80. package/.morph/framework/standards/frontend/nextjs/data-fetching.md +126 -0
  81. package/.morph/framework/standards/frontend/nextjs/forms.md +128 -0
  82. package/.morph/framework/standards/frontend/nextjs/naming-conventions.md +67 -0
  83. package/.morph/framework/standards/frontend/nextjs/nextjs-patterns.md +215 -0
  84. package/.morph/framework/standards/frontend/nextjs/project-structure.md +102 -0
  85. package/.morph/framework/standards/frontend/nextjs/state-management.md +72 -0
  86. package/.morph/framework/standards/frontend/nextjs/testing.md +111 -0
  87. package/.morph/framework/standards/infrastructure/azure/azure.md +624 -0
  88. package/.morph/framework/standards/infrastructure/azure/bicep/bicep-patterns.md +422 -0
  89. package/.morph/framework/standards/infrastructure/azure/devops/azure-devops-setup.md +516 -0
  90. package/.morph/framework/standards/infrastructure/azure/devops/local-development.md +520 -0
  91. package/.morph/framework/standards/infrastructure/azure/services/functions.md +486 -0
  92. package/.morph/framework/standards/infrastructure/azure/services/service-bus.md +459 -0
  93. package/.morph/framework/standards/infrastructure/azure/services/storage.md +407 -0
  94. package/.morph/framework/standards/infrastructure/docker/easypanel-deploy.md +196 -0
  95. package/.morph/framework/standards/infrastructure/supabase/mcp-setup.md +252 -0
  96. package/.morph/framework/standards/infrastructure/supabase/supabase-auth.md +176 -0
  97. package/.morph/framework/standards/infrastructure/supabase/supabase-pgvector.md +169 -0
  98. package/.morph/framework/standards/infrastructure/supabase/supabase-rls.md +184 -0
  99. package/.morph/framework/standards/infrastructure/supabase/supabase-storage.md +153 -0
  100. package/.morph/framework/standards/integration/api/graphql.md +91 -0
  101. package/.morph/framework/standards/integration/api/grpc.md +114 -0
  102. package/.morph/framework/standards/integration/api/rest-design.md +95 -0
  103. package/.morph/framework/standards/integration/event-driven/cqrs.md +101 -0
  104. package/.morph/framework/standards/integration/event-driven/event-sourcing.md +124 -0
  105. package/.morph/framework/standards/integration/event-driven/service-bus.md +95 -0
  106. package/.morph/framework/standards/integration/mcp/mcp-tools.md +384 -0
  107. package/.morph/framework/standards/observability/logging.md +131 -0
  108. package/.morph/framework/standards/observability/metrics.md +121 -0
  109. package/.morph/framework/standards/observability/monitoring.md +114 -0
  110. package/.morph/framework/standards/observability/tracing.md +132 -0
  111. package/.morph/framework/standards/workflows/parallel-execution.md +112 -0
  112. package/.morph/framework/standards/workflows/thread-management.md +113 -0
  113. package/.morph/framework/templates/.idea/morph-templates.xml +92 -0
  114. package/.morph/framework/templates/.vscode/morph-templates.code-snippets +186 -0
  115. package/.morph/framework/templates/IDE-SNIPPETS.md +266 -0
  116. package/.morph/framework/templates/README.md +814 -0
  117. package/.morph/framework/templates/REGISTRY.json +1888 -0
  118. package/.morph/framework/templates/code/dotnet/backend/repository.cs +141 -0
  119. package/.morph/framework/templates/code/dotnet/backend/service.cs +139 -0
  120. package/.morph/framework/templates/code/dotnet/contracts/Commands.cs +74 -0
  121. package/.morph/framework/templates/code/dotnet/contracts/Entities.cs +25 -0
  122. package/.morph/framework/templates/code/dotnet/contracts/Queries.cs +74 -0
  123. package/.morph/framework/templates/code/dotnet/contracts/README.md +74 -0
  124. package/.morph/framework/templates/code/dotnet/contracts/api-contracts.cs +173 -0
  125. package/.morph/framework/templates/code/dotnet/contracts/contracts-level1.cs +69 -0
  126. package/.morph/framework/templates/code/dotnet/contracts/contracts-level2.cs +86 -0
  127. package/.morph/framework/templates/code/dotnet/contracts/contracts-level3.cs +41 -0
  128. package/.morph/framework/templates/code/dotnet/database/migration.cs +83 -0
  129. package/.morph/framework/templates/code/dotnet/frontend/component.razor +239 -0
  130. package/.morph/framework/templates/code/dotnet/jobs/agent.cs +163 -0
  131. package/.morph/framework/templates/code/dotnet/jobs/job.cs +171 -0
  132. package/.morph/framework/templates/code/dotnet/test.cs +239 -0
  133. package/.morph/framework/templates/code/sql/rls-policy.sql +57 -0
  134. package/.morph/framework/templates/code/sql/supabase-migration.sql +100 -0
  135. package/.morph/framework/templates/code/sql/supabase-migration.template.sql +113 -0
  136. package/.morph/framework/templates/code/typescript/contracts.ts +168 -0
  137. package/.morph/framework/templates/context/CONTEXT-FEATURE.md +276 -0
  138. package/.morph/framework/templates/context/CONTEXT.md +181 -0
  139. package/.morph/framework/templates/docs/clarifications.md +253 -0
  140. package/.morph/framework/templates/docs/onboarding.md +123 -0
  141. package/.morph/framework/templates/docs/proposal.md +182 -0
  142. package/.morph/framework/templates/docs/schema-analysis.md +119 -0
  143. package/.morph/framework/templates/docs/spec.md +198 -0
  144. package/.morph/framework/templates/docs/ui-components.md +124 -0
  145. package/.morph/framework/templates/docs/ui-design-system.md +76 -0
  146. package/.morph/framework/templates/docs/ui-flows.md +167 -0
  147. package/.morph/framework/templates/docs/ui-mockups.md +98 -0
  148. package/.morph/framework/templates/docs/user-stories.md +34 -0
  149. package/.morph/framework/templates/examples/design-system-examples.md +357 -0
  150. package/.morph/framework/templates/examples/spec-examples.md +90 -0
  151. package/.morph/framework/templates/feature/decisions.md +187 -0
  152. package/.morph/framework/templates/feature/recap.md +146 -0
  153. package/.morph/framework/templates/feature/tasks.md +199 -0
  154. package/.morph/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +43 -0
  155. package/.morph/framework/templates/frontend/nextjs/client-component.tsx.hbs +26 -0
  156. package/.morph/framework/templates/frontend/nextjs/env.mjs.hbs +32 -0
  157. package/.morph/framework/templates/frontend/nextjs/feature-form.tsx.hbs +56 -0
  158. package/.morph/framework/templates/frontend/nextjs/page.tsx.hbs +22 -0
  159. package/.morph/framework/templates/frontend/nextjs/tsconfig.json.hbs +26 -0
  160. package/.morph/framework/templates/frontend/nextjs/use-feature.ts.hbs +54 -0
  161. package/.morph/framework/templates/infrastructure/azure/Dockerfile.example +82 -0
  162. package/.morph/framework/templates/infrastructure/azure/README.md +286 -0
  163. package/.morph/framework/templates/infrastructure/azure/app-insights.bicep +63 -0
  164. package/.morph/framework/templates/infrastructure/azure/app-service.bicep +164 -0
  165. package/.morph/framework/templates/infrastructure/azure/container-app-env.bicep +49 -0
  166. package/.morph/framework/templates/infrastructure/azure/container-app.bicep +156 -0
  167. package/.morph/framework/templates/infrastructure/azure/deploy-checklist.md +426 -0
  168. package/.morph/framework/templates/infrastructure/azure/deploy.ps1 +229 -0
  169. package/.morph/framework/templates/infrastructure/azure/deploy.sh +208 -0
  170. package/.morph/framework/templates/infrastructure/azure/key-vault.bicep +91 -0
  171. package/.morph/framework/templates/infrastructure/azure/main.bicep +189 -0
  172. package/.morph/framework/templates/infrastructure/azure/parameters.dev.json +29 -0
  173. package/.morph/framework/templates/infrastructure/azure/parameters.prod.json +29 -0
  174. package/.morph/framework/templates/infrastructure/azure/parameters.staging.json +29 -0
  175. package/.morph/framework/templates/infrastructure/azure/sql-database.bicep +103 -0
  176. package/.morph/framework/templates/infrastructure/azure/storage.bicep +106 -0
  177. package/.morph/framework/templates/infrastructure/docker/Dockerfile.template +58 -0
  178. package/.morph/framework/templates/infrastructure/docker/docker-compose.template.yml +67 -0
  179. package/.morph/framework/templates/infrastructure/docker/dockerfile-api.dockerfile +38 -0
  180. package/.morph/framework/templates/infrastructure/docker/dockerfile-web.dockerfile +48 -0
  181. package/.morph/framework/templates/infrastructure/docker/easypanel.template.json +54 -0
  182. package/.morph/framework/templates/infrastructure/github/README.md +593 -0
  183. package/.morph/framework/templates/infrastructure/github/actions/azure-auth/action.yml.hbs +22 -0
  184. package/.morph/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +45 -0
  185. package/.morph/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +27 -0
  186. package/.morph/framework/templates/infrastructure/github/workflows/deploy-azure-app-service.yml.hbs +61 -0
  187. package/.morph/framework/templates/infrastructure/github/workflows/deploy-easypanel.yml.hbs +31 -0
  188. package/.morph/framework/templates/infrastructure/github/workflows/docker-build-push.yml.hbs +59 -0
  189. package/.morph/framework/templates/infrastructure/github/workflows/dotnet-build.yml.hbs +39 -0
  190. package/.morph/framework/templates/integrations/asaas-client.cs +387 -0
  191. package/.morph/framework/templates/integrations/asaas-webhook.cs +351 -0
  192. package/.morph/framework/templates/integrations/azure-identity-config.cs +288 -0
  193. package/.morph/framework/templates/integrations/clerk-config.cs +258 -0
  194. package/.morph/framework/templates/meta-prompts/fusion/fusion-agent.md +76 -0
  195. package/.morph/framework/templates/meta-prompts/fusion/fusion-aggregator.md +100 -0
  196. package/.morph/framework/templates/meta-prompts/hops/hop-retry.md +78 -0
  197. package/.morph/framework/templates/meta-prompts/hops/hop-validation.md +97 -0
  198. package/.morph/framework/templates/meta-prompts/hops/hop-wrapper.md +36 -0
  199. package/.morph/framework/templates/meta-prompts/parallel-workers/parallel-coordinator.md +113 -0
  200. package/.morph/framework/templates/meta-prompts/parallel-workers/parallel-worker.md +80 -0
  201. package/.morph/framework/templates/meta-prompts/squad-leaders/backend-squad.md +90 -0
  202. package/.morph/framework/templates/meta-prompts/squad-leaders/frontend-squad.md +126 -0
  203. package/.morph/framework/templates/meta-prompts/squad-leaders/squad-leader.md +43 -0
  204. package/.morph/framework/templates/meta-prompts/validators/checkpoint-validator.md +107 -0
  205. package/.morph/framework/templates/meta-prompts/validators/pre-commit-validator.md +95 -0
  206. package/.morph/framework/templates/project-structure/dotnet-ddd.md +70 -0
  207. package/.morph/framework/templates/saas/subscription.cs +347 -0
  208. package/.morph/framework/templates/saas/tenant.cs +338 -0
  209. package/.morph/framework/templates/state.template.json +17 -0
  210. package/.morph/framework/templates/ui/FluentDesignTheme.cs +149 -0
  211. package/.morph/framework/templates/ui/MudTheme.cs +281 -0
  212. package/.morph/framework/templates/ui/design-system.css +226 -0
  213. package/.morph/logs/tool-failures.log +17 -0
  214. package/.morph/memory/pre-compact-2026-02-24T17-43-30-049Z.json +16 -0
  215. package/.morph/plans/eager-watching-bunny.md +105 -0
  216. package/.morph/plans/temporal-seeking-nebula.md +45 -0
  217. package/.morph/state.json +48 -0
  218. package/CLAUDE.md +1 -1
  219. package/README.md +2 -2
  220. package/bin/morph-spec.js +0 -9
  221. package/framework/CLAUDE.md +1 -1
  222. package/framework/hooks/README.md +10 -6
  223. package/framework/hooks/claude-code/notification/approval-reminder.js +2 -0
  224. package/framework/hooks/claude-code/post-tool-use/dispatch.js +1 -1
  225. package/framework/hooks/claude-code/stop/validate-completion.js +1 -1
  226. package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +1 -1
  227. package/package.json +1 -1
  228. package/src/commands/project/init.js +15 -42
  229. package/src/commands/project/update.js +22 -37
  230. package/src/lib/installers/mcp-installer.js +18 -3
  231. package/src/utils/hooks-installer.js +5 -15
  232. package/src/commands/project/detect.js +0 -114
@@ -0,0 +1,121 @@
1
+ # Data Standard: Azure AI Search (Vector Search)
2
+
3
+ ## Overview
4
+ Azure AI Search provides vector and hybrid search for RAG (Retrieval-Augmented Generation) patterns.
5
+
6
+ ## Index Design
7
+ ```csharp
8
+ // Define index with vector field
9
+ var index = new SearchIndex("documents-index")
10
+ {
11
+ Fields =
12
+ [
13
+ new SimpleField("id", SearchFieldDataType.String) { IsKey = true },
14
+ new SearchableField("content") { AnalyzerName = "pt.microsoft" },
15
+ new SearchableField("title") { AnalyzerName = "pt.microsoft" },
16
+ new SimpleField("sourceUrl", SearchFieldDataType.String) { IsFilterable = true },
17
+ new SimpleField("category", SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
18
+ new VectorSearchField("contentVector", dimensions: 1536, vectorSearchProfileName: "hnsw-profile")
19
+ ],
20
+ VectorSearch = new VectorSearch
21
+ {
22
+ Profiles = { new VectorSearchProfile("hnsw-profile", "hnsw-config") },
23
+ Algorithms = { new HnswAlgorithmConfiguration("hnsw-config") }
24
+ }
25
+ };
26
+ await indexClient.CreateOrUpdateIndexAsync(index);
27
+ ```
28
+
29
+ ## Embedding Generation
30
+ ```csharp
31
+ public class EmbeddingService : IEmbeddingService
32
+ {
33
+ private readonly OpenAIClient _client;
34
+ private const string EmbeddingModel = "text-embedding-ada-002"; // 1536 dimensions
35
+
36
+ public async Task<float[]> GenerateEmbeddingAsync(string text)
37
+ {
38
+ // Truncate to model limit
39
+ var truncated = text.Length > 8192 ? text[..8192] : text;
40
+
41
+ var response = await _client.GetEmbeddingsAsync(
42
+ new EmbeddingsOptions(EmbeddingModel, [truncated]));
43
+
44
+ return response.Value.Data[0].Embedding.ToArray();
45
+ }
46
+
47
+ public async Task<IReadOnlyList<float[]>> GenerateBatchEmbeddingsAsync(IReadOnlyList<string> texts)
48
+ {
49
+ var response = await _client.GetEmbeddingsAsync(
50
+ new EmbeddingsOptions(EmbeddingModel, texts));
51
+ return response.Value.Data.Select(d => d.Embedding.ToArray()).ToList();
52
+ }
53
+ }
54
+ ```
55
+
56
+ ## Document Indexing
57
+ ```csharp
58
+ public class DocumentIndexer
59
+ {
60
+ public async Task IndexDocumentAsync(Document doc)
61
+ {
62
+ var embedding = await _embeddingService.GenerateEmbeddingAsync(doc.Content);
63
+
64
+ var searchDoc = new SearchDocument
65
+ {
66
+ ["id"] = doc.Id.ToString(),
67
+ ["content"] = doc.Content,
68
+ ["title"] = doc.Title,
69
+ ["sourceUrl"] = doc.SourceUrl,
70
+ ["category"] = doc.Category,
71
+ ["contentVector"] = embedding
72
+ };
73
+
74
+ await _searchClient.MergeOrUploadDocumentsAsync([searchDoc]);
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## Hybrid Search (Vector + Keyword)
80
+ ```csharp
81
+ public async Task<IReadOnlyList<SearchResult>> SearchAsync(string query, string? category = null)
82
+ {
83
+ var queryEmbedding = await _embeddingService.GenerateEmbeddingAsync(query);
84
+
85
+ var options = new SearchOptions
86
+ {
87
+ Filter = category != null ? $"category eq '{category}'" : null,
88
+ Size = 10,
89
+ VectorSearch = new VectorSearchOptions
90
+ {
91
+ Queries =
92
+ {
93
+ new VectorizedQuery(queryEmbedding)
94
+ {
95
+ Fields = { "contentVector" },
96
+ KNearestNeighborsCount = 50
97
+ }
98
+ }
99
+ },
100
+ QueryType = SearchQueryType.Semantic,
101
+ SemanticSearch = new SemanticSearchOptions
102
+ {
103
+ SemanticConfigurationName = "my-semantic-config",
104
+ QueryCaption = new QueryCaption(QueryCaptionType.Extractive)
105
+ }
106
+ };
107
+
108
+ var response = await _searchClient.SearchAsync<SearchDocument>(query, options);
109
+ return await response.Value.GetResultsAsync().Select(r => new SearchResult(
110
+ r.Document["id"].ToString()!,
111
+ r.Document["content"].ToString()!,
112
+ r.Score ?? 0
113
+ )).ToListAsync();
114
+ }
115
+ ```
116
+
117
+ ## Cost Optimization
118
+ - Index only necessary fields (cost per GB/month)
119
+ - Use semantic ranking sparingly (higher cost per query)
120
+ - Cache frequent query embeddings (embeddings are stable for same text)
121
+ - Batch indexing for large document sets (avoid per-document API calls)
@@ -0,0 +1,104 @@
1
+ # Data Standard: RAG Chunking Strategies
2
+
3
+ ## Overview
4
+ Chunking splits documents into segments for embedding. Chunk quality directly impacts RAG answer quality.
5
+
6
+ ## Chunking Strategies
7
+
8
+ ### 1. Fixed-Size (Baseline)
9
+ ```csharp
10
+ public IEnumerable<Chunk> FixedSizeChunk(string text, int size = 512, int overlap = 50)
11
+ {
12
+ for (int i = 0; i < text.Length; i += size - overlap)
13
+ {
14
+ yield return new Chunk
15
+ {
16
+ Content = text[i..Math.Min(i + size, text.Length)],
17
+ StartIndex = i,
18
+ EndIndex = Math.Min(i + size, text.Length)
19
+ };
20
+ }
21
+ }
22
+ ```
23
+
24
+ ### 2. Sentence-Aware (Recommended for prose)
25
+ ```csharp
26
+ public IEnumerable<Chunk> SentenceChunk(string text, int maxTokens = 256)
27
+ {
28
+ var sentences = SplitSentences(text);
29
+ var current = new StringBuilder();
30
+ var tokenCount = 0;
31
+
32
+ foreach (var sentence in sentences)
33
+ {
34
+ var sentenceTokens = EstimateTokens(sentence);
35
+ if (tokenCount + sentenceTokens > maxTokens && current.Length > 0)
36
+ {
37
+ yield return new Chunk { Content = current.ToString().Trim() };
38
+ current.Clear();
39
+ tokenCount = 0;
40
+ }
41
+ current.Append(sentence).Append(' ');
42
+ tokenCount += sentenceTokens;
43
+ }
44
+
45
+ if (current.Length > 0)
46
+ yield return new Chunk { Content = current.ToString().Trim() };
47
+ }
48
+ ```
49
+
50
+ ### 3. Semantic (Best quality, higher cost)
51
+ Split at semantic boundaries (paragraphs, headers, sections) rather than character count.
52
+
53
+ ```csharp
54
+ public IEnumerable<Chunk> SemanticChunk(string markdown)
55
+ {
56
+ // Split at markdown headers
57
+ var sections = Regex.Split(markdown, @"(?=^#{1,3} )", RegexOptions.Multiline);
58
+ foreach (var section in sections.Where(s => s.Trim().Length > 0))
59
+ yield return new Chunk { Content = section.Trim() };
60
+ }
61
+ ```
62
+
63
+ ## Token Estimation
64
+ ```csharp
65
+ // Rough estimate: 1 token ≈ 4 characters (English), ≈ 3 characters (Portuguese)
66
+ private static int EstimateTokens(string text) => text.Length / 4;
67
+
68
+ // More accurate: use tiktoken (if available)
69
+ // var encoder = TiktokenSharp.TikToken.EncodingForModel("gpt-4");
70
+ // return encoder.Encode(text).Count;
71
+ ```
72
+
73
+ ## Chunk Metadata
74
+ Always store metadata with chunks for filtering and citation:
75
+ ```csharp
76
+ public record Chunk
77
+ {
78
+ public string Content { get; init; } = "";
79
+ public string DocumentId { get; init; } = "";
80
+ public string DocumentTitle { get; init; } = "";
81
+ public string SourceUrl { get; init; } = "";
82
+ public int ChunkIndex { get; init; }
83
+ public int StartCharIndex { get; init; }
84
+ public string Section { get; init; } = ""; // H1/H2 header this belongs to
85
+ public DateTime IndexedAt { get; init; } = DateTime.UtcNow;
86
+ }
87
+ ```
88
+
89
+ ## Strategy Selection Guide
90
+ | Document Type | Strategy | Chunk Size |
91
+ |---------------|----------|------------|
92
+ | Legal documents | Sentence-aware | 256 tokens |
93
+ | Technical docs | Semantic (headers) | Variable |
94
+ | Q&A pairs | Keep as-is | Whole Q+A |
95
+ | Code files | Function-boundary | Whole function |
96
+ | News articles | Paragraph | 512 tokens |
97
+
98
+ ## Quality Checklist
99
+ - [ ] Chunks overlap by 10-20% to avoid cutting context at boundaries
100
+ - [ ] Minimum chunk size: 50 tokens (avoid noisy small chunks)
101
+ - [ ] Maximum chunk size: 512 tokens for ada-002 (8192 token model limit)
102
+ - [ ] Metadata preserved and searchable
103
+ - [ ] Source URL included for citation
104
+ - [ ] Re-index when document changes (detect via content hash)
@@ -0,0 +1,222 @@
1
+ # Blazor Design Phase Checklist
2
+
3
+ > **Scope:** blazor-azure
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** blazor, design, checklist, phase, architecture
6
+ > **Load When:** design phase for blazor features
7
+
8
+ Use this checklist during FASE 2 (DESIGN) for features involving Blazor Server
9
+
10
+ ---
11
+
12
+ ## 1. State and Session Management
13
+
14
+ ### State Persistence
15
+
16
+ - [ ] **How will critical state be persisted?**
17
+ - [ ] Database (recommended for important data)
18
+ - [ ] Distributed cache (Redis, SQL Distributed Cache)
19
+ - [ ] Cookie (only for identification, not data)
20
+ - [ ] LocalStorage via JS Interop (only for non-critical preferences)
21
+
22
+ - [ ] **SessionState has `LoadFrom(entity)` method?**
23
+ - Allows reloading state from persisted source
24
+ - See [state.md](./state.md)
25
+
26
+ - [ ] **`IsLoaded` property exists to avoid unnecessary reloads?**
27
+
28
+ - [ ] **SessionId middleware is configured?**
29
+ - HttpOnly cookie with session identifier
30
+ - Injected into HttpContext.Items for component access
31
+
32
+ ### Page Validation
33
+
34
+ - [ ] **All pages in flow reload state in `OnInitializedAsync`?**
35
+ ```csharp
36
+ if (!Session.IsLoaded)
37
+ {
38
+ var entity = await Repository.GetBySessionIdAsync(sessionId);
39
+ Session.LoadFrom(entity);
40
+ }
41
+ ```
42
+
43
+ - [ ] **What happens if user accesses middle page directly?**
44
+ - Redirect to start?
45
+ - Load partial state?
46
+ - Show friendly error?
47
+
48
+ ---
49
+
50
+ ## 2. EF Core Concurrency
51
+
52
+ ### Background Operations
53
+
54
+ - [ ] **Will any service be called via `Task.Run`?**
55
+ - If YES: Use `IDbContextFactory<T>`
56
+ - See [ef-core.md](../../backend/database/ef-core.md)
57
+
58
+ - [ ] **Will any service be called in background job (Hangfire, Timer)?**
59
+ - If YES: Use `IDbContextFactory<T>` or Repository Factory pattern
60
+
61
+ - [ ] **Will multiple operations happen concurrently in same component?**
62
+ - If YES: Each operation needs isolated DbContext
63
+
64
+ ---
65
+
66
+ ## 3. File Upload
67
+
68
+ - [ ] **Will feature handle file uploads?**
69
+ - [ ] Max file size defined?
70
+ - [ ] Allowed file types/extensions specified?
71
+ - [ ] Files read once and bytes stored?
72
+ - [ ] Upload progress indicator planned?
73
+
74
+ - [ ] **Where will files be stored?**
75
+ - [ ] Azure Blob Storage (recommended)
76
+ - [ ] Local file system (not scalable)
77
+ - [ ] Database as byte[] (only for small files < 1MB)
78
+
79
+ ---
80
+
81
+ ## 4. JavaScript Interop
82
+
83
+ - [ ] **Will feature use JavaScript?**
84
+ - [ ] JS calls in `OnAfterRenderAsync`, not `OnInitializedAsync`?
85
+ - [ ] `firstRender` check to prevent duplicate calls?
86
+ - [ ] JS file location planned (wwwroot/js/)?
87
+
88
+ - [ ] **Will feature need external JS libraries?**
89
+ - [ ] Library loaded via CDN or npm?
90
+ - [ ] Initialization strategy planned?
91
+
92
+ ---
93
+
94
+ ## 5. Navigation and Routing
95
+
96
+ - [ ] **How many pages in the feature?**
97
+ - Single page?
98
+ - Multi-page flow?
99
+ - Modal/dialog-based?
100
+
101
+ - [ ] **Will users need to navigate back/forward?**
102
+ - [ ] State persisted before navigation?
103
+ - [ ] Browser back button handled correctly?
104
+
105
+ - [ ] **Are there deep links?**
106
+ - [ ] Each page can load state from URL/DB?
107
+ - [ ] Invalid state handled gracefully?
108
+
109
+ ---
110
+
111
+ ## 6. Real-time Updates
112
+
113
+ - [ ] **Will feature need real-time updates?**
114
+ - SignalR circuit is already available
115
+ - Update strategy planned?
116
+
117
+ - [ ] **Will updates come from background jobs?**
118
+ - [ ] Notification mechanism planned?
119
+ - [ ] UI refresh strategy defined?
120
+
121
+ ---
122
+
123
+ ## 7. Performance
124
+
125
+ - [ ] **Expected data volume?**
126
+ - Pagination needed for lists > 100 items?
127
+ - Lazy loading for large datasets?
128
+
129
+ - [ ] **Heavy computations planned?**
130
+ - [ ] Run in background (Task.Run with factory)?
131
+ - [ ] Cache results?
132
+
133
+ - [ ] **Large components/forms?**
134
+ - [ ] Split into smaller components?
135
+ - [ ] Lazy rendering planned?
136
+
137
+ ---
138
+
139
+ ## 8. Error Handling
140
+
141
+ - [ ] **What errors might occur?**
142
+ - Database errors?
143
+ - Network errors?
144
+ - Validation errors?
145
+ - Permission errors?
146
+
147
+ - [ ] **Error display strategy?**
148
+ - [ ] Toast notifications?
149
+ - [ ] Inline validation messages?
150
+ - [ ] Error page redirect?
151
+
152
+ - [ ] **Retry strategy for transient errors?**
153
+
154
+ ---
155
+
156
+ ## 9. Security
157
+
158
+ - [ ] **Authentication required?**
159
+ - [ ] `[Authorize]` attribute on pages?
160
+ - [ ] Login redirect configured?
161
+
162
+ - [ ] **Authorization rules?**
163
+ - Role-based?
164
+ - Policy-based?
165
+ - Resource-based?
166
+
167
+ - [ ] **Input validation?**
168
+ - [ ] Client-side (Blazor validation)?
169
+ - [ ] Server-side (service layer)?
170
+ - [ ] Both?
171
+
172
+ - [ ] **Sensitive data?**
173
+ - [ ] Not stored in SessionState?
174
+ - [ ] Not logged?
175
+ - [ ] Encrypted in database?
176
+
177
+ ---
178
+
179
+ ## 10. UI/UX
180
+
181
+ - [ ] **Loading states?**
182
+ - Spinners for async operations?
183
+ - Skeleton loaders for data?
184
+ - Disabled buttons during saves?
185
+
186
+ - [ ] **Success feedback?**
187
+ - Toast messages?
188
+ - Inline success indicators?
189
+ - Redirect to confirmation page?
190
+
191
+ - [ ] **Responsive design?**
192
+ - Mobile layout planned?
193
+ - Breakpoints defined?
194
+
195
+ ---
196
+
197
+ ## Quick Design Decisions
198
+
199
+ Before implementing, answer these:
200
+
201
+ | Question | Answer Required |
202
+ |----------|----------------|
203
+ | **State:** Where is critical state stored? | Database / Cache / Cookie |
204
+ | **Files:** Where are uploads stored? | Azure Blob / Database / FileSystem |
205
+ | **Navigation:** Single page or multi-page? | Single / Multi / Modal |
206
+ | **JS:** Is JavaScript needed? | Yes / No |
207
+ | **Auth:** Authentication required? | Yes / No |
208
+ | **Background:** Any background operations? | Yes (use factory) / No |
209
+ | **Real-time:** Real-time updates needed? | Yes / No |
210
+
211
+ ---
212
+
213
+ ## Related Standards
214
+
215
+ - [state.md](./state.md) - Session state patterns
216
+ - [lifecycle.md](./lifecycle.md) - Component lifecycle
217
+ - [pitfalls.md](./pitfalls.md) - Common mistakes
218
+ - [ef-core.md](../../backend/database/ef-core.md) - DbContext concurrency
219
+
220
+ ---
221
+
222
+ *MORPH-SPEC by Polymorphism Tech*