oneie 2.0.1 → 2.0.3

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 (406) hide show
  1. package/AGENTS.md +245 -0
  2. package/CLAUDE.md +534 -0
  3. package/README.md +61 -4
  4. package/one/.obsidian/app.json +1 -0
  5. package/one/.obsidian/appearance.json +1 -0
  6. package/one/.obsidian/core-plugins.json +33 -0
  7. package/one/.obsidian/workspace.json +211 -0
  8. package/one/connections/a2a.md +551 -0
  9. package/one/connections/acp.md +761 -0
  10. package/one/connections/acps.md +731 -0
  11. package/one/connections/agui.md +767 -0
  12. package/one/connections/any-backend.md +1702 -0
  13. package/one/connections/ap2.md +998 -0
  14. package/one/connections/api-docs.md +1891 -0
  15. package/one/connections/api.md +2190 -0
  16. package/one/connections/architecture-diagram.md +94 -0
  17. package/one/connections/communications.md +449 -0
  18. package/one/connections/connections.md +339 -0
  19. package/one/connections/cryptonetworks.md +781 -0
  20. package/one/connections/documentation.md +1120 -0
  21. package/one/connections/effect.md +279 -0
  22. package/one/connections/elizaos.md +1290 -0
  23. package/one/connections/inference.md +58 -0
  24. package/one/connections/kyc.md +632 -0
  25. package/one/connections/mcp.md +842 -0
  26. package/one/connections/membership.md +1152 -0
  27. package/one/connections/middleware.md +1067 -0
  28. package/one/connections/multitenant.md +1341 -0
  29. package/one/connections/n8n.md +1015 -0
  30. package/one/connections/patterns.md +89 -0
  31. package/one/connections/protocols.md +279 -0
  32. package/one/connections/relationships.md +107 -0
  33. package/one/connections/schema.md +587 -0
  34. package/one/connections/service-layer.md +550 -0
  35. package/one/connections/structure.md +0 -0
  36. package/one/connections/vectors.md +207 -0
  37. package/one/connections/wordpress.md +1302 -0
  38. package/one/connections/workflow-copy.md +905 -0
  39. package/one/connections/workflow-examples.md +741 -0
  40. package/one/connections/workflow.md +905 -0
  41. package/one/connections/workflows/delegation.md +885 -0
  42. package/one/connections/workflows/frontend.md +1037 -0
  43. package/one/connections/workflows/strategy.md +903 -0
  44. package/one/connections/workflows/tasks.md +698 -0
  45. package/one/connections/x402.md +1249 -0
  46. package/one/events/events.md +545 -0
  47. package/one/knowledge/ai-platform.md +305 -0
  48. package/one/knowledge/architecture-diagram.md +94 -0
  49. package/one/knowledge/architecture-frontend.md +930 -0
  50. package/one/knowledge/architecture.md +2077 -0
  51. package/one/knowledge/crypto.md +960 -0
  52. package/one/knowledge/dsl.md +1660 -0
  53. package/one/knowledge/files.md +2471 -0
  54. package/one/knowledge/frontend.md +1038 -0
  55. package/one/knowledge/hono.md +2109 -0
  56. package/one/knowledge/implementation-examples.md +2536 -0
  57. package/one/knowledge/inference-score.md +159 -0
  58. package/one/knowledge/knowledge.md +642 -0
  59. package/one/knowledge/language.md +980 -0
  60. package/one/knowledge/lessons-learned.md +70 -0
  61. package/one/knowledge/ontology-6-dimensions.md +0 -0
  62. package/one/knowledge/ontology-documentation.md +356 -0
  63. package/one/knowledge/ontology-engineering-specification.md +1292 -0
  64. package/one/knowledge/ontology-engineering.md +1652 -0
  65. package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
  66. package/one/knowledge/ontology-frontend-copy.md +753 -0
  67. package/one/knowledge/ontology-frontend-specifications.md +2188 -0
  68. package/one/knowledge/ontology-frontend.md +2427 -0
  69. package/one/knowledge/ontology-minimal.yaml +299 -0
  70. package/one/knowledge/ontology.md +2819 -0
  71. package/one/knowledge/ontology.yaml +1165 -0
  72. package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
  73. package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
  74. package/one/knowledge/patterns/backend/mutation-template.md +231 -0
  75. package/one/knowledge/patterns/backend/query-template.md +267 -0
  76. package/one/knowledge/patterns/backend/service-template.md +237 -0
  77. package/one/knowledge/patterns/design/component-architecture.md +399 -0
  78. package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
  79. package/one/knowledge/patterns/design/wireframe-template.md +216 -0
  80. package/one/knowledge/patterns/frontend/component-template.md +195 -0
  81. package/one/knowledge/patterns/frontend/form-template.md +276 -0
  82. package/one/knowledge/patterns/frontend/page-template.md +178 -0
  83. package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
  84. package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
  85. package/one/knowledge/patterns/test/technical-test-template.md +544 -0
  86. package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
  87. package/one/knowledge/patterns/test/user-flow-template.md +254 -0
  88. package/one/knowledge/quality-loop.md +401 -0
  89. package/one/knowledge/readme.md +131 -0
  90. package/one/knowledge/rules.md +626 -0
  91. package/one/knowledge/score.md +67 -0
  92. package/one/knowledge/specifications.md +855 -0
  93. package/one/knowledge/tags.md +130 -0
  94. package/one/organisation/one.md +599 -0
  95. package/one/organisation/organisation.md +438 -0
  96. package/one/organisation/revenue.md +673 -0
  97. package/one/organisation/strategy.md +869 -0
  98. package/one/organisation/vision.md +98 -0
  99. package/one/people/anthony-o-connell.md +440 -0
  100. package/one/people/people.md +567 -0
  101. package/one/repomix-output.md +92634 -0
  102. package/one/things/agentkit.md +349 -0
  103. package/one/things/agents/agent-backend.md +1401 -0
  104. package/one/things/agents/agent-builder.md +955 -0
  105. package/one/things/agents/agent-clean.md +709 -0
  106. package/one/things/agents/agent-clone.md +1341 -0
  107. package/one/things/agents/agent-designer.md +2177 -0
  108. package/one/things/agents/agent-director.md +1508 -0
  109. package/one/things/agents/agent-documenter.md +1049 -0
  110. package/one/things/agents/agent-frontend.md +1119 -0
  111. package/one/things/agents/agent-integrator.md +1192 -0
  112. package/one/things/agents/agent-problem-solver.md +1379 -0
  113. package/one/things/agents/agent-quality.md +1353 -0
  114. package/one/things/agents/agent-sales.md +986 -0
  115. package/one/things/cascade/cascade.yaml +464 -0
  116. package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
  117. package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
  118. package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
  119. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
  120. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
  121. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
  122. package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
  123. package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
  124. package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
  125. package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
  126. package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
  127. package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
  128. package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
  129. package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
  130. package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
  131. package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
  132. package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
  133. package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
  134. package/one/things/cascade/docs/examples/readme.md +222 -0
  135. package/one/things/cascade/docs/getting-started.md +515 -0
  136. package/one/things/cascade/docs/workflow.md +1372 -0
  137. package/one/things/cascade/readme.md +336 -0
  138. package/one/things/cascade/templates/feature-template.md +267 -0
  139. package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
  140. package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
  141. package/one/things/claude/agents/analyst.md +483 -0
  142. package/one/things/claude/agents/architect.md +480 -0
  143. package/one/things/claude/agents/brand-identity-specialist.md +513 -0
  144. package/one/things/claude/agents/bstp-token-strategist.md +667 -0
  145. package/one/things/claude/agents/builder-repo.md +489 -0
  146. package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
  147. package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
  148. package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
  149. package/one/things/claude/agents/company-bullstamp-character.md +587 -0
  150. package/one/things/claude/agents/company-bullstamp-community.md +292 -0
  151. package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
  152. package/one/things/claude/agents/company-bullstamp-token.md +292 -0
  153. package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
  154. package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
  155. package/one/things/claude/agents/content-calendar-planner.md +448 -0
  156. package/one/things/claude/agents/content-chapter-formatter.md +488 -0
  157. package/one/things/claude/agents/content-formatter.md +546 -0
  158. package/one/things/claude/agents/content-hook-specialist.md +462 -0
  159. package/one/things/claude/agents/content-image-formatter.md +535 -0
  160. package/one/things/claude/agents/content-introduction-formatter.md +485 -0
  161. package/one/things/claude/agents/content-multiplication-engine.md +556 -0
  162. package/one/things/claude/agents/content-playbook-writer.md +448 -0
  163. package/one/things/claude/agents/content-team-manager.md +622 -0
  164. package/one/things/claude/agents/content-toc-formatter.md +522 -0
  165. package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
  166. package/one/things/claude/agents/core-manager.md +582 -0
  167. package/one/things/claude/agents/core-master.md +403 -0
  168. package/one/things/claude/agents/cross-functional-manager.md +471 -0
  169. package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
  170. package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
  171. package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
  172. package/one/things/claude/agents/crypto-community-analyst.md +298 -0
  173. package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
  174. package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
  175. package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
  176. package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
  177. package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
  178. package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
  179. package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
  180. package/one/things/claude/agents/crypto-market-researcher.md +292 -0
  181. package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
  182. package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
  183. package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
  184. package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
  185. package/one/things/claude/agents/crypto-team-manager.md +387 -0
  186. package/one/things/claude/agents/crypto-token-analyst.md +278 -0
  187. package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
  188. package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
  189. package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
  190. package/one/things/claude/agents/customer-journey-designer.md +481 -0
  191. package/one/things/claude/agents/customer-success-manager.md +581 -0
  192. package/one/things/claude/agents/dev.md +413 -0
  193. package/one/things/claude/agents/documenter.md +546 -0
  194. package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
  195. package/one/things/claude/agents/engagement-specialist.md +509 -0
  196. package/one/things/claude/agents/engineering-architect.md +387 -0
  197. package/one/things/claude/agents/engineering-business-analyst.md +537 -0
  198. package/one/things/claude/agents/engineering-developer.md +387 -0
  199. package/one/things/claude/agents/engineering-director.md +282 -0
  200. package/one/things/claude/agents/engineering-ingestor.md +649 -0
  201. package/one/things/claude/agents/engineering-product-manager.md +537 -0
  202. package/one/things/claude/agents/engineering-product-owner.md +537 -0
  203. package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
  204. package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
  205. package/one/things/claude/agents/engineering-team-manager.md +512 -0
  206. package/one/things/claude/agents/engineering-user-experience.md +387 -0
  207. package/one/things/claude/agents/framework-elevate-manager.md +294 -0
  208. package/one/things/claude/agents/improver.md +763 -0
  209. package/one/things/claude/agents/intelligence-team-manager.md +385 -0
  210. package/one/things/claude/agents/lead-capture-expert.md +466 -0
  211. package/one/things/claude/agents/lead-magnet-creator.md +453 -0
  212. package/one/things/claude/agents/market-research-analyst.md +412 -0
  213. package/one/things/claude/agents/marketing-brand-identity.md +314 -0
  214. package/one/things/claude/agents/marketing-content-hooks.md +450 -0
  215. package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
  216. package/one/things/claude/agents/marketing-content-poster.md +361 -0
  217. package/one/things/claude/agents/marketing-customer-journey.md +326 -0
  218. package/one/things/claude/agents/marketing-director.md +397 -0
  219. package/one/things/claude/agents/marketing-engagement.md +326 -0
  220. package/one/things/claude/agents/marketing-lead-capture.md +326 -0
  221. package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
  222. package/one/things/claude/agents/marketing-network-effects.md +326 -0
  223. package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
  224. package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
  225. package/one/things/claude/agents/marketing-team-manager.md +446 -0
  226. package/one/things/claude/agents/marketing-viral-growth.md +201 -0
  227. package/one/things/claude/agents/mission-commander.md +373 -0
  228. package/one/things/claude/agents/network-effect-analyst.md +587 -0
  229. package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
  230. package/one/things/claude/agents/npx.md +890 -0
  231. package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
  232. package/one/things/claude/agents/one-master.md +355 -0
  233. package/one/things/claude/agents/one-orchestrator.md +315 -0
  234. package/one/things/claude/agents/one.md +601 -0
  235. package/one/things/claude/agents/playbook-generator.md +503 -0
  236. package/one/things/claude/agents/pm.md +326 -0
  237. package/one/things/claude/agents/po.md +345 -0
  238. package/one/things/claude/agents/qa.md +336 -0
  239. package/one/things/claude/agents/research-foundation-analyst.md +307 -0
  240. package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
  241. package/one/things/claude/agents/research-market-analyst.md +307 -0
  242. package/one/things/claude/agents/research-team-manager.md +482 -0
  243. package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
  244. package/one/things/claude/agents/sales-team-manager.md +400 -0
  245. package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
  246. package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
  247. package/one/things/claude/agents/service-advocacy-manager.md +307 -0
  248. package/one/things/claude/agents/service-success-manager.md +307 -0
  249. package/one/things/claude/agents/service-team-manager.md +400 -0
  250. package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
  251. package/one/things/claude/agents/share-optimization-specialist.md +551 -0
  252. package/one/things/claude/agents/sm.md +327 -0
  253. package/one/things/claude/agents/story-teller.md +473 -0
  254. package/one/things/claude/agents/task-master.md +596 -0
  255. package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
  256. package/one/things/claude/agents/tester.md +556 -0
  257. package/one/things/claude/agents/the-bull-character-manager.md +580 -0
  258. package/one/things/claude/agents/tools-playbook-generator.md +489 -0
  259. package/one/things/claude/agents/turbo-repo-builder.md +316 -0
  260. package/one/things/claude/agents/upsell-strategist.md +480 -0
  261. package/one/things/claude/agents/ux-expert.md +335 -0
  262. package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
  263. package/one/things/claude/claude-code-hooks-development.json +21 -0
  264. package/one/things/claude/claude-code-hooks-production.json +21 -0
  265. package/one/things/claude/claude-code-hooks.json +25 -0
  266. package/one/things/claude/commands/agent.md +104 -0
  267. package/one/things/claude/commands/cascade-status.md +128 -0
  268. package/one/things/claude/commands/ingest.md +290 -0
  269. package/one/things/claude/commands/ingestor.md +136 -0
  270. package/one/things/claude/commands/mission.md +83 -0
  271. package/one/things/claude/commands/npx.md +133 -0
  272. package/one/things/claude/commands/one.md +440 -0
  273. package/one/things/claude/commands/quality-check.md +204 -0
  274. package/one/things/claude/commands/smart-route.md +220 -0
  275. package/one/things/claude/commands/start.md +121 -0
  276. package/one/things/claude/commands/story.md +83 -0
  277. package/one/things/claude/commands/task.md +173 -0
  278. package/one/things/claude/hook-bypass.json +32 -0
  279. package/one/things/claude/hooks/agent-hook-config.json +427 -0
  280. package/one/things/claude/hooks/agent-hook-manager.js +525 -0
  281. package/one/things/claude/hooks/agent-load-balancer.js +271 -0
  282. package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
  283. package/one/things/claude/hooks/build-hook.sh +156 -0
  284. package/one/things/claude/hooks/cascade-feedback.js +297 -0
  285. package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
  286. package/one/things/claude/hooks/cleanup-hook.sh +201 -0
  287. package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
  288. package/one/things/claude/hooks/file-organization-engine.js +427 -0
  289. package/one/things/claude/hooks/file-organization-hook.sh +80 -0
  290. package/one/things/claude/hooks/file-organization-monitor.js +269 -0
  291. package/one/things/claude/hooks/format-hook.sh +43 -0
  292. package/one/things/claude/hooks/hook-bypass.sh +293 -0
  293. package/one/things/claude/hooks/hook-config-manager.js +202 -0
  294. package/one/things/claude/hooks/hook-debouncer.sh +62 -0
  295. package/one/things/claude/hooks/hook-logger.sh +89 -0
  296. package/one/things/claude/hooks/hook-orchestrator.js +662 -0
  297. package/one/things/claude/hooks/hook-performance-report.js +120 -0
  298. package/one/things/claude/hooks/lint-hook.sh +140 -0
  299. package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
  300. package/one/things/claude/hooks/memory-optimizer.js +510 -0
  301. package/one/things/claude/hooks/notification-hook.sh +204 -0
  302. package/one/things/claude/hooks/ontology-compliance.js +394 -0
  303. package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
  304. package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
  305. package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
  306. package/one/things/claude/hooks/performance-metrics.json +25 -0
  307. package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
  308. package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
  309. package/one/things/claude/hooks/security-hook.sh +256 -0
  310. package/one/things/claude/hooks/simple-load-balancer.js +238 -0
  311. package/one/things/claude/hooks/startup-optimizer.js +625 -0
  312. package/one/things/claude/hooks/story-scoring-system.js +445 -0
  313. package/one/things/claude/hooks/story-validation-engine.js +473 -0
  314. package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
  315. package/one/things/claude/hooks/story-validation-hook.sh +145 -0
  316. package/one/things/claude/hooks/structure-synchronizer.js +194 -0
  317. package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
  318. package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
  319. package/one/things/claude/hooks/test-hook.sh +145 -0
  320. package/one/things/claude/hooks/test-story-validation.sh +170 -0
  321. package/one/things/claude/hooks/trinity-validation-system.js +392 -0
  322. package/one/things/claude/settings-local.json +86 -0
  323. package/one/things/cli-code.md +652 -0
  324. package/one/things/cli-compiler-code.md +652 -0
  325. package/one/things/cli.md +1045 -0
  326. package/one/things/components/card-shadcn.md +929 -0
  327. package/one/things/components/card.md +1050 -0
  328. package/one/things/components.md +1669 -0
  329. package/one/things/componets.md +4 -0
  330. package/one/things/copilotkit.md +1559 -0
  331. package/one/things/creator-diagram.md +166 -0
  332. package/one/things/examples/children/lemonade-stand.md +366 -0
  333. package/one/things/examples/enterprise/crm-saas.md +1429 -0
  334. package/one/things/features/1-1-agent-prompts/design.md +470 -0
  335. package/one/things/features/1-1-agent-prompts/tests.md +264 -0
  336. package/one/things/features/1-1-agent-prompts.md +486 -0
  337. package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
  338. package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
  339. package/one/things/features/1-2-yaml-orchestrator.md +516 -0
  340. package/one/things/features/1-3-event-coordination/design.md +544 -0
  341. package/one/things/features/1-3-event-coordination/tests.md +223 -0
  342. package/one/things/features/1-3-event-coordination.md +508 -0
  343. package/one/things/features/1-4-knowledge-management/design.md +609 -0
  344. package/one/things/features/1-4-knowledge-management/tests.md +195 -0
  345. package/one/things/features/1-4-knowledge-management.md +577 -0
  346. package/one/things/features/1-5-quality-loops/design.md +797 -0
  347. package/one/things/features/1-5-quality-loops/tests.md +212 -0
  348. package/one/things/features/1-5-quality-loops.md +641 -0
  349. package/one/things/features/1-6-numbering-structure/design.md +610 -0
  350. package/one/things/features/1-6-numbering-structure/tests.md +213 -0
  351. package/one/things/features/1-6-numbering-structure.md +575 -0
  352. package/one/things/features/2-cli.md +1235 -0
  353. package/one/things/features/use-one-backend.md +1180 -0
  354. package/one/things/ideas/1-create-workflow.md +189 -0
  355. package/one/things/plans/1-create-workflow-status.md +555 -0
  356. package/one/things/plans/1-create-workflow.md +713 -0
  357. package/one/things/plans/app.md +761 -0
  358. package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
  359. package/one/things/plans/better-auth-any-backend.md +1852 -0
  360. package/one/things/plans/better-auth-available-features.md +235 -0
  361. package/one/things/plans/big-plan.md +38 -0
  362. package/one/things/plans/convex-better-auth.md +1109 -0
  363. package/one/things/plans/convex-on-off.md +389 -0
  364. package/one/things/plans/desktop.md +1121 -0
  365. package/one/things/plans/effect-components.md +1669 -0
  366. package/one/things/plans/effect.md +973 -0
  367. package/one/things/plans/email.md +953 -0
  368. package/one/things/plans/enhance-auth.md +1669 -0
  369. package/one/things/plans/install-components.md +198 -0
  370. package/one/things/plans/landing.md +728 -0
  371. package/one/things/plans/layout.md +205 -0
  372. package/one/things/plans/mail-backend.md +1308 -0
  373. package/one/things/plans/mail.md +2624 -0
  374. package/one/things/plans/next-features.md +83 -0
  375. package/one/things/plans/one.md +658 -0
  376. package/one/things/plans/ontology-6-dimensions.md +2216 -0
  377. package/one/things/plans/ontology-driven-strategy.md +866 -0
  378. package/one/things/plans/ontology-ui-approach.md +357 -0
  379. package/one/things/plans/open-agent.md +785 -0
  380. package/one/things/plans/performace.md +90 -0
  381. package/one/things/plans/releases.md +809 -0
  382. package/one/things/plans/repos.md +76 -0
  383. package/one/things/plans/separate-copy-2.md +1293 -0
  384. package/one/things/plans/separate-copy-3.md +2458 -0
  385. package/one/things/plans/separate-copy.md +1293 -0
  386. package/one/things/plans/separate.md +1983 -0
  387. package/one/things/plans/shadcn-integration-summary.md +450 -0
  388. package/one/things/plans/sidebar.md +172 -0
  389. package/one/things/plans/small-fixes.md +5 -0
  390. package/one/things/plans/test-backend-connection.md +476 -0
  391. package/one/things/plans/workflow-files.md +1196 -0
  392. package/one/things/plans/workflow.md +1372 -0
  393. package/one/things/products/cascade-landing-page.md +737 -0
  394. package/one/things/products/cascade.md +1518 -0
  395. package/one/things/products/context-engineering.md +1427 -0
  396. package/one/things/products/onthology.md +0 -0
  397. package/one/things/products/ontology-ui-shadcn.md +1280 -0
  398. package/one/things/products/ontology-ui.md +1387 -0
  399. package/one/things/products/ontology.md +717 -0
  400. package/one/things/products/sdk.md +557 -0
  401. package/one/things/promptkit.md +903 -0
  402. package/one/things/service-providers-new.md +982 -0
  403. package/one/things/service-providers.md +1092 -0
  404. package/one/things/things.md +349 -0
  405. package/one/things/todo.md +1248 -0
  406. package/package.json +5 -2
