oneie 2.0.2 → 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 (405) hide show
  1. package/AGENTS.md +245 -0
  2. package/CLAUDE.md +534 -0
  3. package/one/.obsidian/app.json +1 -0
  4. package/one/.obsidian/appearance.json +1 -0
  5. package/one/.obsidian/core-plugins.json +33 -0
  6. package/one/.obsidian/workspace.json +211 -0
  7. package/one/connections/a2a.md +551 -0
  8. package/one/connections/acp.md +761 -0
  9. package/one/connections/acps.md +731 -0
  10. package/one/connections/agui.md +767 -0
  11. package/one/connections/any-backend.md +1702 -0
  12. package/one/connections/ap2.md +998 -0
  13. package/one/connections/api-docs.md +1891 -0
  14. package/one/connections/api.md +2190 -0
  15. package/one/connections/architecture-diagram.md +94 -0
  16. package/one/connections/communications.md +449 -0
  17. package/one/connections/connections.md +339 -0
  18. package/one/connections/cryptonetworks.md +781 -0
  19. package/one/connections/documentation.md +1120 -0
  20. package/one/connections/effect.md +279 -0
  21. package/one/connections/elizaos.md +1290 -0
  22. package/one/connections/inference.md +58 -0
  23. package/one/connections/kyc.md +632 -0
  24. package/one/connections/mcp.md +842 -0
  25. package/one/connections/membership.md +1152 -0
  26. package/one/connections/middleware.md +1067 -0
  27. package/one/connections/multitenant.md +1341 -0
  28. package/one/connections/n8n.md +1015 -0
  29. package/one/connections/patterns.md +89 -0
  30. package/one/connections/protocols.md +279 -0
  31. package/one/connections/relationships.md +107 -0
  32. package/one/connections/schema.md +587 -0
  33. package/one/connections/service-layer.md +550 -0
  34. package/one/connections/structure.md +0 -0
  35. package/one/connections/vectors.md +207 -0
  36. package/one/connections/wordpress.md +1302 -0
  37. package/one/connections/workflow-copy.md +905 -0
  38. package/one/connections/workflow-examples.md +741 -0
  39. package/one/connections/workflow.md +905 -0
  40. package/one/connections/workflows/delegation.md +885 -0
  41. package/one/connections/workflows/frontend.md +1037 -0
  42. package/one/connections/workflows/strategy.md +903 -0
  43. package/one/connections/workflows/tasks.md +698 -0
  44. package/one/connections/x402.md +1249 -0
  45. package/one/events/events.md +545 -0
  46. package/one/knowledge/ai-platform.md +305 -0
  47. package/one/knowledge/architecture-diagram.md +94 -0
  48. package/one/knowledge/architecture-frontend.md +930 -0
  49. package/one/knowledge/architecture.md +2077 -0
  50. package/one/knowledge/crypto.md +960 -0
  51. package/one/knowledge/dsl.md +1660 -0
  52. package/one/knowledge/files.md +2471 -0
  53. package/one/knowledge/frontend.md +1038 -0
  54. package/one/knowledge/hono.md +2109 -0
  55. package/one/knowledge/implementation-examples.md +2536 -0
  56. package/one/knowledge/inference-score.md +159 -0
  57. package/one/knowledge/knowledge.md +642 -0
  58. package/one/knowledge/language.md +980 -0
  59. package/one/knowledge/lessons-learned.md +70 -0
  60. package/one/knowledge/ontology-6-dimensions.md +0 -0
  61. package/one/knowledge/ontology-documentation.md +356 -0
  62. package/one/knowledge/ontology-engineering-specification.md +1292 -0
  63. package/one/knowledge/ontology-engineering.md +1652 -0
  64. package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
  65. package/one/knowledge/ontology-frontend-copy.md +753 -0
  66. package/one/knowledge/ontology-frontend-specifications.md +2188 -0
  67. package/one/knowledge/ontology-frontend.md +2427 -0
  68. package/one/knowledge/ontology-minimal.yaml +299 -0
  69. package/one/knowledge/ontology.md +2819 -0
  70. package/one/knowledge/ontology.yaml +1165 -0
  71. package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
  72. package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
  73. package/one/knowledge/patterns/backend/mutation-template.md +231 -0
  74. package/one/knowledge/patterns/backend/query-template.md +267 -0
  75. package/one/knowledge/patterns/backend/service-template.md +237 -0
  76. package/one/knowledge/patterns/design/component-architecture.md +399 -0
  77. package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
  78. package/one/knowledge/patterns/design/wireframe-template.md +216 -0
  79. package/one/knowledge/patterns/frontend/component-template.md +195 -0
  80. package/one/knowledge/patterns/frontend/form-template.md +276 -0
  81. package/one/knowledge/patterns/frontend/page-template.md +178 -0
  82. package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
  83. package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
  84. package/one/knowledge/patterns/test/technical-test-template.md +544 -0
  85. package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
  86. package/one/knowledge/patterns/test/user-flow-template.md +254 -0
  87. package/one/knowledge/quality-loop.md +401 -0
  88. package/one/knowledge/readme.md +131 -0
  89. package/one/knowledge/rules.md +626 -0
  90. package/one/knowledge/score.md +67 -0
  91. package/one/knowledge/specifications.md +855 -0
  92. package/one/knowledge/tags.md +130 -0
  93. package/one/organisation/one.md +599 -0
  94. package/one/organisation/organisation.md +438 -0
  95. package/one/organisation/revenue.md +673 -0
  96. package/one/organisation/strategy.md +869 -0
  97. package/one/organisation/vision.md +98 -0
  98. package/one/people/anthony-o-connell.md +440 -0
  99. package/one/people/people.md +567 -0
  100. package/one/repomix-output.md +92634 -0
  101. package/one/things/agentkit.md +349 -0
  102. package/one/things/agents/agent-backend.md +1401 -0
  103. package/one/things/agents/agent-builder.md +955 -0
  104. package/one/things/agents/agent-clean.md +709 -0
  105. package/one/things/agents/agent-clone.md +1341 -0
  106. package/one/things/agents/agent-designer.md +2177 -0
  107. package/one/things/agents/agent-director.md +1508 -0
  108. package/one/things/agents/agent-documenter.md +1049 -0
  109. package/one/things/agents/agent-frontend.md +1119 -0
  110. package/one/things/agents/agent-integrator.md +1192 -0
  111. package/one/things/agents/agent-problem-solver.md +1379 -0
  112. package/one/things/agents/agent-quality.md +1353 -0
  113. package/one/things/agents/agent-sales.md +986 -0
  114. package/one/things/cascade/cascade.yaml +464 -0
  115. package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
  116. package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
  117. package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
  118. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
  119. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
  120. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
  121. package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
  122. package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
  123. package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
  124. package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
  125. package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
  126. package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
  127. package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
  128. package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
  129. package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
  130. package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
  131. package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
  132. package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
  133. package/one/things/cascade/docs/examples/readme.md +222 -0
  134. package/one/things/cascade/docs/getting-started.md +515 -0
  135. package/one/things/cascade/docs/workflow.md +1372 -0
  136. package/one/things/cascade/readme.md +336 -0
  137. package/one/things/cascade/templates/feature-template.md +267 -0
  138. package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
  139. package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
  140. package/one/things/claude/agents/analyst.md +483 -0
  141. package/one/things/claude/agents/architect.md +480 -0
  142. package/one/things/claude/agents/brand-identity-specialist.md +513 -0
  143. package/one/things/claude/agents/bstp-token-strategist.md +667 -0
  144. package/one/things/claude/agents/builder-repo.md +489 -0
  145. package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
  146. package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
  147. package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
  148. package/one/things/claude/agents/company-bullstamp-character.md +587 -0
  149. package/one/things/claude/agents/company-bullstamp-community.md +292 -0
  150. package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
  151. package/one/things/claude/agents/company-bullstamp-token.md +292 -0
  152. package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
  153. package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
  154. package/one/things/claude/agents/content-calendar-planner.md +448 -0
  155. package/one/things/claude/agents/content-chapter-formatter.md +488 -0
  156. package/one/things/claude/agents/content-formatter.md +546 -0
  157. package/one/things/claude/agents/content-hook-specialist.md +462 -0
  158. package/one/things/claude/agents/content-image-formatter.md +535 -0
  159. package/one/things/claude/agents/content-introduction-formatter.md +485 -0
  160. package/one/things/claude/agents/content-multiplication-engine.md +556 -0
  161. package/one/things/claude/agents/content-playbook-writer.md +448 -0
  162. package/one/things/claude/agents/content-team-manager.md +622 -0
  163. package/one/things/claude/agents/content-toc-formatter.md +522 -0
  164. package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
  165. package/one/things/claude/agents/core-manager.md +582 -0
  166. package/one/things/claude/agents/core-master.md +403 -0
  167. package/one/things/claude/agents/cross-functional-manager.md +471 -0
  168. package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
  169. package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
  170. package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
  171. package/one/things/claude/agents/crypto-community-analyst.md +298 -0
  172. package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
  173. package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
  174. package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
  175. package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
  176. package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
  177. package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
  178. package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
  179. package/one/things/claude/agents/crypto-market-researcher.md +292 -0
  180. package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
  181. package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
  182. package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
  183. package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
  184. package/one/things/claude/agents/crypto-team-manager.md +387 -0
  185. package/one/things/claude/agents/crypto-token-analyst.md +278 -0
  186. package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
  187. package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
  188. package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
  189. package/one/things/claude/agents/customer-journey-designer.md +481 -0
  190. package/one/things/claude/agents/customer-success-manager.md +581 -0
  191. package/one/things/claude/agents/dev.md +413 -0
  192. package/one/things/claude/agents/documenter.md +546 -0
  193. package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
  194. package/one/things/claude/agents/engagement-specialist.md +509 -0
  195. package/one/things/claude/agents/engineering-architect.md +387 -0
  196. package/one/things/claude/agents/engineering-business-analyst.md +537 -0
  197. package/one/things/claude/agents/engineering-developer.md +387 -0
  198. package/one/things/claude/agents/engineering-director.md +282 -0
  199. package/one/things/claude/agents/engineering-ingestor.md +649 -0
  200. package/one/things/claude/agents/engineering-product-manager.md +537 -0
  201. package/one/things/claude/agents/engineering-product-owner.md +537 -0
  202. package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
  203. package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
  204. package/one/things/claude/agents/engineering-team-manager.md +512 -0
  205. package/one/things/claude/agents/engineering-user-experience.md +387 -0
  206. package/one/things/claude/agents/framework-elevate-manager.md +294 -0
  207. package/one/things/claude/agents/improver.md +763 -0
  208. package/one/things/claude/agents/intelligence-team-manager.md +385 -0
  209. package/one/things/claude/agents/lead-capture-expert.md +466 -0
  210. package/one/things/claude/agents/lead-magnet-creator.md +453 -0
  211. package/one/things/claude/agents/market-research-analyst.md +412 -0
  212. package/one/things/claude/agents/marketing-brand-identity.md +314 -0
  213. package/one/things/claude/agents/marketing-content-hooks.md +450 -0
  214. package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
  215. package/one/things/claude/agents/marketing-content-poster.md +361 -0
  216. package/one/things/claude/agents/marketing-customer-journey.md +326 -0
  217. package/one/things/claude/agents/marketing-director.md +397 -0
  218. package/one/things/claude/agents/marketing-engagement.md +326 -0
  219. package/one/things/claude/agents/marketing-lead-capture.md +326 -0
  220. package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
  221. package/one/things/claude/agents/marketing-network-effects.md +326 -0
  222. package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
  223. package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
  224. package/one/things/claude/agents/marketing-team-manager.md +446 -0
  225. package/one/things/claude/agents/marketing-viral-growth.md +201 -0
  226. package/one/things/claude/agents/mission-commander.md +373 -0
  227. package/one/things/claude/agents/network-effect-analyst.md +587 -0
  228. package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
  229. package/one/things/claude/agents/npx.md +890 -0
  230. package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
  231. package/one/things/claude/agents/one-master.md +355 -0
  232. package/one/things/claude/agents/one-orchestrator.md +315 -0
  233. package/one/things/claude/agents/one.md +601 -0
  234. package/one/things/claude/agents/playbook-generator.md +503 -0
  235. package/one/things/claude/agents/pm.md +326 -0
  236. package/one/things/claude/agents/po.md +345 -0
  237. package/one/things/claude/agents/qa.md +336 -0
  238. package/one/things/claude/agents/research-foundation-analyst.md +307 -0
  239. package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
  240. package/one/things/claude/agents/research-market-analyst.md +307 -0
  241. package/one/things/claude/agents/research-team-manager.md +482 -0
  242. package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
  243. package/one/things/claude/agents/sales-team-manager.md +400 -0
  244. package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
  245. package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
  246. package/one/things/claude/agents/service-advocacy-manager.md +307 -0
  247. package/one/things/claude/agents/service-success-manager.md +307 -0
  248. package/one/things/claude/agents/service-team-manager.md +400 -0
  249. package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
  250. package/one/things/claude/agents/share-optimization-specialist.md +551 -0
  251. package/one/things/claude/agents/sm.md +327 -0
  252. package/one/things/claude/agents/story-teller.md +473 -0
  253. package/one/things/claude/agents/task-master.md +596 -0
  254. package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
  255. package/one/things/claude/agents/tester.md +556 -0
  256. package/one/things/claude/agents/the-bull-character-manager.md +580 -0
  257. package/one/things/claude/agents/tools-playbook-generator.md +489 -0
  258. package/one/things/claude/agents/turbo-repo-builder.md +316 -0
  259. package/one/things/claude/agents/upsell-strategist.md +480 -0
  260. package/one/things/claude/agents/ux-expert.md +335 -0
  261. package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
  262. package/one/things/claude/claude-code-hooks-development.json +21 -0
  263. package/one/things/claude/claude-code-hooks-production.json +21 -0
  264. package/one/things/claude/claude-code-hooks.json +25 -0
  265. package/one/things/claude/commands/agent.md +104 -0
  266. package/one/things/claude/commands/cascade-status.md +128 -0
  267. package/one/things/claude/commands/ingest.md +290 -0
  268. package/one/things/claude/commands/ingestor.md +136 -0
  269. package/one/things/claude/commands/mission.md +83 -0
  270. package/one/things/claude/commands/npx.md +133 -0
  271. package/one/things/claude/commands/one.md +440 -0
  272. package/one/things/claude/commands/quality-check.md +204 -0
  273. package/one/things/claude/commands/smart-route.md +220 -0
  274. package/one/things/claude/commands/start.md +121 -0
  275. package/one/things/claude/commands/story.md +83 -0
  276. package/one/things/claude/commands/task.md +173 -0
  277. package/one/things/claude/hook-bypass.json +32 -0
  278. package/one/things/claude/hooks/agent-hook-config.json +427 -0
  279. package/one/things/claude/hooks/agent-hook-manager.js +525 -0
  280. package/one/things/claude/hooks/agent-load-balancer.js +271 -0
  281. package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
  282. package/one/things/claude/hooks/build-hook.sh +156 -0
  283. package/one/things/claude/hooks/cascade-feedback.js +297 -0
  284. package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
  285. package/one/things/claude/hooks/cleanup-hook.sh +201 -0
  286. package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
  287. package/one/things/claude/hooks/file-organization-engine.js +427 -0
  288. package/one/things/claude/hooks/file-organization-hook.sh +80 -0
  289. package/one/things/claude/hooks/file-organization-monitor.js +269 -0
  290. package/one/things/claude/hooks/format-hook.sh +43 -0
  291. package/one/things/claude/hooks/hook-bypass.sh +293 -0
  292. package/one/things/claude/hooks/hook-config-manager.js +202 -0
  293. package/one/things/claude/hooks/hook-debouncer.sh +62 -0
  294. package/one/things/claude/hooks/hook-logger.sh +89 -0
  295. package/one/things/claude/hooks/hook-orchestrator.js +662 -0
  296. package/one/things/claude/hooks/hook-performance-report.js +120 -0
  297. package/one/things/claude/hooks/lint-hook.sh +140 -0
  298. package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
  299. package/one/things/claude/hooks/memory-optimizer.js +510 -0
  300. package/one/things/claude/hooks/notification-hook.sh +204 -0
  301. package/one/things/claude/hooks/ontology-compliance.js +394 -0
  302. package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
  303. package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
  304. package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
  305. package/one/things/claude/hooks/performance-metrics.json +25 -0
  306. package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
  307. package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
  308. package/one/things/claude/hooks/security-hook.sh +256 -0
  309. package/one/things/claude/hooks/simple-load-balancer.js +238 -0
  310. package/one/things/claude/hooks/startup-optimizer.js +625 -0
  311. package/one/things/claude/hooks/story-scoring-system.js +445 -0
  312. package/one/things/claude/hooks/story-validation-engine.js +473 -0
  313. package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
  314. package/one/things/claude/hooks/story-validation-hook.sh +145 -0
  315. package/one/things/claude/hooks/structure-synchronizer.js +194 -0
  316. package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
  317. package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
  318. package/one/things/claude/hooks/test-hook.sh +145 -0
  319. package/one/things/claude/hooks/test-story-validation.sh +170 -0
  320. package/one/things/claude/hooks/trinity-validation-system.js +392 -0
  321. package/one/things/claude/settings-local.json +86 -0
  322. package/one/things/cli-code.md +652 -0
  323. package/one/things/cli-compiler-code.md +652 -0
  324. package/one/things/cli.md +1045 -0
  325. package/one/things/components/card-shadcn.md +929 -0
  326. package/one/things/components/card.md +1050 -0
  327. package/one/things/components.md +1669 -0
  328. package/one/things/componets.md +4 -0
  329. package/one/things/copilotkit.md +1559 -0
  330. package/one/things/creator-diagram.md +166 -0
  331. package/one/things/examples/children/lemonade-stand.md +366 -0
  332. package/one/things/examples/enterprise/crm-saas.md +1429 -0
  333. package/one/things/features/1-1-agent-prompts/design.md +470 -0
  334. package/one/things/features/1-1-agent-prompts/tests.md +264 -0
  335. package/one/things/features/1-1-agent-prompts.md +486 -0
  336. package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
  337. package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
  338. package/one/things/features/1-2-yaml-orchestrator.md +516 -0
  339. package/one/things/features/1-3-event-coordination/design.md +544 -0
  340. package/one/things/features/1-3-event-coordination/tests.md +223 -0
  341. package/one/things/features/1-3-event-coordination.md +508 -0
  342. package/one/things/features/1-4-knowledge-management/design.md +609 -0
  343. package/one/things/features/1-4-knowledge-management/tests.md +195 -0
  344. package/one/things/features/1-4-knowledge-management.md +577 -0
  345. package/one/things/features/1-5-quality-loops/design.md +797 -0
  346. package/one/things/features/1-5-quality-loops/tests.md +212 -0
  347. package/one/things/features/1-5-quality-loops.md +641 -0
  348. package/one/things/features/1-6-numbering-structure/design.md +610 -0
  349. package/one/things/features/1-6-numbering-structure/tests.md +213 -0
  350. package/one/things/features/1-6-numbering-structure.md +575 -0
  351. package/one/things/features/2-cli.md +1235 -0
  352. package/one/things/features/use-one-backend.md +1180 -0
  353. package/one/things/ideas/1-create-workflow.md +189 -0
  354. package/one/things/plans/1-create-workflow-status.md +555 -0
  355. package/one/things/plans/1-create-workflow.md +713 -0
  356. package/one/things/plans/app.md +761 -0
  357. package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
  358. package/one/things/plans/better-auth-any-backend.md +1852 -0
  359. package/one/things/plans/better-auth-available-features.md +235 -0
  360. package/one/things/plans/big-plan.md +38 -0
  361. package/one/things/plans/convex-better-auth.md +1109 -0
  362. package/one/things/plans/convex-on-off.md +389 -0
  363. package/one/things/plans/desktop.md +1121 -0
  364. package/one/things/plans/effect-components.md +1669 -0
  365. package/one/things/plans/effect.md +973 -0
  366. package/one/things/plans/email.md +953 -0
  367. package/one/things/plans/enhance-auth.md +1669 -0
  368. package/one/things/plans/install-components.md +198 -0
  369. package/one/things/plans/landing.md +728 -0
  370. package/one/things/plans/layout.md +205 -0
  371. package/one/things/plans/mail-backend.md +1308 -0
  372. package/one/things/plans/mail.md +2624 -0
  373. package/one/things/plans/next-features.md +83 -0
  374. package/one/things/plans/one.md +658 -0
  375. package/one/things/plans/ontology-6-dimensions.md +2216 -0
  376. package/one/things/plans/ontology-driven-strategy.md +866 -0
  377. package/one/things/plans/ontology-ui-approach.md +357 -0
  378. package/one/things/plans/open-agent.md +785 -0
  379. package/one/things/plans/performace.md +90 -0
  380. package/one/things/plans/releases.md +809 -0
  381. package/one/things/plans/repos.md +76 -0
  382. package/one/things/plans/separate-copy-2.md +1293 -0
  383. package/one/things/plans/separate-copy-3.md +2458 -0
  384. package/one/things/plans/separate-copy.md +1293 -0
  385. package/one/things/plans/separate.md +1983 -0
  386. package/one/things/plans/shadcn-integration-summary.md +450 -0
  387. package/one/things/plans/sidebar.md +172 -0
  388. package/one/things/plans/small-fixes.md +5 -0
  389. package/one/things/plans/test-backend-connection.md +476 -0
  390. package/one/things/plans/workflow-files.md +1196 -0
  391. package/one/things/plans/workflow.md +1372 -0
  392. package/one/things/products/cascade-landing-page.md +737 -0
  393. package/one/things/products/cascade.md +1518 -0
  394. package/one/things/products/context-engineering.md +1427 -0
  395. package/one/things/products/onthology.md +0 -0
  396. package/one/things/products/ontology-ui-shadcn.md +1280 -0
  397. package/one/things/products/ontology-ui.md +1387 -0
  398. package/one/things/products/ontology.md +717 -0
  399. package/one/things/products/sdk.md +557 -0
  400. package/one/things/promptkit.md +903 -0
  401. package/one/things/service-providers-new.md +982 -0
  402. package/one/things/service-providers.md +1092 -0
  403. package/one/things/things.md +349 -0
  404. package/one/things/todo.md +1248 -0
  405. package/package.json +5 -2
