oneie 3.6.7 → 3.6.11

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 (165) hide show
  1. package/.claude/agents/agent-backend.md +83 -0
  2. package/.claude/agents/agent-designer.md +97 -0
  3. package/.claude/agents/agent-director.md +118 -7
  4. package/.claude/agents/agent-documenter.md +93 -0
  5. package/.claude/agents/agent-frontend.md +96 -0
  6. package/.claude/agents/agent-ops.md +182 -25
  7. package/.claude/agents/agent-problem-solver.md +166 -0
  8. package/.claude/agents/agent-quality.md +127 -0
  9. package/.claude/commands/build.md +293 -0
  10. package/.claude/commands/cascade.md +231 -127
  11. package/.claude/commands/mcp-toggle.md +93 -0
  12. package/.claude/commands/one.md +198 -116
  13. package/.claude/commands/plan.md +394 -80
  14. package/.claude/commands/release.md +41 -19
  15. package/.claude/commands/server.md +2 -0
  16. package/.claude/hooks/root-cleanup.py +75 -0
  17. package/.claude/skills/INDEX.md +523 -0
  18. package/.claude/skills/REGISTRY.md +529 -0
  19. package/.claude/skills/agent-backend-create-mutation.md +319 -0
  20. package/.claude/skills/agent-designer-create-wireframe.md +341 -0
  21. package/.claude/skills/agent-frontend-create-page.md +413 -0
  22. package/.claude/skills/agents/README.md +238 -0
  23. package/dist/clone-web.js +1 -1
  24. package/dist/clone-web.js.map +1 -1
  25. package/folders.yaml +1 -1
  26. package/one/.obsidian/workspace.json +38 -38
  27. package/one/connections/api/queries-reference.md +842 -0
  28. package/one/connections/api-reference.md +1011 -0
  29. package/one/connections/integration-examples.md +875 -0
  30. package/one/connections/integration-guide.md +869 -0
  31. package/one/connections/integration-phase2.md +736 -0
  32. package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
  33. package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
  34. package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
  35. package/one/events/CONNECTIONS_DEMO.md +501 -0
  36. package/one/events/DELIVERABLES.md +432 -0
  37. package/one/events/DEMO-GROUPS-PAGE.md +392 -0
  38. package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
  39. package/one/events/DEMO_COMPONENTS.md +487 -0
  40. package/one/events/DEMO_HOOKS_INDEX.md +334 -0
  41. package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
  42. package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
  43. package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
  44. package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
  45. package/one/events/DEMO_SETUP.md +476 -0
  46. package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
  47. package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
  48. package/one/events/HOOKS-DEMO.md +441 -0
  49. package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
  50. package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
  51. package/one/events/QA-CHECKLIST.md +674 -0
  52. package/one/events/QUICK-START-ONTOLOGY.md +408 -0
  53. package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
  54. package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
  55. package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
  56. package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
  57. package/one/events/TEST-PLAN-INDEX.md +346 -0
  58. package/one/events/TEST-PLAN.md +1417 -0
  59. package/one/events/TESTING-DELIVERY.txt +372 -0
  60. package/one/events/TRANSITIONS-QUICK-START.md +141 -0
  61. package/one/events/TYPESCRIPT_FIXES.md +152 -0
  62. package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
  63. package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
  64. package/one/events/VIEW-TRANSITIONS.md +428 -0
  65. package/one/events/backend-integration-tests.md +606 -0
  66. package/one/events/backend-structure-diagram.txt +393 -0
  67. package/one/events/backend-structure-summary.txt +269 -0
  68. package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
  69. package/one/events/convex-analysis-index.md +304 -0
  70. package/one/events/convex-structure-analysis.md +700 -0
  71. package/one/events/design-spec-complete.md +208 -0
  72. package/one/events/ontology-test-examples.md +562 -0
  73. package/one/events/phase1-backend-implementation-complete.md +518 -0
  74. package/one/events/test-dashboard.md +345 -0
  75. package/one/events/test-index.md +361 -0
  76. package/one/events/test-report-ontology.md +582 -0
  77. package/one/events/testing-summary.md +344 -0
  78. package/one/groups/features.md +2878 -0
  79. package/one/groups/strategy copy.md +869 -0
  80. package/one/knowledge/backend-api-reference.md +710 -0
  81. package/one/knowledge/documentation-summary.md +285 -0
  82. package/one/knowledge/lessons-learned.md +294 -4
  83. package/one/knowledge/ontology-visual-guide.md +360 -0
  84. package/one/knowledge/ontology.md +9 -17
  85. package/one/things/demo-accessibility-animations.md +999 -0
  86. package/one/things/demo-components.md +1304 -0
  87. package/one/things/demo-design-summary.md +629 -0
  88. package/one/things/demo-design-system.md +919 -0
  89. package/one/things/demo-page-layouts.md +989 -0
  90. package/one/things/designs/accessibility-audit.md +790 -0
  91. package/one/things/designs/component-specifications.md +757 -0
  92. package/one/things/designs/design-overview.md +318 -0
  93. package/one/things/designs/design-tokens.md +414 -0
  94. package/one/things/designs/wireframes-dashboard.md +653 -0
  95. package/one/things/docs/api-requests.md +923 -0
  96. package/one/things/features/0 All Features.md +2 -0
  97. package/one/things/implementation/backend-guide.md +412 -0
  98. package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
  99. package/one/things/plans/ai-elements.md +1259 -0
  100. package/one/things/plans/ai-integration.md +947 -0
  101. package/one/things/plans/ai-sdk.md +761 -0
  102. package/one/things/plans/app.md +1 -1
  103. package/one/things/plans/architecture-summary.md +283 -0
  104. package/one/things/plans/async-ai-agents.md +215 -0
  105. package/one/things/plans/backend-agnostic-frontend.md +11 -6
  106. package/one/things/plans/backend-cleanup-quickstart.md +346 -0
  107. package/one/things/plans/backend-ontology-conformance.md +416 -0
  108. package/one/things/plans/backend-status.md +541 -0
  109. package/one/things/plans/backend-structure.md +799 -0
  110. package/one/things/plans/backend-target-structure.md +438 -0
  111. package/one/things/plans/backend.md +1133 -0
  112. package/one/things/plans/better-auth-any-backend.md +11 -11
  113. package/one/things/plans/cli-updates-required.md +280 -0
  114. package/one/things/plans/complete-step-by-step.md +1302 -0
  115. package/one/things/plans/convex-agents.md +1005 -0
  116. package/one/things/plans/deployment-architecture.md +426 -0
  117. package/one/things/plans/development-plan.md +1220 -0
  118. package/one/things/plans/effect.md +808 -48
  119. package/one/things/plans/integrate-frontend-and-backend.md +579 -0
  120. package/one/things/plans/mcp-clear-context-prompt.md +60 -0
  121. package/one/things/plans/mcp-simple.md +228 -0
  122. package/one/things/plans/one.md +8 -7
  123. package/one/things/plans/ontology-6-dimensions.md +20 -14
  124. package/one/things/plans/quick-wins.md +1273 -0
  125. package/one/things/plans/readme-backend-cleanup.md +361 -0
  126. package/one/things/plans/separate-demo.md +830 -0
  127. package/one/things/plans/separate.md +3 -3
  128. package/one/things/plans/sequence.md +1897 -0
  129. package/one/things/plans/sync-checklist.md +321 -0
  130. package/one/things/plans/unified-implementation-plan.md +3 -3
  131. package/one/things/plans/update-demos.md +513 -0
  132. package/package.json +1 -1
  133. package/.claude/agents/backend-specialist.md +0 -169
  134. package/.claude/agents/designer.md +0 -216
  135. package/.claude/agents/frontend-specialist.md +0 -236
  136. package/.claude/commands/done.md +0 -35
  137. package/.claude/commands/infer.md +0 -138
  138. package/.claude/commands/next.md +0 -53
  139. package/.claude/commands/one copy.md +0 -565
  140. package/.claude/commands/one-template.md +0 -106
  141. package/.claude/commands/one-v1.md +0 -609
  142. package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
  143. package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
  144. package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
  145. package/one/groups/nine-padel-customers.md +0 -138
  146. package/one/groups/nine-padel-data-structure.md +0 -167
  147. package/one/groups/nine-padel-ontology-specification.md +0 -359
  148. package/one/groups/nine-padel-ontology.md +0 -143
  149. package/one/groups/nine-padel-strategy.md +0 -234
  150. package/one/groups/nine-padel.md +0 -211
  151. package/one/groups/nine-padle-contents.baked.md +0 -1252
  152. package/one/groups/nine-padle-contents.md +0 -6
  153. package/one/things/features/1-1-agent-prompts/design.md +0 -470
  154. package/one/things/features/1-1-agent-prompts/tests.md +0 -264
  155. package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
  156. package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
  157. package/one/things/features/1-3-event-coordination/design.md +0 -544
  158. package/one/things/features/1-3-event-coordination/tests.md +0 -223
  159. package/one/things/features/1-4-knowledge-management/design.md +0 -609
  160. package/one/things/features/1-4-knowledge-management/tests.md +0 -195
  161. package/one/things/features/1-5-quality-loops/design.md +0 -797
  162. package/one/things/features/1-5-quality-loops/tests.md +0 -212
  163. package/one/things/features/1-6-numbering-structure/design.md +0 -610
  164. package/one/things/features/1-6-numbering-structure/tests.md +0 -213
  165. package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