@@ -0,0 +1,1429 @@
1
+ # Building Enterprise SaaS with the 6-Dimension Ontology
2
+
3
+ ## Introduction: Enterprise-Grade Architecture
4
+
5
+ The ONE Platform's 6-dimension ontology provides a complete foundation for building enterprise SaaS platforms that scale from startups to global enterprises. Unlike traditional architectures that require hundreds of tables and complex schemas, the 6-dimension model delivers:
6
+
7
+ **Key Enterprise Benefits:**
8
+
9
+ - **Perfect Multi-Tenant Isolation:** Each customer organization has completely isolated data
10
+ - **Clear Ownership & Governance:** Role-based access control with audit trails
11
+ - **Infinite Scalability:** Add customers without schema changes or architectural refactoring
12
+ - **Cost Attribution:** Per-organization billing, quotas, and usage tracking
13
+ - **AI-Native Design:** Built-in knowledge layer for intelligent features
14
+ - **Compliance Ready:** GDPR, SOC2, HIPAA-compatible architecture
15
+
16
+ This example demonstrates building a complete CRM SaaS platform using the 6-dimension ontology, showcasing multi-tenancy, authorization, and enterprise features.
17
+
18
+ ---
19
+
20
+ ## The 6 Dimensions (Enterprise Version)
21
+
22
+ ### 1. Organizations - Multi-Tenant Isolation Boundary
23
+
24
+ Organizations are the fundamental partitioning unit for multi-tenant SaaS. Every resource (thing, connection, event, knowledge) belongs to exactly one organization, providing perfect data isolation.
25
+
26
+ **Enterprise Value:**
27
+
28
+ - Each customer company is an organization
29
+ - Zero cross-tenant data leaks (enforced at database level)
30
+ - Independent billing, quotas, and rate limits
31
+ - Custom branding and feature flags per organization
32
+ - Platform-level services with centralized infrastructure
33
+
34
+ **Organization Schema:**
35
+
36
+ ```typescript
37
+ interface Organization {
38
+ _id: Id<"organizations">;
39
+ name: string; // "Acme Corporation"
40
+ slug: string; // "acme-corp" (URL-friendly)
41
+ domain?: string; // "crm.acme.com" (custom domain)
42
+ status: "active" | "suspended" | "trial" | "cancelled";
43
+ plan: "starter" | "pro" | "enterprise";
44
+
45
+ // Resource Limits
46
+ limits: {
47
+ users: number; // Max users in organization
48
+ storage: number; // GB
49
+ apiCalls: number; // Per month
50
+ inference: number; // LLM calls per month
51
+ };
52
+
53
+ // Current Usage
54
+ usage: {
55
+ users: number;
56
+ storage: number;
57
+ apiCalls: number;
58
+ inference: number;
59
+ };
60
+
61
+ // Billing Integration
62
+ billing: {
63
+ customerId?: string; // Stripe customer ID
64
+ subscriptionId?: string; // Stripe subscription ID
65
+ billingEmail?: string;
66
+ };
67
+
68
+ // Organization Settings
69
+ settings: {
70
+ allowSignups: boolean;
71
+ requireEmailVerification: boolean;
72
+ enableTwoFactor: boolean;
73
+ customBranding?: {
74
+ logo?: string;
75
+ primaryColor?: string;
76
+ accentColor?: string;
77
+ };
78
+ };
79
+
80
+ createdAt: number;
81
+ updatedAt: number;
82
+ trialEndsAt?: number;
83
+ }
84
+ ```
85
+
86
+ ### 2. People - Authorization & Governance Layer
87
+
88
+ People define who can do what within the system. In the 6-dimension architecture, people are represented as things with `type: 'creator'` and a `role` property, providing a flexible yet type-safe authorization model.
89
+
90
+ **Four Enterprise Roles:**
91
+
92
+ 1. **Platform Owner**
93
+
94
+ - Owns the entire SaaS platform infrastructure
95
+ - Can access all organizations (for support and debugging)
96
+ - Manages platform-level services and billing
97
+ - Revenue: 100% of platform fees + revenue share from organizations
98
+
99
+ 2. **Org Owner**
100
+
101
+ - Owns and manages one or more customer organizations
102
+ - Full control over users, permissions, and billing within their org
103
+ - Can customize AI agents, branding, and features
104
+ - Revenue: Percentage share of org subscription fees
105
+
106
+ 3. **Org User**
107
+
108
+ - Works within a specific organization
109
+ - Limited permissions defined by org owner
110
+ - Can create content, manage leads, run AI agents (within quotas)
111
+ - No billing or administrative access
112
+
113
+ 4. **Customer**
114
+ - External user consuming services (e.g., lead in CRM)
115
+ - No administrative access
116
+ - Purchases products or services
117
+ - Tracked for analytics and billing
118
+
119
+ **Person Schema (as Thing):**
120
+
121
+ ```typescript
122
+ interface PersonThing {
123
+ _id: Id<"things">;
124
+ thingType: "creator";
125
+ name: string; // "Jane CEO"
126
+ organizationId: Id<"organizations">;
127
+
128
+ properties: {
129
+ email: string;
130
+ username: string;
131
+ displayName: string;
132
+
133
+ // CRITICAL: Role determines access level
134
+ role: "platform_owner" | "org_owner" | "org_user" | "customer";
135
+
136
+ // Organization memberships (can belong to multiple orgs)
137
+ organizations: Id<"organizations">[];
138
+ permissions?: string[]; // Custom permissions array
139
+
140
+ // Profile information
141
+ bio?: string;
142
+ avatar?: string;
143
+ timezone?: string;
144
+
145
+ // Authentication metadata
146
+ authProvider?: string;
147
+ lastLoginAt?: number;
148
+ };
149
+
150
+ status: "active" | "inactive" | "suspended";
151
+ createdAt: number;
152
+ updatedAt: number;
153
+ }
154
+ ```
155
+
156
+ ### 3. Things - Domain Entities
157
+
158
+ Things represent all entities in your CRM: leads, accounts, opportunities, AI agents, products, etc. The 66 pre-defined thing types cover most use cases, with extensibility via metadata.
159
+
160
+ **Relevant Thing Types for CRM:**
161
+
162
+ - `creator` - People (employees, customers)
163
+ - `sales_agent` - AI-powered sales assistants
164
+ - `support_agent` - AI-powered support agents
165
+ - `lead` - Sales leads
166
+ - `account` - Customer accounts
167
+ - `opportunity` - Sales opportunities
168
+ - `product` - Products or services
169
+ - `task` - Action items
170
+ - `email` - Email messages
171
+ - `note` - Notes and memos
172
+
173
+ ### 4. Connections - Business Relationships
174
+
175
+ Connections define how entities relate to each other. In a CRM, this includes ownership, communication, task assignment, and deal stages.
176
+
177
+ **Relevant Connection Types for CRM:**
178
+
179
+ - `owns` - Person owns account/opportunity
180
+ - `member_of` - Person is member of organization
181
+ - `assigned_to` - Task assigned to person
182
+ - `communicated` - Agent communicated with lead
183
+ - `related_to` - Opportunity related to account
184
+ - `purchased` - Customer purchased product
185
+
186
+ ### 5. Events - Complete Audit Trail
187
+
188
+ Events record every action in the system, providing compliance, analytics, and debugging capabilities.
189
+
190
+ **Key Event Types for CRM:**
191
+
192
+ - `user_created` - New user registered
193
+ - `org_created` - New organization created
194
+ - `communication_event` - Email/call/meeting logged
195
+ - `deal_stage_changed` - Opportunity progressed
196
+ - `task_completed` - Task marked done
197
+ - `content_viewed` - User viewed content
198
+ - `inference_request` - AI agent invoked
199
+
200
+ ### 6. Knowledge - Intelligence Layer
201
+
202
+ Knowledge stores vectors, embeddings, and semantic search capabilities, enabling AI agents to provide context-aware assistance.
203
+
204
+ **Knowledge Types:**
205
+
206
+ - `label` - Tags and categories
207
+ - `vector` - Embeddings for semantic search
208
+ - `chunk` - Text chunks for RAG (Retrieval Augmented Generation)
209
+ - `summary` - Generated summaries
210
+
211
+ ---
212
+
213
+ ## Example: Building a CRM SaaS Platform
214
+
215
+ This complete example demonstrates implementing a multi-tenant CRM SaaS using the 6-dimension ontology.
216
+
217
+ ### Step 1: Customer Signs Up (Create Organization)
218
+
219
+ When a new customer signs up, create their organization with appropriate limits and settings.
220
+
221
+ ```typescript
222
+ import { mutation } from "./_generated/server";
223
+ import { v } from "convex/values";
224
+
225
+ export const createOrganization = mutation({
226
+ args: {
227
+ name: v.string(),
228
+ ownerEmail: v.string(),
229
+ plan: v.optional(
230
+ v.union(v.literal("starter"), v.literal("pro"), v.literal("enterprise"))
231
+ ),
232
+ },
233
+ handler: async (ctx, args) => {
234
+ // Define plan limits
235
+ const planLimits = {
236
+ starter: { users: 5, storage: 10, apiCalls: 10000, inference: 5000 },
237
+ pro: { users: 25, storage: 100, apiCalls: 100000, inference: 50000 },
238
+ enterprise: {
239
+ users: 1000,
240
+ storage: 1000,
241
+ apiCalls: 1000000,
242
+ inference: 500000,
243
+ },
244
+ };
245
+
246
+ const plan = args.plan || "starter";
247
+ const slug = args.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
248
+
249
+ // Create organization
250
+ const orgId = await ctx.db.insert("organizations", {
251
+ name: args.name,
252
+ slug,
253
+ status: "trial",
254
+ plan,
255
+ limits: planLimits[plan],
256
+ usage: { users: 0, storage: 0, apiCalls: 0, inference: 0 },
257
+ billing: { billingEmail: args.ownerEmail },
258
+ settings: {
259
+ allowSignups: true,
260
+ requireEmailVerification: true,
261
+ enableTwoFactor: false,
262
+ },
263
+ createdAt: Date.now(),
264
+ updatedAt: Date.now(),
265
+ trialEndsAt: Date.now() + 14 * 24 * 60 * 60 * 1000, // 14-day trial
266
+ });
267
+
268
+ // Create org owner (person)
269
+ const ownerId = await ctx.db.insert("things", {
270
+ thingType: "creator",
271
+ name: args.ownerEmail.split("@")[0],
272
+ organizationId: orgId,
273
+ properties: {
274
+ email: args.ownerEmail,
275
+ username: args.ownerEmail.split("@")[0],
276
+ displayName: args.ownerEmail.split("@")[0],
277
+ role: "org_owner",
278
+ organizations: [orgId],
279
+ permissions: ["*"], // Full access
280
+ },
281
+ status: "active",
282
+ createdAt: Date.now(),
283
+ updatedAt: Date.now(),
284
+ });
285
+
286
+ // Create membership connection
287
+ await ctx.db.insert("connections", {
288
+ fromThingId: ownerId,
289
+ toThingId: orgId as any, // Note: In practice, you'd use a thing representing the org
290
+ relationshipType: "member_of",
291
+ organizationId: orgId,
292
+ metadata: { role: "org_owner" },
293
+ createdAt: Date.now(),
294
+ });
295
+
296
+ // Log organization creation event
297
+ await ctx.db.insert("events", {
298
+ eventType: "org_created",
299
+ actorId: ownerId,
300
+ organizationId: orgId,
301
+ metadata: {
302
+ plan,
303
+ trialDays: 14,
304
+ },
305
+ timestamp: Date.now(),
306
+ });
307
+
308
+ // Increment usage
309
+ await ctx.db.patch(orgId, {
310
+ usage: { users: 1, storage: 0, apiCalls: 0, inference: 0 },
311
+ });
312
+
313
+ return { orgId, ownerId };
314
+ },
315
+ });
316
+ ```
317
+
318
+ ### Step 2: Create AI Sales Agent
319
+
320
+ Set up an AI-powered sales agent for the organization.
321
+
322
+ ```typescript
323
+ export const createSalesAgent = mutation({
324
+ args: {
325
+ orgId: v.id("organizations"),
326
+ name: v.string(),
327
+ systemPrompt: v.optional(v.string()),
328
+ },
329
+ handler: async (ctx, args) => {
330
+ // Authorization: Require org owner
331
+ await requireOrgAccess(ctx, args.orgId, "org_owner");
332
+
333
+ const userId = await getUserId(ctx);
334
+
335
+ // Default system prompt if not provided
336
+ const defaultPrompt = `You are a friendly and professional sales assistant for ${args.name}.
337
+ Your goals are to:
338
+ 1. Qualify leads by understanding their needs and budget
339
+ 2. Provide helpful information about products and services
340
+ 3. Schedule meetings with the sales team when appropriate
341
+ 4. Maintain a warm, consultative tone
342
+
343
+ Always be helpful, never pushy. Focus on understanding the customer's challenges before pitching solutions.`;
344
+
345
+ // Create sales agent
346
+ const agentId = await ctx.db.insert("things", {
347
+ thingType: "sales_agent",
348
+ name: args.name,
349
+ organizationId: args.orgId,
350
+ properties: {
351
+ systemPrompt: args.systemPrompt || defaultPrompt,
352
+ temperature: 0.7,
353
+ maxTokens: 1000,
354
+ model: "claude-3-5-sonnet-20250101",
355
+ capabilities: ["email", "chat", "calendar_scheduling"],
356
+ },
357
+ status: "active",
358
+ createdAt: Date.now(),
359
+ updatedAt: Date.now(),
360
+ });
361
+
362
+ // Create ownership connection
363
+ await ctx.db.insert("connections", {
364
+ fromThingId: userId,
365
+ toThingId: agentId,
366
+ relationshipType: "owns",
367
+ organizationId: args.orgId,
368
+ metadata: {},
369
+ createdAt: Date.now(),
370
+ });
371
+
372
+ // Log agent creation
373
+ await ctx.db.insert("events", {
374
+ eventType: "agent_created",
375
+ actorId: userId,
376
+ thingId: agentId,
377
+ organizationId: args.orgId,
378
+ metadata: { agentType: "sales_agent" },
379
+ timestamp: Date.now(),
380
+ });
381
+
382
+ return agentId;
383
+ },
384
+ });
385
+ ```
386
+
387
+ ### Step 3: Import Leads
388
+
389
+ Add leads to the CRM system.
390
+
391
+ ```typescript
392
+ export const createLead = mutation({
393
+ args: {
394
+ orgId: v.id("organizations"),
395
+ name: v.string(),
396
+ email: v.string(),
397
+ company: v.optional(v.string()),
398
+ phone: v.optional(v.string()),
399
+ budget: v.optional(v.number()),
400
+ source: v.optional(v.string()),
401
+ },
402
+ handler: async (ctx, args) => {
403
+ // Authorization: Require org user or owner
404
+ await requireOrgAccess(ctx, args.orgId, "org_user");
405
+
406
+ const userId = await getUserId(ctx);
407
+
408
+ // Create lead as a thing
409
+ const leadId = await ctx.db.insert("things", {
410
+ thingType: "creator", // Using creator for customer/lead
411
+ name: args.name,
412
+ organizationId: args.orgId,
413
+ properties: {
414
+ email: args.email,
415
+ username: args.email,
416
+ displayName: args.name,
417
+ role: "customer",
418
+ company: args.company,
419
+ phone: args.phone,
420
+ budget: args.budget,
421
+ source: args.source || "manual",
422
+ status: "new",
423
+ qualificationScore: 0,
424
+ },
425
+ status: "active",
426
+ createdAt: Date.now(),
427
+ updatedAt: Date.now(),
428
+ });
429
+
430
+ // Assign lead to user
431
+ await ctx.db.insert("connections", {
432
+ fromThingId: userId,
433
+ toThingId: leadId,
434
+ relationshipType: "owns",
435
+ organizationId: args.orgId,
436
+ metadata: { assignedAt: Date.now() },
437
+ createdAt: Date.now(),
438
+ });
439
+
440
+ // Log lead creation
441
+ await ctx.db.insert("events", {
442
+ eventType: "user_created",
443
+ actorId: userId,
444
+ thingId: leadId,
445
+ organizationId: args.orgId,
446
+ metadata: {
447
+ leadSource: args.source || "manual",
448
+ company: args.company,
449
+ },
450
+ timestamp: Date.now(),
451
+ });
452
+
453
+ // Generate knowledge chunks for RAG
454
+ const leadContext = `Lead: ${args.name} from ${
455
+ args.company || "unknown company"
456
+ }.
457
+ Email: ${args.email}. Budget: $${args.budget || "unknown"}. Source: ${
458
+ args.source || "manual"
459
+ }.`;
460
+
461
+ await generateKnowledge(ctx, {
462
+ orgId: args.orgId,
463
+ sourceThingId: leadId,
464
+ text: leadContext,
465
+ });
466
+
467
+ return leadId;
468
+ },
469
+ });
470
+ ```
471
+
472
+ ### Step 4: AI Agent Communicates with Lead
473
+
474
+ AI sales agent sends personalized outreach based on lead profile.
475
+
476
+ ```typescript
477
+ export const sendAIOutreach = mutation({
478
+ args: {
479
+ orgId: v.id("organizations"),
480
+ agentId: v.id("things"),
481
+ leadId: v.id("things"),
482
+ },
483
+ handler: async (ctx, args) => {
484
+ // Authorization
485
+ await requireOrgAccess(ctx, args.orgId, "org_user");
486
+
487
+ // Get agent and lead details
488
+ const agent = await ctx.db.get(args.agentId);
489
+ const lead = await ctx.db.get(args.leadId);
490
+
491
+ if (!agent || agent.thingType !== "sales_agent") {
492
+ throw new Error("Invalid sales agent");
493
+ }
494
+
495
+ if (!lead) {
496
+ throw new Error("Lead not found");
497
+ }
498
+
499
+ // Query knowledge for relevant context
500
+ const relevantContext = await queryKnowledge(ctx, {
501
+ organizationId: args.orgId,
502
+ query: `sales outreach ${lead.properties.company} ${lead.properties.source}`,
503
+ k: 5,
504
+ });
505
+
506
+ // Generate personalized email using LLM
507
+ const emailContent = await generateEmail(ctx, {
508
+ systemPrompt: agent.properties.systemPrompt,
509
+ leadName: lead.name,
510
+ leadCompany: lead.properties.company,
511
+ context: relevantContext,
512
+ });
513
+
514
+ // Create email thing
515
+ const emailId = await ctx.db.insert("things", {
516
+ thingType: "email",
517
+ name: `Outreach to ${lead.name}`,
518
+ organizationId: args.orgId,
519
+ properties: {
520
+ from: agent.name,
521
+ to: lead.properties.email,
522
+ subject: emailContent.subject,
523
+ body: emailContent.body,
524
+ status: "sent",
525
+ sentAt: Date.now(),
526
+ },
527
+ status: "active",
528
+ createdAt: Date.now(),
529
+ updatedAt: Date.now(),
530
+ });
531
+
532
+ // Create communication connection
533
+ await ctx.db.insert("connections", {
534
+ fromThingId: args.agentId,
535
+ toThingId: args.leadId,
536
+ relationshipType: "communicated",
537
+ organizationId: args.orgId,
538
+ metadata: {
539
+ protocol: "email",
540
+ emailId,
541
+ subject: emailContent.subject,
542
+ },
543
+ createdAt: Date.now(),
544
+ });
545
+
546
+ // Log communication event
547
+ await ctx.db.insert("events", {
548
+ eventType: "communication_event",
549
+ actorId: args.agentId,
550
+ thingId: args.leadId,
551
+ organizationId: args.orgId,
552
+ metadata: {
553
+ protocol: "email",
554
+ messageType: "outreach",
555
+ emailId,
556
+ sentiment: "positive",
557
+ },
558
+ timestamp: Date.now(),
559
+ });
560
+
561
+ // Update inference usage
562
+ await incrementUsage(ctx, args.orgId, "inference", 1);
563
+
564
+ return { emailId, emailContent };
565
+ },
566
+ });
567
+ ```
568
+
569
+ ### Step 5: Track Lead Progression
570
+
571
+ Monitor and update lead status as they move through the sales pipeline.
572
+
573
+ ```typescript
574
+ export const updateLeadStatus = mutation({
575
+ args: {
576
+ orgId: v.id("organizations"),
577
+ leadId: v.id("things"),
578
+ newStatus: v.string(),
579
+ notes: v.optional(v.string()),
580
+ },
581
+ handler: async (ctx, args) => {
582
+ await requireOrgAccess(ctx, args.orgId, "org_user");
583
+
584
+ const userId = await getUserId(ctx);
585
+ const lead = await ctx.db.get(args.leadId);
586
+
587
+ if (!lead || lead.organizationId !== args.orgId) {
588
+ throw new Error("Lead not found or access denied");
589
+ }
590
+
591
+ const oldStatus = lead.properties.status;
592
+
593
+ // Update lead status
594
+ await ctx.db.patch(args.leadId, {
595
+ properties: {
596
+ ...lead.properties,
597
+ status: args.newStatus,
598
+ lastUpdatedBy: userId,
599
+ },
600
+ updatedAt: Date.now(),
601
+ });
602
+
603
+ // Create note if provided
604
+ if (args.notes) {
605
+ const noteId = await ctx.db.insert("things", {
606
+ thingType: "note",
607
+ name: `Note: ${lead.name} status change`,
608
+ organizationId: args.orgId,
609
+ properties: {
610
+ content: args.notes,
611
+ authorId: userId,
612
+ },
613
+ status: "active",
614
+ createdAt: Date.now(),
615
+ updatedAt: Date.now(),
616
+ });
617
+
618
+ // Link note to lead
619
+ await ctx.db.insert("connections", {
620
+ fromThingId: noteId,
621
+ toThingId: args.leadId,
622
+ relationshipType: "related_to",
623
+ organizationId: args.orgId,
624
+ metadata: {},
625
+ createdAt: Date.now(),
626
+ });
627
+ }
628
+
629
+ // Log status change event
630
+ await ctx.db.insert("events", {
631
+ eventType: "deal_stage_changed",
632
+ actorId: userId,
633
+ thingId: args.leadId,
634
+ organizationId: args.orgId,
635
+ metadata: {
636
+ oldStatus,
637
+ newStatus: args.newStatus,
638
+ notes: args.notes,
639
+ },
640
+ timestamp: Date.now(),
641
+ });
642
+
643
+ return { success: true, oldStatus, newStatus: args.newStatus };
644
+ },
645
+ });
646
+ ```
647
+
648
+ ### Step 6: Query Organization Data
649
+
650
+ Retrieve CRM data with proper multi-tenant scoping.
651
+
652
+ ```typescript
653
+ import { query } from "./_generated/server";
654
+
655
+ export const getLeads = query({
656
+ args: {
657
+ orgId: v.id("organizations"),
658
+ status: v.optional(v.string()),
659
+ limit: v.optional(v.number()),
660
+ },
661
+ handler: async (ctx, args) => {
662
+ // Authorization: Require org access
663
+ await requireOrgAccess(ctx, args.orgId, "org_user");
664
+
665
+ // Query leads scoped to organization
666
+ let leadsQuery = ctx.db
667
+ .query("things")
668
+ .withIndex("by_org_type", (q) =>
669
+ q.eq("organizationId", args.orgId).eq("thingType", "creator")
670
+ )
671
+ .filter((q) => q.eq(q.field("properties").role, "customer"));
672
+
673
+ // Optional status filter
674
+ if (args.status) {
675
+ leadsQuery = leadsQuery.filter((q) =>
676
+ q.eq(q.field("properties").status, args.status)
677
+ );
678
+ }
679
+
680
+ const leads = await leadsQuery.order("desc").take(args.limit || 50);
681
+
682
+ // Get assigned users for each lead
683
+ const leadsWithOwners = await Promise.all(
684
+ leads.map(async (lead) => {
685
+ const ownerConnection = await ctx.db
686
+ .query("connections")
687
+ .withIndex("by_to", (q) => q.eq("toThingId", lead._id))
688
+ .filter((q) => q.eq(q.field("relationshipType"), "owns"))
689
+ .first();
690
+
691
+ const owner = ownerConnection
692
+ ? await ctx.db.get(ownerConnection.fromThingId)
693
+ : null;
694
+
695
+ return {
696
+ ...lead,
697
+ owner: owner
698
+ ? {
699
+ id: owner._id,
700
+ name: owner.name,
701
+ email: owner.properties.email,
702
+ }
703
+ : null,
704
+ };
705
+ })
706
+ );
707
+
708
+ return leadsWithOwners;
709
+ },
710
+ });
711
+
712
+ export const getOrganizationStats = query({
713
+ args: {
714
+ orgId: v.id("organizations"),
715
+ },
716
+ handler: async (ctx, args) => {
717
+ await requireOrgAccess(ctx, args.orgId, "org_owner");
718
+
719
+ const org = await ctx.db.get(args.orgId);
720
+
721
+ if (!org) {
722
+ throw new Error("Organization not found");
723
+ }
724
+
725
+ // Count entities by type
726
+ const leads = await ctx.db
727
+ .query("things")
728
+ .withIndex("by_org_type", (q) =>
729
+ q.eq("organizationId", args.orgId).eq("thingType", "creator")
730
+ )
731
+ .filter((q) => q.eq(q.field("properties").role, "customer"))
732
+ .collect();
733
+
734
+ const agents = await ctx.db
735
+ .query("things")
736
+ .withIndex("by_org_type", (q) =>
737
+ q.eq("organizationId", args.orgId).eq("thingType", "sales_agent")
738
+ )
739
+ .collect();
740
+
741
+ const events = await ctx.db
742
+ .query("events")
743
+ .withIndex("by_org", (q) => q.eq("organizationId", args.orgId))
744
+ .collect();
745
+
746
+ // Calculate conversion metrics
747
+ const convertedLeads = leads.filter(
748
+ (lead) => lead.properties.status === "won"
749
+ ).length;
750
+
751
+ const conversionRate =
752
+ leads.length > 0 ? (convertedLeads / leads.length) * 100 : 0;
753
+
754
+ return {
755
+ organization: {
756
+ name: org.name,
757
+ plan: org.plan,
758
+ status: org.status,
759
+ },
760
+ usage: org.usage,
761
+ limits: org.limits,
762
+ stats: {
763
+ totalLeads: leads.length,
764
+ convertedLeads,
765
+ conversionRate: Math.round(conversionRate * 100) / 100,
766
+ activeAgents: agents.filter((a) => a.status === "active").length,
767
+ totalEvents: events.length,
768
+ },
769
+ };
770
+ },
771
+ });
772
+ ```
773
+
774
+ ---
775
+
776
+ ## Multi-Tenancy Benefits
777
+
778
+ ### 1. Perfect Data Isolation
779
+
780
+ The 6-dimension architecture enforces data isolation at the database level through organization scoping.
781
+
782
+ **Example: Cross-Org Query Prevention**
783
+
784
+ ```typescript
785
+ // SAFE: All queries automatically scoped to organization
786
+ export const getLeads = query({
787
+ args: { orgId: v.id("organizations") },
788
+ handler: async (ctx, args) => {
789
+ // This query can ONLY return leads from args.orgId
790
+ const leads = await ctx.db
791
+ .query("things")
792
+ .withIndex("by_org_type", (q) =>
793
+ q
794
+ .eq("organizationId", args.orgId) // Enforces isolation
795
+ .eq("thingType", "creator")
796
+ )
797
+ .collect();
798
+
799
+ return leads;
800
+ },
801
+ });
802
+
803
+ // UNSAFE PATTERN (avoided in our architecture)
804
+ // const allLeads = await ctx.db.query("things").collect();
805
+ // This would violate multi-tenancy!
806
+ ```
807
+
808
+ **Benefits:**
809
+
810
+ - Zero chance of cross-organization data leaks
811
+ - Compliance with data privacy regulations (GDPR, CCPA)
812
+ - Customer trust and confidence
813
+ - Simplified security audits
814
+
815
+ ### 2. Independent Scaling & Resource Management
816
+
817
+ Each organization has independent quotas and billing.
818
+
819
+ ```typescript
820
+ export const checkQuota = async (
821
+ ctx: any,
822
+ orgId: Id<"organizations">,
823
+ resourceType: "users" | "storage" | "apiCalls" | "inference"
824
+ ) => {
825
+ const org = await ctx.db.get(orgId);
826
+
827
+ if (!org) {
828
+ throw new Error("Organization not found");
829
+ }
830
+
831
+ const current = org.usage[resourceType];
832
+ const limit = org.limits[resourceType];
833
+
834
+ if (current >= limit) {
835
+ throw new Error(
836
+ `${resourceType} quota exceeded. Current: ${current}, Limit: ${limit}`
837
+ );
838
+ }
839
+
840
+ return {
841
+ current,
842
+ limit,
843
+ available: limit - current,
844
+ percentUsed: Math.round((current / limit) * 100),
845
+ };
846
+ };
847
+
848
+ export const incrementUsage = async (
849
+ ctx: any,
850
+ orgId: Id<"organizations">,
851
+ resourceType: "users" | "storage" | "apiCalls" | "inference",
852
+ amount: number = 1
853
+ ) => {
854
+ const org = await ctx.db.get(orgId);
855
+
856
+ if (!org) {
857
+ throw new Error("Organization not found");
858
+ }
859
+
860
+ // Check quota before incrementing
861
+ await checkQuota(ctx, orgId, resourceType);
862
+
863
+ // Increment usage
864
+ await ctx.db.patch(orgId, {
865
+ usage: {
866
+ ...org.usage,
867
+ [resourceType]: org.usage[resourceType] + amount,
868
+ },
869
+ });
870
+ };
871
+ ```
872
+
873
+ **Benefits:**
874
+
875
+ - Per-organization billing and invoicing
876
+ - Prevent resource abuse and overages
877
+ - Upgrade/downgrade plans without affecting others
878
+ - Clear cost attribution for platform economics
879
+
880
+ ### 3. Customization & White-Labeling
881
+
882
+ Organizations can customize their experience independently.
883
+
884
+ ```typescript
885
+ export const updateBranding = mutation({
886
+ args: {
887
+ orgId: v.id("organizations"),
888
+ logo: v.optional(v.string()),
889
+ primaryColor: v.optional(v.string()),
890
+ accentColor: v.optional(v.string()),
891
+ },
892
+ handler: async (ctx, args) => {
893
+ await requireOrgAccess(ctx, args.orgId, "org_owner");
894
+
895
+ const org = await ctx.db.get(args.orgId);
896
+
897
+ if (!org) {
898
+ throw new Error("Organization not found");
899
+ }
900
+
901
+ await ctx.db.patch(args.orgId, {
902
+ settings: {
903
+ ...org.settings,
904
+ customBranding: {
905
+ logo: args.logo || org.settings.customBranding?.logo,
906
+ primaryColor:
907
+ args.primaryColor || org.settings.customBranding?.primaryColor,
908
+ accentColor:
909
+ args.accentColor || org.settings.customBranding?.accentColor,
910
+ },
911
+ },
912
+ updatedAt: Date.now(),
913
+ });
914
+
915
+ return { success: true };
916
+ },
917
+ });
918
+
919
+ export const customizeAIAgent = mutation({
920
+ args: {
921
+ orgId: v.id("organizations"),
922
+ agentId: v.id("things"),
923
+ systemPrompt: v.string(),
924
+ temperature: v.optional(v.number()),
925
+ },
926
+ handler: async (ctx, args) => {
927
+ await requireOrgAccess(ctx, args.orgId, "org_owner");
928
+
929
+ const agent = await ctx.db.get(args.agentId);
930
+
931
+ if (!agent || agent.organizationId !== args.orgId) {
932
+ throw new Error("Agent not found or access denied");
933
+ }
934
+
935
+ await ctx.db.patch(args.agentId, {
936
+ properties: {
937
+ ...agent.properties,
938
+ systemPrompt: args.systemPrompt,
939
+ temperature: args.temperature || agent.properties.temperature,
940
+ customizedBy: await getUserId(ctx),
941
+ customizedAt: Date.now(),
942
+ },
943
+ updatedAt: Date.now(),
944
+ });
945
+
946
+ return { success: true };
947
+ },
948
+ });
949
+ ```
950
+
951
+ **Benefits:**
952
+
953
+ - Each customer can brand their CRM instance
954
+ - Custom AI agent personalities per organization
955
+ - Feature flags and custom workflows
956
+ - White-label deployment options
957
+
958
+ ### 4. Platform Revenue & Economics
959
+
960
+ Clear revenue attribution through the organization dimension.
961
+
962
+ ```typescript
963
+ export const calculateRevenue = query({
964
+ args: {
965
+ startDate: v.number(),
966
+ endDate: v.number(),
967
+ },
968
+ handler: async (ctx, args) => {
969
+ // Platform owner only
970
+ const userId = await getUserId(ctx);
971
+ const user = await ctx.db.get(userId);
972
+
973
+ if (user?.properties.role !== "platform_owner") {
974
+ throw new Error("Platform owner access required");
975
+ }
976
+
977
+ // Get all active organizations
978
+ const orgs = await ctx.db
979
+ .query("organizations")
980
+ .withIndex("by_status", (q) => q.eq("status", "active"))
981
+ .collect();
982
+
983
+ // Calculate revenue by plan
984
+ const revenueByPlan = {
985
+ starter: { count: 0, mrr: 0 },
986
+ pro: { count: 0, mrr: 0 },
987
+ enterprise: { count: 0, mrr: 0 },
988
+ };
989
+
990
+ const planPricing = {
991
+ starter: 29,
992
+ pro: 99,
993
+ enterprise: 499,
994
+ };
995
+
996
+ orgs.forEach((org) => {
997
+ revenueByPlan[org.plan].count += 1;
998
+ revenueByPlan[org.plan].mrr += planPricing[org.plan];
999
+ });
1000
+
1001
+ // Calculate inference costs
1002
+ const totalInferenceCalls = orgs.reduce(
1003
+ (sum, org) => sum + org.usage.inference,
1004
+ 0
1005
+ );
1006
+
1007
+ const costPerInference = 0.01; // $0.01 per call
1008
+ const inferenceCosts = totalInferenceCalls * costPerInference;
1009
+
1010
+ // Platform revenue = subscription fees + inference markup
1011
+ const subscriptionRevenue = Object.values(revenueByPlan).reduce(
1012
+ (sum, plan) => sum + plan.mrr,
1013
+ 0
1014
+ );
1015
+
1016
+ const inferenceRevenue = inferenceCosts * 0.3; // 30% markup
1017
+
1018
+ const totalRevenue = subscriptionRevenue + inferenceRevenue;
1019
+
1020
+ return {
1021
+ period: { startDate: args.startDate, endDate: args.endDate },
1022
+ organizations: {
1023
+ total: orgs.length,
1024
+ byPlan: revenueByPlan,
1025
+ },
1026
+ revenue: {
1027
+ subscriptions: subscriptionRevenue,
1028
+ inference: inferenceRevenue,
1029
+ total: totalRevenue,
1030
+ },
1031
+ costs: {
1032
+ inference: inferenceCosts,
1033
+ },
1034
+ profit: totalRevenue - inferenceCosts,
1035
+ };
1036
+ },
1037
+ });
1038
+ ```
1039
+
1040
+ **Benefits:**
1041
+
1042
+ - Clear revenue attribution per organization
1043
+ - Track costs (inference, storage, API calls)
1044
+ - Revenue sharing between platform and org owners
1045
+ - Financial analytics for business decisions
1046
+
1047
+ ---
1048
+
1049
+ ## Security & Compliance
1050
+
1051
+ ### GDPR Compliance - Right to Erasure
1052
+
1053
+ The organization dimension makes GDPR compliance straightforward.
1054
+
1055
+ ```typescript
1056
+ export const deleteOrganizationData = mutation({
1057
+ args: {
1058
+ orgId: v.id("organizations"),
1059
+ confirmationCode: v.string(),
1060
+ },
1061
+ handler: async (ctx, args) => {
1062
+ // Platform owner or org owner only
1063
+ const userId = await getUserId(ctx);
1064
+ const user = await ctx.db.get(userId);
1065
+
1066
+ const isPlatformOwner = user?.properties.role === "platform_owner";
1067
+ const isOrgOwner =
1068
+ user?.properties.role === "org_owner" &&
1069
+ user?.organizationId === args.orgId;
1070
+
1071
+ if (!isPlatformOwner && !isOrgOwner) {
1072
+ throw new Error(
1073
+ "Unauthorized: Only platform or org owner can delete org data"
1074
+ );
1075
+ }
1076
+
1077
+ // Verify confirmation code
1078
+ const expectedCode = `DELETE-${args.orgId.slice(0, 8)}`;
1079
+ if (args.confirmationCode !== expectedCode) {
1080
+ throw new Error("Invalid confirmation code");
1081
+ }
1082
+
1083
+ // Delete all organization data
1084
+ const deletionCounts = {
1085
+ things: 0,
1086
+ connections: 0,
1087
+ events: 0,
1088
+ knowledge: 0,
1089
+ };
1090
+
1091
+ // Delete things
1092
+ const things = await ctx.db
1093
+ .query("things")
1094
+ .withIndex("by_org", (q) => q.eq("organizationId", args.orgId))
1095
+ .collect();
1096
+
1097
+ for (const thing of things) {
1098
+ await ctx.db.delete(thing._id);
1099
+ deletionCounts.things += 1;
1100
+ }
1101
+
1102
+ // Delete connections
1103
+ const connections = await ctx.db
1104
+ .query("connections")
1105
+ .withIndex("by_org", (q) => q.eq("organizationId", args.orgId))
1106
+ .collect();
1107
+
1108
+ for (const connection of connections) {
1109
+ await ctx.db.delete(connection._id);
1110
+ deletionCounts.connections += 1;
1111
+ }
1112
+
1113
+ // Delete events
1114
+ const events = await ctx.db
1115
+ .query("events")
1116
+ .withIndex("by_org", (q) => q.eq("organizationId", args.orgId))
1117
+ .collect();
1118
+
1119
+ for (const event of events) {
1120
+ await ctx.db.delete(event._id);
1121
+ deletionCounts.events += 1;
1122
+ }
1123
+
1124
+ // Delete knowledge
1125
+ const knowledge = await ctx.db
1126
+ .query("knowledge")
1127
+ .withIndex("by_org", (q) => q.eq("organizationId", args.orgId))
1128
+ .collect();
1129
+
1130
+ for (const k of knowledge) {
1131
+ await ctx.db.delete(k._id);
1132
+ deletionCounts.knowledge += 1;
1133
+ }
1134
+
1135
+ // Delete organization itself
1136
+ await ctx.db.delete(args.orgId);
1137
+
1138
+ // Log deletion (to a separate audit table not shown here)
1139
+ console.log(
1140
+ `Organization ${args.orgId} deleted by ${userId}`,
1141
+ deletionCounts
1142
+ );
1143
+
1144
+ return {
1145
+ success: true,
1146
+ deletionCounts,
1147
+ message: "All organization data permanently deleted",
1148
+ };
1149
+ },
1150
+ });
1151
+ ```
1152
+
1153
+ ### Audit Trails - Complete Event Logging
1154
+
1155
+ Every action is logged with actor, timestamp, and organization context.
1156
+
1157
+ ```typescript
1158
+ export const getAuditLog = query({
1159
+ args: {
1160
+ orgId: v.id("organizations"),
1161
+ startDate: v.optional(v.number()),
1162
+ endDate: v.optional(v.number()),
1163
+ eventType: v.optional(v.string()),
1164
+ actorId: v.optional(v.id("things")),
1165
+ limit: v.optional(v.number()),
1166
+ },
1167
+ handler: async (ctx, args) => {
1168
+ // Org owner only
1169
+ await requireOrgAccess(ctx, args.orgId, "org_owner");
1170
+
1171
+ // Query events for organization
1172
+ let eventsQuery = ctx.db
1173
+ .query("events")
1174
+ .withIndex("by_org", (q) => q.eq("organizationId", args.orgId))
1175
+ .order("desc");
1176
+
1177
+ // Apply filters
1178
+ if (args.eventType) {
1179
+ eventsQuery = eventsQuery.filter((q) =>
1180
+ q.eq(q.field("eventType"), args.eventType)
1181
+ );
1182
+ }
1183
+
1184
+ if (args.actorId) {
1185
+ eventsQuery = eventsQuery.filter((q) =>
1186
+ q.eq(q.field("actorId"), args.actorId)
1187
+ );
1188
+ }
1189
+
1190
+ if (args.startDate) {
1191
+ eventsQuery = eventsQuery.filter((q) =>
1192
+ q.gte(q.field("timestamp"), args.startDate!)
1193
+ );
1194
+ }
1195
+
1196
+ if (args.endDate) {
1197
+ eventsQuery = eventsQuery.filter((q) =>
1198
+ q.lte(q.field("timestamp"), args.endDate!)
1199
+ );
1200
+ }
1201
+
1202
+ const events = await eventsQuery.take(args.limit || 100);
1203
+
1204
+ // Enrich with actor and thing details
1205
+ const enrichedEvents = await Promise.all(
1206
+ events.map(async (event) => {
1207
+ const actor = await ctx.db.get(event.actorId);
1208
+ const thing = event.thingId ? await ctx.db.get(event.thingId) : null;
1209
+
1210
+ return {
1211
+ ...event,
1212
+ actor: actor
1213
+ ? {
1214
+ id: actor._id,
1215
+ name: actor.name,
1216
+ email: actor.properties.email,
1217
+ role: actor.properties.role,
1218
+ }
1219
+ : null,
1220
+ thing: thing
1221
+ ? {
1222
+ id: thing._id,
1223
+ name: thing.name,
1224
+ type: thing.thingType,
1225
+ }
1226
+ : null,
1227
+ };
1228
+ })
1229
+ );
1230
+
1231
+ return enrichedEvents;
1232
+ },
1233
+ });
1234
+ ```
1235
+
1236
+ ### Access Control - Role-Based Permissions
1237
+
1238
+ Implement fine-grained access control using the people dimension.
1239
+
1240
+ ```typescript
1241
+ // Authorization middleware
1242
+ export async function requireOrgAccess(
1243
+ ctx: any,
1244
+ orgId: Id<"organizations">,
1245
+ requiredRole: "org_owner" | "org_user"
1246
+ ) {
1247
+ const userId = await getUserId(ctx);
1248
+ const user = await ctx.db.get(userId);
1249
+
1250
+ if (!user) {
1251
+ throw new Error("User not found");
1252
+ }
1253
+
1254
+ // Platform owner can access everything
1255
+ if (user.properties.role === "platform_owner") {
1256
+ return true;
1257
+ }
1258
+
1259
+ // Check if user belongs to organization
1260
+ const membership = await ctx.db
1261
+ .query("connections")
1262
+ .withIndex("from_type", (q) =>
1263
+ q.eq("fromThingId", userId).eq("relationshipType", "member_of")
1264
+ )
1265
+ .filter((q) => q.eq(q.field("metadata").organizationId, orgId))
1266
+ .first();
1267
+
1268
+ if (!membership) {
1269
+ throw new Error("User not member of organization");
1270
+ }
1271
+
1272
+ // Check role
1273
+ const userRole = user.properties.role;
1274
+
1275
+ if (requiredRole === "org_owner" && userRole !== "org_owner") {
1276
+ throw new Error("Organization owner access required");
1277
+ }
1278
+
1279
+ return true;
1280
+ }
1281
+
1282
+ // Permission check for specific actions
1283
+ export async function checkPermission(
1284
+ ctx: any,
1285
+ userId: Id<"things">,
1286
+ permission: string
1287
+ ): Promise<boolean> {
1288
+ const user = await ctx.db.get(userId);
1289
+
1290
+ if (!user) {
1291
+ return false;
1292
+ }
1293
+
1294
+ // Platform owner has all permissions
1295
+ if (user.properties.role === "platform_owner") {
1296
+ return true;
1297
+ }
1298
+
1299
+ // Check if user has specific permission
1300
+ const permissions = user.properties.permissions || [];
1301
+
1302
+ // Wildcard permission
1303
+ if (permissions.includes("*")) {
1304
+ return true;
1305
+ }
1306
+
1307
+ // Exact match
1308
+ if (permissions.includes(permission)) {
1309
+ return true;
1310
+ }
1311
+
1312
+ // Pattern match (e.g., "leads.*" matches "leads.create", "leads.update")
1313
+ const hasMatch = permissions.some((p) => {
1314
+ if (p.endsWith("*")) {
1315
+ const prefix = p.slice(0, -1);
1316
+ return permission.startsWith(prefix);
1317
+ }
1318
+ return false;
1319
+ });
1320
+
1321
+ return hasMatch;
1322
+ }
1323
+ ```
1324
+
1325
+ ### Data Encryption & Privacy
1326
+
1327
+ Implement organization-scoped encryption for sensitive data.
1328
+
1329
+ ```typescript
1330
+ export const encryptSensitiveData = async (
1331
+ ctx: any,
1332
+ orgId: Id<"organizations">,
1333
+ data: string
1334
+ ): Promise<string> => {
1335
+ // In production, use org-specific encryption keys
1336
+ // Stored securely in a key management service (KMS)
1337
+ const orgKey = await getOrganizationEncryptionKey(orgId);
1338
+
1339
+ // Encrypt data using AES-256
1340
+ const encrypted = await encrypt(data, orgKey);
1341
+
1342
+ return encrypted;
1343
+ };
1344
+
1345
+ export const decryptSensitiveData = async (
1346
+ ctx: any,
1347
+ orgId: Id<"organizations">,
1348
+ encryptedData: string
1349
+ ): Promise<string> => {
1350
+ const orgKey = await getOrganizationEncryptionKey(orgId);
1351
+ const decrypted = await decrypt(encryptedData, orgKey);
1352
+
1353
+ return decrypted;
1354
+ };
1355
+
1356
+ // Example: Storing encrypted customer data
1357
+ export const createLeadWithEncryption = mutation({
1358
+ args: {
1359
+ orgId: v.id("organizations"),
1360
+ name: v.string(),
1361
+ email: v.string(),
1362
+ phone: v.optional(v.string()),
1363
+ ssn: v.optional(v.string()), // Sensitive data
1364
+ },
1365
+ handler: async (ctx, args) => {
1366
+ await requireOrgAccess(ctx, args.orgId, "org_user");
1367
+
1368
+ const userId = await getUserId(ctx);
1369
+
1370
+ // Encrypt sensitive data
1371
+ const encryptedSSN = args.ssn
1372
+ ? await encryptSensitiveData(ctx, args.orgId, args.ssn)
1373
+ : undefined;
1374
+
1375
+ const leadId = await ctx.db.insert("things", {
1376
+ thingType: "creator",
1377
+ name: args.name,
1378
+ organizationId: args.orgId,
1379
+ properties: {
1380
+ email: args.email,
1381
+ phone: args.phone,
1382
+ encryptedSSN, // Stored encrypted
1383
+ role: "customer",
1384
+ },
1385
+ status: "active",
1386
+ createdAt: Date.now(),
1387
+ updatedAt: Date.now(),
1388
+ });
1389
+
1390
+ return leadId;
1391
+ },
1392
+ });
1393
+ ```
1394
+
1395
+ ---
1396
+
1397
+ ## Conclusion
1398
+
1399
+ The 6-dimension ontology provides a complete, production-ready foundation for building enterprise SaaS platforms:
1400
+
1401
+ **Key Takeaways:**
1402
+
1403
+ 1. **Organizations** provide perfect multi-tenant isolation at the database level
1404
+ 2. **People** enable role-based access control and governance
1405
+ 3. **Things, Connections, Events** model all business entities and relationships
1406
+ 4. **Knowledge** powers AI-driven features with RAG and semantic search
1407
+ 5. **Security & Compliance** are built-in, not bolted-on
1408
+ 6. **Infinite Scalability** without schema changes or architectural refactoring
1409
+
1410
+ **What You Can Build:**
1411
+
1412
+ - CRM platforms (demonstrated in this example)
1413
+ - Project management tools
1414
+ - E-commerce marketplaces
1415
+ - Content management systems
1416
+ - Customer support platforms
1417
+ - Analytics and BI tools
1418
+ - And any other multi-tenant SaaS application
1419
+
1420
+ **Next Steps:**
1421
+
1422
+ 1. Review the [6-Dimension Ontology specification](/Users/toc/Server/ONE/one/knowledge/ontology.md)
1423
+ 2. Explore the [Architecture documentation](/Users/toc/Server/ONE/one/knowledge/architecture.md)
1424
+ 3. Study additional [enterprise examples](/Users/toc/Server/ONE/one/examples/enterprise/)
1425
+ 4. Start building your own SaaS platform with the ONE Platform
1426
+
1427
+ The 6-dimension architecture proves you don't need hundreds of tables or complex schemas to build enterprise-grade software. You need clarity, simplicity, and a reality-aware model that scales infinitely.
1428
+
1429
+ **Build smarter. Build with ONE.**