oneie 3.6.7 → 3.6.12

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 (168) 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 +264 -32
  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/deploy.md +56 -17
  12. package/.claude/commands/mcp-toggle.md +93 -0
  13. package/.claude/commands/one.md +78 -127
  14. package/.claude/commands/plan.md +394 -80
  15. package/.claude/commands/push.md +75 -14
  16. package/.claude/commands/release.md +89 -25
  17. package/.claude/commands/server.md +2 -0
  18. package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
  19. package/.claude/hooks/root-cleanup.py +75 -0
  20. package/.claude/skills/INDEX.md +523 -0
  21. package/.claude/skills/REGISTRY.md +529 -0
  22. package/.claude/skills/agent-backend-create-mutation.md +319 -0
  23. package/.claude/skills/agent-designer-create-wireframe.md +341 -0
  24. package/.claude/skills/agent-frontend-create-page.md +413 -0
  25. package/.claude/skills/agents/README.md +238 -0
  26. package/dist/clone-web.js +1 -1
  27. package/dist/clone-web.js.map +1 -1
  28. package/folders.yaml +1 -1
  29. package/one/.obsidian/workspace.json +38 -38
  30. package/one/connections/api/queries-reference.md +842 -0
  31. package/one/connections/api-reference.md +1011 -0
  32. package/one/connections/integration-examples.md +875 -0
  33. package/one/connections/integration-guide.md +869 -0
  34. package/one/connections/integration-phase2.md +736 -0
  35. package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
  36. package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
  37. package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
  38. package/one/events/CONNECTIONS_DEMO.md +501 -0
  39. package/one/events/DELIVERABLES.md +432 -0
  40. package/one/events/DEMO-GROUPS-PAGE.md +392 -0
  41. package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
  42. package/one/events/DEMO_COMPONENTS.md +487 -0
  43. package/one/events/DEMO_HOOKS_INDEX.md +334 -0
  44. package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
  45. package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
  46. package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
  47. package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
  48. package/one/events/DEMO_SETUP.md +476 -0
  49. package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
  50. package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
  51. package/one/events/HOOKS-DEMO.md +441 -0
  52. package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
  53. package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
  54. package/one/events/QA-CHECKLIST.md +674 -0
  55. package/one/events/QUICK-START-ONTOLOGY.md +408 -0
  56. package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
  57. package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
  58. package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
  59. package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
  60. package/one/events/TEST-PLAN-INDEX.md +346 -0
  61. package/one/events/TEST-PLAN.md +1417 -0
  62. package/one/events/TESTING-DELIVERY.txt +372 -0
  63. package/one/events/TRANSITIONS-QUICK-START.md +141 -0
  64. package/one/events/TYPESCRIPT_FIXES.md +152 -0
  65. package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
  66. package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
  67. package/one/events/VIEW-TRANSITIONS.md +428 -0
  68. package/one/events/backend-integration-tests.md +606 -0
  69. package/one/events/backend-structure-diagram.txt +393 -0
  70. package/one/events/backend-structure-summary.txt +269 -0
  71. package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
  72. package/one/events/convex-analysis-index.md +304 -0
  73. package/one/events/convex-structure-analysis.md +700 -0
  74. package/one/events/design-spec-complete.md +208 -0
  75. package/one/events/ontology-test-examples.md +562 -0
  76. package/one/events/phase1-backend-implementation-complete.md +518 -0
  77. package/one/events/test-dashboard.md +345 -0
  78. package/one/events/test-index.md +361 -0
  79. package/one/events/test-report-ontology.md +582 -0
  80. package/one/events/testing-summary.md +344 -0
  81. package/one/groups/features.md +2878 -0
  82. package/one/groups/strategy copy.md +869 -0
  83. package/one/knowledge/backend-api-reference.md +710 -0
  84. package/one/knowledge/documentation-summary.md +285 -0
  85. package/one/knowledge/lessons-learned.md +294 -4
  86. package/one/knowledge/ontology-visual-guide.md +360 -0
  87. package/one/knowledge/ontology.md +9 -17
  88. package/one/things/demo-accessibility-animations.md +999 -0
  89. package/one/things/demo-components.md +1304 -0
  90. package/one/things/demo-design-summary.md +629 -0
  91. package/one/things/demo-design-system.md +919 -0
  92. package/one/things/demo-page-layouts.md +989 -0
  93. package/one/things/designs/accessibility-audit.md +790 -0
  94. package/one/things/designs/component-specifications.md +757 -0
  95. package/one/things/designs/design-overview.md +318 -0
  96. package/one/things/designs/design-tokens.md +414 -0
  97. package/one/things/designs/wireframes-dashboard.md +653 -0
  98. package/one/things/docs/api-requests.md +923 -0
  99. package/one/things/features/0 All Features.md +2 -0
  100. package/one/things/implementation/backend-guide.md +412 -0
  101. package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
  102. package/one/things/plans/2-sites.md +895 -0
  103. package/one/things/plans/ai-elements.md +1259 -0
  104. package/one/things/plans/ai-integration.md +947 -0
  105. package/one/things/plans/ai-sdk.md +761 -0
  106. package/one/things/plans/app.md +1 -1
  107. package/one/things/plans/architecture-summary.md +283 -0
  108. package/one/things/plans/async-ai-agents.md +215 -0
  109. package/one/things/plans/backend-agnostic-frontend.md +11 -6
  110. package/one/things/plans/backend-cleanup-quickstart.md +346 -0
  111. package/one/things/plans/backend-ontology-conformance.md +416 -0
  112. package/one/things/plans/backend-status.md +541 -0
  113. package/one/things/plans/backend-structure.md +799 -0
  114. package/one/things/plans/backend-target-structure.md +438 -0
  115. package/one/things/plans/backend.md +1133 -0
  116. package/one/things/plans/better-auth-any-backend.md +11 -11
  117. package/one/things/plans/cli-updates-required.md +280 -0
  118. package/one/things/plans/complete-step-by-step.md +1302 -0
  119. package/one/things/plans/convex-agents.md +1005 -0
  120. package/one/things/plans/deployment-architecture.md +426 -0
  121. package/one/things/plans/development-plan.md +1220 -0
  122. package/one/things/plans/effect.md +808 -48
  123. package/one/things/plans/integrate-frontend-and-backend.md +579 -0
  124. package/one/things/plans/mcp-clear-context-prompt.md +60 -0
  125. package/one/things/plans/mcp-simple.md +228 -0
  126. package/one/things/plans/one.md +8 -7
  127. package/one/things/plans/ontology-6-dimensions.md +20 -14
  128. package/one/things/plans/quick-wins.md +1273 -0
  129. package/one/things/plans/readme-backend-cleanup.md +361 -0
  130. package/one/things/plans/separate-demo.md +830 -0
  131. package/one/things/plans/separate.md +3 -3
  132. package/one/things/plans/sequence.md +1897 -0
  133. package/one/things/plans/sync-checklist.md +321 -0
  134. package/one/things/plans/unified-implementation-plan.md +3 -3
  135. package/one/things/plans/update-demos.md +513 -0
  136. package/package.json +1 -1
  137. package/.claude/agents/backend-specialist.md +0 -169
  138. package/.claude/agents/designer.md +0 -216
  139. package/.claude/agents/frontend-specialist.md +0 -236
  140. package/.claude/commands/done.md +0 -35
  141. package/.claude/commands/infer.md +0 -138
  142. package/.claude/commands/next.md +0 -53
  143. package/.claude/commands/one copy.md +0 -565
  144. package/.claude/commands/one-template.md +0 -106
  145. package/.claude/commands/one-v1.md +0 -609
  146. package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
  147. package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
  148. package/one/groups/nine-padel-customers.md +0 -138
  149. package/one/groups/nine-padel-data-structure.md +0 -167
  150. package/one/groups/nine-padel-ontology-specification.md +0 -359
  151. package/one/groups/nine-padel-ontology.md +0 -143
  152. package/one/groups/nine-padel-strategy.md +0 -234
  153. package/one/groups/nine-padel.md +0 -211
  154. package/one/groups/nine-padle-contents.baked.md +0 -1252
  155. package/one/groups/nine-padle-contents.md +0 -6
  156. package/one/things/features/1-1-agent-prompts/design.md +0 -470
  157. package/one/things/features/1-1-agent-prompts/tests.md +0 -264
  158. package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
  159. package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
  160. package/one/things/features/1-3-event-coordination/design.md +0 -544
  161. package/one/things/features/1-3-event-coordination/tests.md +0 -223
  162. package/one/things/features/1-4-knowledge-management/design.md +0 -609
  163. package/one/things/features/1-4-knowledge-management/tests.md +0 -195
  164. package/one/things/features/1-5-quality-loops/design.md +0 -797
  165. package/one/things/features/1-5-quality-loops/tests.md +0 -212
  166. package/one/things/features/1-6-numbering-structure/design.md +0 -610
  167. package/one/things/features/1-6-numbering-structure/tests.md +0 -213
  168. package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