@@ -0,0 +1,710 @@
1
+ # Backend API Reference - Quick Guide
2
+
3
+ **Status:** Production-Ready
4
+ **Last Updated:** 2025-10-24
5
+ **Version:** 1.0.0
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ Complete backend API for the 6-dimension ontology. All endpoints follow multi-tenant isolation (scoped to groupId).
12
+
13
+ ---
14
+
15
+ ## Groups API
16
+
17
+ ### Queries
18
+
19
+ ```typescript
20
+ // Get group by slug (URL routing)
21
+ api.queries.groups.getBySlug({ slug: "acme" })
22
+
23
+ // Get group by ID
24
+ api.queries.groups.getById({ groupId })
25
+
26
+ // List groups with filters
27
+ api.queries.groups.list({
28
+ type?: "organization" | "business" | "community" | "dao" | "government" | "friend_circle",
29
+ status?: "active" | "archived",
30
+ limit?: number
31
+ })
32
+
33
+ // Get direct children
34
+ api.queries.groups.getSubgroups({ parentGroupId })
35
+
36
+ // Get entire hierarchy (recursive)
37
+ api.queries.groups.getHierarchy({
38
+ rootGroupId,
39
+ maxDepth?: number // Default: 10
40
+ })
41
+
42
+ // Get breadcrumb trail
43
+ api.queries.groups.getGroupPath({ groupId })
44
+
45
+ // Check if group is descendant
46
+ api.queries.groups.isDescendantOf({ groupId, ancestorGroupId })
47
+
48
+ // Get entities in hierarchy
49
+ api.queries.groups.getEntitiesInHierarchy({
50
+ rootGroupId,
51
+ entityType?: string,
52
+ limit?: number
53
+ })
54
+
55
+ // Get statistics
56
+ api.queries.groups.getStats({
57
+ groupId,
58
+ includeSubgroups?: boolean
59
+ })
60
+
61
+ // Search groups
62
+ api.queries.groups.search({
63
+ query: string,
64
+ type?: string,
65
+ visibility?: "public" | "private",
66
+ limit?: number
67
+ })
68
+ ```
69
+
70
+ ### Mutations
71
+
72
+ ```typescript
73
+ // Create group
74
+ api.mutations.groups.create({
75
+ slug: string,
76
+ name: string,
77
+ type: "organization" | "business" | "community" | "dao" | "government" | "friend_circle",
78
+ parentGroupId?: Id<"groups">,
79
+ description?: string,
80
+ metadata?: any,
81
+ settings?: {
82
+ visibility: "public" | "private",
83
+ joinPolicy: "open" | "invite_only" | "approval_required",
84
+ plan?: "starter" | "pro" | "enterprise",
85
+ limits?: {
86
+ users: number,
87
+ storage: number,
88
+ apiCalls: number
89
+ }
90
+ }
91
+ })
92
+
93
+ // Update group
94
+ api.mutations.groups.update({
95
+ groupId: Id<"groups">,
96
+ name?: string,
97
+ description?: string,
98
+ metadata?: any,
99
+ settings?: { ... }
100
+ })
101
+
102
+ // Archive group (soft delete)
103
+ api.mutations.groups.archive({ groupId })
104
+
105
+ // Restore archived group
106
+ api.mutations.groups.restore({ groupId })
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Things (Entities) API
112
+
113
+ ### Queries
114
+
115
+ ```typescript
116
+ // List entities with filters
117
+ api.queries.entities.list({
118
+ groupId: Id<"groups">,
119
+ type?: string, // Any THING_TYPE from ontology
120
+ status?: "draft" | "active" | "published" | "archived" | "inactive",
121
+ limit?: number
122
+ })
123
+
124
+ // Get entity by ID
125
+ api.queries.entities.getById({
126
+ entityId: Id<"entities">,
127
+ groupId?: Id<"groups"> // Optional security validation
128
+ })
129
+
130
+ // Search entities by name
131
+ api.queries.entities.search({
132
+ groupId: Id<"groups">,
133
+ query: string,
134
+ type?: string,
135
+ limit?: number
136
+ })
137
+
138
+ // Get entity with connections
139
+ api.queries.entities.getWithConnections({
140
+ entityId: Id<"entities">,
141
+ groupId?: Id<"groups">
142
+ })
143
+ // Returns: { entity, connectionsFrom, connectionsTo }
144
+
145
+ // Get entity activity timeline
146
+ api.queries.entities.getActivity({
147
+ entityId: Id<"entities">,
148
+ limit?: number
149
+ })
150
+
151
+ // Count entities by type
152
+ api.queries.entities.countByType({ groupId })
153
+ // Returns: { [type: string]: number }
154
+
155
+ // Count entities by status
156
+ api.queries.entities.countByStatus({
157
+ groupId: Id<"groups">,
158
+ type?: string
159
+ })
160
+ // Returns: { [status: string]: number }
161
+
162
+ // Get recent entities
163
+ api.queries.entities.getRecent({
164
+ groupId: Id<"groups">,
165
+ type?: string,
166
+ limit?: number
167
+ })
168
+
169
+ // Get recently updated
170
+ api.queries.entities.getRecentlyUpdated({
171
+ groupId: Id<"groups">,
172
+ type?: string,
173
+ limit?: number
174
+ })
175
+ ```
176
+
177
+ ### Mutations
178
+
179
+ ```typescript
180
+ // Create entity
181
+ api.mutations.entities.create({
182
+ groupId: Id<"groups">,
183
+ type: string, // Must be valid THING_TYPE
184
+ name: string,
185
+ properties?: any,
186
+ status?: "draft" | "active" | "published" | "archived" | "inactive"
187
+ })
188
+
189
+ // Update entity
190
+ api.mutations.entities.update({
191
+ entityId: Id<"entities">,
192
+ name?: string,
193
+ properties?: any,
194
+ status?: "draft" | "active" | "published" | "archived" | "inactive"
195
+ })
196
+
197
+ // Archive entity (soft delete)
198
+ api.mutations.entities.archive({ entityId })
199
+
200
+ // Restore archived entity
201
+ api.mutations.entities.restore({ entityId })
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Connections API
207
+
208
+ ### Queries
209
+
210
+ ```typescript
211
+ // List connections FROM an entity
212
+ api.queries.connections.listFrom({
213
+ groupId: Id<"groups">,
214
+ fromEntityId: Id<"entities">,
215
+ relationshipType?: string // 25 connection types
216
+ })
217
+
218
+ // List connections TO an entity
219
+ api.queries.connections.listTo({
220
+ groupId: Id<"groups">,
221
+ toEntityId: Id<"entities">,
222
+ relationshipType?: string
223
+ })
224
+
225
+ // List connections between two entities
226
+ api.queries.connections.listBetween({
227
+ groupId: Id<"groups">,
228
+ fromEntityId: Id<"entities">,
229
+ toEntityId: Id<"entities">,
230
+ relationshipType?: string
231
+ })
232
+
233
+ // List connections by type
234
+ api.queries.connections.listByType({
235
+ groupId: Id<"groups">,
236
+ relationshipType: string,
237
+ limit?: number
238
+ })
239
+ ```
240
+
241
+ ### Mutations
242
+
243
+ ```typescript
244
+ // Create connection
245
+ api.mutations.connections.create({
246
+ groupId: Id<"groups">,
247
+ fromEntityId: Id<"entities">,
248
+ toEntityId: Id<"entities">,
249
+ relationshipType: string, // 25 types: owns, created_by, clone_of, etc.
250
+ metadata?: any,
251
+ strength?: number,
252
+ validFrom?: number,
253
+ validTo?: number
254
+ })
255
+
256
+ // Upsert connection (create or update)
257
+ api.mutations.connections.upsert({
258
+ groupId: Id<"groups">,
259
+ fromEntityId: Id<"entities">,
260
+ toEntityId: Id<"entities">,
261
+ relationshipType: string,
262
+ metadata?: any,
263
+ strength?: number,
264
+ validFrom?: number,
265
+ validTo?: number
266
+ })
267
+
268
+ // Bulk create connections
269
+ api.mutations.connections.bulkCreate({
270
+ groupId: Id<"groups">,
271
+ connections: Array<{
272
+ fromEntityId: Id<"entities">,
273
+ toEntityId: Id<"entities">,
274
+ relationshipType: string,
275
+ metadata?: any
276
+ }>
277
+ })
278
+ ```
279
+
280
+ ---
281
+
282
+ ## Events API (Read-Only)
283
+
284
+ ### Queries
285
+
286
+ ```typescript
287
+ // List events (timeline view)
288
+ api.queries.events.list({
289
+ groupId: Id<"groups">,
290
+ eventType?: string, // 67 event types
291
+ limit?: number,
292
+ offset?: number
293
+ })
294
+
295
+ // Events by actor (person who performed action)
296
+ api.queries.events.byActor({
297
+ groupId: Id<"groups">,
298
+ actorId: Id<"entities">,
299
+ eventType?: string,
300
+ limit?: number
301
+ })
302
+
303
+ // Events by target (thing that was affected)
304
+ api.queries.events.byTarget({
305
+ groupId: Id<"groups">,
306
+ targetId: Id<"entities">,
307
+ eventType?: string,
308
+ limit?: number
309
+ })
310
+
311
+ // Events by time range
312
+ api.queries.events.byTimeRange({
313
+ groupId: Id<"groups">,
314
+ startTime: number,
315
+ endTime: number,
316
+ eventType?: string,
317
+ limit?: number
318
+ })
319
+
320
+ // Event statistics
321
+ api.queries.events.stats({
322
+ groupId: Id<"groups">,
323
+ startTime?: number,
324
+ endTime?: number
325
+ })
326
+ // Returns: { total, byType, byActor, topTypes, topActors, timeRange }
327
+
328
+ // Recent events
329
+ api.queries.events.recent({
330
+ groupId: Id<"groups">,
331
+ limit?: number // Default: 20
332
+ })
333
+
334
+ // Get event by ID
335
+ api.queries.events.getById({
336
+ eventId: Id<"events">,
337
+ groupId?: Id<"groups">
338
+ })
339
+ ```
340
+
341
+ ---
342
+
343
+ ## Knowledge API (Read-Only)
344
+
345
+ ### Queries
346
+
347
+ ```typescript
348
+ // List knowledge items
349
+ api.queries.knowledge.list({
350
+ groupId: Id<"groups">,
351
+ knowledgeType?: "label" | "document" | "chunk" | "vector_only",
352
+ limit?: number
353
+ })
354
+
355
+ // Search knowledge (basic text search)
356
+ api.queries.knowledge.search({
357
+ groupId: Id<"groups">,
358
+ query: string,
359
+ knowledgeType?: "label" | "document" | "chunk" | "vector_only",
360
+ limit?: number
361
+ })
362
+
363
+ // Knowledge by source thing
364
+ api.queries.knowledge.bySourceThing({
365
+ groupId: Id<"groups">,
366
+ sourceThingId: Id<"entities">,
367
+ knowledgeType?: "label" | "document" | "chunk" | "vector_only"
368
+ })
369
+
370
+ // Knowledge linked to thing (via junction)
371
+ api.queries.knowledge.byThing({
372
+ thingId: Id<"entities">,
373
+ role?: "label" | "summary" | "chunk_of" | "caption" | "keyword"
374
+ })
375
+
376
+ // Knowledge by label
377
+ api.queries.knowledge.byLabel({
378
+ groupId: Id<"groups">,
379
+ label: string,
380
+ limit?: number
381
+ })
382
+
383
+ // List all labels
384
+ api.queries.knowledge.listLabels({ groupId })
385
+ // Returns: Array<{ label: string, count: number }>
386
+
387
+ // Knowledge statistics
388
+ api.queries.knowledge.stats({ groupId })
389
+ // Returns: { total, byType, withEmbeddings, withLabels, uniqueLabels }
390
+
391
+ // Get knowledge by ID
392
+ api.queries.knowledge.getById({
393
+ knowledgeId: Id<"knowledge">,
394
+ groupId?: Id<"groups">
395
+ })
396
+ ```
397
+
398
+ ---
399
+
400
+ ## Effect.ts Services
401
+
402
+ ### AgentService
403
+
404
+ ```typescript
405
+ import { AgentService, runWithServices } from "./services/layers";
406
+
407
+ const program = Effect.gen(function* () {
408
+ const agent = yield* AgentService;
409
+
410
+ // Create thread
411
+ const { threadId } = yield* agent.createThread("user123", { topic: "support" });
412
+
413
+ // Send message
414
+ const { response, tokensUsed } = yield* agent.sendMessage(threadId, "Hello!");
415
+
416
+ // Stream response
417
+ const stream = yield* agent.streamResponse(threadId, "Tell me more");
418
+
419
+ // List threads
420
+ const threads = yield* agent.listThreads("user123");
421
+
422
+ return { threadId, response, tokensUsed };
423
+ });
424
+
425
+ // Run with services
426
+ const result = await runWithServices(program);
427
+ ```
428
+
429
+ ### RAGService
430
+
431
+ ```typescript
432
+ import { RAGService, runWithServices } from "./services/layers";
433
+
434
+ const program = Effect.gen(function* () {
435
+ const rag = yield* RAGService;
436
+
437
+ // Add document
438
+ const { documentId } = yield* rag.addDocument(
439
+ "group:acme",
440
+ "This is searchable content",
441
+ { title: "Blog Post", author: "John" }
442
+ );
443
+
444
+ // Search
445
+ const results = yield* rag.search("group:acme", "searchable", 10, 0.6);
446
+
447
+ // Delete document
448
+ yield* rag.deleteDocument("group:acme", documentId);
449
+
450
+ return results;
451
+ });
452
+
453
+ const results = await runWithServices(program);
454
+ ```
455
+
456
+ ### RateLimiterService
457
+
458
+ ```typescript
459
+ import { RateLimiterService, runWithServices } from "./services/layers";
460
+
461
+ const program = Effect.gen(function* () {
462
+ const limiter = yield* RateLimiterService;
463
+
464
+ // Check limit (100 requests per minute)
465
+ const { allowed, remaining } = yield* limiter.checkLimit(
466
+ "user:123",
467
+ 100,
468
+ 60000
469
+ );
470
+
471
+ if (!allowed) {
472
+ throw new Error("Rate limit exceeded");
473
+ }
474
+
475
+ // Get usage
476
+ const usage = yield* limiter.getUsage("user:123");
477
+
478
+ // Reset limit (admin operation)
479
+ yield* limiter.resetLimit("user:123");
480
+
481
+ return { allowed, remaining, usage };
482
+ });
483
+
484
+ const result = await runWithServices(program);
485
+ ```
486
+
487
+ ### WorkflowService
488
+
489
+ ```typescript
490
+ import { WorkflowService, runWithServices } from "./services/layers";
491
+
492
+ const program = Effect.gen(function* () {
493
+ const workflow = yield* WorkflowService;
494
+
495
+ // Start workflow
496
+ const { workflowId } = yield* workflow.startWorkflow("processOrder", {
497
+ orderId: "order_123",
498
+ items: [...]
499
+ });
500
+
501
+ // Check status
502
+ const { status, result } = yield* workflow.getWorkflowStatus(workflowId);
503
+
504
+ // Cancel if needed
505
+ if (status === "running") {
506
+ yield* workflow.cancelWorkflow(workflowId);
507
+ }
508
+
509
+ return { workflowId, status, result };
510
+ });
511
+
512
+ const result = await runWithServices(program);
513
+ ```
514
+
515
+ ---
516
+
517
+ ## Common Patterns
518
+
519
+ ### Authentication
520
+
521
+ ```typescript
522
+ // In mutations
523
+ const identity = await ctx.auth.getUserIdentity();
524
+ if (!identity) {
525
+ throw new Error("Unauthenticated");
526
+ }
527
+
528
+ // Find user entity
529
+ const user = await ctx.db
530
+ .query("entities")
531
+ .withIndex("group_type", q => q.eq("groupId", groupId).eq("type", "user"))
532
+ .filter(q => q.eq(q.field("properties.userId"), identity.tokenIdentifier))
533
+ .first();
534
+ ```
535
+
536
+ ### Multi-Tenant Isolation
537
+
538
+ ```typescript
539
+ // ALWAYS filter by groupId
540
+ const entities = await ctx.db
541
+ .query("entities")
542
+ .withIndex("by_group", q => q.eq("groupId", groupId))
543
+ .collect();
544
+ ```
545
+
546
+ ### Event Logging
547
+
548
+ ```typescript
549
+ // After any mutation
550
+ await ctx.db.insert("events", {
551
+ groupId,
552
+ type: "thing_created", // or thing_updated, thing_deleted
553
+ actorId: user._id,
554
+ targetId: entityId,
555
+ timestamp: Date.now(),
556
+ metadata: {
557
+ entityType: "blog_post",
558
+ entityName: "My First Post",
559
+ action: "created"
560
+ }
561
+ });
562
+ ```
563
+
564
+ ### Error Handling with Effect.ts
565
+
566
+ ```typescript
567
+ import { Effect } from "effect";
568
+ import { ValidationError, DatabaseError } from "./services/layers";
569
+
570
+ const program = Effect.gen(function* () {
571
+ // Validate input
572
+ if (!name || name.trim().length < 2) {
573
+ return yield* Effect.fail(new ValidationError({
574
+ field: "name",
575
+ message: "Name must be at least 2 characters"
576
+ }));
577
+ }
578
+
579
+ // Wrap database operation
580
+ const result = yield* Effect.tryPromise({
581
+ try: () => ctx.db.insert("entities", { ... }),
582
+ catch: (cause) => new DatabaseError({ cause, operation: "mutation", table: "entities" })
583
+ });
584
+
585
+ return result;
586
+ });
587
+
588
+ // Handle errors
589
+ const result = await Effect.match(program, {
590
+ onFailure: (error) => {
591
+ if (error._tag === "ValidationError") {
592
+ console.error(`Validation failed: ${error.message}`);
593
+ } else if (error._tag === "DatabaseError") {
594
+ console.error(`Database error: ${error.operation}`);
595
+ }
596
+ },
597
+ onSuccess: (value) => {
598
+ console.log("Success:", value);
599
+ }
600
+ });
601
+ ```
602
+
603
+ ---
604
+
605
+ ## Connection Types (25 total)
606
+
607
+ ```typescript
608
+ // Ownership (2)
609
+ "owns" | "created_by"
610
+
611
+ // AI Relationships (3)
612
+ "clone_of" | "trained_on" | "powers"
613
+
614
+ // Content Relationships (5)
615
+ "authored" | "generated_by" | "published_to" | "part_of" | "references"
616
+
617
+ // Community Relationships (4)
618
+ "member_of" | "following" | "moderates" | "participated_in"
619
+
620
+ // Business Relationships (3)
621
+ "manages" | "reports_to" | "collaborates_with"
622
+
623
+ // Token Relationships (3)
624
+ "holds_tokens" | "staked_in" | "earned_from"
625
+
626
+ // Product Relationships (4)
627
+ "purchased" | "enrolled_in" | "completed" | "teaching"
628
+
629
+ // Consolidated Types (7)
630
+ "transacted" | "notified" | "referred" | "communicated" | "delegated" | "approved" | "fulfilled"
631
+ ```
632
+
633
+ ---
634
+
635
+ ## Event Types (67 total, subset shown)
636
+
637
+ ```typescript
638
+ // Thing Lifecycle
639
+ "thing_created" | "thing_updated" | "thing_deleted"
640
+
641
+ // User Events
642
+ "user_registered" | "user_verified" | "user_login" | "profile_updated"
643
+
644
+ // Authentication Events
645
+ "password_reset_requested" | "email_verified" | "two_factor_enabled"
646
+
647
+ // Group Events
648
+ "user_invited_to_group" | "user_joined_group" | "user_removed_from_group"
649
+
650
+ // Agent Events
651
+ "agent_executed" | "agent_completed" | "agent_failed"
652
+
653
+ // Token Events
654
+ "token_minted" | "tokens_purchased" | "tokens_transferred"
655
+
656
+ // Course Events
657
+ "course_enrolled" | "lesson_completed" | "certificate_earned"
658
+
659
+ // Analytics Events
660
+ "metric_calculated" | "insight_generated" | "prediction_made"
661
+
662
+ // Consolidated Events
663
+ "content_event" | "payment_event" | "commerce_event" | "communication_event"
664
+ ```
665
+
666
+ ---
667
+
668
+ ## Type Safety
669
+
670
+ All types are auto-generated from the schema. Use the generated types:
671
+
672
+ ```typescript
673
+ import { Id, Doc } from "./_generated/dataModel";
674
+
675
+ // Type-safe IDs
676
+ const groupId: Id<"groups"> = "...";
677
+ const entityId: Id<"entities"> = "...";
678
+
679
+ // Type-safe documents
680
+ const group: Doc<"groups"> = await ctx.db.get(groupId);
681
+ const entity: Doc<"entities"> = await ctx.db.get(entityId);
682
+ ```
683
+
684
+ ---
685
+
686
+ ## Performance Tips
687
+
688
+ 1. **Use indexes:** Always use indexed fields for queries
689
+ 2. **Paginate:** Use limit/offset for large result sets
690
+ 3. **Filter efficiently:** Filter by indexed fields first
691
+ 4. **Avoid full scans:** Use .withIndex() instead of .filter() when possible
692
+ 5. **Batch operations:** Use bulkCreate for multiple connections
693
+
694
+ ---
695
+
696
+ ## Security Checklist
697
+
698
+ - ✅ Authenticate user (ctx.auth.getUserIdentity())
699
+ - ✅ Validate group access
700
+ - ✅ Filter by groupId (multi-tenant isolation)
701
+ - ✅ Check entity belongs to group
702
+ - ✅ Log all mutations (audit trail)
703
+ - ✅ Validate inputs
704
+ - ✅ Handle errors gracefully
705
+
706
+ ---
707
+
708
+ **Status:** Production-Ready
709
+ **Last Updated:** 2025-10-24
710
+ **Version:** 1.0.0