@@ -0,0 +1,2188 @@
1
+ # ONE Ontology: Frontend Implementation Guide
2
+
3
+ **Building /frontend/* - The Rendering Layer**
4
+
5
+ ---
6
+
7
+ ## Executive Summary
8
+
9
+ The frontend is **purely a rendering and interaction layer**. It has ZERO business logic, ZERO database access, ZERO data validation. It only:
10
+
11
+ 1. **Renders UI** from data
12
+ 2. **Calls backend APIs** via abstract data providers
13
+ 3. **Manages local UI state** (loading, errors, forms)
14
+ 4. **Displays real-time updates** via subscriptions
15
+
16
+ **Backend-Agnostic Architecture:**
17
+ ```
18
+ ┌────────────────────────────────────────────────────────┐
19
+ │ FRONTEND (Astro + React) │
20
+ │ ✅ Renders HTML/React components │
21
+ │ ✅ Calls DataProvider interface │
22
+ │ ✅ Manages UI state only │
23
+ │ ✅ Displays data from any backend │
24
+ │ ❌ NO database access │
25
+ │ ❌ NO business logic │
26
+ │ ❌ NO data validation │
27
+ │ ❌ NO event logging │
28
+ └──────────────────────┬─────────────────────────────────┘
29
+ │ DataProvider Interface
30
+ │ (Ontology = Universal API)
31
+ ↓
32
+ ┌────────────────────────────────────────────────────────┐
33
+ │ BACKEND PROVIDERS (Choose One) │
34
+ │ │
35
+ │ ├─ ConvexProvider → Convex backend │
36
+ │ ├─ WordPressProvider → WordPress + WooCommerce │
37
+ │ ├─ NotionProvider → Notion databases │
38
+ │ ├─ SupabaseProvider → Supabase PostgreSQL │
39
+ │ ├─ StrapiProvider → Strapi CMS │
40
+ │ └─ CustomProvider → Your own API │
41
+ │ │
42
+ │ All providers implement the same interface: │
43
+ │ - organizations: { get, list, update } │
44
+ │ - people: { get, list, create, update, delete } │
45
+ │ - things: { get, list, create, update, delete } │
46
+ │ - connections: { create, getRelated, getCount } │
47
+ │ - events: { log, query } │
48
+ │ - knowledge: { embed, search } │
49
+ └────────────────────────────────────────────────────────┘
50
+ ```
51
+
52
+ **Key Insight:** The ONE 6-dimension ontology becomes a **universal data API**. Frontend doesn't care if data comes from Convex, WordPress, or Notion—it only knows the 6 dimensions.
53
+
54
+ **What Frontend Builds:**
55
+ - 66 thing types → 198 UI components (card, list, detail per type)
56
+ - 25 connection types → 75 relationship UIs
57
+ - Organizations → Multi-tenant websites at `{slug}.one.ie`
58
+
59
+ **Tech Stack:**
60
+ - **Astro** - SSR/SSG (pages, layouts)
61
+ - **React 19** - Interactive components
62
+ - **Effect.ts** - Type-safe, composable data operations
63
+ - **DataProvider Pattern** - Backend-agnostic interface (inspired by Astro's content layer)
64
+ - **Tailwind + shadcn/ui** - Styling
65
+ - **TypeScript** - Type safety
66
+
67
+ **Architecture Philosophy:**
68
+
69
+ 1. **Backend-Agnostic**
70
+ - Frontend talks to `DataProvider` interface, not specific backends
71
+ - Swap backends by changing ONE line in config
72
+ - Ontology = universal API that works with ANY backend
73
+
74
+ 2. **Provider Pattern**
75
+ - `ConvexProvider`, `WordPressProvider`, `NotionProvider`, etc.
76
+ - Each provider translates ontology operations → backend-specific calls
77
+ - Organizations can use their existing infrastructure
78
+
79
+ 3. **Generic Services**
80
+ - `ThingService` + `ConnectionService` handle ALL 66 thing types
81
+ - No specialized services needed (courses, products, lessons are all things)
82
+ - Add convenience wrappers only when you repeat patterns 3+ times
83
+
84
+ ---
85
+
86
+ ## Table of Contents
87
+
88
+ 1. [What Frontend IS and IS NOT](#what-frontend-is-and-is-not)
89
+ 2. [Frontend File Structure](#frontend-file-structure)
90
+ 3. [Backend-Agnostic Data Layer](#backend-agnostic-data-layer)
91
+ 4. [DataProvider Interface](#dataprovider-interface)
92
+ 5. [Provider Implementations](#provider-implementations)
93
+ 6. [Configuration (Astro-Style)](#configuration-astro-style)
94
+ 7. [Ontology Config (Display Only)](#ontology-config-display-only)
95
+ 8. [Effect.ts Service Layer](#effectts-service-layer)
96
+ 9. [React Integration (useEffectRunner)](#react-integration-useeffectrunner)
97
+ 10. [Component Patterns](#component-patterns)
98
+ 11. [Page Patterns (SSR)](#page-patterns-ssr)
99
+ 12. [Real-Time Components](#real-time-components)
100
+ 13. [Forms (Calls Backend)](#forms-calls-backend)
101
+ 14. [Multi-Tenant Routing](#multi-tenant-routing)
102
+ 15. [Deployment](#deployment)
103
+
104
+ ---
105
+
106
+ ## What Frontend IS and IS NOT
107
+
108
+ ### ✅ Frontend IS Responsible For:
109
+
110
+ **1. Rendering**
111
+ ```tsx
112
+ // Display data from backend
113
+ <h1>{course.name}</h1>
114
+ <p>{course.properties.description}</p>
115
+ ```
116
+
117
+ **2. Calling Backend APIs**
118
+ ```tsx
119
+ // Get data from backend
120
+ const courses = useQuery(api.queries.things.list, { type: 'course' })
121
+
122
+ // Send data to backend
123
+ const create = useMutation(api.mutations.things.create)
124
+ await create({ type: 'course', name: 'Fitness 101', properties: {...} })
125
+ ```
126
+
127
+ **3. Managing UI State**
128
+ ```tsx
129
+ const [loading, setLoading] = useState(false)
130
+ const [error, setError] = useState(null)
131
+ ```
132
+
133
+ **4. User Interactions**
134
+ ```tsx
135
+ <button onClick={handleClick}>Create Course</button>
136
+ <input onChange={handleChange} />
137
+ ```
138
+
139
+ **5. Client-Side Routing**
140
+ ```tsx
141
+ // Navigate between pages
142
+ <Link href="/courses">View Courses</Link>
143
+ ```
144
+
145
+ ### ❌ Frontend IS NOT Responsible For:
146
+
147
+ **1. Database Operations**
148
+ ```tsx
149
+ // ❌ NEVER do this in frontend
150
+ const courses = await db.query('things').filter(...).collect()
151
+ ```
152
+
153
+ **2. Business Logic**
154
+ ```tsx
155
+ // ❌ NEVER do this in frontend
156
+ if (user.tokens < course.price) {
157
+ // Calculate discount, check quotas, etc.
158
+ }
159
+ ```
160
+
161
+ **3. Data Validation**
162
+ ```tsx
163
+ // ❌ NEVER trust frontend validation alone
164
+ if (formData.email.includes('@')) {
165
+ // Backend MUST validate, frontend only for UX
166
+ }
167
+ ```
168
+
169
+ **4. Event Logging**
170
+ ```tsx
171
+ // ❌ NEVER log events in frontend
172
+ await db.insert('events', { type: 'course_created', ... })
173
+ ```
174
+
175
+ **5. Authorization**
176
+ ```tsx
177
+ // ❌ NEVER check permissions in frontend alone
178
+ if (user.role === 'admin') {
179
+ // Backend MUST authorize, frontend only for UI hints
180
+ }
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Frontend File Structure
186
+
187
+ ```
188
+ frontend/ # Frontend repo (separate from backend)
189
+ ├── src/
190
+ │ ├── pages/ # Astro pages (SSR/SSG)
191
+ │ │ ├── index.astro # Homepage
192
+ │ │ ├── courses/
193
+ │ │ │ ├── index.astro # Course list (SSR)
194
+ │ │ │ └── [id].astro # Course detail (SSR)
195
+ │ │ └── [thingType]/ # Dynamic routes
196
+ │ │ ├── index.astro # Generic list page
197
+ │ │ └── [id].astro # Generic detail page
198
+ │ ├── components/ # React components
199
+ │ │ ├── cards/
200
+ │ │ │ └── ThingCard.tsx # Generic card (adapts to any type)
201
+ │ │ ├── lists/
202
+ │ │ │ └── ThingList.tsx # Generic list
203
+ │ │ ├── forms/
204
+ │ │ │ └── ThingForm.tsx # Generic form (calls backend)
205
+ │ │ └── ui/ # shadcn/ui components
206
+ │ ├── services/ # Effect.ts client services
207
+ │ │ ├── ConvexHttpClient.ts # Convex client wrapper (required)
208
+ │ │ ├── ThingClientService.ts # Thing operations (required)
209
+ │ │ ├── ConnectionClientService.ts # Connection operations (required)
210
+ │ │ ├── ClientLayer.ts # Dependency injection layer (required)
211
+ │ │ └── CourseClientService.ts # OPTIONAL: Course-specific convenience
212
+ │ ├── hooks/ # React hooks
213
+ │ │ └── useEffectRunner.ts # Run Effect programs in React
214
+ │ ├── layouts/
215
+ │ │ └── Layout.astro # Main layout
216
+ │ ├── ontology/ # Display config ONLY
217
+ │ │ ├── types.ts # Type definitions (synced from backend)
218
+ │ │ └── config.ts # UI display config (colors, icons, labels)
219
+ │ ├── lib/
220
+ │ │ └── convex.ts # Backend client setup
221
+ │ └── middleware.ts # Multi-tenant routing
222
+ ├── .env
223
+ │ PUBLIC_CONVEX_URL=https://backend.convex.cloud # Backend URL
224
+ └── package.json
225
+ ```
226
+
227
+ **Key Point:** Frontend has NO `convex/` directory. Backend-specific code lives in provider implementations.
228
+
229
+ ---
230
+
231
+ ## Backend-Agnostic Data Layer
232
+
233
+ **Inspired by Astro's Content Layer Pattern**
234
+
235
+ Astro elegantly abstracts content sources via a universal interface:
236
+
237
+ ```typescript
238
+ // astro.config.ts
239
+ import { defineConfig } from 'astro/config'
240
+ import { glob } from 'astro/loaders'
241
+
242
+ export default defineConfig({
243
+ collections: {
244
+ blog: {
245
+ loader: glob({ pattern: '**/*.md', base: './src/content/blog' })
246
+ }
247
+ }
248
+ })
249
+ ```
250
+
251
+ ONE applies this pattern to **data operations**:
252
+
253
+ ```typescript
254
+ // frontend/astro.config.ts
255
+ import { defineConfig } from 'astro/config'
256
+ import { convexProvider } from './src/providers/convex'
257
+ // import { wordpressProvider } from './src/providers/wordpress'
258
+ // import { notionProvider } from './src/providers/notion'
259
+
260
+ export default defineConfig({
261
+ integrations: [
262
+ one({
263
+ // ✅ Change this ONE line to swap backends
264
+ provider: convexProvider({
265
+ url: import.meta.env.PUBLIC_BACKEND_URL
266
+ })
267
+
268
+ // Or use WordPress:
269
+ // provider: wordpressProvider({
270
+ // url: 'https://yoursite.com',
271
+ // apiKey: import.meta.env.WORDPRESS_API_KEY
272
+ // })
273
+
274
+ // Or use Notion:
275
+ // provider: notionProvider({
276
+ // apiKey: import.meta.env.NOTION_API_KEY,
277
+ // databaseId: import.meta.env.NOTION_DB_ID
278
+ // })
279
+ })
280
+ ]
281
+ })
282
+ ```
283
+
284
+ **Key Principle:** Frontend components never know which backend they're talking to.
285
+
286
+ ---
287
+
288
+ ## DataProvider Interface
289
+
290
+ **The universal ontology API.**
291
+
292
+ ```typescript
293
+ // frontend/src/providers/DataProvider.ts
294
+ import { Effect } from 'effect'
295
+
296
+ // Error types (universal across all providers)
297
+ export class ThingNotFoundError {
298
+ readonly _tag = 'ThingNotFoundError'
299
+ constructor(readonly thingId: string) {}
300
+ }
301
+
302
+ export class ConnectionCreateError {
303
+ readonly _tag = 'ConnectionCreateError'
304
+ constructor(readonly reason: string) {}
305
+ }
306
+
307
+ export class UnauthorizedError {
308
+ readonly _tag = 'UnauthorizedError'
309
+ }
310
+
311
+ export class OrganizationNotFoundError {
312
+ readonly _tag = 'OrganizationNotFoundError'
313
+ constructor(readonly organizationId: string) {}
314
+ }
315
+
316
+ export class PersonNotFoundError {
317
+ readonly _tag = 'PersonNotFoundError'
318
+ constructor(readonly personId: string) {}
319
+ }
320
+
321
+ export class PersonCreateError {
322
+ readonly _tag = 'PersonCreateError'
323
+ constructor(readonly reason: string) {}
324
+ }
325
+
326
+ // Type definitions for 6 dimensions
327
+ export interface Organization {
328
+ _id: string
329
+ name: string
330
+ slug: string
331
+ status: 'active' | 'suspended' | 'trial' | 'cancelled'
332
+ plan: 'starter' | 'pro' | 'enterprise'
333
+ settings: {
334
+ allowSignups: boolean
335
+ requireEmailVerification: boolean
336
+ enableTwoFactor: boolean
337
+ }
338
+ limits: {
339
+ users: number
340
+ storage: number
341
+ apiCalls: number
342
+ inference: number
343
+ }
344
+ usage: {
345
+ users: number
346
+ storage: number
347
+ apiCalls: number
348
+ inference: number
349
+ }
350
+ createdAt: number
351
+ updatedAt: number
352
+ }
353
+
354
+ export interface Person {
355
+ _id: string
356
+ email: string
357
+ username: string
358
+ displayName: string
359
+ emailVerified: boolean
360
+ role: 'platform_owner' | 'org_owner' | 'org_user' | 'customer'
361
+ organizationId: string
362
+ organizations: string[] // All orgs this person belongs to
363
+ permissions?: string[]
364
+ image?: string
365
+ bio?: string
366
+ createdAt: number
367
+ updatedAt: number
368
+ }
369
+
370
+ // DataProvider interface (every backend must implement this)
371
+ export interface DataProvider {
372
+ // Dimension 1: Organizations operations
373
+ organizations: {
374
+ get: (id: string) => Effect.Effect<Organization, OrganizationNotFoundError>
375
+ list: (params: {
376
+ status?: 'active' | 'suspended' | 'trial' | 'cancelled'
377
+ limit?: number
378
+ }) => Effect.Effect<Organization[], Error>
379
+ update: (id: string, updates: Partial<Organization>) => Effect.Effect<void, Error>
380
+ }
381
+
382
+ // Dimension 2: People operations
383
+ people: {
384
+ get: (id: string) => Effect.Effect<Person, PersonNotFoundError | UnauthorizedError>
385
+ list: (params: {
386
+ organizationId?: string
387
+ role?: 'platform_owner' | 'org_owner' | 'org_user' | 'customer'
388
+ filters?: Record<string, any>
389
+ limit?: number
390
+ }) => Effect.Effect<Person[], Error>
391
+ create: (input: {
392
+ email: string
393
+ displayName: string
394
+ role: 'platform_owner' | 'org_owner' | 'org_user' | 'customer'
395
+ organizationId: string
396
+ password?: string
397
+ }) => Effect.Effect<string, PersonCreateError>
398
+ update: (id: string, updates: Partial<Person>) => Effect.Effect<void, Error>
399
+ delete: (id: string) => Effect.Effect<void, Error>
400
+ }
401
+
402
+ // Dimension 3: Things operations
403
+ things: {
404
+ get: (id: string) => Effect.Effect<Thing, ThingNotFoundError | UnauthorizedError>
405
+ list: (params: {
406
+ type: ThingType
407
+ organizationId?: string
408
+ filters?: Record<string, any>
409
+ limit?: number
410
+ }) => Effect.Effect<Thing[], Error>
411
+ create: (input: {
412
+ type: ThingType
413
+ name: string
414
+ organizationId: string
415
+ properties: Record<string, any>
416
+ }) => Effect.Effect<string, ConnectionCreateError>
417
+ update: (id: string, updates: Partial<Thing>) => Effect.Effect<void, Error>
418
+ delete: (id: string) => Effect.Effect<void, Error>
419
+ }
420
+
421
+ // Dimension 4: Connections operations
422
+ connections: {
423
+ create: (input: {
424
+ fromThingId: string
425
+ toThingId: string
426
+ relationshipType: ConnectionType
427
+ metadata?: Record<string, any>
428
+ }) => Effect.Effect<string, ConnectionCreateError>
429
+ getRelated: (params: {
430
+ thingId: string
431
+ relationshipType: ConnectionType
432
+ direction: 'from' | 'to' | 'both'
433
+ }) => Effect.Effect<Thing[], Error>
434
+ getCount: (thingId: string, relationshipType: ConnectionType) => Effect.Effect<number, Error>
435
+ delete: (id: string) => Effect.Effect<void, Error>
436
+ }
437
+
438
+ // Dimension 5: Events operations
439
+ events: {
440
+ log: (event: {
441
+ type: EventType
442
+ actorId: string // Person ID (who did it)
443
+ targetId?: string // Thing/Person/Connection ID (what was acted upon)
444
+ organizationId: string // Org scope
445
+ metadata?: Record<string, any>
446
+ }) => Effect.Effect<void, Error>
447
+ query: (params: {
448
+ type?: EventType
449
+ actorId?: string // Person ID
450
+ targetId?: string
451
+ organizationId?: string
452
+ from?: Date
453
+ to?: Date
454
+ }) => Effect.Effect<Event[], Error>
455
+ }
456
+
457
+ // Dimension 6: Knowledge operations
458
+ knowledge: {
459
+ embed: (params: {
460
+ text: string
461
+ sourceThingId?: string // Thing ID
462
+ sourcePersonId?: string // Person ID
463
+ organizationId: string
464
+ labels?: string[]
465
+ }) => Effect.Effect<string, Error>
466
+ search: (params: {
467
+ query: string
468
+ organizationId?: string
469
+ limit?: number
470
+ }) => Effect.Effect<KnowledgeMatch[], Error>
471
+ }
472
+
473
+ // Real-time subscriptions (optional - not all backends support this)
474
+ subscriptions?: {
475
+ watchThing: (id: string) => Effect.Effect<Observable<Thing>, Error>
476
+ watchList: (type: ThingType, organizationId?: string) => Effect.Effect<Observable<Thing[]>, Error>
477
+ }
478
+ }
479
+ ```
480
+
481
+ **Key Insight:** This interface IS the ONE 6-dimension ontology. Any backend that implements this interface can power ONE—Organizations partition, People authorize, Things exist, Connections relate, Events record, Knowledge understands.
482
+
483
+ ---
484
+
485
+ ## Provider Implementations
486
+
487
+ ### Convex Provider
488
+
489
+ ```typescript
490
+ // frontend/src/providers/convex/ConvexProvider.ts
491
+ import { Effect, Layer } from 'effect'
492
+ import { ConvexHttpClient } from 'convex/browser'
493
+ import { DataProvider } from '../DataProvider'
494
+ import { api } from './api'
495
+
496
+ export class ConvexProvider implements DataProvider {
497
+ constructor(private client: ConvexHttpClient) {}
498
+
499
+ things = {
500
+ get: (id: string) =>
501
+ Effect.gen(function* () {
502
+ const thing = yield* Effect.tryPromise({
503
+ try: () => this.client.query(api.queries.things.get, { id }),
504
+ catch: (error) => new Error(String(error))
505
+ })
506
+
507
+ if (!thing) {
508
+ return yield* Effect.fail(new ThingNotFoundError(id))
509
+ }
510
+
511
+ return thing
512
+ }),
513
+
514
+ list: (params) =>
515
+ Effect.tryPromise({
516
+ try: () => this.client.query(api.queries.things.list, params),
517
+ catch: (error) => new Error(String(error))
518
+ }),
519
+
520
+ create: (input) =>
521
+ Effect.tryPromise({
522
+ try: () => this.client.mutation(api.mutations.things.create, input),
523
+ catch: (error) => new ConnectionCreateError(String(error))
524
+ }),
525
+
526
+ update: (id, updates) =>
527
+ Effect.tryPromise({
528
+ try: () => this.client.mutation(api.mutations.things.update, { id, updates }),
529
+ catch: (error) => new Error(String(error))
530
+ }),
531
+
532
+ delete: (id) =>
533
+ Effect.tryPromise({
534
+ try: () => this.client.mutation(api.mutations.things.delete, { id }),
535
+ catch: (error) => new Error(String(error))
536
+ })
537
+ }
538
+
539
+ connections = {
540
+ // Similar implementation for connections...
541
+ }
542
+
543
+ events = {
544
+ // Similar implementation for events...
545
+ }
546
+
547
+ knowledge = {
548
+ // Similar implementation for knowledge...
549
+ }
550
+ }
551
+
552
+ // Factory function
553
+ export function convexProvider(config: { url: string }) {
554
+ return Layer.succeed(
555
+ DataProvider,
556
+ new ConvexProvider(new ConvexHttpClient(config.url))
557
+ )
558
+ }
559
+ ```
560
+
561
+ ### WordPress Provider
562
+
563
+ ```typescript
564
+ // frontend/src/providers/wordpress/WordPressProvider.ts
565
+ import { Effect, Layer } from 'effect'
566
+ import { DataProvider } from '../DataProvider'
567
+
568
+ export class WordPressProvider implements DataProvider {
569
+ constructor(
570
+ private baseUrl: string,
571
+ private apiKey: string
572
+ ) {}
573
+
574
+ things = {
575
+ get: (id: string) =>
576
+ Effect.gen(function* () {
577
+ // Map ONE ontology → WordPress REST API
578
+ const response = yield* Effect.tryPromise({
579
+ try: () =>
580
+ fetch(`${this.baseUrl}/wp-json/wp/v2/posts/${id}`, {
581
+ headers: { Authorization: `Bearer ${this.apiKey}` }
582
+ }),
583
+ catch: (error) => new Error(String(error))
584
+ })
585
+
586
+ if (!response.ok) {
587
+ return yield* Effect.fail(new ThingNotFoundError(id))
588
+ }
589
+
590
+ const post = yield* Effect.tryPromise({
591
+ try: () => response.json(),
592
+ catch: (error) => new Error(String(error))
593
+ })
594
+
595
+ // Transform WordPress post → ONE thing
596
+ return {
597
+ _id: post.id.toString(),
598
+ type: 'post' as ThingType,
599
+ name: post.title.rendered,
600
+ properties: {
601
+ content: post.content.rendered,
602
+ excerpt: post.excerpt.rendered,
603
+ author: post.author,
604
+ publishedAt: post.date
605
+ },
606
+ status: post.status,
607
+ createdAt: new Date(post.date).getTime(),
608
+ updatedAt: new Date(post.modified).getTime()
609
+ }
610
+ }),
611
+
612
+ list: (params) =>
613
+ Effect.gen(function* () {
614
+ // Map ONE list query → WordPress REST API query
615
+ const query = new URLSearchParams({
616
+ per_page: String(params.limit || 10),
617
+ // Map ontology filters → WordPress query params
618
+ })
619
+
620
+ const response = yield* Effect.tryPromise({
621
+ try: () =>
622
+ fetch(`${this.baseUrl}/wp-json/wp/v2/posts?${query}`, {
623
+ headers: { Authorization: `Bearer ${this.apiKey}` }
624
+ }),
625
+ catch: (error) => new Error(String(error))
626
+ })
627
+
628
+ const posts = yield* Effect.tryPromise({
629
+ try: () => response.json(),
630
+ catch: (error) => new Error(String(error))
631
+ })
632
+
633
+ // Transform WordPress posts → ONE things
634
+ return posts.map((post: any) => ({
635
+ _id: post.id.toString(),
636
+ type: 'post' as ThingType,
637
+ name: post.title.rendered,
638
+ properties: {
639
+ content: post.content.rendered,
640
+ excerpt: post.excerpt.rendered
641
+ },
642
+ status: post.status,
643
+ createdAt: new Date(post.date).getTime(),
644
+ updatedAt: new Date(post.modified).getTime()
645
+ }))
646
+ }),
647
+
648
+ create: (input) =>
649
+ Effect.gen(function* () {
650
+ // Map ONE create → WordPress create post
651
+ const response = yield* Effect.tryPromise({
652
+ try: () =>
653
+ fetch(`${this.baseUrl}/wp-json/wp/v2/posts`, {
654
+ method: 'POST',
655
+ headers: {
656
+ 'Content-Type': 'application/json',
657
+ Authorization: `Bearer ${this.apiKey}`
658
+ },
659
+ body: JSON.stringify({
660
+ title: input.name,
661
+ content: input.properties.content || '',
662
+ status: 'draft'
663
+ })
664
+ }),
665
+ catch: (error) => new ConnectionCreateError(String(error))
666
+ })
667
+
668
+ const post = yield* Effect.tryPromise({
669
+ try: () => response.json(),
670
+ catch: (error) => new ConnectionCreateError(String(error))
671
+ })
672
+
673
+ return post.id.toString()
674
+ }),
675
+
676
+ update: (id, updates) => {
677
+ // Similar WordPress update implementation
678
+ },
679
+
680
+ delete: (id) => {
681
+ // Similar WordPress delete implementation
682
+ }
683
+ }
684
+
685
+ connections = {
686
+ // WordPress doesn't have native connections
687
+ // Could use:
688
+ // - Post relationships (parent/child)
689
+ // - Categories/tags as connections
690
+ // - Custom post meta
691
+ // - Custom tables
692
+ }
693
+
694
+ events = {
695
+ // Log to WordPress activity log or custom table
696
+ }
697
+
698
+ knowledge = {
699
+ // Could integrate with:
700
+ // - Elasticsearch
701
+ // - Algolia
702
+ // - Custom vector search
703
+ }
704
+ }
705
+
706
+ // Factory function
707
+ export function wordpressProvider(config: { url: string; apiKey: string }) {
708
+ return Layer.succeed(
709
+ DataProvider,
710
+ new WordPressProvider(config.url, config.apiKey)
711
+ )
712
+ }
713
+ ```
714
+
715
+ ### Notion Provider
716
+
717
+ ```typescript
718
+ // frontend/src/providers/notion/NotionProvider.ts
719
+ import { Effect, Layer } from 'effect'
720
+ import { Client } from '@notionhq/client'
721
+ import { DataProvider } from '../DataProvider'
722
+
723
+ export class NotionProvider implements DataProvider {
724
+ private notion: Client
725
+
726
+ constructor(apiKey: string, private databaseId: string) {
727
+ this.notion = new Client({ auth: apiKey })
728
+ }
729
+
730
+ things = {
731
+ get: (id: string) =>
732
+ Effect.gen(function* () {
733
+ // Map ONE thing → Notion page
734
+ const page = yield* Effect.tryPromise({
735
+ try: () => this.notion.pages.retrieve({ page_id: id }),
736
+ catch: (error) => new Error(String(error))
737
+ })
738
+
739
+ // Transform Notion page → ONE thing
740
+ return {
741
+ _id: page.id,
742
+ type: 'document' as ThingType,
743
+ name: (page.properties.Name as any).title[0]?.plain_text || '',
744
+ properties: {
745
+ // Map Notion properties → ONE properties
746
+ },
747
+ status: 'active',
748
+ createdAt: new Date(page.created_time).getTime(),
749
+ updatedAt: new Date(page.last_edited_time).getTime()
750
+ }
751
+ }),
752
+
753
+ list: (params) =>
754
+ Effect.gen(function* () {
755
+ // Map ONE list query → Notion database query
756
+ const response = yield* Effect.tryPromise({
757
+ try: () =>
758
+ this.notion.databases.query({
759
+ database_id: this.databaseId,
760
+ page_size: params.limit || 10
761
+ }),
762
+ catch: (error) => new Error(String(error))
763
+ })
764
+
765
+ // Transform Notion pages → ONE things
766
+ return response.results.map((page: any) => ({
767
+ _id: page.id,
768
+ type: params.type,
769
+ name: page.properties.Name?.title[0]?.plain_text || '',
770
+ properties: {},
771
+ status: 'active',
772
+ createdAt: new Date(page.created_time).getTime(),
773
+ updatedAt: new Date(page.last_edited_time).getTime()
774
+ }))
775
+ }),
776
+
777
+ create: (input) =>
778
+ Effect.gen(function* () {
779
+ // Map ONE create → Notion create page
780
+ const page = yield* Effect.tryPromise({
781
+ try: () =>
782
+ this.notion.pages.create({
783
+ parent: { database_id: this.databaseId },
784
+ properties: {
785
+ Name: {
786
+ title: [{ text: { content: input.name } }]
787
+ }
788
+ // Map input.properties → Notion properties
789
+ }
790
+ }),
791
+ catch: (error) => new ConnectionCreateError(String(error))
792
+ })
793
+
794
+ return page.id
795
+ }),
796
+
797
+ update: (id, updates) => {
798
+ // Similar Notion update implementation
799
+ },
800
+
801
+ delete: (id) => {
802
+ // Notion archive page
803
+ }
804
+ }
805
+
806
+ connections = {
807
+ // Notion relations can map to connections
808
+ }
809
+
810
+ events = {
811
+ // Log to separate Notion database
812
+ }
813
+
814
+ knowledge = {
815
+ // Use Notion's built-in search or external vector DB
816
+ }
817
+ }
818
+
819
+ // Factory function
820
+ export function notionProvider(config: { apiKey: string; databaseId: string }) {
821
+ return Layer.succeed(
822
+ DataProvider,
823
+ new NotionProvider(config.apiKey, config.databaseId)
824
+ )
825
+ }
826
+ ```
827
+
828
+ ### Supabase Provider
829
+
830
+ ```typescript
831
+ // frontend/src/providers/supabase/SupabaseProvider.ts
832
+ import { Effect, Layer } from 'effect'
833
+ import { createClient, SupabaseClient } from '@supabase/supabase-js'
834
+ import { DataProvider } from '../DataProvider'
835
+
836
+ export class SupabaseProvider implements DataProvider {
837
+ private supabase: SupabaseClient
838
+
839
+ constructor(url: string, apiKey: string) {
840
+ this.supabase = createClient(url, apiKey)
841
+ }
842
+
843
+ things = {
844
+ get: (id: string) =>
845
+ Effect.gen(function* () {
846
+ // Map ONE thing → Supabase row
847
+ const { data, error } = yield* Effect.tryPromise({
848
+ try: () => this.supabase.from('things').select('*').eq('id', id).single(),
849
+ catch: (err) => new Error(String(err))
850
+ })
851
+
852
+ if (error) {
853
+ return yield* Effect.fail(new ThingNotFoundError(id))
854
+ }
855
+
856
+ return data
857
+ }),
858
+
859
+ list: (params) =>
860
+ Effect.gen(function* () {
861
+ let query = this.supabase
862
+ .from('things')
863
+ .select('*')
864
+ .eq('type', params.type)
865
+ .limit(params.limit || 10)
866
+
867
+ if (params.organizationId) {
868
+ query = query.eq('organizationId', params.organizationId)
869
+ }
870
+
871
+ const { data, error } = yield* Effect.tryPromise({
872
+ try: () => query,
873
+ catch: (err) => new Error(String(err))
874
+ })
875
+
876
+ if (error) {
877
+ return yield* Effect.fail(new Error(error.message))
878
+ }
879
+
880
+ return data
881
+ }),
882
+
883
+ create: (input) =>
884
+ Effect.gen(function* () {
885
+ const { data, error } = yield* Effect.tryPromise({
886
+ try: () =>
887
+ this.supabase.from('things').insert([input]).select().single(),
888
+ catch: (err) => new ConnectionCreateError(String(err))
889
+ })
890
+
891
+ if (error) {
892
+ return yield* Effect.fail(new ConnectionCreateError(error.message))
893
+ }
894
+
895
+ return data.id
896
+ }),
897
+
898
+ update: (id, updates) => {
899
+ // Similar Supabase update
900
+ },
901
+
902
+ delete: (id) => {
903
+ // Similar Supabase delete
904
+ }
905
+ }
906
+
907
+ connections = {
908
+ // Use Supabase 'connections' table
909
+ }
910
+
911
+ events = {
912
+ // Use Supabase 'events' table
913
+ }
914
+
915
+ knowledge = {
916
+ // Use pgvector extension for embeddings
917
+ }
918
+
919
+ // ✅ Supabase supports real-time!
920
+ subscriptions = {
921
+ watchThing: (id: string) =>
922
+ Effect.gen(function* () {
923
+ // Use Supabase real-time subscriptions
924
+ const channel = this.supabase
925
+ .channel(`thing:${id}`)
926
+ .on('postgres_changes', {
927
+ event: '*',
928
+ schema: 'public',
929
+ table: 'things',
930
+ filter: `id=eq.${id}`
931
+ }, (payload) => {
932
+ // Emit updates
933
+ })
934
+
935
+ yield* Effect.tryPromise({
936
+ try: () => channel.subscribe(),
937
+ catch: (err) => new Error(String(err))
938
+ })
939
+
940
+ // Return observable
941
+ })
942
+ }
943
+ }
944
+
945
+ // Factory function
946
+ export function supabaseProvider(config: { url: string; apiKey: string }) {
947
+ return Layer.succeed(
948
+ DataProvider,
949
+ new SupabaseProvider(config.url, config.apiKey)
950
+ )
951
+ }
952
+ ```
953
+
954
+ **Key Insight:** Each provider translates between ONE ontology ↔ backend-specific API.
955
+
956
+ ---
957
+
958
+ ## Configuration (Astro-Style)
959
+
960
+ **Swap backends by changing ONE line.**
961
+
962
+ ```typescript
963
+ // frontend/astro.config.ts
964
+ import { defineConfig } from 'astro/config'
965
+ import react from '@astrojs/react'
966
+ import { one } from '@one/astro-integration'
967
+
968
+ // Import providers
969
+ import { convexProvider } from './src/providers/convex'
970
+ import { wordpressProvider } from './src/providers/wordpress'
971
+ import { notionProvider } from './src/providers/notion'
972
+ import { supabaseProvider } from './src/providers/supabase'
973
+
974
+ export default defineConfig({
975
+ integrations: [
976
+ react(),
977
+ one({
978
+ // ✅ Choose your backend (change this ONE line)
979
+
980
+ // Option 1: Convex (real-time, serverless)
981
+ provider: convexProvider({
982
+ url: import.meta.env.PUBLIC_CONVEX_URL
983
+ })
984
+
985
+ // Option 2: WordPress (existing CMS)
986
+ // provider: wordpressProvider({
987
+ // url: 'https://yoursite.com',
988
+ // apiKey: import.meta.env.WORDPRESS_API_KEY
989
+ // })
990
+
991
+ // Option 3: Notion (databases as backend)
992
+ // provider: notionProvider({
993
+ // apiKey: import.meta.env.NOTION_API_KEY,
994
+ // databaseId: import.meta.env.NOTION_DB_ID
995
+ // })
996
+
997
+ // Option 4: Supabase (PostgreSQL + real-time)
998
+ // provider: supabaseProvider({
999
+ // url: import.meta.env.PUBLIC_SUPABASE_URL,
1000
+ // apiKey: import.meta.env.PUBLIC_SUPABASE_ANON_KEY
1001
+ // })
1002
+
1003
+ // Option 5: Custom backend
1004
+ // provider: customProvider({ ... })
1005
+ })
1006
+ ]
1007
+ })
1008
+ ```
1009
+
1010
+ **Result:**
1011
+ - Frontend components don't change
1012
+ - UI stays the same
1013
+ - Only data source changes
1014
+ - Organizations can use their existing infrastructure
1015
+
1016
+ ---
1017
+
1018
+ ## Ontology Config (Display Only)
1019
+
1020
+ Frontend needs **display configuration** for UI rendering. NOT business logic.
1021
+
1022
+ ```typescript
1023
+ // frontend/src/ontology/config.ts
1024
+ // THIS IS NOT BUSINESS LOGIC - JUST UI CONFIGURATION
1025
+
1026
+ export const thingConfigs = {
1027
+ course: {
1028
+ // Display names
1029
+ displayName: 'Course',
1030
+ displayNamePlural: 'Courses',
1031
+
1032
+ // UI presentation
1033
+ icon: 'BookOpen', // Lucide icon name
1034
+ color: 'green', // Tailwind color
1035
+
1036
+ // Which fields to show in UI
1037
+ primaryField: 'title', // Main display field
1038
+ secondaryField: 'description',
1039
+ imageField: 'thumbnail',
1040
+
1041
+ // Form fields (for UI only, backend validates)
1042
+ fields: {
1043
+ title: {
1044
+ label: 'Course Title',
1045
+ type: 'text',
1046
+ required: true,
1047
+ placeholder: 'e.g., Fitness 101'
1048
+ },
1049
+ description: {
1050
+ label: 'Description',
1051
+ type: 'textarea',
1052
+ required: true
1053
+ },
1054
+ price: {
1055
+ label: 'Price (USD)',
1056
+ type: 'number',
1057
+ required: true
1058
+ }
1059
+ }
1060
+ },
1061
+
1062
+ creator: {
1063
+ displayName: 'Creator',
1064
+ displayNamePlural: 'Creators',
1065
+ icon: 'User',
1066
+ color: 'blue',
1067
+ primaryField: 'name',
1068
+ secondaryField: 'bio',
1069
+ imageField: 'avatar',
1070
+ fields: {
1071
+ name: { label: 'Name', type: 'text', required: true },
1072
+ email: { label: 'Email', type: 'text', required: true },
1073
+ bio: { label: 'Bio', type: 'textarea', required: false }
1074
+ }
1075
+ }
1076
+
1077
+ // ... all 66 types (UI config only)
1078
+ }
1079
+
1080
+ // Helper function
1081
+ export function getThingConfig(type: ThingType) {
1082
+ return thingConfigs[type]
1083
+ }
1084
+ ```
1085
+
1086
+ **What This Is:**
1087
+ - ✅ UI labels and placeholders
1088
+ - ✅ Icon and color choices
1089
+ - ✅ Which fields to display
1090
+ - ✅ Form field types
1091
+
1092
+ **What This Is NOT:**
1093
+ - ❌ Business logic
1094
+ - ❌ Validation rules (backend validates)
1095
+ - ❌ Authorization rules (backend authorizes)
1096
+ - ❌ Database schema (that's in backend)
1097
+
1098
+ ---
1099
+
1100
+ ## Effect.ts Service Layer
1101
+
1102
+ **Effect.ts services consume the DataProvider interface.**
1103
+
1104
+ The frontend service layer sits between React components and the DataProvider, providing:
1105
+ - Type-safe operations
1106
+ - Composable workflows
1107
+ - Consistent error handling
1108
+ - Testability
1109
+
1110
+ ### Architecture
1111
+
1112
+ ```
1113
+ ┌────────────────────────────────────────────┐
1114
+ │ React Components │
1115
+ │ - useEffectRunner hook │
1116
+ │ - Render UI from Effect results │
1117
+ │ - Handle typed errors │
1118
+ └────────────────┬───────────────────────────┘
1119
+ │ Effect.runPromise
1120
+ ↓
1121
+ ┌────────────────────────────────────────────┐
1122
+ │ Service Layer (Effect.ts) │
1123
+ │ - ThingService │
1124
+ │ - ConnectionService │
1125
+ │ - Composable, testable │
1126
+ └────────────────┬───────────────────────────┘
1127
+ │ DataProvider Interface
1128
+ ↓
1129
+ ┌────────────────────────────────────────────┐
1130
+ │ DataProvider (Backend-Agnostic) │
1131
+ │ - ConvexProvider │
1132
+ │ - WordPressProvider │
1133
+ │ - NotionProvider │
1134
+ │ - SupabaseProvider │
1135
+ └────────────────────────────────────────────┘
1136
+ ```
1137
+
1138
+ ### Why Effect.ts?
1139
+
1140
+ ```typescript
1141
+ // ❌ Traditional approach - untyped errors, hard to compose
1142
+ async function getCourse(id: string) {
1143
+ try {
1144
+ const response = await fetch(`/api/courses/${id}`)
1145
+ const course = await response.json()
1146
+ return course
1147
+ } catch (error) {
1148
+ // What type of error? Network? 404? 500?
1149
+ console.error(error)
1150
+ throw error
1151
+ }
1152
+ }
1153
+
1154
+ // ✅ Effect.ts approach - typed errors, backend-agnostic
1155
+ import { Effect } from 'effect'
1156
+
1157
+ function getCourse(id: string) {
1158
+ return Effect.gen(function* () {
1159
+ const provider = yield* DataProvider
1160
+
1161
+ // Works with ANY backend (Convex, WordPress, Notion, etc.)
1162
+ const course = yield* provider.things.get(id)
1163
+
1164
+ return course
1165
+ }).pipe(
1166
+ // Handle specific errors
1167
+ Effect.catchTag('ThingNotFoundError', err =>
1168
+ Effect.fail(new Error(`Course ${err.thingId} not found`))
1169
+ )
1170
+ )
1171
+ }
1172
+ ```
1173
+
1174
+ **Key Benefits:**
1175
+ 1. **Backend-Agnostic** - Works with any DataProvider implementation
1176
+ 2. **Type-Safe Errors** - Compiler enforces error handling
1177
+ 3. **Composability** - Small functions combine into complex flows
1178
+ 4. **Testability** - Test layers replace real providers
1179
+
1180
+ ---
1181
+
1182
+ ## Service Implementations
1183
+
1184
+ **Client services wrap backend API calls in Effect.ts patterns.**
1185
+
1186
+ ### Core Principle: Generic Services Handle Everything
1187
+
1188
+ The ontology has **66 thing types**, but you only need **2 generic services**:
1189
+
1190
+ 1. **ThingClientService** - All CRUD for all 66 types
1191
+ 2. **ConnectionClientService** - All relationships
1192
+
1193
+ ```typescript
1194
+ // ✅ This handles courses, lessons, products, everything
1195
+ // Works with ANY backend (Convex, WordPress, Notion, Supabase, etc.)
1196
+ const provider = yield* DataProvider
1197
+
1198
+ // Get any thing
1199
+ const course = yield* provider.things.get(courseId)
1200
+ const lesson = yield* provider.things.get(lessonId)
1201
+
1202
+ // List any type
1203
+ const courses = yield* provider.things.list({ type: 'course', organizationId: orgId })
1204
+ const products = yield* provider.things.list({ type: 'product', organizationId: orgId })
1205
+
1206
+ // Create any type
1207
+ const courseId = yield* provider.things.create({
1208
+ type: 'course',
1209
+ name: 'Fitness 101',
1210
+ properties: { price: 99, description: '...' }
1211
+ })
1212
+ ```
1213
+
1214
+ **Specialized services are OPTIONAL** - only add them if you repeat the same multi-step operations frequently.
1215
+
1216
+ ---
1217
+
1218
+ ### Pattern: Generic Thing Service (Thin Wrapper)
1219
+
1220
+ **Services are thin wrappers around DataProvider - backend-agnostic.**
1221
+
1222
+ ```typescript
1223
+ // frontend/src/services/ThingService.ts
1224
+ import { Effect } from 'effect'
1225
+ import { DataProvider } from '@/providers/DataProvider'
1226
+
1227
+ // Services just delegate to the configured provider
1228
+ export class ThingService extends Effect.Service<ThingService>()(
1229
+ 'ThingService',
1230
+ {
1231
+ effect: Effect.gen(function* () {
1232
+ // Get the configured provider (Convex, WordPress, etc.)
1233
+ const provider = yield* DataProvider
1234
+
1235
+ return {
1236
+ // All methods delegate to provider
1237
+ get: (id: string) => provider.things.get(id),
1238
+
1239
+ list: (type: ThingType, orgId?: string) =>
1240
+ provider.things.list({
1241
+ type,
1242
+ organizationId: orgId
1243
+ }),
1244
+
1245
+ create: (input: { type: ThingType; name: string; properties: any }) =>
1246
+ provider.things.create(input),
1247
+
1248
+ update: (id: string, updates: any) =>
1249
+ provider.things.update(id, updates),
1250
+
1251
+ delete: (id: string) =>
1252
+ provider.things.delete(id)
1253
+ }
1254
+ }),
1255
+ dependencies: [DataProvider] // Depends on DataProvider (backend-agnostic)
1256
+ }
1257
+ ) {}
1258
+ ```
1259
+
1260
+ **Key Point:** `ThingService` doesn't care if provider is Convex, WordPress, or Notion. It just calls `provider.things.get()`. The provider handles backend-specific logic.
1261
+
1262
+ ### Pattern: Specialized Service (Optional - Course Example)
1263
+
1264
+ **You don't need this!** A course is just a thing. But if you repeat operations, add convenience methods:
1265
+
1266
+ ```typescript
1267
+ // frontend/src/services/CourseClientService.ts (OPTIONAL)
1268
+ import { Effect } from 'effect'
1269
+ import { ThingClientService } from './ThingClientService'
1270
+ import { ConnectionClientService } from './ConnectionClientService'
1271
+
1272
+ export class CourseClientService extends Effect.Service<CourseClientService>()(
1273
+ 'CourseClientService',
1274
+ {
1275
+ effect: Effect.gen(function* () {
1276
+ const thingService = yield* ThingClientService
1277
+ const connectionService = yield* ConnectionClientService
1278
+
1279
+ return {
1280
+ // Convenience: Get course with lessons
1281
+ // Without this, you'd do:
1282
+ // const course = yield* thingService.get(courseId)
1283
+ // const lessons = yield* connectionService.getRelated(courseId, 'part_of', 'to')
1284
+ getCourseWithLessons: (courseId: string) =>
1285
+ Effect.gen(function* () {
1286
+ const [course, lessons] = yield* Effect.all([
1287
+ thingService.get(courseId),
1288
+ connectionService.getRelated(courseId, 'part_of', 'to')
1289
+ ])
1290
+
1291
+ return { course, lessons }
1292
+ }),
1293
+
1294
+ // Convenience: Clearer domain vocabulary
1295
+ // Without this, you'd do:
1296
+ // yield* connectionService.create({
1297
+ // fromThingId: userId,
1298
+ // toThingId: courseId,
1299
+ // relationshipType: 'enrolled_in'
1300
+ // })
1301
+ enrollUser: (userId: string, courseId: string) =>
1302
+ Effect.gen(function* () {
1303
+ return yield* connectionService.create({
1304
+ fromThingId: userId,
1305
+ toThingId: courseId,
1306
+ relationshipType: 'enrolled_in'
1307
+ })
1308
+ }),
1309
+
1310
+ // Convenience: Specific count query
1311
+ getEnrollmentCount: (courseId: string) =>
1312
+ Effect.gen(function* () {
1313
+ return yield* connectionService.getCount(courseId, 'enrolled_in')
1314
+ })
1315
+ }
1316
+ }),
1317
+ dependencies: [ThingClientService.Default, ConnectionClientService.Default]
1318
+ }
1319
+ ) {}
1320
+ ```
1321
+
1322
+ **When to add specialized services:**
1323
+ - ✅ Repeat the same multi-step operation 3+ times
1324
+ - ✅ Want domain vocabulary (`enrollUser` vs `create connection`)
1325
+ - ✅ Need to encapsulate complex business workflows
1326
+ - ❌ Don't add them upfront for all 66 types
1327
+ - ❌ Don't add them for simple CRUD (use ThingClientService)
1328
+
1329
+ ### ConvexHttpClient Wrapper
1330
+
1331
+ ```typescript
1332
+ // frontend/src/services/ConvexHttpClient.ts
1333
+ import { Effect, Context, Layer } from 'effect'
1334
+ import { ConvexHttpClient as ConvexClient } from 'convex/browser'
1335
+
1336
+ // Define client interface
1337
+ export class ConvexHttpClient extends Context.Tag('ConvexHttpClient')<
1338
+ ConvexHttpClient,
1339
+ {
1340
+ query: <T>(endpoint: any, args: any) => Effect.Effect<T, Error>
1341
+ mutation: <T>(endpoint: any, args: any) => Effect.Effect<T, Error>
1342
+ }
1343
+ >() {}
1344
+
1345
+ // Live implementation
1346
+ export const ConvexHttpClientLive = Layer.succeed(
1347
+ ConvexHttpClient,
1348
+ {
1349
+ query: (endpoint, args) =>
1350
+ Effect.tryPromise({
1351
+ try: () => {
1352
+ const client = new ConvexClient(import.meta.env.PUBLIC_CONVEX_URL)
1353
+ return client.query(endpoint, args)
1354
+ },
1355
+ catch: (error) => new Error(String(error))
1356
+ }),
1357
+
1358
+ mutation: (endpoint, args) =>
1359
+ Effect.tryPromise({
1360
+ try: () => {
1361
+ const client = new ConvexClient(import.meta.env.PUBLIC_CONVEX_URL)
1362
+ return client.mutation(endpoint, args)
1363
+ },
1364
+ catch: (error) => new Error(String(error))
1365
+ })
1366
+ }
1367
+ )
1368
+ ```
1369
+
1370
+ ### Client Layer (Dependency Injection)
1371
+
1372
+ ```typescript
1373
+ // frontend/src/services/ClientLayer.ts
1374
+ import { Layer } from 'effect'
1375
+ import { ConvexHttpClientLive } from './ConvexHttpClient'
1376
+ import { ThingClientService } from './ThingClientService'
1377
+ import { ConnectionClientService } from './ConnectionClientService'
1378
+ // import { CourseClientService } from './CourseClientService' // OPTIONAL
1379
+
1380
+ // ✅ Minimal layer - handles all 66 thing types
1381
+ export const ClientLayer = Layer.mergeAll(
1382
+ ConvexHttpClientLive,
1383
+ ThingClientService.Default,
1384
+ ConnectionClientService.Default
1385
+ // CourseClientService.Default // Add ONLY if you created it
1386
+ )
1387
+ ```
1388
+
1389
+ **Most apps only need the 2 generic services.** Add specialized services as you discover repeated patterns.
1390
+
1391
+ ---
1392
+
1393
+ ## React Integration (useEffectRunner)
1394
+
1395
+ **Custom hook for running Effect programs in React components.**
1396
+
1397
+ ### useEffectRunner Hook
1398
+
1399
+ ```typescript
1400
+ // frontend/src/hooks/useEffectRunner.ts
1401
+ import { useCallback, useState } from 'react'
1402
+ import { Effect } from 'effect'
1403
+ import { ClientLayer } from '@/services/ClientLayer'
1404
+
1405
+ export function useEffectRunner() {
1406
+ const [loading, setLoading] = useState(false)
1407
+ const [error, setError] = useState<string | null>(null)
1408
+
1409
+ const run = useCallback(async <A, E>(
1410
+ effect: Effect.Effect<A, E>,
1411
+ options?: {
1412
+ onSuccess?: (result: A) => void
1413
+ onError?: (error: E) => void
1414
+ }
1415
+ ) => {
1416
+ setLoading(true)
1417
+ setError(null)
1418
+
1419
+ try {
1420
+ const result = await Effect.runPromise(
1421
+ effect.pipe(Effect.provide(ClientLayer))
1422
+ )
1423
+
1424
+ options?.onSuccess?.(result)
1425
+ return result
1426
+ } catch (err) {
1427
+ const errorMessage = err instanceof Error ? err.message : String(err)
1428
+ setError(errorMessage)
1429
+ options?.onError?.(err as E)
1430
+ throw err
1431
+ } finally {
1432
+ setLoading(false)
1433
+ }
1434
+ }, [])
1435
+
1436
+ return { run, loading, error }
1437
+ }
1438
+ ```
1439
+
1440
+ ### Using in Components
1441
+
1442
+ ```tsx
1443
+ // frontend/src/components/CourseEnrollButton.tsx
1444
+ import { useEffectRunner } from '@/hooks/useEffectRunner'
1445
+ import { ConnectionClientService } from '@/services/ConnectionClientService'
1446
+ import { Effect } from 'effect'
1447
+ import { Button } from '@/components/ui/button'
1448
+ import { Alert } from '@/components/ui/alert'
1449
+
1450
+ interface Props {
1451
+ courseId: string
1452
+ userId: string
1453
+ }
1454
+
1455
+ export function CourseEnrollButton({ courseId, userId }: Props) {
1456
+ const { run, loading, error } = useEffectRunner()
1457
+
1458
+ const handleEnroll = () => {
1459
+ // Define Effect program using GENERIC service
1460
+ const program = Effect.gen(function* () {
1461
+ const connectionService = yield* ConnectionClientService
1462
+
1463
+ // Enroll = create connection (course is just a thing)
1464
+ const enrollmentId = yield* connectionService.create({
1465
+ fromThingId: userId,
1466
+ toThingId: courseId,
1467
+ relationshipType: 'enrolled_in'
1468
+ })
1469
+
1470
+ // Log success (client-side only for UX)
1471
+ yield* Effect.logInfo(`Enrolled in course ${courseId}`)
1472
+
1473
+ return enrollmentId
1474
+ })
1475
+
1476
+ // Run Effect program
1477
+ run(program, {
1478
+ onSuccess: (enrollmentId) => {
1479
+ console.log('Enrolled successfully:', enrollmentId)
1480
+ window.location.href = `/courses/${courseId}/learn`
1481
+ },
1482
+ onError: (err) => {
1483
+ console.error('Enrollment failed:', err)
1484
+ }
1485
+ })
1486
+ }
1487
+
1488
+ return (
1489
+ <div>
1490
+ <Button onClick={handleEnroll} disabled={loading}>
1491
+ {loading ? 'Enrolling...' : 'Enroll Now'}
1492
+ </Button>
1493
+
1494
+ {error && (
1495
+ <Alert variant="destructive">{error}</Alert>
1496
+ )}
1497
+ </div>
1498
+ )
1499
+ }
1500
+ ```
1501
+
1502
+ **Alternative with specialized service (if you created CourseClientService):**
1503
+ ```tsx
1504
+ // OPTIONAL: If you have CourseClientService
1505
+ const program = Effect.gen(function* () {
1506
+ const courseService = yield* CourseClientService
1507
+ return yield* courseService.enrollUser(userId, courseId)
1508
+ })
1509
+ ```
1510
+
1511
+ ### Pattern: Composable Operations
1512
+
1513
+ ```tsx
1514
+ // frontend/src/components/CourseCreator.tsx
1515
+ import { useEffectRunner } from '@/hooks/useEffectRunner'
1516
+ import { ThingClientService } from '@/services/ThingClientService'
1517
+ import { ConnectionClientService } from '@/services/ConnectionClientService'
1518
+ import { Effect } from 'effect'
1519
+ import { useState } from 'react'
1520
+
1521
+ export function CourseCreator() {
1522
+ const { run, loading, error } = useEffectRunner()
1523
+ const [formData, setFormData] = useState({
1524
+ title: '',
1525
+ description: '',
1526
+ price: 0
1527
+ })
1528
+
1529
+ const handleSubmit = async (e: React.FormEvent) => {
1530
+ e.preventDefault()
1531
+
1532
+ // Define COMPLEX Effect program with ONLY generic services
1533
+ const program = Effect.gen(function* () {
1534
+ const thingService = yield* ThingClientService
1535
+ const connectionService = yield* ConnectionClientService
1536
+
1537
+ // 1. Create course (just a thing with type='course')
1538
+ const courseId = yield* thingService.create({
1539
+ type: 'course',
1540
+ name: formData.title,
1541
+ properties: {
1542
+ title: formData.title,
1543
+ description: formData.description,
1544
+ price: formData.price
1545
+ }
1546
+ })
1547
+
1548
+ // 2. Create default lesson (just a thing with type='lesson')
1549
+ const lessonId = yield* thingService.create({
1550
+ type: 'lesson',
1551
+ name: 'Introduction',
1552
+ properties: {
1553
+ content: 'Welcome to the course!'
1554
+ }
1555
+ })
1556
+
1557
+ // 3. Connect lesson to course (generic connection)
1558
+ yield* connectionService.create({
1559
+ fromThingId: lessonId,
1560
+ toThingId: courseId,
1561
+ relationshipType: 'part_of'
1562
+ })
1563
+
1564
+ // 4. Return course ID
1565
+ return courseId
1566
+ }).pipe(
1567
+ // Add retry logic
1568
+ Effect.retry({ times: 3 }),
1569
+ // Add timeout
1570
+ Effect.timeout('5 seconds'),
1571
+ // Handle specific errors
1572
+ Effect.catchTag('ThingCreateError', err =>
1573
+ Effect.fail(new Error(`Failed to create course: ${err.reason}`))
1574
+ )
1575
+ )
1576
+
1577
+ // Run the program
1578
+ const courseId = await run(program, {
1579
+ onSuccess: (id) => {
1580
+ window.location.href = `/courses/${id}`
1581
+ }
1582
+ })
1583
+ }
1584
+
1585
+ return (
1586
+ <form onSubmit={handleSubmit}>
1587
+ <input
1588
+ type="text"
1589
+ value={formData.title}
1590
+ onChange={(e) => setFormData({ ...formData, title: e.target.value })}
1591
+ placeholder="Course Title"
1592
+ />
1593
+
1594
+ <textarea
1595
+ value={formData.description}
1596
+ onChange={(e) => setFormData({ ...formData, description: e.target.value })}
1597
+ placeholder="Description"
1598
+ />
1599
+
1600
+ <input
1601
+ type="number"
1602
+ value={formData.price}
1603
+ onChange={(e) => setFormData({ ...formData, price: parseFloat(e.target.value) })}
1604
+ placeholder="Price"
1605
+ />
1606
+
1607
+ <button type="submit" disabled={loading}>
1608
+ {loading ? 'Creating...' : 'Create Course'}
1609
+ </button>
1610
+
1611
+ {error && <Alert variant="destructive">{error}</Alert>}
1612
+ </form>
1613
+ )
1614
+ }
1615
+ ```
1616
+
1617
+ **Key Point:** This handles courses, products, lessons, EVERYTHING with just 2 generic services. No specialized services needed.
1618
+
1619
+ ### Pattern: Parallel Data Fetching
1620
+
1621
+ ```tsx
1622
+ // frontend/src/components/CourseDashboard.tsx
1623
+ import { useEffect, useState } from 'react'
1624
+ import { useEffectRunner } from '@/hooks/useEffectRunner'
1625
+ import { ThingClientService } from '@/services/ThingClientService'
1626
+ import { ConnectionClientService } from '@/services/ConnectionClientService'
1627
+ import { Effect } from 'effect'
1628
+
1629
+ interface Props {
1630
+ courseId: string
1631
+ }
1632
+
1633
+ export function CourseDashboard({ courseId }: Props) {
1634
+ const { run, loading } = useEffectRunner()
1635
+ const [data, setData] = useState<any>(null)
1636
+
1637
+ useEffect(() => {
1638
+ // Fetch all data in parallel using GENERIC services
1639
+ const program = Effect.gen(function* () {
1640
+ const thingService = yield* ThingClientService
1641
+ const connectionService = yield* ConnectionClientService
1642
+
1643
+ // Parallel fetch (all run at once)
1644
+ // Course is just a thing, lessons are connected things
1645
+ const [course, lessons, enrollmentCount] = yield* Effect.all([
1646
+ thingService.get(courseId),
1647
+ connectionService.getRelated(courseId, 'part_of', 'to'),
1648
+ connectionService.getCount(courseId, 'enrolled_in')
1649
+ ], { concurrency: 'unbounded' })
1650
+
1651
+ return { course, lessons, enrollmentCount }
1652
+ })
1653
+
1654
+ run(program, {
1655
+ onSuccess: setData
1656
+ })
1657
+ }, [courseId])
1658
+
1659
+ if (loading) return <div>Loading...</div>
1660
+ if (!data) return <div>No data</div>
1661
+
1662
+ return (
1663
+ <div>
1664
+ <h1>{data.course.name}</h1>
1665
+ <p>{data.enrollmentCount} students enrolled</p>
1666
+
1667
+ <h2>Lessons</h2>
1668
+ {data.lessons.map((lesson: any) => (
1669
+ <div key={lesson._id}>{lesson.name}</div>
1670
+ ))}
1671
+ </div>
1672
+ )
1673
+ }
1674
+ ```
1675
+
1676
+ **This is where a specialized service provides value** - compare:
1677
+
1678
+ ```tsx
1679
+ // ❌ Without specialized service (3 separate operations)
1680
+ const [course, lessons, enrollmentCount] = yield* Effect.all([
1681
+ thingService.get(courseId),
1682
+ connectionService.getRelated(courseId, 'part_of', 'to'),
1683
+ connectionService.getCount(courseId, 'enrolled_in')
1684
+ ])
1685
+
1686
+ // ✅ With specialized service (cleaner, if you repeat this pattern)
1687
+ const data = yield* courseService.getCourseWithLessons(courseId)
1688
+ const count = yield* courseService.getEnrollmentCount(courseId)
1689
+ ```
1690
+
1691
+ But you only add `CourseClientService` **after** you repeat this pattern 3+ times.
1692
+
1693
+ ---
1694
+
1695
+ ### Summary: Generic vs Specialized Services
1696
+
1697
+ ```
1698
+ ┌─────────────────────────────────────────────────────────┐
1699
+ │ 66 Thing Types │
1700
+ │ course, lesson, product, video, post, comment, etc. │
1701
+ └──────────────────────┬──────────────────────────────────┘
1702
+ │
1703
+ ↓
1704
+ ┌─────────────────────────────────────────────────────────┐
1705
+ │ 2 GENERIC SERVICES (handle everything) │
1706
+ │ │
1707
+ │ ThingClientService: │
1708
+ │ - get(id) │
1709
+ │ - list(type, orgId) │
1710
+ │ - create({ type, name, properties }) │
1711
+ │ - update(id, updates) │
1712
+ │ - delete(id) │
1713
+ │ │
1714
+ │ ConnectionClientService: │
1715
+ │ - create({ fromThingId, toThingId, relationshipType })│
1716
+ │ - getRelated(thingId, relationshipType, direction) │
1717
+ │ - getCount(thingId, relationshipType) │
1718
+ │ - delete(connectionId) │
1719
+ └──────────────────────┬──────────────────────────────────┘
1720
+ │
1721
+ ↓
1722
+ ┌─────────────────────────────────────────────────────────┐
1723
+ │ SPECIALIZED SERVICES (optional, add as needed) │
1724
+ │ │
1725
+ │ CourseClientService (if you repeat patterns): │
1726
+ │ - getCourseWithLessons() → wraps 2 calls │
1727
+ │ - enrollUser() → clearer vocabulary │
1728
+ │ - getEnrollmentCount() → specific query │
1729
+ │ │
1730
+ │ Add specialized services ONLY when: │
1731
+ │ ✅ You repeat the same 2-3 step operation 3+ times │
1732
+ │ ✅ You want clearer domain vocabulary │
1733
+ │ ❌ Don't add upfront for all 66 types │
1734
+ └─────────────────────────────────────────────────────────┘
1735
+ ```
1736
+
1737
+ **Start with generic services. Add specialized services as patterns emerge.**
1738
+
1739
+ ---
1740
+
1741
+ ## Component Patterns
1742
+
1743
+ ### Pattern 1: Generic Card (Pure Presentation)
1744
+
1745
+ ```tsx
1746
+ // frontend/src/components/cards/ThingCard.tsx
1747
+ import { Card } from '@/components/ui/card'
1748
+ import { getThingConfig } from '@/ontology/config'
1749
+ import * as Icons from 'lucide-react'
1750
+
1751
+ interface ThingCardProps {
1752
+ thing: {
1753
+ _id: string
1754
+ type: string
1755
+ name: string
1756
+ properties: Record<string, any>
1757
+ }
1758
+ }
1759
+
1760
+ export function ThingCard({ thing }: ThingCardProps) {
1761
+ // Get UI config
1762
+ const config = getThingConfig(thing.type as any)
1763
+ const Icon = Icons[config.icon as keyof typeof Icons]
1764
+
1765
+ // Extract display values
1766
+ const title = thing.properties[config.primaryField] || thing.name
1767
+ const subtitle = config.secondaryField
1768
+ ? thing.properties[config.secondaryField]
1769
+ : null
1770
+ const image = config.imageField
1771
+ ? thing.properties[config.imageField]
1772
+ : null
1773
+
1774
+ // Pure presentation - NO logic
1775
+ return (
1776
+ <Card>
1777
+ {image && <img src={image} alt={title} />}
1778
+
1779
+ <div className="p-4">
1780
+ <div className="flex items-center gap-2">
1781
+ <Icon className="w-5 h-5" />
1782
+ <span>{config.displayName}</span>
1783
+ </div>
1784
+
1785
+ <h3 className="text-xl font-bold">{title}</h3>
1786
+ {subtitle && <p className="text-gray-600">{subtitle}</p>}
1787
+
1788
+ <a href={`/${thing.type}s/${thing._id}`}>
1789
+ <button>View Details</button>
1790
+ </a>
1791
+ </div>
1792
+ </Card>
1793
+ )
1794
+ }
1795
+ ```
1796
+
1797
+ **Key Points:**
1798
+ - ✅ Receives data as props
1799
+ - ✅ Uses UI config for display
1800
+ - ✅ Pure presentation logic
1801
+ - ❌ NO database calls
1802
+ - ❌ NO business logic
1803
+ - ❌ NO validation
1804
+
1805
+ ---
1806
+
1807
+ ## Page Patterns (SSR)
1808
+
1809
+ ### Pattern: Fetch from Backend, Render HTML
1810
+
1811
+ ```astro
1812
+ ---
1813
+ // frontend/src/pages/courses/[id].astro
1814
+ import { getConvexClient } from '@/lib/convex'
1815
+ import { api } from '@/lib/api'
1816
+ import Layout from '@/layouts/Layout.astro'
1817
+
1818
+ // SSR: Fetch data from backend via HTTP
1819
+ const convex = getConvexClient()
1820
+
1821
+ const course = await convex.query(api.queries.things.get, {
1822
+ id: Astro.params.id
1823
+ })
1824
+
1825
+ if (!course) {
1826
+ return Astro.redirect('/404')
1827
+ }
1828
+
1829
+ // Get related lessons from backend
1830
+ const lessons = await convex.query(api.queries.things.getRelated, {
1831
+ thingId: course._id,
1832
+ relationshipType: 'part_of',
1833
+ direction: 'to'
1834
+ })
1835
+ ---
1836
+
1837
+ <Layout title={course.name}>
1838
+ <!-- Static HTML rendered on server -->
1839
+ <header>
1840
+ <h1>{course.name}</h1>
1841
+ <p>{course.properties.description}</p>
1842
+ <span className="text-2xl">${course.properties.price}</span>
1843
+ </header>
1844
+
1845
+ <!-- Lessons list (static) -->
1846
+ <section>
1847
+ <h2>Lessons</h2>
1848
+ {lessons.map(lesson => (
1849
+ <div>
1850
+ <h3>{lesson.name}</h3>
1851
+ <p>{lesson.properties.content}</p>
1852
+ </div>
1853
+ ))}
1854
+ </section>
1855
+
1856
+ <!-- Interactive enrollment button (React Island) -->
1857
+ <EnrollButton client:load courseId={course._id} />
1858
+ </Layout>
1859
+ ```
1860
+
1861
+ **Key Points:**
1862
+ - ✅ Calls backend API to get data
1863
+ - ✅ Renders static HTML
1864
+ - ✅ Fast initial load (SSR)
1865
+ - ❌ NO database access
1866
+ - ❌ NO business logic in page
1867
+
1868
+ ---
1869
+
1870
+ ## Real-Time Components
1871
+
1872
+ ### Pattern: Subscribe to Backend Changes
1873
+
1874
+ ```tsx
1875
+ // frontend/src/components/LiveEnrollmentCount.tsx
1876
+ import { useQuery } from 'convex/react'
1877
+ import { api } from '@/lib/api'
1878
+
1879
+ export function LiveEnrollmentCount({ courseId }: Props) {
1880
+ // Real-time subscription to backend
1881
+ // When ANYONE enrolls, this updates EVERYWHERE instantly
1882
+ const count = useQuery(api.queries.connections.getCount, {
1883
+ toThingId: courseId,
1884
+ relationshipType: 'enrolled_in'
1885
+ })
1886
+
1887
+ if (count === undefined) return <div>Loading...</div>
1888
+
1889
+ return (
1890
+ <div>
1891
+ <span className="text-3xl font-bold">{count}</span>
1892
+ <span className="text-sm text-gray-600"> students enrolled</span>
1893
+ </div>
1894
+ )
1895
+ }
1896
+ ```
1897
+
1898
+ **How It Works:**
1899
+ 1. Component subscribes to backend query via WebSocket
1900
+ 2. Backend watches database for changes
1901
+ 3. When connection created → backend pushes update to frontend
1902
+ 4. Component auto-re-renders
1903
+ 5. **Frontend does NOTHING except display the number**
1904
+
1905
+ ---
1906
+
1907
+ ## Forms (Calls Backend)
1908
+
1909
+ ### Pattern: Collect Input, Send to Backend
1910
+
1911
+ ```tsx
1912
+ // frontend/src/components/forms/ThingForm.tsx
1913
+ import { useMutation } from 'convex/react'
1914
+ import { api } from '@/lib/api'
1915
+ import { getThingConfig } from '@/ontology/config'
1916
+ import { useState } from 'react'
1917
+
1918
+ interface ThingFormProps {
1919
+ type: ThingType
1920
+ onSuccess?: (id: string) => void
1921
+ }
1922
+
1923
+ export function ThingForm({ type, onSuccess }: ThingFormProps) {
1924
+ const config = getThingConfig(type)
1925
+ const [formData, setFormData] = useState({})
1926
+ const [error, setError] = useState<string | null>(null)
1927
+
1928
+ // Backend mutation (frontend just calls it)
1929
+ const createThing = useMutation(api.mutations.things.create)
1930
+
1931
+ const handleSubmit = async (e: React.FormEvent) => {
1932
+ e.preventDefault()
1933
+ setError(null)
1934
+
1935
+ try {
1936
+ // Send to backend - backend validates, creates, logs events
1937
+ const id = await createThing({
1938
+ type,
1939
+ name: formData[config.primaryField],
1940
+ properties: formData
1941
+ })
1942
+
1943
+ onSuccess?.(id)
1944
+ } catch (err) {
1945
+ // Display backend error
1946
+ setError(err.message)
1947
+ }
1948
+ }
1949
+
1950
+ return (
1951
+ <form onSubmit={handleSubmit}>
1952
+ {/* Form fields from UI config */}
1953
+ {Object.entries(config.fields).map(([field, fieldConfig]) => (
1954
+ <div key={field}>
1955
+ <label>{fieldConfig.label}</label>
1956
+ <input
1957
+ type={fieldConfig.type}
1958
+ value={formData[field] || ''}
1959
+ onChange={(e) => setFormData({ ...formData, [field]: e.target.value })}
1960
+ placeholder={fieldConfig.placeholder}
1961
+ required={fieldConfig.required}
1962
+ />
1963
+ </div>
1964
+ ))}
1965
+
1966
+ {error && <div className="text-red-600">{error}</div>}
1967
+
1968
+ <button type="submit">Create</button>
1969
+ </form>
1970
+ )
1971
+ }
1972
+ ```
1973
+
1974
+ **Key Points:**
1975
+ - ✅ Collects user input
1976
+ - ✅ Sends to backend mutation
1977
+ - ✅ Displays backend errors
1978
+ - ⚠️ Frontend validation is optional (UX only)
1979
+ - ❌ Backend MUST validate (security)
1980
+ - ❌ Frontend does NOT create database records
1981
+
1982
+ ---
1983
+
1984
+ ## Multi-Tenant Routing
1985
+
1986
+ ### Middleware: Extract Org from Subdomain
1987
+
1988
+ ```typescript
1989
+ // frontend/src/middleware.ts
1990
+ import { defineMiddleware } from 'astro:middleware'
1991
+ import { getConvexClient } from './lib/convex'
1992
+ import { api } from './lib/api'
1993
+
1994
+ export const onRequest = defineMiddleware(async (context, next) => {
1995
+ const url = new URL(context.request.url)
1996
+
1997
+ // Extract org slug from subdomain
1998
+ // fitnesspro.one.ie → "fitnesspro"
1999
+ const hostname = url.hostname
2000
+ const orgSlug = hostname.split('.')[0]
2001
+
2002
+ // Skip for main domains
2003
+ if (['api', 'www', 'localhost'].includes(orgSlug)) {
2004
+ return next()
2005
+ }
2006
+
2007
+ // Fetch org from backend
2008
+ const convex = getConvexClient()
2009
+ const org = await convex.query(api.queries.orgs.getBySlug, {
2010
+ slug: orgSlug
2011
+ })
2012
+
2013
+ if (org) {
2014
+ // Inject org context for pages to use
2015
+ context.locals.org = org
2016
+ context.locals.orgId = org._id
2017
+ }
2018
+
2019
+ return next()
2020
+ })
2021
+ ```
2022
+
2023
+ ### Use Org Context in Pages
2024
+
2025
+ ```astro
2026
+ ---
2027
+ // frontend/src/pages/courses/index.astro
2028
+ import { getConvexClient } from '@/lib/convex'
2029
+ import { api } from '@/lib/api'
2030
+
2031
+ // Get org from middleware
2032
+ const org = Astro.locals.org
2033
+
2034
+ if (!org) {
2035
+ return Astro.redirect('/404')
2036
+ }
2037
+
2038
+ // Fetch org's courses from backend
2039
+ const convex = getConvexClient()
2040
+ const courses = await convex.query(api.queries.things.list, {
2041
+ type: 'course',
2042
+ organizationId: org._id // Backend filters by org
2043
+ })
2044
+ ---
2045
+
2046
+ <Layout title={`${org.name} - Courses`}>
2047
+ <h1>{org.name} Courses</h1>
2048
+
2049
+ <!-- Display org's courses -->
2050
+ {courses.map(course => (
2051
+ <CourseCard thing={course} />
2052
+ ))}
2053
+ </Layout>
2054
+ ```
2055
+
2056
+ **Result:**
2057
+ - `fitnesspro.one.ie/courses` → FitnessPro courses only
2058
+ - `techcorp.one.ie/courses` → TechCorp courses only
2059
+ - **Backend enforces data isolation, frontend just passes orgId**
2060
+
2061
+ ---
2062
+
2063
+ ## Deployment
2064
+
2065
+ ### Frontend Deployment (Separate from Backend)
2066
+
2067
+ ```bash
2068
+ # Frontend (Astro)
2069
+ cd frontend
2070
+ npm run build
2071
+ # Deploy to Cloudflare Pages / Vercel / Netlify
2072
+
2073
+ # Backend (Convex - separate deployment)
2074
+ cd backend
2075
+ npx convex deploy
2076
+ # Deployed to shocking-falcon-870.convex.cloud
2077
+ ```
2078
+
2079
+ ### Environment Setup
2080
+
2081
+ ```bash
2082
+ # Frontend .env
2083
+ PUBLIC_CONVEX_URL=https://shocking-falcon-870.convex.cloud
2084
+
2085
+ # Frontend connects to this URL
2086
+ # Frontend NEVER deploys to Convex
2087
+ # Frontend is static site on Cloudflare Pages
2088
+ ```
2089
+
2090
+ ---
2091
+
2092
+ ## Summary
2093
+
2094
+ ### Frontend Responsibilities (ONLY These)
2095
+
2096
+ | What | How | Example |
2097
+ |------|-----|---------|
2098
+ | **Render UI** | Astro pages + React components | `<h1>{course.name}</h1>` |
2099
+ | **Call Backend** | Effect.ts services or Convex hooks | `yield* courseService.get(id)` or `useQuery(api.queries.things.list)` |
2100
+ | **Manage UI State** | `useState`, `useReducer`, `useEffectRunner` | `const { run, loading, error } = useEffectRunner()` |
2101
+ | **Route Users** | Astro routing, middleware | `/courses/[id].astro` |
2102
+ | **Display Errors** | Show typed backend errors | `Effect.catchTag('NotFoundError', ...)` |
2103
+
2104
+ ### Backend Responsibilities (See ontology-backend.md)
2105
+
2106
+ | What | Where | Example |
2107
+ |------|-------|---------|
2108
+ | **Database Operations** | Backend only | `ctx.db.query('things')...` |
2109
+ | **Business Logic** | Backend only | Calculate prices, check quotas |
2110
+ | **Data Validation** | Backend only | Validate email, check permissions |
2111
+ | **Event Logging** | Backend only | `ctx.db.insert('events', ...)` |
2112
+ | **Authorization** | Backend only | Check if user can access resource |
2113
+
2114
+ ### The Contract
2115
+
2116
+ ```typescript
2117
+ // Frontend → Backend (only way to interact)
2118
+
2119
+ // ✅ Frontend calls backend query
2120
+ const courses = useQuery(api.queries.things.list, { type: 'course' })
2121
+
2122
+ // ✅ Frontend calls backend mutation
2123
+ const create = useMutation(api.mutations.things.create)
2124
+ await create({ type: 'course', name: 'Fitness 101', properties: {...} })
2125
+
2126
+ // ✅ Backend implements logic
2127
+ export const create = mutation({
2128
+ handler: async (ctx, args) => {
2129
+ // Validate
2130
+ // Create in database
2131
+ // Log event
2132
+ // Return result
2133
+ }
2134
+ })
2135
+
2136
+ // ❌ Frontend NEVER accesses database directly
2137
+ const courses = await ctx.db.query('things') // IMPOSSIBLE in frontend
2138
+ ```
2139
+
2140
+ ### Key Principles
2141
+
2142
+ 1. **Separation:** Frontend renders, backend manages data
2143
+ 2. **Type-Safe:** Effect.ts enforces error handling, backend generates types
2144
+ 3. **Composability:** Effect.ts services combine into complex flows
2145
+ 4. **Real-Time:** WebSocket subscriptions auto-update UI
2146
+ 5. **Multi-Tenant:** Middleware extracts org → pages filter by org
2147
+ 6. **Testability:** Effect.ts test layers replace mocks
2148
+ 7. **Stateless:** Frontend has no state beyond UI, backend is source of truth
2149
+
2150
+ ### Next Steps
2151
+
2152
+ 1. **Setup Backend First** (see ontology-backend.md)
2153
+ 2. **Get Backend URL** from Convex deployment
2154
+ 3. **Create Frontend** with `npm create astro@latest`
2155
+ 4. **Install Effect.ts** - `npm install effect @effect/schema`
2156
+ 5. **Add Convex Client** and set `PUBLIC_CONVEX_URL`
2157
+ 6. **Create Client Services** (ThingClientService, CourseClientService, etc.)
2158
+ 7. **Build ClientLayer** with all service dependencies
2159
+ 8. **Create useEffectRunner Hook** for React integration
2160
+ 9. **Sync Types** from backend to frontend
2161
+ 10. **Build UI Config** for all 66 thing types
2162
+ 11. **Create Generic Components** (ThingCard, ThingList, ThingForm)
2163
+ 12. **Add Pages** that call backend via Effect.ts services
2164
+ 13. **Deploy Frontend** to Cloudflare Pages
2165
+
2166
+ ---
2167
+
2168
+ **Frontend is pure rendering. Backend is everything else.**
2169
+
2170
+ Effect.ts for type-safe composability. Separate deployments. Real-time updates.
2171
+
2172
+ ---
2173
+
2174
+ ## Additional Resources
2175
+
2176
+ ### Effect.ts Documentation
2177
+ - [Frontend Integration](../things/docs/effect/frontend.mdx) - React + Effect.ts patterns
2178
+ - [Testing](../things/docs/effect/testing.mdx) - Test layers and no-mock testing
2179
+ - [Effect.ts Official Docs](https://effect.website) - Complete Effect.ts guide
2180
+
2181
+ ### Related Guides
2182
+ - **ontology-backend.md** - Backend implementation (Convex + Effect.ts)
2183
+ - **ontology-documentation.md** - Complete ontology overview
2184
+ - **Ontology.md** - Full technical specification
2185
+
2186
+ ---
2187
+
2188
+ **END OF FRONTEND GUIDE**