@@ -0,0 +1,799 @@
1
+ # Backend Structure: 6-Dimension Ontology
2
+
3
+ **Status:** Production-Ready
4
+ **Architecture:** 6-Dimension Ontology (Version 1.0.0)
5
+ **Last Updated:** 2025-10-25
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Overview](#overview)
12
+ 2. [6-Dimension Foundation](#6-dimension-foundation)
13
+ 3. [Current File Structure](#current-file-structure)
14
+ 4. [Perfect/Target Structure](#perfecttarget-structure)
15
+ 5. [Schema Compliance](#schema-compliance)
16
+ 6. [Development Patterns](#development-patterns)
17
+ 7. [Multi-Tenant Isolation](#multi-tenant-isolation)
18
+ 8. [Performance Guidelines](#performance-guidelines)
19
+ 9. [Migration Path](#migration-path)
20
+
21
+ ---
22
+
23
+ ## Overview
24
+
25
+ The ONE Platform backend is organized around the **6-dimension ontology** that models reality through groups, people, things, connections, events, and knowledge.
26
+
27
+ Every file follows a consistent pattern:
28
+ - **Dimension** (1-6) - Which dimension of the ontology it handles
29
+ - **Operation Type** - mutation (write), query (read), action (async), or internal action (utility)
30
+ - **Purpose** - What problems it solves
31
+ - **Pattern** - How it's structured for clarity and maintainability
32
+
33
+ ### Philosophy
34
+
35
+ **Simple enough for children. Powerful enough for enterprises.**
36
+
37
+ Groups partition the space (hierarchical containers from friend circles to governments), people authorize and govern (role-based access), things exist (entities with flexible properties), connections relate (relationships with metadata), events record (complete audit trail), and knowledge understands (embeddings and vectors). Everything else is just data. This ontology scales from friend circles (2 people) to global governments (billions) without schema changes.
38
+
39
+ ---
40
+
41
+ ## 6-Dimension Foundation
42
+
43
+ ### Dimension 1: GROUPS
44
+ **Multi-tenant isolation boundary with hierarchical nesting**
45
+
46
+ - **Purpose:** Create isolated data spaces for organizations, communities, friend circles, DAOs, governments
47
+ - **Multi-tenancy:** All other dimensions scoped by groupId
48
+ - **Hierarchy:** Infinite nesting via parentGroupId (parent → child → grandchild...)
49
+ - **6 Types:** friend_circle, business, community, dao, government, organization
50
+ - **Settings:** visibility, joinPolicy, plan (starter, pro, enterprise), resource limits
51
+ - **Key Pattern:** Every mutation validates groupId; every query filters by groupId
52
+
53
+ ### Dimension 2: PEOPLE
54
+ **Authorization & governance: who can do what**
55
+
56
+ - **Representation:** Things with type="creator" (not separate table)
57
+ - **4 Standard Roles:** platform_owner, org_owner, org_user, customer
58
+ - **Auth Link:** Linked to Better Auth via properties.userId
59
+ - **Group Membership:** Managed via connections (member_of relationship)
60
+ - **Key Pattern:** People operations in mutations/people.ts; people queries use entities queries with type filter
61
+
62
+ ### Dimension 3: THINGS
63
+ **All nouns in the system: users, agents, content, tokens, courses, etc.**
64
+
65
+ - **Universal Table:** "entities" in database, referenced as "things" in code
66
+ - **Type Safety:** 66+ entity types validated against ontology composition
67
+ - **Flexibility:** Flexible `properties` field for type-specific data
68
+ - **Lifecycle:** draft → active → published → archived (soft delete with audit trail)
69
+ - **Multi-tenant:** Every thing has groupId for data isolation
70
+ - **Key Pattern:** All operations preserve functionality, never hard delete
71
+
72
+ ### Dimension 4: CONNECTIONS
73
+ **All relationships between entities**
74
+
75
+ - **Bidirectional:** Relationships with temporal validity (validFrom/validTo)
76
+ - **Rich Types:** 25+ connection types (owns, authored, holds_tokens, enrolled_in, member_of, etc.)
77
+ - **Metadata:** Support for strength/weight, status, and context
78
+ - **Scoping:** Every connection scoped by groupId
79
+ - **Key Pattern:** Graph queries (from/to/between patterns)
80
+
81
+ ### Dimension 5: EVENTS
82
+ **Complete audit trail of all actions and state changes**
83
+
84
+ - **Immutable:** Events created by mutations, never edited
85
+ - **WHO, WHAT, WHEN, TO:** Records actor, event type, timestamp, target
86
+ - **Automation:** All mutations automatically log events via internal actions
87
+ - **Use Cases:** Compliance, debugging, analytics, activity feeds, audit trails
88
+ - **Key Pattern:** Events are read-only; logged via internalActions/events.ts
89
+
90
+ ### Dimension 6: KNOWLEDGE
91
+ **Labels, embeddings, and semantic search (RAG)**
92
+
93
+ - **Knowledge Types:** label, document, chunk, vector_only
94
+ - **Embeddings:** Ready for semantic search and vector similarity
95
+ - **Junction Table:** thingKnowledge links knowledge to things
96
+ - **Role Metadata:** label, summary, chunk_of, caption, keyword
97
+ - **Scoping:** Every knowledge item scoped by groupId
98
+ - **Key Pattern:** Enables RAG, taxonomy, and intelligent search
99
+
100
+ ---
101
+
102
+ ## Current File Structure
103
+
104
+ ### Overview
105
+
106
+ ```
107
+ backend/convex/
108
+ ├── schema.ts # 6-dimension ontology schema
109
+ ├── auth.ts # Better Auth configuration
110
+ ├── http.ts # Hono HTTP layer (ontology-aligned)
111
+ │
112
+ ├── queries/ # READ operations (by dimension)
113
+ │ ├── groups.ts # Dimension 1: Groups (multi-tenancy)
114
+ │ ├── entities.ts # Dimension 3: Things (all entity types)
115
+ │ ├── connections.ts # Dimension 4: Connections (relationships)
116
+ │ ├── events.ts # Dimension 5: Events (audit trail)
117
+ │ ├── knowledge.ts # Dimension 6: Knowledge (RAG, search)
118
+ │ │
119
+ │ ├── contact.ts # Special: Contact forms (uses Things)
120
+ │ ├── onboarding.ts # Special: Onboarding flows (uses Groups)
121
+ │ ├── ontology.ts # Special: Ontology metadata
122
+ │ └── init.ts # Special: Initialization
123
+ │
124
+ ├── mutations/ # WRITE operations (by dimension)
125
+ │ ├── groups.ts # Dimension 1: Groups CRUD
126
+ │ ├── people.ts # Dimension 2: People management
127
+ │ ├── entities.ts # Dimension 3: Things CRUD
128
+ │ ├── connections.ts # Dimension 4: Connections CRUD
129
+ │ ├── knowledge.ts # Dimension 6: Knowledge CRUD
130
+ │ │
131
+ │ ├── contact.ts # Special: Contact forms (uses Things)
132
+ │ ├── onboarding.ts # Special: Onboarding (uses Groups)
133
+ │ └── init.ts # Special: Initialization
134
+ │
135
+ ├── lib/ # Shared utilities
136
+ │ ├── validation.ts # Input validation + error types
137
+ │ └── jwt.ts # JWT utilities
138
+ │
139
+ ├── services/ # Business logic services
140
+ │ ├── layers.ts # Effect.ts service layer
141
+ │ ├── entityService.ts # Entity business logic
142
+ │ ├── websiteAnalyzer.ts # Onboarding: Website analysis
143
+ │ ├── ontologyMapper.ts # Onboarding: Ontology mapping
144
+ │ ├── brandGuideGenerator.ts # Onboarding: Brand extraction
145
+ │ └── featureRecommender.ts # Onboarding: Feature suggestions
146
+ │
147
+ └── types/ # Type definitions
148
+ └── ontology.ts # Ontology types (66+ entity types)
149
+ ```
150
+
151
+ ### Ontology Mapping - Current State
152
+
153
+ | Dimension | Queries | Mutations | Purpose |
154
+ |-----------|---------|-----------|---------|
155
+ | **1. Groups** | `queries/groups.ts` | `mutations/groups.ts` | Multi-tenant isolation, hierarchy |
156
+ | **2. People** | (via entities) | `mutations/people.ts` | Authorization, roles, governance |
157
+ | **3. Things** | `queries/entities.ts` | `mutations/entities.ts` | All nouns, flexible properties |
158
+ | **4. Connections** | `queries/connections.ts` | `mutations/connections.ts` | Relationships, graph queries |
159
+ | **5. Events** | `queries/events.ts` | (auto-logged) | Audit trail, immutable log |
160
+ | **6. Knowledge** | `queries/knowledge.ts` | `mutations/knowledge.ts` | RAG, embeddings, search |
161
+
162
+ ### Special Files (Ontology-Compliant)
163
+
164
+ | File | Purpose | Maps To |
165
+ |------|---------|---------|
166
+ | `contact.ts` | Contact form submission | Creates **Things** (type="contact_submission") + **Events** |
167
+ | `onboarding.ts` | Website analysis & setup | Works with **Groups**, creates **Things**, logs **Events** |
168
+ | `ontology.ts` | Ontology metadata queries | Reads ontology structure from schema |
169
+ | `init.ts` | Initialization & defaults | Creates default **Group**, initial **Things** |
170
+
171
+ ### HTTP Endpoints (25+ total)
172
+
173
+ All endpoints map to the 6 dimensions:
174
+
175
+ ```
176
+ Dimension 1: Groups
177
+ ├── GET /groups
178
+ ├── GET /groups/:id
179
+ ├── POST /groups
180
+ ├── PATCH /groups/:id
181
+ └── DELETE /groups/:id
182
+
183
+ Dimension 2: People
184
+ ├── GET /people
185
+ ├── POST /people
186
+ ├── PATCH /people/:id
187
+ ├── PATCH /people/:id/role
188
+ └── DELETE /people/:id
189
+
190
+ Dimension 3: Things
191
+ ├── GET /things
192
+ ├── GET /things/:id
193
+ ├── POST /things
194
+ ├── PATCH /things/:id
195
+ └── DELETE /things/:id
196
+
197
+ Dimension 4: Connections
198
+ ├── GET /connections
199
+ ├── POST /connections
200
+ └── DELETE /connections/:id
201
+
202
+ Dimension 5: Events
203
+ ├── GET /events
204
+ └── GET /events/timeline
205
+
206
+ Dimension 6: Knowledge
207
+ ├── GET /knowledge
208
+ ├── POST /knowledge
209
+ ├── POST /knowledge/search
210
+ └── POST /knowledge/bulk
211
+
212
+ Special (Ontology-Compliant)
213
+ ├── GET /contact # Uses Things
214
+ ├── POST /contact # Uses Things
215
+ └── GET /health # Utility
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Perfect/Target Structure
221
+
222
+ ### Vision
223
+
224
+ The backend follows ONLY the 6 dimensions from the ontology. Every file, function, mutation, query, action, and internal action maps perfectly to ONE of these dimensions.
225
+
226
+ ### Target File Organization
227
+
228
+ ```
229
+ convex/
230
+ ├── schema.ts ← CRITICAL: Schema defines all 6 dimensions
231
+ │ ├── groups table
232
+ │ ├── people (as things with type="creator")
233
+ │ ├── things (stored as "entities" table)
234
+ │ ├── connections table
235
+ │ ├── events table
236
+ │ └── knowledge table (+ junction)
237
+ │
238
+ ├── mutations/ ← Write operations by dimension (5 files)
239
+ │ ├── groups.ts → Dimension 1
240
+ │ ├── people.ts → Dimension 2
241
+ │ ├── things.ts → Dimension 3 (rename: entities.ts)
242
+ │ ├── connections.ts → Dimension 4
243
+ │ ├── knowledge.ts → Dimension 6
244
+ │ └── NO OTHER FILES
245
+ │
246
+ ├── queries/ ← Read operations by dimension (6 files)
247
+ │ ├── groups.ts → Dimension 1
248
+ │ ├── people.ts → Dimension 2 (add if missing)
249
+ │ ├── things.ts → Dimension 3 (rename: entities.ts)
250
+ │ ├── connections.ts → Dimension 4
251
+ │ ├── events.ts → Dimension 5 (read-only)
252
+ │ ├── knowledge.ts → Dimension 6
253
+ │ └── NO OTHER FILES (init, onboarding, contact consolidate to things or deleted)
254
+ │
255
+ ├── actions/ ← Async external integrations (4 files)
256
+ │ ├── groups.ts → Dimension 1 (email, webhooks, directories)
257
+ │ ├── things.ts → Dimension 3 (AI, files, publishing)
258
+ │ ├── connections.ts → Dimension 4 (payments, graph)
259
+ │ ├── knowledge.ts → Dimension 6 (embeddings, search)
260
+ │ └── NO OTHER FILES (Dimension 2 people typically use groups actions)
261
+ │
262
+ ├── internalActions/ ← Shared utilities, called only from above (3 files)
263
+ │ ├── events.ts → Dimension 5 (centralized event logging)
264
+ │ ├── search.ts → Cross-dimensional search
265
+ │ ├── validation.ts → Cross-dimensional validation
266
+ │ └── NO OTHER FILES
267
+ │
268
+ ├── services/ ← Business logic (Effect.ts, pure functions)
269
+ │ ├── entityService.ts → Thing operations
270
+ │ ├── layers.ts → Error types and infrastructure
271
+ │ └── [FUTURE] dimension-specific services
272
+ │
273
+ ├── lib/ ← Utilities (validation helpers, jwt, etc.)
274
+ │ ├── validation.ts
275
+ │ └── jwt.ts
276
+ │
277
+ ├── types/ ← Generated types from ontology YAML
278
+ │ └── ontology.ts
279
+ │
280
+ └── [CONSOLIDATE/DELETE]
281
+ ├── contact.ts → Merge into things (contact_submission thing)
282
+ ├── init.ts → Move to convex.config.ts or script
283
+ ├── onboarding.ts → Move to services/onboarding.ts
284
+ └── eventLogger.ts → Renamed to events.ts
285
+ ```
286
+
287
+ ### Perfect File Count
288
+
289
+ **Core Ontology (6 dimensions):**
290
+ ```
291
+ Mutations: 5 files (groups, people, things, connections, knowledge)
292
+ Queries: 6 files (groups, people, things, connections, events, knowledge)
293
+ Actions: 4 files (groups, things, connections, knowledge)
294
+ Internal: 3 files (events, search, validation)
295
+ Total: 18 core files
296
+ ```
297
+
298
+ **Infrastructure:**
299
+ ```
300
+ HTTP: 1 file (http.ts - Hono with ontology-aligned routes)
301
+ Schema: 1 file (schema.ts - 6-dimension tables)
302
+ Auth: 1 file (auth.ts)
303
+ Services: 2 files (layers.ts, entityService.ts)
304
+ Types: 1 file (types/ontology.ts)
305
+ Utilities: 2 files (lib/validation.ts, lib/jwt.ts)
306
+ Total: 8 infrastructure files
307
+ ```
308
+
309
+ **Grand Total: 26 files, 100% ontology-aligned**
310
+
311
+ ### Perfect Function Count
312
+
313
+ | Dimension | Mutations | Queries | Actions | Internal | Total |
314
+ |-----------|-----------|---------|---------|----------|-------|
315
+ | 1: Groups | 4 | 10+ | 6 | - | 20+ |
316
+ | 2: People | 5 | 4 | - | - | 9 |
317
+ | 3: Things | 4 | 8 | 6 | - | 18 |
318
+ | 4: Connections | 3 | 4 | 6 | - | 13 |
319
+ | 5: Events | - | 7 | - | 10 | 17 |
320
+ | 6: Knowledge | 5 | 8 | 7 | - | 20 |
321
+ | **Shared** | - | - | - | 19 | 19 |
322
+ | **TOTAL** | **21** | **41** | **25** | **29** | **116** |
323
+
324
+ ---
325
+
326
+ ## Schema Compliance
327
+
328
+ ### Database Schema (5 Tables)
329
+
330
+ The schema implements the 6-dimension ontology using 5 database tables (people represented as things with type="creator"):
331
+
332
+ ```typescript
333
+ // groups table - Dimension 1
334
+ {
335
+ _id: Id<"groups">,
336
+ slug: string,
337
+ name: string,
338
+ type: "friend_circle" | "business" | "community" | "dao" | "government" | "organization",
339
+ parentGroupId?: Id<"groups">, // Hierarchical nesting
340
+ properties: { description?, plan?, settings?, ...type-specific },
341
+ status: "draft" | "active" | "archived",
342
+ createdAt: number,
343
+ updatedAt: number
344
+ }
345
+
346
+ // entities table - Dimension 3 (all nouns including people as type="creator")
347
+ {
348
+ _id: Id<"entities">,
349
+ groupId: Id<"groups">,
350
+ type: string, // 66+ types including "creator" for people
351
+ name: string,
352
+ properties: { ...type-specific, userId? for people },
353
+ status: "draft" | "active" | "published" | "archived",
354
+ createdAt: number,
355
+ updatedAt: number
356
+ }
357
+
358
+ // connections table - Dimension 4
359
+ {
360
+ _id: Id<"connections">,
361
+ groupId: Id<"groups">,
362
+ fromEntityId: Id<"entities">,
363
+ toEntityId: Id<"entities">,
364
+ relationshipType: string, // 25+ types
365
+ strength?: number,
366
+ metadata?: any,
367
+ validFrom?: number,
368
+ validTo?: number,
369
+ status: "active" | "inactive",
370
+ createdAt: number,
371
+ updatedAt: number
372
+ }
373
+
374
+ // events table - Dimension 5
375
+ {
376
+ _id: Id<"events">,
377
+ groupId: Id<"groups">,
378
+ type: string, // 67+ event types
379
+ actorId?: Id<"entities">, // Person who acted (optional for system events)
380
+ targetId?: Id<"entities">, // Thing/group affected
381
+ timestamp: number,
382
+ metadata?: any,
383
+ createdAt: number // immutable
384
+ }
385
+
386
+ // knowledge table - Dimension 6
387
+ {
388
+ _id: Id<"knowledge">,
389
+ groupId: Id<"groups">,
390
+ type: "label" | "document" | "chunk" | "vector_only",
391
+ text: string,
392
+ labels?: string[],
393
+ embedding?: number[], // For vector search
394
+ source?: string,
395
+ metadata?: any,
396
+ createdAt: number,
397
+ updatedAt: number
398
+ }
399
+
400
+ // thingKnowledge junction table
401
+ {
402
+ _id: Id<"thingKnowledge">,
403
+ thingId: Id<"entities">,
404
+ knowledgeId: Id<"knowledge">,
405
+ role: "label" | "summary" | "chunk_of" | "caption" | "keyword",
406
+ metadata?: any,
407
+ createdAt: number
408
+ }
409
+ ```
410
+
411
+ ### Entity Type Validation (66+ types)
412
+
413
+ All validated in `lib/validation.ts`:
414
+
415
+ ```typescript
416
+ // Samples of valid THING_TYPES
417
+ validateThingType("user") // ✅
418
+ validateThingType("course") // ✅
419
+ validateThingType("blog_post") // ✅
420
+ validateThingType("contact_submission") // ✅
421
+ validateThingType("token") // ✅
422
+ validateThingType("creator") // ✅ (people)
423
+ validateThingType("invalid_type") // ❌ ValidationError
424
+ ```
425
+
426
+ ### Connection Type Validation (25+ types)
427
+
428
+ ```typescript
429
+ validateConnectionType("owns") // ✅
430
+ validateConnectionType("enrolled_in") // ✅
431
+ validateConnectionType("member_of") // ✅
432
+ validateConnectionType("authored") // ✅
433
+ validateConnectionType("invalid") // ❌ ValidationError
434
+ ```
435
+
436
+ ### Event Type Validation (67+ types)
437
+
438
+ ```typescript
439
+ validateEventType("thing_created") // ✅
440
+ validateEventType("group_updated") // ✅
441
+ validateEventType("contact_submitted") // ✅
442
+ validateEventType("connection_created") // ✅
443
+ validateEventType("invalid") // ❌ ValidationError
444
+ ```
445
+
446
+ ---
447
+
448
+ ## Development Patterns
449
+
450
+ ### Mutation Pattern (Universal - 6 Steps)
451
+
452
+ All mutations follow this pattern:
453
+
454
+ ```typescript
455
+ export const create = mutation({
456
+ args: { /* typed arguments */ },
457
+ handler: async (ctx, args) => {
458
+ // 1. AUTHENTICATE user via Better Auth
459
+ const identity = await ctx.auth.getUserIdentity();
460
+ if (!identity) throw new Error("Unauthenticated");
461
+
462
+ // 2. VALIDATE group exists and is active
463
+ const group = await ctx.db.get(args.groupId);
464
+ if (!group) throw new Error("Group not found");
465
+ if (group.status !== "active") throw new Error("Group not active");
466
+
467
+ // 3. VALIDATE inputs (type, constraints, etc.)
468
+ if (!isValidType(args.type)) throw new Error("Invalid type");
469
+
470
+ // 4. GET ACTOR (user entity) for event logging
471
+ const actor = await ctx.db.query("entities")
472
+ .withIndex("group_type", q => q.eq("groupId", args.groupId).eq("type", "creator"))
473
+ .filter(q => q.eq(q.field("properties.userId"), identity.tokenIdentifier))
474
+ .first();
475
+
476
+ // 5. CREATE entity/connection/knowledge in database
477
+ const id = await ctx.db.insert("entities", { /* ... */ });
478
+
479
+ // 6. LOG EVENT (audit trail)
480
+ await ctx.db.insert("events", {
481
+ groupId: args.groupId,
482
+ type: "thing_created",
483
+ actorId: actor._id,
484
+ targetId: id,
485
+ timestamp: Date.now(),
486
+ metadata: { /* context */ }
487
+ });
488
+
489
+ return id;
490
+ }
491
+ });
492
+ ```
493
+
494
+ ### Query Pattern (Efficient)
495
+
496
+ All queries follow this pattern:
497
+
498
+ ```typescript
499
+ export const list = query({
500
+ args: {
501
+ groupId: v.id("groups"),
502
+ // optional filters
503
+ },
504
+ handler: async (ctx, args) => {
505
+ // 1. Use appropriate index (critical for performance)
506
+ return await ctx.db.query("entities")
507
+ .withIndex("group_type", q =>
508
+ q.eq("groupId", args.groupId)
509
+ .eq("type", args.type)
510
+ )
511
+ .collect();
512
+ }
513
+ });
514
+ ```
515
+
516
+ ### Key Indexes by Dimension
517
+
518
+ - **Dimension 1 (Groups)**: by_slug, by_type, by_parent, by_status
519
+ - **Dimension 3 (Things)**: group_type, group_status, by_created, by_updated
520
+ - **Dimension 4 (Connections)**: from_entity, to_entity, bidirectional, group_type
521
+ - **Dimension 5 (Events)**: group_timestamp, by_actor, by_target, by_type
522
+ - **Dimension 6 (Knowledge)**: group_type, by_source, by_created
523
+
524
+ ---
525
+
526
+ ## Multi-Tenant Isolation
527
+
528
+ ### Critical Principle
529
+
530
+ **CRITICAL: Every mutation and query includes groupId filtering**
531
+
532
+ Pattern enforced everywhere:
533
+
534
+ ```typescript
535
+ // Mutations MUST validate groupId
536
+ const group = await ctx.db.get(args.groupId);
537
+ if (!group) throw new Error("Group not found");
538
+
539
+ // Queries MUST filter by groupId
540
+ await ctx.db.query("entities")
541
+ .withIndex("group_type", (q) => q.eq("groupId", groupId).eq("type", type))
542
+ .collect()
543
+ ```
544
+
545
+ ### Benefits
546
+
547
+ - Data for Organization A never leaks to Organization B
548
+ - Each group has independent quotas, plans, settings
549
+ - Hierarchical groups can optionally share data (with configuration)
550
+ - No special "admin queries" that bypass isolation
551
+ - Enforced at database query level, not application logic
552
+
553
+ ### File Organization Rules
554
+
555
+ 1. **One file per dimension** - groups.ts, entities.ts, connections.ts, etc.
556
+ 2. **Separate mutation/query files** - mutations/entities.ts vs queries/entities.ts
557
+ 3. **Clear dimension header** - `/** DIMENSION X: NAME */` at top of file
558
+ 4. **Consistent comments** - Explain pattern, indexes, use cases
559
+ 5. **No cross-dimension mixing** - People operations in people.ts only
560
+ 6. **groupId everywhere** - Every mutation/query includes it
561
+ 7. **Consistent naming** - Use "things" not "entities" in code comments and function descriptions
562
+
563
+ ---
564
+
565
+ ## Performance Guidelines
566
+
567
+ ### Critical Indexes to Use
568
+
569
+ 1. **group_type** - Most common pattern (dimension + group)
570
+ 2. **group_timestamp** - Events timeline queries
571
+ 3. **by_actor** - Activity feeds
572
+ 4. **by_target** - Entity audit trails
573
+ 5. **from_entity / to_entity** - Graph queries
574
+
575
+ ### Query Optimization
576
+
577
+ - ALWAYS use indexes (withIndex is non-negotiable)
578
+ - Filter by groupId first (multi-tenant isolation)
579
+ - Filter by type/status second (narrow the result set)
580
+ - Avoid full table scans (filter before collecting)
581
+ - Use `.first()` for single results (early exit)
582
+ - Use `.collect()` only for reasonable result sets
583
+
584
+ ### Soft Delete Pattern
585
+
586
+ - Never hard delete (archives instead)
587
+ - Filter out archived items (status !== "archived")
588
+ - Keep deletedAt timestamp (for compliance)
589
+ - Maintain audit trail (events never deleted)
590
+
591
+ ---
592
+
593
+ ## Migration Path
594
+
595
+ ### What We've Done
596
+
597
+ 1. ✅ Analyzed 3 existing structure documentation files
598
+ 2. ✅ Identified overlap and consolidation opportunities
599
+ 3. ✅ Created unified source of truth
600
+
601
+ ### Next Steps
602
+
603
+ 1. 🔄 Rename mutations/entities.ts → mutations/things.ts
604
+ 2. 🔄 Rename queries/entities.ts → queries/things.ts
605
+ 3. 🔄 Update all API references (http.ts)
606
+ 4. 🔄 Update all comments to say "things" not "entities"
607
+ 5. 🔄 Create queries/people.ts if missing
608
+ 6. 🔄 Create actions/ directory with dimension-specific files
609
+ 7. 🔄 Create internalActions/ directory with shared utilities
610
+ 8. 🔄 Remove/consolidate contact.ts, init.ts, onboarding.ts into things.ts or services/
611
+ 9. 🔄 Verify complete ontology compliance
612
+ 10. 🔄 Zero TypeScript errors
613
+ 11. 🔄 Create API endpoint documentation
614
+
615
+ ### Perfect File Organization Checklist
616
+
617
+ - [ ] mutations/ has ONLY 5 files (groups, people, things, connections, knowledge)
618
+ - [ ] queries/ has ONLY 6 files (groups, people, things, connections, events, knowledge)
619
+ - [ ] actions/ has ONLY 4 files (groups, things, connections, knowledge)
620
+ - [ ] internalActions/ has ONLY 3 files (events, search, validation)
621
+ - [ ] No init.ts, onboarding.ts, contact.ts files in mutations/ or queries/
622
+ - [ ] entities.ts renamed to things.ts everywhere
623
+ - [ ] eventLogger.ts renamed to events.ts
624
+ - [ ] All functions map to exactly ONE dimension
625
+ - [ ] All mutations validate groupId
626
+ - [ ] All mutations log events
627
+ - [ ] All queries use efficient indexes
628
+ - [ ] All actions are multi-tenant safe
629
+ - [ ] All internal actions are reusable
630
+ - [ ] Zero TypeScript errors
631
+ - [ ] Comments clearly indicate which dimension
632
+
633
+ ---
634
+
635
+ ## Key Rules for Perfect Compliance
636
+
637
+ ### Rule 1: Only 6 Dimensions
638
+
639
+ Every file must map to exactly ONE of the 6 dimensions. No exceptions.
640
+
641
+ ```
642
+ ❌ WRONG: convex/mutations/contact.ts (doesn't fit)
643
+ ❌ WRONG: convex/mutations/init.ts (system utility, not a dimension)
644
+ ❌ WRONG: convex/mutations/onboarding.ts (not a dimension)
645
+
646
+ ✅ RIGHT: convex/mutations/things.ts (contact_submission is a thing)
647
+ ✅ RIGHT: System utilities in convex.config.ts or scripts/
648
+ ```
649
+
650
+ ### Rule 2: Consistent Naming
651
+
652
+ - Database table: "entities" (schema.ts) - but code calls it "things"
653
+ - File names: things.ts (not entities.ts)
654
+ - Comments: Refer to "Dimension 3: Things"
655
+ - Functions: Describe operating on "things" or "things of type X"
656
+
657
+ ### Rule 3: Multi-tenant Isolation
658
+
659
+ Every mutation and query MUST validate groupId:
660
+
661
+ ```typescript
662
+ // ✅ CORRECT
663
+ const group = await ctx.db.get(args.groupId);
664
+ if (!group || group.status !== "active") throw new Error("Invalid group");
665
+
666
+ // ❌ WRONG
667
+ // (no groupId validation)
668
+ ```
669
+
670
+ ### Rule 4: Event Logging
671
+
672
+ Every mutation MUST log its action:
673
+
674
+ ```typescript
675
+ // ✅ CORRECT
676
+ await ctx.runAction(api.internalActions.events.logThingCreated, {
677
+ groupId: args.groupId,
678
+ thingId,
679
+ thingType: args.type,
680
+ actorId,
681
+ });
682
+
683
+ // ❌ WRONG
684
+ // (no logging)
685
+ ```
686
+
687
+ ### Rule 5: No Cross-Dimension Mixing
688
+
689
+ Each file has ONE responsibility:
690
+
691
+ ```
692
+ ❌ WRONG: mutations/things.ts also handles people creation
693
+ ✅ RIGHT: mutations/things.ts handles things only
694
+ mutations/people.ts handles people only
695
+ ```
696
+
697
+ ### Rule 6: Use Internal Actions for Shared Logic
698
+
699
+ Don't duplicate validation or logging:
700
+
701
+ ```
702
+ ❌ WRONG: Copy validation logic into each mutation
703
+ ✅ RIGHT: Use internalActions/validation.ts for shared validation
704
+ ```
705
+
706
+ ---
707
+
708
+ ## Why This Structure Is Solid
709
+
710
+ ### 1. Clear Organization
711
+ - Files organized by ontology dimension
712
+ - Easy to find what you need
713
+ - Consistent naming patterns
714
+
715
+ ### 2. 100% Ontology Compliance
716
+ - Every file maps to dimensions
717
+ - No special-case logic
718
+ - Universal patterns
719
+
720
+ ### 3. Extensible
721
+ - Add new entity types → No new files needed
722
+ - Add new connection types → No new files needed
723
+ - Add new event types → Auto-logged
724
+
725
+ ### 4. Maintainable
726
+ - Clear separation of concerns
727
+ - Validation in one place
728
+ - Services orchestrate dimensions
729
+
730
+ ### 5. Type-Safe
731
+ - TypeScript throughout
732
+ - Validated against ontology
733
+ - Tagged error types
734
+
735
+ ### 6. Auditable
736
+ - All data changes logged consistently
737
+ - Complete audit trail via events
738
+ - No silent modifications
739
+
740
+ ### 7. Secure
741
+ - Multi-tenant isolation enforced everywhere
742
+ - Role-based access via people
743
+ - No data leaks between groups
744
+
745
+ ---
746
+
747
+ ## Development Workflow
748
+
749
+ ### Adding a New Feature
750
+
751
+ 1. **Map to dimensions**: What groups, people, things, connections, events, knowledge are involved?
752
+ 2. **Update schema** (if needed): convex/schema.ts
753
+ 3. **Add mutation** (if write): convex/mutations/[dimension].ts
754
+ 4. **Add query** (if read): convex/queries/[dimension].ts
755
+ 5. **Follow patterns**: Use 6-step mutation pattern, efficient indexes
756
+ 6. **Test isolation**: Verify groupId filtering works
757
+ 7. **Update documentation**: Keep ontology alignment verified
758
+
759
+ ### Testing Checklist
760
+
761
+ Every mutation should test:
762
+ - ✅ Authentication (logged in user)
763
+ - ✅ Group exists and is active
764
+ - ✅ Input validation (type, constraints)
765
+ - ✅ Multi-tenant isolation (groupId filtering)
766
+ - ✅ Event logging (audit trail)
767
+
768
+ ---
769
+
770
+ ## Future Enhancements
771
+
772
+ - [ ] Role-based access control (RBAC) per group
773
+ - [ ] Quota enforcement (users, storage, apiCalls)
774
+ - [ ] Rate limiting (brute force protection)
775
+ - [ ] Cascade delete (deleting group deletes contents)
776
+ - [ ] Effect.ts service layer (business logic)
777
+ - [ ] Vector search (embeddings via Pinecone/Weaviate)
778
+ - [ ] GraphQL API (more expressive queries)
779
+ - [ ] Webhook events (external system integration)
780
+ - [ ] Distributed tracing (observability)
781
+ - [ ] A/B testing events
782
+
783
+ ---
784
+
785
+ ## References
786
+
787
+ For more information:
788
+ - **6-Dimension Specification:** `/one/knowledge/ontology.md` (Version 1.0.0)
789
+ - **Platform Architecture:** `/one/knowledge/architecture.md`
790
+ - **Development Workflow:** `/one/connections/workflow.md`
791
+ - **Code Patterns:** `/one/connections/patterns.md`
792
+ - **Quick Reference:** `web/AGENTS.md`
793
+ - **Golden Rules:** `/one/knowledge/rules.md`
794
+
795
+ ---
796
+
797
+ **Built with clarity, simplicity, and infinite scale in mind.**
798
+
799
+ Every file follows the 6-dimension ontology. No exceptions. Clean foundation.