oneie 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +245 -0
- package/CLAUDE.md +534 -0
- package/README.md +61 -4
- package/one/.obsidian/app.json +1 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/workspace.json +211 -0
- package/one/connections/a2a.md +551 -0
- package/one/connections/acp.md +761 -0
- package/one/connections/acps.md +731 -0
- package/one/connections/agui.md +767 -0
- package/one/connections/any-backend.md +1702 -0
- package/one/connections/ap2.md +998 -0
- package/one/connections/api-docs.md +1891 -0
- package/one/connections/api.md +2190 -0
- package/one/connections/architecture-diagram.md +94 -0
- package/one/connections/communications.md +449 -0
- package/one/connections/connections.md +339 -0
- package/one/connections/cryptonetworks.md +781 -0
- package/one/connections/documentation.md +1120 -0
- package/one/connections/effect.md +279 -0
- package/one/connections/elizaos.md +1290 -0
- package/one/connections/inference.md +58 -0
- package/one/connections/kyc.md +632 -0
- package/one/connections/mcp.md +842 -0
- package/one/connections/membership.md +1152 -0
- package/one/connections/middleware.md +1067 -0
- package/one/connections/multitenant.md +1341 -0
- package/one/connections/n8n.md +1015 -0
- package/one/connections/patterns.md +89 -0
- package/one/connections/protocols.md +279 -0
- package/one/connections/relationships.md +107 -0
- package/one/connections/schema.md +587 -0
- package/one/connections/service-layer.md +550 -0
- package/one/connections/structure.md +0 -0
- package/one/connections/vectors.md +207 -0
- package/one/connections/wordpress.md +1302 -0
- package/one/connections/workflow-copy.md +905 -0
- package/one/connections/workflow-examples.md +741 -0
- package/one/connections/workflow.md +905 -0
- package/one/connections/workflows/delegation.md +885 -0
- package/one/connections/workflows/frontend.md +1037 -0
- package/one/connections/workflows/strategy.md +903 -0
- package/one/connections/workflows/tasks.md +698 -0
- package/one/connections/x402.md +1249 -0
- package/one/events/events.md +545 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-diagram.md +94 -0
- package/one/knowledge/architecture-frontend.md +930 -0
- package/one/knowledge/architecture.md +2077 -0
- package/one/knowledge/crypto.md +960 -0
- package/one/knowledge/dsl.md +1660 -0
- package/one/knowledge/files.md +2471 -0
- package/one/knowledge/frontend.md +1038 -0
- package/one/knowledge/hono.md +2109 -0
- package/one/knowledge/implementation-examples.md +2536 -0
- package/one/knowledge/inference-score.md +159 -0
- package/one/knowledge/knowledge.md +642 -0
- package/one/knowledge/language.md +980 -0
- package/one/knowledge/lessons-learned.md +70 -0
- package/one/knowledge/ontology-6-dimensions.md +0 -0
- package/one/knowledge/ontology-documentation.md +356 -0
- package/one/knowledge/ontology-engineering-specification.md +1292 -0
- package/one/knowledge/ontology-engineering.md +1652 -0
- package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
- package/one/knowledge/ontology-frontend-copy.md +753 -0
- package/one/knowledge/ontology-frontend-specifications.md +2188 -0
- package/one/knowledge/ontology-frontend.md +2427 -0
- package/one/knowledge/ontology-minimal.yaml +299 -0
- package/one/knowledge/ontology.md +2819 -0
- package/one/knowledge/ontology.yaml +1165 -0
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
- package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
- package/one/knowledge/patterns/backend/mutation-template.md +231 -0
- package/one/knowledge/patterns/backend/query-template.md +267 -0
- package/one/knowledge/patterns/backend/service-template.md +237 -0
- package/one/knowledge/patterns/design/component-architecture.md +399 -0
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
- package/one/knowledge/patterns/design/wireframe-template.md +216 -0
- package/one/knowledge/patterns/frontend/component-template.md +195 -0
- package/one/knowledge/patterns/frontend/form-template.md +276 -0
- package/one/knowledge/patterns/frontend/page-template.md +178 -0
- package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
- package/one/knowledge/patterns/test/technical-test-template.md +544 -0
- package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
- package/one/knowledge/patterns/test/user-flow-template.md +254 -0
- package/one/knowledge/quality-loop.md +401 -0
- package/one/knowledge/readme.md +131 -0
- package/one/knowledge/rules.md +626 -0
- package/one/knowledge/score.md +67 -0
- package/one/knowledge/specifications.md +855 -0
- package/one/knowledge/tags.md +130 -0
- package/one/organisation/one.md +599 -0
- package/one/organisation/organisation.md +438 -0
- package/one/organisation/revenue.md +673 -0
- package/one/organisation/strategy.md +869 -0
- package/one/organisation/vision.md +98 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/repomix-output.md +92634 -0
- package/one/things/agentkit.md +349 -0
- package/one/things/agents/agent-backend.md +1401 -0
- package/one/things/agents/agent-builder.md +955 -0
- package/one/things/agents/agent-clean.md +709 -0
- package/one/things/agents/agent-clone.md +1341 -0
- package/one/things/agents/agent-designer.md +2177 -0
- package/one/things/agents/agent-director.md +1508 -0
- package/one/things/agents/agent-documenter.md +1049 -0
- package/one/things/agents/agent-frontend.md +1119 -0
- package/one/things/agents/agent-integrator.md +1192 -0
- package/one/things/agents/agent-problem-solver.md +1379 -0
- package/one/things/agents/agent-quality.md +1353 -0
- package/one/things/agents/agent-sales.md +986 -0
- package/one/things/cascade/cascade.yaml +464 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
- package/one/things/cascade/docs/examples/readme.md +222 -0
- package/one/things/cascade/docs/getting-started.md +515 -0
- package/one/things/cascade/docs/workflow.md +1372 -0
- package/one/things/cascade/readme.md +336 -0
- package/one/things/cascade/templates/feature-template.md +267 -0
- package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
- package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
- package/one/things/claude/agents/analyst.md +483 -0
- package/one/things/claude/agents/architect.md +480 -0
- package/one/things/claude/agents/brand-identity-specialist.md +513 -0
- package/one/things/claude/agents/bstp-token-strategist.md +667 -0
- package/one/things/claude/agents/builder-repo.md +489 -0
- package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
- package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
- package/one/things/claude/agents/company-bullstamp-character.md +587 -0
- package/one/things/claude/agents/company-bullstamp-community.md +292 -0
- package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
- package/one/things/claude/agents/company-bullstamp-token.md +292 -0
- package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
- package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
- package/one/things/claude/agents/content-calendar-planner.md +448 -0
- package/one/things/claude/agents/content-chapter-formatter.md +488 -0
- package/one/things/claude/agents/content-formatter.md +546 -0
- package/one/things/claude/agents/content-hook-specialist.md +462 -0
- package/one/things/claude/agents/content-image-formatter.md +535 -0
- package/one/things/claude/agents/content-introduction-formatter.md +485 -0
- package/one/things/claude/agents/content-multiplication-engine.md +556 -0
- package/one/things/claude/agents/content-playbook-writer.md +448 -0
- package/one/things/claude/agents/content-team-manager.md +622 -0
- package/one/things/claude/agents/content-toc-formatter.md +522 -0
- package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
- package/one/things/claude/agents/core-manager.md +582 -0
- package/one/things/claude/agents/core-master.md +403 -0
- package/one/things/claude/agents/cross-functional-manager.md +471 -0
- package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
- package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
- package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
- package/one/things/claude/agents/crypto-community-analyst.md +298 -0
- package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
- package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
- package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
- package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
- package/one/things/claude/agents/crypto-market-researcher.md +292 -0
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
- package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
- package/one/things/claude/agents/crypto-team-manager.md +387 -0
- package/one/things/claude/agents/crypto-token-analyst.md +278 -0
- package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
- package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
- package/one/things/claude/agents/customer-journey-designer.md +481 -0
- package/one/things/claude/agents/customer-success-manager.md +581 -0
- package/one/things/claude/agents/dev.md +413 -0
- package/one/things/claude/agents/documenter.md +546 -0
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
- package/one/things/claude/agents/engagement-specialist.md +509 -0
- package/one/things/claude/agents/engineering-architect.md +387 -0
- package/one/things/claude/agents/engineering-business-analyst.md +537 -0
- package/one/things/claude/agents/engineering-developer.md +387 -0
- package/one/things/claude/agents/engineering-director.md +282 -0
- package/one/things/claude/agents/engineering-ingestor.md +649 -0
- package/one/things/claude/agents/engineering-product-manager.md +537 -0
- package/one/things/claude/agents/engineering-product-owner.md +537 -0
- package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
- package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
- package/one/things/claude/agents/engineering-team-manager.md +512 -0
- package/one/things/claude/agents/engineering-user-experience.md +387 -0
- package/one/things/claude/agents/framework-elevate-manager.md +294 -0
- package/one/things/claude/agents/improver.md +763 -0
- package/one/things/claude/agents/intelligence-team-manager.md +385 -0
- package/one/things/claude/agents/lead-capture-expert.md +466 -0
- package/one/things/claude/agents/lead-magnet-creator.md +453 -0
- package/one/things/claude/agents/market-research-analyst.md +412 -0
- package/one/things/claude/agents/marketing-brand-identity.md +314 -0
- package/one/things/claude/agents/marketing-content-hooks.md +450 -0
- package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
- package/one/things/claude/agents/marketing-content-poster.md +361 -0
- package/one/things/claude/agents/marketing-customer-journey.md +326 -0
- package/one/things/claude/agents/marketing-director.md +397 -0
- package/one/things/claude/agents/marketing-engagement.md +326 -0
- package/one/things/claude/agents/marketing-lead-capture.md +326 -0
- package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
- package/one/things/claude/agents/marketing-network-effects.md +326 -0
- package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
- package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
- package/one/things/claude/agents/marketing-team-manager.md +446 -0
- package/one/things/claude/agents/marketing-viral-growth.md +201 -0
- package/one/things/claude/agents/mission-commander.md +373 -0
- package/one/things/claude/agents/network-effect-analyst.md +587 -0
- package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
- package/one/things/claude/agents/npx.md +890 -0
- package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
- package/one/things/claude/agents/one-master.md +355 -0
- package/one/things/claude/agents/one-orchestrator.md +315 -0
- package/one/things/claude/agents/one.md +601 -0
- package/one/things/claude/agents/playbook-generator.md +503 -0
- package/one/things/claude/agents/pm.md +326 -0
- package/one/things/claude/agents/po.md +345 -0
- package/one/things/claude/agents/qa.md +336 -0
- package/one/things/claude/agents/research-foundation-analyst.md +307 -0
- package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
- package/one/things/claude/agents/research-market-analyst.md +307 -0
- package/one/things/claude/agents/research-team-manager.md +482 -0
- package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
- package/one/things/claude/agents/sales-team-manager.md +400 -0
- package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
- package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
- package/one/things/claude/agents/service-advocacy-manager.md +307 -0
- package/one/things/claude/agents/service-success-manager.md +307 -0
- package/one/things/claude/agents/service-team-manager.md +400 -0
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
- package/one/things/claude/agents/share-optimization-specialist.md +551 -0
- package/one/things/claude/agents/sm.md +327 -0
- package/one/things/claude/agents/story-teller.md +473 -0
- package/one/things/claude/agents/task-master.md +596 -0
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
- package/one/things/claude/agents/tester.md +556 -0
- package/one/things/claude/agents/the-bull-character-manager.md +580 -0
- package/one/things/claude/agents/tools-playbook-generator.md +489 -0
- package/one/things/claude/agents/turbo-repo-builder.md +316 -0
- package/one/things/claude/agents/upsell-strategist.md +480 -0
- package/one/things/claude/agents/ux-expert.md +335 -0
- package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
- package/one/things/claude/claude-code-hooks-development.json +21 -0
- package/one/things/claude/claude-code-hooks-production.json +21 -0
- package/one/things/claude/claude-code-hooks.json +25 -0
- package/one/things/claude/commands/agent.md +104 -0
- package/one/things/claude/commands/cascade-status.md +128 -0
- package/one/things/claude/commands/ingest.md +290 -0
- package/one/things/claude/commands/ingestor.md +136 -0
- package/one/things/claude/commands/mission.md +83 -0
- package/one/things/claude/commands/npx.md +133 -0
- package/one/things/claude/commands/one.md +440 -0
- package/one/things/claude/commands/quality-check.md +204 -0
- package/one/things/claude/commands/smart-route.md +220 -0
- package/one/things/claude/commands/start.md +121 -0
- package/one/things/claude/commands/story.md +83 -0
- package/one/things/claude/commands/task.md +173 -0
- package/one/things/claude/hook-bypass.json +32 -0
- package/one/things/claude/hooks/agent-hook-config.json +427 -0
- package/one/things/claude/hooks/agent-hook-manager.js +525 -0
- package/one/things/claude/hooks/agent-load-balancer.js +271 -0
- package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
- package/one/things/claude/hooks/build-hook.sh +156 -0
- package/one/things/claude/hooks/cascade-feedback.js +297 -0
- package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
- package/one/things/claude/hooks/cleanup-hook.sh +201 -0
- package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
- package/one/things/claude/hooks/file-organization-engine.js +427 -0
- package/one/things/claude/hooks/file-organization-hook.sh +80 -0
- package/one/things/claude/hooks/file-organization-monitor.js +269 -0
- package/one/things/claude/hooks/format-hook.sh +43 -0
- package/one/things/claude/hooks/hook-bypass.sh +293 -0
- package/one/things/claude/hooks/hook-config-manager.js +202 -0
- package/one/things/claude/hooks/hook-debouncer.sh +62 -0
- package/one/things/claude/hooks/hook-logger.sh +89 -0
- package/one/things/claude/hooks/hook-orchestrator.js +662 -0
- package/one/things/claude/hooks/hook-performance-report.js +120 -0
- package/one/things/claude/hooks/lint-hook.sh +140 -0
- package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
- package/one/things/claude/hooks/memory-optimizer.js +510 -0
- package/one/things/claude/hooks/notification-hook.sh +204 -0
- package/one/things/claude/hooks/ontology-compliance.js +394 -0
- package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
- package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
- package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
- package/one/things/claude/hooks/performance-metrics.json +25 -0
- package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
- package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
- package/one/things/claude/hooks/security-hook.sh +256 -0
- package/one/things/claude/hooks/simple-load-balancer.js +238 -0
- package/one/things/claude/hooks/startup-optimizer.js +625 -0
- package/one/things/claude/hooks/story-scoring-system.js +445 -0
- package/one/things/claude/hooks/story-validation-engine.js +473 -0
- package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
- package/one/things/claude/hooks/story-validation-hook.sh +145 -0
- package/one/things/claude/hooks/structure-synchronizer.js +194 -0
- package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
- package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
- package/one/things/claude/hooks/test-hook.sh +145 -0
- package/one/things/claude/hooks/test-story-validation.sh +170 -0
- package/one/things/claude/hooks/trinity-validation-system.js +392 -0
- package/one/things/claude/settings-local.json +86 -0
- package/one/things/cli-code.md +652 -0
- package/one/things/cli-compiler-code.md +652 -0
- package/one/things/cli.md +1045 -0
- package/one/things/components/card-shadcn.md +929 -0
- package/one/things/components/card.md +1050 -0
- package/one/things/components.md +1669 -0
- package/one/things/componets.md +4 -0
- package/one/things/copilotkit.md +1559 -0
- package/one/things/creator-diagram.md +166 -0
- package/one/things/examples/children/lemonade-stand.md +366 -0
- package/one/things/examples/enterprise/crm-saas.md +1429 -0
- package/one/things/features/1-1-agent-prompts/design.md +470 -0
- package/one/things/features/1-1-agent-prompts/tests.md +264 -0
- package/one/things/features/1-1-agent-prompts.md +486 -0
- package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/features/1-2-yaml-orchestrator.md +516 -0
- package/one/things/features/1-3-event-coordination/design.md +544 -0
- package/one/things/features/1-3-event-coordination/tests.md +223 -0
- package/one/things/features/1-3-event-coordination.md +508 -0
- package/one/things/features/1-4-knowledge-management/design.md +609 -0
- package/one/things/features/1-4-knowledge-management/tests.md +195 -0
- package/one/things/features/1-4-knowledge-management.md +577 -0
- package/one/things/features/1-5-quality-loops/design.md +797 -0
- package/one/things/features/1-5-quality-loops/tests.md +212 -0
- package/one/things/features/1-5-quality-loops.md +641 -0
- package/one/things/features/1-6-numbering-structure/design.md +610 -0
- package/one/things/features/1-6-numbering-structure/tests.md +213 -0
- package/one/things/features/1-6-numbering-structure.md +575 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/plans/1-create-workflow-status.md +555 -0
- package/one/things/plans/1-create-workflow.md +713 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
- package/one/things/plans/better-auth-any-backend.md +1852 -0
- package/one/things/plans/better-auth-available-features.md +235 -0
- package/one/things/plans/big-plan.md +38 -0
- package/one/things/plans/convex-better-auth.md +1109 -0
- package/one/things/plans/convex-on-off.md +389 -0
- package/one/things/plans/desktop.md +1121 -0
- package/one/things/plans/effect-components.md +1669 -0
- package/one/things/plans/effect.md +973 -0
- package/one/things/plans/email.md +953 -0
- package/one/things/plans/enhance-auth.md +1669 -0
- package/one/things/plans/install-components.md +198 -0
- package/one/things/plans/landing.md +728 -0
- package/one/things/plans/layout.md +205 -0
- package/one/things/plans/mail-backend.md +1308 -0
- package/one/things/plans/mail.md +2624 -0
- package/one/things/plans/next-features.md +83 -0
- package/one/things/plans/one.md +658 -0
- package/one/things/plans/ontology-6-dimensions.md +2216 -0
- package/one/things/plans/ontology-driven-strategy.md +866 -0
- package/one/things/plans/ontology-ui-approach.md +357 -0
- package/one/things/plans/open-agent.md +785 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/releases.md +809 -0
- package/one/things/plans/repos.md +76 -0
- package/one/things/plans/separate-copy-2.md +1293 -0
- package/one/things/plans/separate-copy-3.md +2458 -0
- package/one/things/plans/separate-copy.md +1293 -0
- package/one/things/plans/separate.md +1983 -0
- package/one/things/plans/shadcn-integration-summary.md +450 -0
- package/one/things/plans/sidebar.md +172 -0
- package/one/things/plans/small-fixes.md +5 -0
- package/one/things/plans/test-backend-connection.md +476 -0
- package/one/things/plans/workflow-files.md +1196 -0
- package/one/things/plans/workflow.md +1372 -0
- package/one/things/products/cascade-landing-page.md +737 -0
- package/one/things/products/cascade.md +1518 -0
- package/one/things/products/context-engineering.md +1427 -0
- package/one/things/products/onthology.md +0 -0
- package/one/things/products/ontology-ui-shadcn.md +1280 -0
- package/one/things/products/ontology-ui.md +1387 -0
- package/one/things/products/ontology.md +717 -0
- package/one/things/products/sdk.md +557 -0
- package/one/things/promptkit.md +903 -0
- package/one/things/service-providers-new.md +982 -0
- package/one/things/service-providers.md +1092 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/package.json +5 -2
|
@@ -0,0 +1,2077 @@
|
|
|
1
|
+
# ONE Platform - System Architecture
|
|
2
|
+
|
|
3
|
+
**Version:** 2.0.0
|
|
4
|
+
**Purpose:** Explain the beautiful three-layer separation with Effect.ts as the glue layer
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🎯 The Beautiful Separation
|
|
9
|
+
|
|
10
|
+
This architecture achieves **perfect separation of concerns** with three distinct layers:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
14
|
+
│ LAYER 1: ASTRO FRONTEND │
|
|
15
|
+
│ Documentation: docs/Frontend.md │
|
|
16
|
+
├─────────────────────────────────────────────────────────────────────┤
|
|
17
|
+
│ ✅ User-customizable "vibe code" │
|
|
18
|
+
│ ✅ Islands architecture (static + selective hydration) │
|
|
19
|
+
│ ✅ Content collections (type-safe blog, docs, marketing) │
|
|
20
|
+
│ ✅ shadcn/ui components + Tailwind v4 │
|
|
21
|
+
│ ✅ Deployed to Cloudflare Pages (global edge SSR) │
|
|
22
|
+
│ │
|
|
23
|
+
│ Pages (.astro) React Islands Content Collections │
|
|
24
|
+
│ ├─ SEO-optimized ├─ Interactive UI ├─ Type-safe schemas │
|
|
25
|
+
│ ├─ Fast load ├─ Real-time data ├─ References │
|
|
26
|
+
│ └─ Static gen └─ Convex hooks └─ Search/filter │
|
|
27
|
+
└──────────────────┬──────────────────────────────────────────────────┘
|
|
28
|
+
│
|
|
29
|
+
│ Convex hooks (useQuery, useMutation)
|
|
30
|
+
│ Hono API client (REST for mutations)
|
|
31
|
+
↓
|
|
32
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
33
|
+
│ LAYER 2: EFFECT.TS GLUE LAYER (100% Coverage) │
|
|
34
|
+
│ Documentation: docs/Hono.md + docs/Architecture.md │
|
|
35
|
+
├─────────────────────────────────────────────────────────────────────┤
|
|
36
|
+
│ ✅ ALL business logic (pure functional programming) │
|
|
37
|
+
│ ✅ Service providers for external APIs │
|
|
38
|
+
│ ✅ Typed errors throughout (no try/catch) │
|
|
39
|
+
│ ✅ Automatic dependency injection │
|
|
40
|
+
│ ✅ Built-in retry, timeout, resource management │
|
|
41
|
+
│ │
|
|
42
|
+
│ Services Providers Layers │
|
|
43
|
+
│ ├─ TokenService ├─ StripeProvider ├─ MainLayer │
|
|
44
|
+
│ ├─ AgentService ├─ SuiProvider ├─ TestLayer │
|
|
45
|
+
│ ├─ ContentService ├─ OpenAIProvider ├─ DevLayer │
|
|
46
|
+
│ └─ 100% Effect.ts └─ ResendProvider └─ DI automatic │
|
|
47
|
+
└──────────────────┬──────────────────────────────────────────────────┘
|
|
48
|
+
│
|
|
49
|
+
│ Confect bridge (Effect.ts ↔ Convex)
|
|
50
|
+
│ Hono routes (Effect.ts ↔ HTTP)
|
|
51
|
+
↓
|
|
52
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
53
|
+
│ LAYER 3: BACKEND (Hono + Convex) │
|
|
54
|
+
│ Documentation: docs/Hono.md │
|
|
55
|
+
├─────────────────────────────────────────────────────────────────────┤
|
|
56
|
+
│ ✅ Hono: REST API routes (Cloudflare Workers) │
|
|
57
|
+
│ ✅ Convex: Real-time database + typed functions │
|
|
58
|
+
│ ✅ Better Auth: Authentication with Convex adapter │
|
|
59
|
+
│ ✅ 6-Dimension Ontology: Reality-aware data model │
|
|
60
|
+
│ │
|
|
61
|
+
│ Hono API Routes Convex Functions 6-Dimension Ontology │
|
|
62
|
+
│ ├─ /api/auth/* ├─ Queries (reads) ├─ organizations │
|
|
63
|
+
│ ├─ /api/tokens/* ├─ Mutations (writes) ├─ people │
|
|
64
|
+
│ ├─ /api/agents/* ├─ Actions (external) ├─ things (entities) │
|
|
65
|
+
│ └─ /api/content/* └─ Real-time subs ├─ connections │
|
|
66
|
+
│ ├─ events │
|
|
67
|
+
│ └─ knowledge │
|
|
68
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 🔑 Key Architectural Decisions
|
|
72
|
+
|
|
73
|
+
### 1. Effect.ts as the Glue Layer (100% Coverage)
|
|
74
|
+
|
|
75
|
+
**Decision:** ALL business logic uses Effect.ts (no raw async/await)
|
|
76
|
+
|
|
77
|
+
**Why:**
|
|
78
|
+
- **Consistency:** Same patterns across entire codebase
|
|
79
|
+
- **Type Safety:** Errors are explicit in type signatures
|
|
80
|
+
- **Composability:** Services combine cleanly without callback hell
|
|
81
|
+
- **Testability:** Easy to mock dependencies via layers
|
|
82
|
+
- **Observability:** Built-in tracing, logging, metrics
|
|
83
|
+
|
|
84
|
+
**Example:**
|
|
85
|
+
```typescript
|
|
86
|
+
// ❌ WRONG: Raw async/await in business logic
|
|
87
|
+
export const purchaseTokens = mutation({
|
|
88
|
+
handler: async (ctx, args) => {
|
|
89
|
+
try {
|
|
90
|
+
const payment = await stripe.charge(args.amount);
|
|
91
|
+
const tokens = await blockchain.mint(args.tokenId);
|
|
92
|
+
await ctx.db.insert("events", { /* ... */ });
|
|
93
|
+
return { success: true };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new Error("Purchase failed");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// ✅ CORRECT: 100% Effect.ts
|
|
101
|
+
export const purchaseTokens = confect.mutation({
|
|
102
|
+
handler: (ctx, args) =>
|
|
103
|
+
Effect.gen(function* () {
|
|
104
|
+
const tokenService = yield* TokenService;
|
|
105
|
+
return yield* tokenService.purchase(args);
|
|
106
|
+
}).pipe(Effect.provide(MainLayer))
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Business logic in pure Effect service
|
|
110
|
+
export class TokenService extends Effect.Service<TokenService>()(
|
|
111
|
+
"TokenService",
|
|
112
|
+
{
|
|
113
|
+
effect: Effect.gen(function* () {
|
|
114
|
+
const stripe = yield* StripeProvider;
|
|
115
|
+
const blockchain = yield* BlockchainProvider;
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
purchase: (args) =>
|
|
119
|
+
Effect.gen(function* () {
|
|
120
|
+
const payment = yield* stripe.charge(args.amount);
|
|
121
|
+
const tokens = yield* blockchain.mint(args.tokenId);
|
|
122
|
+
return { success: true, payment, tokens };
|
|
123
|
+
}).pipe(
|
|
124
|
+
Effect.retry({ times: 3 }),
|
|
125
|
+
Effect.timeout("30 seconds"),
|
|
126
|
+
Effect.onError((e) => /* automatic rollback */)
|
|
127
|
+
)
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
dependencies: [StripeProvider.Default, BlockchainProvider.Default]
|
|
131
|
+
}
|
|
132
|
+
) {}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 2. Hono for API Backend Separation
|
|
136
|
+
|
|
137
|
+
**Decision:** Separate Hono API backend from Astro frontend
|
|
138
|
+
|
|
139
|
+
**Why:**
|
|
140
|
+
- **Multi-Tenancy:** Different orgs can customize frontend while sharing backend
|
|
141
|
+
- **API Portability:** Backend logic reusable across web, mobile, desktop
|
|
142
|
+
- **Clear Contracts:** REST API endpoints define clear boundaries
|
|
143
|
+
- **Independent Deployment:** Deploy frontend and backend separately
|
|
144
|
+
- **Team Specialization:** Frontend devs work on UI, backend devs work on logic
|
|
145
|
+
|
|
146
|
+
**Workflow:**
|
|
147
|
+
```
|
|
148
|
+
User clicks "Buy Tokens"
|
|
149
|
+
↓
|
|
150
|
+
React component calls Hono API (POST /api/tokens/purchase)
|
|
151
|
+
↓
|
|
152
|
+
Hono route validates session (Better Auth)
|
|
153
|
+
↓
|
|
154
|
+
Effect.ts service processes business logic
|
|
155
|
+
↓
|
|
156
|
+
Service calls Convex mutation via ConvexHttpClient
|
|
157
|
+
↓
|
|
158
|
+
Convex updates entities/events tables
|
|
159
|
+
↓
|
|
160
|
+
Convex real-time subscription pushes update to UI
|
|
161
|
+
↓
|
|
162
|
+
Component re-renders with new balance ✅
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 3. Dual Integration Pattern (Frontend)
|
|
166
|
+
|
|
167
|
+
**Decision:** Convex hooks for queries, Hono API for mutations
|
|
168
|
+
|
|
169
|
+
**Why:**
|
|
170
|
+
- **Real-Time Data:** Convex hooks provide live subscriptions
|
|
171
|
+
- **Business Logic:** Hono API handles complex validation, payments, external APIs
|
|
172
|
+
- **Best of Both:** Real-time updates + robust backend processing
|
|
173
|
+
|
|
174
|
+
**Example:**
|
|
175
|
+
```typescript
|
|
176
|
+
// src/components/TokenPurchase.tsx
|
|
177
|
+
export function TokenPurchase({ tokenId }) {
|
|
178
|
+
// Real-time data via Convex hook
|
|
179
|
+
const token = useQuery(api.queries.tokens.get, { id: tokenId });
|
|
180
|
+
|
|
181
|
+
// Purchase via Hono API (handles validation, payment, etc.)
|
|
182
|
+
const handlePurchase = async () => {
|
|
183
|
+
const result = await honoApi.purchaseTokens(tokenId, 100);
|
|
184
|
+
// Convex subscription automatically updates balance!
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div>
|
|
189
|
+
<p>Balance: {token?.properties.balance || 0}</p>
|
|
190
|
+
<Button onClick={handlePurchase}>Buy 100 Tokens</Button>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## System Overview
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
200
|
+
│ USER'S BROWSER │
|
|
201
|
+
├─────────────────────────────────────────────────────────────────────┤
|
|
202
|
+
│ Astro Pages (SSR) React Components (Islands) │
|
|
203
|
+
│ ├─ SEO-optimized ├─ Interactive UI │
|
|
204
|
+
│ ├─ Fast initial load ├─ Real-time updates │
|
|
205
|
+
│ └─ Static generation └─ Client hydration │
|
|
206
|
+
└──────────────────┬──────────────────────────┬────────────────────────┘
|
|
207
|
+
│ │
|
|
208
|
+
↓ ↓
|
|
209
|
+
┌───────────────┐ ┌──────────────┐
|
|
210
|
+
│ Convex Hooks │ │ Hono API │
|
|
211
|
+
│ useQuery │ │ Client │
|
|
212
|
+
│ useMutation │ │ REST calls │
|
|
213
|
+
└───────┬───────┘ └──────┬───────┘
|
|
214
|
+
│ │
|
|
215
|
+
↓ ↓
|
|
216
|
+
┌───────────────────────────────────────┐
|
|
217
|
+
│ EFFECT.TS GLUE LAYER │
|
|
218
|
+
│ - Services (business logic) │
|
|
219
|
+
│ - Providers (external APIs) │
|
|
220
|
+
│ - Layers (dependency injection) │
|
|
221
|
+
└───────┬───────────────────────────────┘
|
|
222
|
+
│
|
|
223
|
+
├──────────────────┬──────────────┐
|
|
224
|
+
↓ ↓ ↓
|
|
225
|
+
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
226
|
+
│ HONO API │ │ CONVEX │ │ EXTERNAL │
|
|
227
|
+
│ /api/auth/* │ │ Real-time DB │ │ PROVIDERS │
|
|
228
|
+
│ /api/tokens/*│ │ Functions │ │ Stripe, etc. │
|
|
229
|
+
└──────────────┘ └──────────────┘ └──────────────┘
|
|
230
|
+
│
|
|
231
|
+
↓
|
|
232
|
+
┌───────────────┐
|
|
233
|
+
│ Confect │ ← Bridge Layer (Convex ↔ Effect)
|
|
234
|
+
│ (E→C Bridge) │
|
|
235
|
+
└───────┬───────┘
|
|
236
|
+
│
|
|
237
|
+
↓
|
|
238
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
239
|
+
│ EFFECT.TS SERVICE LAYER (100% Coverage) │
|
|
240
|
+
├─────────────────────────────────────────────────────────────────────┤
|
|
241
|
+
│ ALL Business Logic (Pure Functional Programming) │
|
|
242
|
+
│ ├─ AICloneService ├─ TokenService ├─ CourseService │
|
|
243
|
+
│ ├─ AgentOrchestrator ├─ CommunityService ├─ AnalyticsService │
|
|
244
|
+
│ ├─ PaymentService ├─ LivestreamService ├─ ReferralService │
|
|
245
|
+
│ ├─ NotificationService ├─ MetricsService ├─ WebsiteService │
|
|
246
|
+
│ └─ All services compose, errors typed, DI automatic, retry/timeout │
|
|
247
|
+
└──────────────────┬──────────────────────────────────────────────────┘
|
|
248
|
+
│
|
|
249
|
+
├─────────────────────────┬────────────────────────┐
|
|
250
|
+
│ │ │
|
|
251
|
+
↓ ↓ ↓
|
|
252
|
+
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
|
|
253
|
+
│ External Providers│ │ Blockchain (3x) │ │ Payments │
|
|
254
|
+
│ ├─ OpenAI │ │ ├─ SuiProvider │ │ ├─ Stripe (FIAT) │
|
|
255
|
+
│ ├─ ElevenLabs │ │ ├─ BaseProvider │ │ └─ Crypto via │
|
|
256
|
+
│ ├─ D-ID │ │ ├─ SolanaProvider│ │ blockchain │
|
|
257
|
+
│ ├─ HeyGen │ │ └─ Alchemy (RPC) │ └──────────────────┘
|
|
258
|
+
│ ├─ Resend │ └──────────────────┘
|
|
259
|
+
│ ├─ SendGrid │ ┌──────────────────┐
|
|
260
|
+
│ ├─ Twilio │ │ Infrastructure │
|
|
261
|
+
│ ├─ AWS │ │ ├─ Cloudflare │
|
|
262
|
+
│ └─ Cloudflare │ │ │ (Livestream) │
|
|
263
|
+
│ (Livestream) │ │ └─ AWS (Storage) │
|
|
264
|
+
└──────────────────┘ └──────────────────┘
|
|
265
|
+
│
|
|
266
|
+
↓
|
|
267
|
+
┌───────────────────────────┐
|
|
268
|
+
│ 6-Dimension Ontology │
|
|
269
|
+
│ (Plain Convex Schema) │
|
|
270
|
+
│ ├─ organizations │
|
|
271
|
+
│ ├─ people (via things) │
|
|
272
|
+
│ ├─ things (66 types) │
|
|
273
|
+
│ ├─ connections (25 types)│
|
|
274
|
+
│ ├─ events (67 types) │
|
|
275
|
+
│ └─ knowledge │
|
|
276
|
+
│ │
|
|
277
|
+
│ NO Convex Ents │
|
|
278
|
+
│ Direct DB access │
|
|
279
|
+
└───────────────────────────┘
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Layer Responsibilities
|
|
285
|
+
|
|
286
|
+
### Layer 1: Frontend (Astro + React)
|
|
287
|
+
|
|
288
|
+
**Astro's Role:**
|
|
289
|
+
- Server-side render pages for SEO and performance
|
|
290
|
+
- Generate static HTML where possible
|
|
291
|
+
- Route requests to correct pages
|
|
292
|
+
- Provide data to React islands via props
|
|
293
|
+
|
|
294
|
+
**React's Role:**
|
|
295
|
+
- Interactive components only (not the whole page)
|
|
296
|
+
- Real-time UI updates via Convex subscriptions
|
|
297
|
+
- Form handling and user interactions
|
|
298
|
+
- Client-side state management
|
|
299
|
+
|
|
300
|
+
**Why This Split:**
|
|
301
|
+
```typescript
|
|
302
|
+
// ✅ CORRECT: Astro SSR with React island
|
|
303
|
+
---
|
|
304
|
+
// Astro (server-side)
|
|
305
|
+
const creator = await convex.query(api.creators.get, { id });
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
<Layout>
|
|
309
|
+
<h1>{creator.name}</h1> <!-- Astro renders -->
|
|
310
|
+
<CreatorChat client:load creatorId={id} /> <!-- React hydrates -->
|
|
311
|
+
</Layout>
|
|
312
|
+
|
|
313
|
+
// ❌ WRONG: All React (loses SSR benefits)
|
|
314
|
+
export default function Page() {
|
|
315
|
+
const creator = useQuery(api.creators.get, { id });
|
|
316
|
+
// Everything client-side, slow initial load, bad SEO
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Key Principle:** Astro for content, React for interactivity.
|
|
321
|
+
|
|
322
|
+
### Layer 2: Convex Backend
|
|
323
|
+
|
|
324
|
+
**Three Function Types:**
|
|
325
|
+
|
|
326
|
+
**Queries (Read):**
|
|
327
|
+
```typescript
|
|
328
|
+
export const get = query({
|
|
329
|
+
args: { id: v.id("entities") },
|
|
330
|
+
handler: async (ctx, args) => {
|
|
331
|
+
return await ctx.db.get(args.id);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
- Read-only
|
|
336
|
+
- Automatically cached
|
|
337
|
+
- Real-time subscriptions
|
|
338
|
+
- Can run in parallel
|
|
339
|
+
|
|
340
|
+
**Mutations (Write):**
|
|
341
|
+
```typescript
|
|
342
|
+
export const update = mutation({
|
|
343
|
+
args: { id: v.id("entities"), name: v.string() },
|
|
344
|
+
handler: async (ctx, args) => {
|
|
345
|
+
await ctx.db.patch(args.id, { name: args.name });
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
- Write operations
|
|
350
|
+
- Transactional (all-or-nothing)
|
|
351
|
+
- Optimistic UI updates
|
|
352
|
+
- Validated with Convex validators
|
|
353
|
+
|
|
354
|
+
**Actions (External APIs):**
|
|
355
|
+
```typescript
|
|
356
|
+
export const cloneVoice = action({
|
|
357
|
+
args: { samples: v.array(v.string()) },
|
|
358
|
+
handler: async (ctx, args) => {
|
|
359
|
+
const result = await elevenLabs.cloneVoice(args.samples);
|
|
360
|
+
return result.voiceId;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
- Call external services (OpenAI, Stripe, etc.)
|
|
365
|
+
- Can call mutations/queries
|
|
366
|
+
- Not transactional
|
|
367
|
+
- Can be long-running
|
|
368
|
+
|
|
369
|
+
**Why Convex:**
|
|
370
|
+
- Real-time by default (no websockets to manage)
|
|
371
|
+
- Automatic caching and optimization
|
|
372
|
+
- Edge deployment (fast globally)
|
|
373
|
+
- Built-in auth and file storage
|
|
374
|
+
- TypeScript-first
|
|
375
|
+
|
|
376
|
+
### Layer 3: Effect.ts Service Layer (100% Coverage)
|
|
377
|
+
|
|
378
|
+
**This is where ALL business logic lives.**
|
|
379
|
+
|
|
380
|
+
**CRITICAL: Effect.ts is used for 100% of business logic** - not just complex flows:
|
|
381
|
+
- Every service is an Effect.ts service
|
|
382
|
+
- Every business operation is an Effect pipeline
|
|
383
|
+
- Every external API call goes through Effect providers
|
|
384
|
+
- NO raw async/await in business logic
|
|
385
|
+
- NO try/catch blocks (errors are typed)
|
|
386
|
+
- NO imperative state management
|
|
387
|
+
|
|
388
|
+
Effect.ts is a functional programming library that makes code:
|
|
389
|
+
1. **Predictable** - Same input always produces same output
|
|
390
|
+
2. **Composable** - Small functions combine into larger ones
|
|
391
|
+
3. **Typed** - Errors are explicit in the type system
|
|
392
|
+
4. **Testable** - Dependencies can be mocked easily
|
|
393
|
+
5. **Observable** - Built-in tracing and logging
|
|
394
|
+
|
|
395
|
+
**100% Effect.ts Coverage Means:**
|
|
396
|
+
```typescript
|
|
397
|
+
// ❌ WRONG: Direct async/await in business logic
|
|
398
|
+
export const createToken = mutation({
|
|
399
|
+
handler: async (ctx, args) => {
|
|
400
|
+
try {
|
|
401
|
+
const result = await fetch("https://api.blockchain.com/mint");
|
|
402
|
+
const token = await ctx.db.insert("entities", { ...result });
|
|
403
|
+
return token;
|
|
404
|
+
} catch (error) {
|
|
405
|
+
throw new Error("Failed to create token");
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// ✅ CORRECT: Everything through Effect.ts
|
|
411
|
+
export const createToken = confect.mutation({
|
|
412
|
+
handler: (ctx, args) =>
|
|
413
|
+
Effect.gen(function* () {
|
|
414
|
+
const tokenService = yield* TokenService;
|
|
415
|
+
return yield* tokenService.create(args);
|
|
416
|
+
}).pipe(Effect.provide(MainLayer))
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// Business logic in pure Effect service
|
|
420
|
+
export class TokenService extends Effect.Service<TokenService>()("TokenService", {
|
|
421
|
+
effect: Effect.gen(function* () {
|
|
422
|
+
const db = yield* ConvexDatabase;
|
|
423
|
+
const blockchain = yield* BlockchainProvider;
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
create: (args) =>
|
|
427
|
+
Effect.gen(function* () {
|
|
428
|
+
const result = yield* blockchain.mint(args);
|
|
429
|
+
const token = yield* db.insert("entities", {
|
|
430
|
+
entityType: "token",
|
|
431
|
+
metadata: result,
|
|
432
|
+
});
|
|
433
|
+
return token;
|
|
434
|
+
}).pipe(
|
|
435
|
+
Effect.retry({ times: 3, schedule: Schedule.exponential("100 millis") }),
|
|
436
|
+
Effect.timeout("30 seconds"),
|
|
437
|
+
Effect.catchTags({
|
|
438
|
+
BlockchainError: (e) => Effect.fail(new TokenCreationError(e)),
|
|
439
|
+
DatabaseError: (e) => Effect.fail(new TokenCreationError(e)),
|
|
440
|
+
})
|
|
441
|
+
)
|
|
442
|
+
};
|
|
443
|
+
}),
|
|
444
|
+
}) {}
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
**Why 100% Effect.ts:**
|
|
448
|
+
- AI generates consistent patterns across entire codebase
|
|
449
|
+
- No mixing of error handling styles (typed vs try/catch)
|
|
450
|
+
- All dependencies visible in type signatures
|
|
451
|
+
- Automatic retry, timeout, resource management everywhere
|
|
452
|
+
- Testing is uniform (always mock Effect services)
|
|
453
|
+
- Observability built-in (traces, logs, metrics)
|
|
454
|
+
|
|
455
|
+
**Example Service:**
|
|
456
|
+
```typescript
|
|
457
|
+
export class AICloneService extends Effect.Service<AICloneService>()(
|
|
458
|
+
"AICloneService",
|
|
459
|
+
{
|
|
460
|
+
effect: Effect.gen(function* () {
|
|
461
|
+
// Dependencies injected automatically
|
|
462
|
+
const db = yield* ConvexDatabase;
|
|
463
|
+
const elevenlabs = yield* ElevenLabsProvider;
|
|
464
|
+
const openai = yield* OpenAIProvider;
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
createClone: (creatorId: Id<"entities">) =>
|
|
468
|
+
Effect.gen(function* () {
|
|
469
|
+
// Business logic here
|
|
470
|
+
// Every step is explicit
|
|
471
|
+
// Every error is typed
|
|
472
|
+
const content = yield* db.getCreatorContent(creatorId);
|
|
473
|
+
const voiceId = yield* elevenlabs.cloneVoice(content.samples);
|
|
474
|
+
const personality = yield* openai.extractPersonality(content.text);
|
|
475
|
+
|
|
476
|
+
return { voiceId, personality };
|
|
477
|
+
}).pipe(
|
|
478
|
+
// Composition: add retry, timeout, error handling
|
|
479
|
+
Effect.retry({ times: 3 }),
|
|
480
|
+
Effect.timeout("5 minutes"),
|
|
481
|
+
Effect.catchTag("VoiceCloneError", handleError)
|
|
482
|
+
)
|
|
483
|
+
};
|
|
484
|
+
}),
|
|
485
|
+
dependencies: [ConvexDatabase.Default, ElevenLabsProvider.Default, OpenAIProvider.Default]
|
|
486
|
+
}
|
|
487
|
+
) {}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Why Effect.ts:**
|
|
491
|
+
- Business logic separated from Convex infrastructure
|
|
492
|
+
- Services compose cleanly (no callback hell)
|
|
493
|
+
- Errors are in the type signature (no silent failures)
|
|
494
|
+
- Easy to test (mock dependencies)
|
|
495
|
+
- Built-in retry, timeout, resource management
|
|
496
|
+
|
|
497
|
+
### Layer 4: Confect Bridge
|
|
498
|
+
|
|
499
|
+
Connects Effect.ts ↔ Convex:
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
// Regular Convex mutation
|
|
503
|
+
export const purchaseTokens = mutation({
|
|
504
|
+
handler: async (ctx, args) => {
|
|
505
|
+
// Lots of try/catch, manual error handling
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// Confect mutation (Effect.ts wrapper)
|
|
510
|
+
export const purchaseTokens = confect.mutation({
|
|
511
|
+
handler: (ctx, args) =>
|
|
512
|
+
Effect.gen(function* () {
|
|
513
|
+
const tokenService = yield* TokenService;
|
|
514
|
+
return yield* tokenService.purchase(args);
|
|
515
|
+
}).pipe(Effect.provide(MainLayer))
|
|
516
|
+
});
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
**Confect provides:**
|
|
520
|
+
- Automatic conversion of Convex context to Effect services
|
|
521
|
+
- Error handling (Convex errors → Effect errors)
|
|
522
|
+
- Type safety across the boundary
|
|
523
|
+
|
|
524
|
+
### Layer 4.5: DataProvider Interface (Backend-Agnostic)
|
|
525
|
+
|
|
526
|
+
**The Universal Ontology API**
|
|
527
|
+
|
|
528
|
+
The frontend communicates with ANY backend through the DataProvider interface. This makes the platform truly backend-agnostic—swap Convex for WordPress, Supabase, or Notion by changing ONE line.
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
// frontend/src/providers/DataProvider.ts
|
|
532
|
+
import { Effect } from 'effect'
|
|
533
|
+
|
|
534
|
+
// DataProvider interface (every backend must implement this)
|
|
535
|
+
export interface DataProvider {
|
|
536
|
+
// Dimension 1: Organizations operations
|
|
537
|
+
organizations: {
|
|
538
|
+
get: (id: string) => Effect.Effect<Organization, OrganizationNotFoundError>
|
|
539
|
+
list: (params: {
|
|
540
|
+
status?: 'active' | 'suspended' | 'trial' | 'cancelled'
|
|
541
|
+
limit?: number
|
|
542
|
+
}) => Effect.Effect<Organization[], Error>
|
|
543
|
+
update: (id: string, updates: Partial<Organization>) => Effect.Effect<void, Error>
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Dimension 2: People operations
|
|
547
|
+
people: {
|
|
548
|
+
get: (id: string) => Effect.Effect<Person, PersonNotFoundError | UnauthorizedError>
|
|
549
|
+
list: (params: {
|
|
550
|
+
organizationId?: string
|
|
551
|
+
role?: 'platform_owner' | 'org_owner' | 'org_user' | 'customer'
|
|
552
|
+
filters?: Record<string, any>
|
|
553
|
+
limit?: number
|
|
554
|
+
}) => Effect.Effect<Person[], Error>
|
|
555
|
+
create: (input: {
|
|
556
|
+
email: string
|
|
557
|
+
displayName: string
|
|
558
|
+
role: string
|
|
559
|
+
organizationId: string
|
|
560
|
+
password?: string
|
|
561
|
+
}) => Effect.Effect<string, PersonCreateError>
|
|
562
|
+
update: (id: string, updates: Partial<Person>) => Effect.Effect<void, Error>
|
|
563
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// Dimension 3: Things operations
|
|
567
|
+
things: {
|
|
568
|
+
get: (id: string) => Effect.Effect<Thing, ThingNotFoundError | UnauthorizedError>
|
|
569
|
+
list: (params: {
|
|
570
|
+
type: ThingType
|
|
571
|
+
organizationId?: string
|
|
572
|
+
filters?: Record<string, any>
|
|
573
|
+
limit?: number
|
|
574
|
+
}) => Effect.Effect<Thing[], Error>
|
|
575
|
+
create: (input: {
|
|
576
|
+
type: ThingType
|
|
577
|
+
name: string
|
|
578
|
+
organizationId: string
|
|
579
|
+
properties: Record<string, any>
|
|
580
|
+
}) => Effect.Effect<string, Error>
|
|
581
|
+
update: (id: string, updates: Partial<Thing>) => Effect.Effect<void, Error>
|
|
582
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Dimension 4: Connections operations
|
|
586
|
+
connections: {
|
|
587
|
+
create: (input: {
|
|
588
|
+
fromThingId: string
|
|
589
|
+
toThingId: string
|
|
590
|
+
relationshipType: ConnectionType
|
|
591
|
+
metadata?: Record<string, any>
|
|
592
|
+
}) => Effect.Effect<string, ConnectionCreateError>
|
|
593
|
+
getRelated: (params: {
|
|
594
|
+
thingId: string
|
|
595
|
+
relationshipType: ConnectionType
|
|
596
|
+
direction: 'from' | 'to' | 'both'
|
|
597
|
+
}) => Effect.Effect<Thing[], Error>
|
|
598
|
+
getCount: (thingId: string, relationshipType: ConnectionType) => Effect.Effect<number, Error>
|
|
599
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Dimension 5: Events operations
|
|
603
|
+
events: {
|
|
604
|
+
log: (event: {
|
|
605
|
+
type: EventType
|
|
606
|
+
actorId: string // Person ID (who did it)
|
|
607
|
+
targetId?: string // Thing/Person/Connection ID
|
|
608
|
+
organizationId: string // Org scope
|
|
609
|
+
metadata?: Record<string, any>
|
|
610
|
+
}) => Effect.Effect<void, Error>
|
|
611
|
+
query: (params: {
|
|
612
|
+
type?: EventType
|
|
613
|
+
actorId?: string
|
|
614
|
+
targetId?: string
|
|
615
|
+
organizationId?: string
|
|
616
|
+
from?: Date
|
|
617
|
+
to?: Date
|
|
618
|
+
}) => Effect.Effect<Event[], Error>
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Dimension 6: Knowledge operations
|
|
622
|
+
knowledge: {
|
|
623
|
+
embed: (params: {
|
|
624
|
+
text: string
|
|
625
|
+
sourceThingId?: string
|
|
626
|
+
sourcePersonId?: string
|
|
627
|
+
organizationId: string
|
|
628
|
+
labels?: string[]
|
|
629
|
+
}) => Effect.Effect<string, Error>
|
|
630
|
+
search: (params: {
|
|
631
|
+
query: string
|
|
632
|
+
organizationId?: string
|
|
633
|
+
limit?: number
|
|
634
|
+
}) => Effect.Effect<KnowledgeMatch[], Error>
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
**Provider Implementations:**
|
|
640
|
+
|
|
641
|
+
```typescript
|
|
642
|
+
// frontend/src/providers/convex/ConvexProvider.ts
|
|
643
|
+
export class ConvexProvider implements DataProvider {
|
|
644
|
+
constructor(private client: ConvexHttpClient) {}
|
|
645
|
+
|
|
646
|
+
organizations = {
|
|
647
|
+
get: (id) =>
|
|
648
|
+
Effect.tryPromise({
|
|
649
|
+
try: () => this.client.query(api.organizations.get, { id }),
|
|
650
|
+
catch: (error) => new OrganizationNotFoundError(id)
|
|
651
|
+
})
|
|
652
|
+
// ... other operations
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
people = {
|
|
656
|
+
get: (id) =>
|
|
657
|
+
Effect.tryPromise({
|
|
658
|
+
try: () => this.client.query(api.people.get, { id }),
|
|
659
|
+
catch: (error) => new PersonNotFoundError(id)
|
|
660
|
+
}),
|
|
661
|
+
list: (params) =>
|
|
662
|
+
Effect.tryPromise({
|
|
663
|
+
try: () => this.client.query(api.people.list, params),
|
|
664
|
+
catch: (error) => new Error(String(error))
|
|
665
|
+
})
|
|
666
|
+
// ... other operations
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
things = {
|
|
670
|
+
list: (params) =>
|
|
671
|
+
Effect.tryPromise({
|
|
672
|
+
try: () => this.client.query(api.things.list, params),
|
|
673
|
+
catch: (error) => new Error(String(error))
|
|
674
|
+
}),
|
|
675
|
+
create: (input) =>
|
|
676
|
+
Effect.tryPromise({
|
|
677
|
+
try: () => this.client.mutation(api.things.create, input),
|
|
678
|
+
catch: (error) => new Error(String(error))
|
|
679
|
+
})
|
|
680
|
+
// ... other operations
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// ... connections, events, knowledge
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// frontend/astro.config.ts - Change backend with ONE line
|
|
687
|
+
export default defineConfig({
|
|
688
|
+
integrations: [
|
|
689
|
+
one({
|
|
690
|
+
// ✅ Using Convex
|
|
691
|
+
provider: convexProvider({
|
|
692
|
+
url: import.meta.env.PUBLIC_BACKEND_URL
|
|
693
|
+
})
|
|
694
|
+
|
|
695
|
+
// Or use WordPress:
|
|
696
|
+
// provider: wordpressProvider({
|
|
697
|
+
// url: 'https://yoursite.com',
|
|
698
|
+
// apiKey: import.meta.env.WORDPRESS_API_KEY
|
|
699
|
+
// })
|
|
700
|
+
|
|
701
|
+
// Or use Supabase:
|
|
702
|
+
// provider: supabaseProvider({
|
|
703
|
+
// url: import.meta.env.PUBLIC_SUPABASE_URL,
|
|
704
|
+
// key: import.meta.env.PUBLIC_SUPABASE_KEY
|
|
705
|
+
// })
|
|
706
|
+
})
|
|
707
|
+
]
|
|
708
|
+
})
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
**Key Benefits:**
|
|
712
|
+
- ✅ Frontend code never changes when swapping backends
|
|
713
|
+
- ✅ Organizations can bring their own infrastructure
|
|
714
|
+
- ✅ Effect.ts provides type-safety across all providers
|
|
715
|
+
- ✅ Same interface for Convex, WordPress, Supabase, Notion
|
|
716
|
+
- ✅ All 6 dimensions supported universally
|
|
717
|
+
|
|
718
|
+
### Layer 5: Data Layer (6-Dimension Ontology - Plain Convex)
|
|
719
|
+
|
|
720
|
+
All data maps to 6 dimensions using **plain Convex schema** (no Convex Ents):
|
|
721
|
+
|
|
722
|
+
**Core Tables:**
|
|
723
|
+
- **organizations** - Multi-tenant partitioning (Dimension 1)
|
|
724
|
+
- **people** - Users & authorization (Dimension 2, separate from things!)
|
|
725
|
+
- **things** - Domain entities (Dimension 3) - All 66 entity types (courses, products, lessons, etc.)
|
|
726
|
+
- **connections** - Relationships (Dimension 4) - All 25 relationship types
|
|
727
|
+
- **events** - Actions (Dimension 5) - All 67 event types with actorId
|
|
728
|
+
- **knowledge** - AI intelligence (Dimension 6) - Vectors, embeddings, labels
|
|
729
|
+
|
|
730
|
+
**Schema Implementation:**
|
|
731
|
+
```typescript
|
|
732
|
+
// Plain Convex schema - NO Convex Ents
|
|
733
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
734
|
+
import { v } from "convex/values";
|
|
735
|
+
|
|
736
|
+
export default defineSchema({
|
|
737
|
+
// Dimension 1: Organizations
|
|
738
|
+
organizations: defineTable({
|
|
739
|
+
name: v.string(),
|
|
740
|
+
slug: v.string(),
|
|
741
|
+
status: v.string(),
|
|
742
|
+
plan: v.string(),
|
|
743
|
+
limits: v.any(),
|
|
744
|
+
usage: v.any(),
|
|
745
|
+
billing: v.any(),
|
|
746
|
+
settings: v.any(),
|
|
747
|
+
createdAt: v.number(),
|
|
748
|
+
updatedAt: v.number(),
|
|
749
|
+
})
|
|
750
|
+
.index("by_slug", ["slug"])
|
|
751
|
+
.index("by_status", ["status"]),
|
|
752
|
+
|
|
753
|
+
// Dimension 2: People (separate table, NOT things!)
|
|
754
|
+
people: defineTable({
|
|
755
|
+
email: v.string(),
|
|
756
|
+
username: v.string(),
|
|
757
|
+
displayName: v.string(),
|
|
758
|
+
emailVerified: v.boolean(),
|
|
759
|
+
role: v.string(), // platform_owner, org_owner, org_user, customer
|
|
760
|
+
organizationId: v.id("organizations"),
|
|
761
|
+
organizations: v.array(v.id("organizations")), // Multi-org membership
|
|
762
|
+
permissions: v.optional(v.array(v.string())),
|
|
763
|
+
image: v.optional(v.string()),
|
|
764
|
+
bio: v.optional(v.string()),
|
|
765
|
+
createdAt: v.number(),
|
|
766
|
+
updatedAt: v.number(),
|
|
767
|
+
})
|
|
768
|
+
.index("by_email", ["email"])
|
|
769
|
+
.index("by_org", ["organizationId"])
|
|
770
|
+
.index("by_role", ["role"]),
|
|
771
|
+
|
|
772
|
+
// Dimension 3: Things
|
|
773
|
+
things: defineTable({
|
|
774
|
+
thingType: v.string(),
|
|
775
|
+
name: v.string(),
|
|
776
|
+
organizationId: v.id("organizations"), // NEW: Every thing belongs to an org
|
|
777
|
+
description: v.optional(v.string()),
|
|
778
|
+
properties: v.any(),
|
|
779
|
+
status: v.string(),
|
|
780
|
+
createdAt: v.number(),
|
|
781
|
+
updatedAt: v.number(),
|
|
782
|
+
})
|
|
783
|
+
.index("by_type", ["thingType"])
|
|
784
|
+
.index("by_org", ["organizationId"]) // NEW: Query things by org
|
|
785
|
+
.index("by_org_type", ["organizationId", "thingType"])
|
|
786
|
+
.searchIndex("search_things", {
|
|
787
|
+
searchField: "name",
|
|
788
|
+
filterFields: ["thingType", "organizationId"],
|
|
789
|
+
}),
|
|
790
|
+
|
|
791
|
+
// Dimension 4: Connections
|
|
792
|
+
connections: defineTable({
|
|
793
|
+
fromThingId: v.id("things"), // Can connect things
|
|
794
|
+
toThingId: v.id("things"),
|
|
795
|
+
fromPersonId: v.optional(v.id("people")), // OR connect people → things
|
|
796
|
+
toPersonId: v.optional(v.id("people")),
|
|
797
|
+
relationshipType: v.string(),
|
|
798
|
+
organizationId: v.id("organizations"), // Connections scoped to org
|
|
799
|
+
metadata: v.any(),
|
|
800
|
+
createdAt: v.number(),
|
|
801
|
+
})
|
|
802
|
+
.index("by_from", ["fromThingId"])
|
|
803
|
+
.index("by_to", ["toThingId"])
|
|
804
|
+
.index("by_org", ["organizationId"])
|
|
805
|
+
.index("by_relationship", ["relationshipType"])
|
|
806
|
+
.index("by_from_person", ["fromPersonId"]) // Query connections by person
|
|
807
|
+
.index("by_to_person", ["toPersonId"]),
|
|
808
|
+
|
|
809
|
+
// Dimension 5: Events
|
|
810
|
+
events: defineTable({
|
|
811
|
+
eventType: v.string(),
|
|
812
|
+
actorId: v.id("people"), // REQUIRED: Actor is always a person
|
|
813
|
+
targetId: v.optional(v.union(
|
|
814
|
+
v.id("things"),
|
|
815
|
+
v.id("people"),
|
|
816
|
+
v.id("connections")
|
|
817
|
+
)),
|
|
818
|
+
organizationId: v.id("organizations"), // Events scoped to org
|
|
819
|
+
metadata: v.any(),
|
|
820
|
+
timestamp: v.number(),
|
|
821
|
+
})
|
|
822
|
+
.index("by_actor", ["actorId"]) // Query by who did it
|
|
823
|
+
.index("by_target", ["targetId"]) // Query by what was acted upon
|
|
824
|
+
.index("by_org", ["organizationId"]) // Query events by org
|
|
825
|
+
.index("by_type", ["eventType"])
|
|
826
|
+
.index("by_timestamp", ["timestamp"])
|
|
827
|
+
.index("by_org_actor", ["organizationId", "actorId"]),
|
|
828
|
+
|
|
829
|
+
// Dimension 6: Knowledge
|
|
830
|
+
knowledge: defineTable({
|
|
831
|
+
knowledgeType: v.string(),
|
|
832
|
+
text: v.optional(v.string()),
|
|
833
|
+
embedding: v.optional(v.array(v.number())),
|
|
834
|
+
embeddingModel: v.optional(v.string()),
|
|
835
|
+
embeddingDim: v.optional(v.number()),
|
|
836
|
+
sourceThingId: v.optional(v.id("things")),
|
|
837
|
+
sourcePersonId: v.optional(v.id("people")), // Knowledge can come from people
|
|
838
|
+
sourceField: v.optional(v.string()),
|
|
839
|
+
organizationId: v.id("organizations"), // Knowledge scoped to org
|
|
840
|
+
chunk: v.optional(v.any()),
|
|
841
|
+
labels: v.optional(v.array(v.string())),
|
|
842
|
+
metadata: v.optional(v.any()),
|
|
843
|
+
createdAt: v.number(),
|
|
844
|
+
updatedAt: v.number(),
|
|
845
|
+
})
|
|
846
|
+
.index("by_type", ["knowledgeType"])
|
|
847
|
+
.index("by_source_thing", ["sourceThingId"])
|
|
848
|
+
.index("by_source_person", ["sourcePersonId"]) // Query knowledge by person
|
|
849
|
+
.index("by_org", ["organizationId"])
|
|
850
|
+
.index("by_created", ["createdAt"])
|
|
851
|
+
.vectorIndex("by_embedding", {
|
|
852
|
+
vectorField: "embedding",
|
|
853
|
+
dimensions: 768,
|
|
854
|
+
filterFields: ["knowledgeType", "organizationId"]
|
|
855
|
+
}),
|
|
856
|
+
});
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
**Key Design Principles:**
|
|
860
|
+
- Organizations partition ALL data (perfect multi-tenant isolation)
|
|
861
|
+
- People are represented as things with `role` property (platform_owner, org_owner, org_user, customer)
|
|
862
|
+
- Every thing, connection, event, and knowledge item is scoped to an organization
|
|
863
|
+
- No ORM layer (Convex Ents) - direct database access
|
|
864
|
+
- Flexible metadata fields for type-specific data
|
|
865
|
+
- Comprehensive indexing for query performance (including org-scoped indexes)
|
|
866
|
+
|
|
867
|
+
**New Entity Types** (Strategy.md support):
|
|
868
|
+
- **Platform**: website, landing_page, template, livestream, recording, media_asset
|
|
869
|
+
- **Business**: payment, subscription, invoice, metric, insight, prediction, report
|
|
870
|
+
- **Marketing**: notification, email_campaign, announcement, referral, campaign, lead
|
|
871
|
+
|
|
872
|
+
**Optimized Connection Types (24 total):**
|
|
873
|
+
- User relationships: follows, subscribes_to, owns, purchased
|
|
874
|
+
- Content relationships: created, belongs_to, tagged_with, appears_in
|
|
875
|
+
- Token relationships: holds_tokens, staked_in, earned_from, spent_on
|
|
876
|
+
- Platform relationships: hosted_on, deployed_to, integrated_with
|
|
877
|
+
- Business relationships: paid_for, invoiced_by, tracked_by, referred_by
|
|
878
|
+
|
|
879
|
+
**Optimized Event Types (38 total):**
|
|
880
|
+
- User events: user_registered, profile_updated, preferences_changed
|
|
881
|
+
- Content events: content_created, published, viewed, liked, shared
|
|
882
|
+
- Token events: tokens_purchased, transferred, staked, unstaked
|
|
883
|
+
- Platform events: website_created, livestream_started, recording_created
|
|
884
|
+
- Business events: payment_processed, subscription_started, invoice_generated
|
|
885
|
+
|
|
886
|
+
See `docs/Ontology.md` for complete details.
|
|
887
|
+
|
|
888
|
+
#### Type System Optimization: 24 Connections + 38 Events
|
|
889
|
+
|
|
890
|
+
**Previous Approach:** 33 connection types + 54 event types = 87 total types
|
|
891
|
+
**Optimized Approach:** 25 connection types + 35 event types = 62 total types (-29% reduction)
|
|
892
|
+
|
|
893
|
+
**Why Fewer Types is Better:**
|
|
894
|
+
- Less cognitive load for AI agents
|
|
895
|
+
- Fewer type discriminations in code
|
|
896
|
+
- Easier to maintain type consistency
|
|
897
|
+
- More generic types handle more use cases
|
|
898
|
+
- Reduced documentation burden
|
|
899
|
+
|
|
900
|
+
**Connection Type Consolidation Strategy:**
|
|
901
|
+
```typescript
|
|
902
|
+
// ❌ BEFORE: Too specific (33 types)
|
|
903
|
+
"follows_creator"
|
|
904
|
+
"follows_community"
|
|
905
|
+
"follows_course"
|
|
906
|
+
// Each follow type was separate
|
|
907
|
+
|
|
908
|
+
// ✅ AFTER: Generic (24 types)
|
|
909
|
+
"follows"
|
|
910
|
+
// Single type, entity metadata determines what's being followed
|
|
911
|
+
// Connection from User → Creator/Community/Course all use "follows"
|
|
912
|
+
|
|
913
|
+
// Metadata example:
|
|
914
|
+
{
|
|
915
|
+
fromEntityId: "user-123",
|
|
916
|
+
toEntityId: "creator-456",
|
|
917
|
+
relationshipType: "follows",
|
|
918
|
+
metadata: {
|
|
919
|
+
followedEntityType: "creator", // Stored in metadata
|
|
920
|
+
notificationsEnabled: true
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
**24 Core Connection Types:**
|
|
926
|
+
1. **User Relationships** (6 types):
|
|
927
|
+
- `follows` - User follows any entity (creator, community, course)
|
|
928
|
+
- `subscribes_to` - Paid subscription to any entity
|
|
929
|
+
- `owns` - Ownership of any entity
|
|
930
|
+
- `purchased` - Purchase of any entity
|
|
931
|
+
- `created` - Creation of any entity
|
|
932
|
+
- `manages` - Management/admin rights
|
|
933
|
+
|
|
934
|
+
2. **Content Relationships** (6 types):
|
|
935
|
+
- `belongs_to` - Entity belongs to parent entity
|
|
936
|
+
- `tagged_with` - Entity tagged with category
|
|
937
|
+
- `appears_in` - Entity appears in another entity
|
|
938
|
+
- `references` - Entity references another entity
|
|
939
|
+
- `derived_from` - Entity derived from source entity
|
|
940
|
+
- `version_of` - Entity is version of another entity
|
|
941
|
+
|
|
942
|
+
3. **Token & Financial** (5 types):
|
|
943
|
+
- `holds_tokens` - Token balance
|
|
944
|
+
- `staked_in` - Staked token position
|
|
945
|
+
- `earned_from` - Token earnings source
|
|
946
|
+
- `spent_on` - Token expenditure
|
|
947
|
+
- `paid_for` - Fiat payment for entity
|
|
948
|
+
|
|
949
|
+
4. **Platform & Infrastructure** (4 types):
|
|
950
|
+
- `hosted_on` - Platform hosting
|
|
951
|
+
- `deployed_to` - Deployment location
|
|
952
|
+
- `integrated_with` - Integration connection
|
|
953
|
+
- `streamed_on` - Livestream platform
|
|
954
|
+
|
|
955
|
+
5. **Business & Analytics** (3 types):
|
|
956
|
+
- `tracked_by` - Metric tracking
|
|
957
|
+
- `invoiced_by` - Invoice relationship
|
|
958
|
+
- `referred_by` - Referral source
|
|
959
|
+
|
|
960
|
+
**38 Core Event Types:**
|
|
961
|
+
1. **User Events** (8 types):
|
|
962
|
+
- `user_registered`, `user_updated`, `user_deleted`
|
|
963
|
+
- `profile_updated`, `preferences_changed`
|
|
964
|
+
- `login`, `logout`, `password_reset`
|
|
965
|
+
|
|
966
|
+
2. **Content Events** (10 types):
|
|
967
|
+
- `content_created`, `content_updated`, `content_deleted`
|
|
968
|
+
- `published`, `unpublished`, `archived`
|
|
969
|
+
- `viewed`, `liked`, `shared`, `commented`
|
|
970
|
+
|
|
971
|
+
3. **Token Events** (8 types):
|
|
972
|
+
- `tokens_purchased`, `tokens_transferred`, `tokens_burned`
|
|
973
|
+
- `tokens_staked`, `tokens_unstaked`
|
|
974
|
+
- `tokens_earned`, `tokens_spent`, `tokens_claimed`
|
|
975
|
+
|
|
976
|
+
4. **Platform Events** (5 types):
|
|
977
|
+
- `website_created`, `website_deployed`, `website_updated`
|
|
978
|
+
- `livestream_started`, `livestream_ended`
|
|
979
|
+
|
|
980
|
+
5. **Business Events** (7 types):
|
|
981
|
+
- `payment_processed`, `payment_failed`, `payment_refunded`
|
|
982
|
+
- `subscription_started`, `subscription_cancelled`
|
|
983
|
+
- `invoice_generated`, `invoice_paid`
|
|
984
|
+
|
|
985
|
+
**Benefits of Consolidation:**
|
|
986
|
+
- **AI Generation**: Fewer types = more consistent patterns
|
|
987
|
+
- **Type Safety**: Still strongly typed via metadata
|
|
988
|
+
- **Flexibility**: Generic types handle edge cases
|
|
989
|
+
- **Maintainability**: Less code duplication
|
|
990
|
+
- **Query Performance**: Fewer index types to maintain
|
|
991
|
+
|
|
992
|
+
**Metadata Pattern for Type Specificity:**
|
|
993
|
+
```typescript
|
|
994
|
+
// Generic type + rich metadata = type-safe flexibility
|
|
995
|
+
interface Connection {
|
|
996
|
+
fromEntityId: Id<"entities">;
|
|
997
|
+
toEntityId: Id<"entities">;
|
|
998
|
+
relationshipType: "follows" | "owns" | "subscribes_to" | /* ... 21 more */;
|
|
999
|
+
metadata: {
|
|
1000
|
+
// Type-specific metadata stored here
|
|
1001
|
+
entityType?: string;
|
|
1002
|
+
amount?: number;
|
|
1003
|
+
status?: string;
|
|
1004
|
+
permissions?: string[];
|
|
1005
|
+
// Any additional context
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// Query example: Get all follows (regardless of what's being followed)
|
|
1010
|
+
await ctx.db
|
|
1011
|
+
.query("connections")
|
|
1012
|
+
.withIndex("by_relationship", (q) =>
|
|
1013
|
+
q.eq("relationshipType", "follows")
|
|
1014
|
+
)
|
|
1015
|
+
.filter((q) => q.eq(q.field("fromEntityId"), userId))
|
|
1016
|
+
.collect();
|
|
1017
|
+
|
|
1018
|
+
// Query example: Get all creator follows specifically
|
|
1019
|
+
await ctx.db
|
|
1020
|
+
.query("connections")
|
|
1021
|
+
.withIndex("by_relationship", (q) =>
|
|
1022
|
+
q.eq("relationshipType", "follows")
|
|
1023
|
+
)
|
|
1024
|
+
.filter((q) =>
|
|
1025
|
+
q.and(
|
|
1026
|
+
q.eq(q.field("fromEntityId"), userId),
|
|
1027
|
+
q.eq(q.field("metadata.entityType"), "creator")
|
|
1028
|
+
)
|
|
1029
|
+
)
|
|
1030
|
+
.collect();
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
See `docs/Ontology.md` for complete details.
|
|
1034
|
+
|
|
1035
|
+
### Layer 6: External Service Providers
|
|
1036
|
+
|
|
1037
|
+
14 external service providers integrated via Effect.ts with **multi-chain architecture**:
|
|
1038
|
+
|
|
1039
|
+
**Core AI & Content**:
|
|
1040
|
+
- **OpenAI** - LLM, embeddings, content generation
|
|
1041
|
+
- **ElevenLabs** - Voice cloning and synthesis
|
|
1042
|
+
- **D-ID** - AI appearance/avatar cloning
|
|
1043
|
+
- **HeyGen** - Premium AI video avatars
|
|
1044
|
+
|
|
1045
|
+
**Multi-Chain Blockchain Providers** (separate services per chain):
|
|
1046
|
+
- **SuiProvider** - Sui blockchain integration (Move language, high throughput)
|
|
1047
|
+
- **BaseProvider** - Base (Coinbase L2) integration (EVM-compatible, low fees)
|
|
1048
|
+
- **SolanaProvider** - Solana blockchain integration (high-speed, low-cost)
|
|
1049
|
+
- **Alchemy** - Multi-chain RPC infrastructure (supports all chains)
|
|
1050
|
+
|
|
1051
|
+
**CRITICAL: Stripe is for FIAT ONLY** (not blockchain):
|
|
1052
|
+
- **StripeProvider** - Fiat payment processing, subscriptions, traditional invoicing
|
|
1053
|
+
- Used ONLY for USD/EUR/etc payments
|
|
1054
|
+
- Does NOT handle crypto or blockchain transactions
|
|
1055
|
+
- Separate from all blockchain providers
|
|
1056
|
+
|
|
1057
|
+
**CRITICAL: Cloudflare is for LIVESTREAMING ONLY**:
|
|
1058
|
+
- **CloudflareProvider** - Live streaming and video hosting ONLY
|
|
1059
|
+
- Stream API for live broadcasts
|
|
1060
|
+
- Video storage and playback
|
|
1061
|
+
- NOT used for web hosting (that's Cloudflare Pages, different service)
|
|
1062
|
+
|
|
1063
|
+
**Communications**:
|
|
1064
|
+
- **Resend** - Primary email service
|
|
1065
|
+
- **SendGrid** - Advanced email with tracking
|
|
1066
|
+
- **Twilio** - SMS and voice communications
|
|
1067
|
+
|
|
1068
|
+
**Infrastructure**:
|
|
1069
|
+
- **AWS** - Media storage (S3), CDN (CloudFront)
|
|
1070
|
+
|
|
1071
|
+
**Multi-Chain Architecture Pattern:**
|
|
1072
|
+
```typescript
|
|
1073
|
+
// Each blockchain is a separate Effect.ts provider
|
|
1074
|
+
export class SuiProvider extends Effect.Service<SuiProvider>()("SuiProvider", {
|
|
1075
|
+
effect: Effect.gen(function* () {
|
|
1076
|
+
return {
|
|
1077
|
+
transfer: (args) => Effect.gen(function* () { /* Sui-specific */ }),
|
|
1078
|
+
mintNFT: (args) => Effect.gen(function* () { /* Sui Move contract */ }),
|
|
1079
|
+
getBalance: (address) => Effect.gen(function* () { /* Sui RPC */ }),
|
|
1080
|
+
};
|
|
1081
|
+
}),
|
|
1082
|
+
}) {}
|
|
1083
|
+
|
|
1084
|
+
export class BaseProvider extends Effect.Service<BaseProvider>()("BaseProvider", {
|
|
1085
|
+
effect: Effect.gen(function* () {
|
|
1086
|
+
return {
|
|
1087
|
+
transfer: (args) => Effect.gen(function* () { /* Base L2 */ }),
|
|
1088
|
+
mintNFT: (args) => Effect.gen(function* () { /* ERC-721 on Base */ }),
|
|
1089
|
+
getBalance: (address) => Effect.gen(function* () { /* Base RPC */ }),
|
|
1090
|
+
};
|
|
1091
|
+
}),
|
|
1092
|
+
}) {}
|
|
1093
|
+
|
|
1094
|
+
export class SolanaProvider extends Effect.Service<SolanaProvider>()("SolanaProvider", {
|
|
1095
|
+
effect: Effect.gen(function* () {
|
|
1096
|
+
return {
|
|
1097
|
+
transfer: (args) => Effect.gen(function* () { /* Solana web3.js */ }),
|
|
1098
|
+
mintNFT: (args) => Effect.gen(function* () { /* Metaplex */ }),
|
|
1099
|
+
getBalance: (address) => Effect.gen(function* () { /* Solana RPC */ }),
|
|
1100
|
+
};
|
|
1101
|
+
}),
|
|
1102
|
+
}) {}
|
|
1103
|
+
|
|
1104
|
+
// Services choose which chain based on user preference or entity metadata
|
|
1105
|
+
export class TokenService extends Effect.Service<TokenService>()(
|
|
1106
|
+
"TokenService",
|
|
1107
|
+
{
|
|
1108
|
+
effect: Effect.gen(function* () {
|
|
1109
|
+
const sui = yield* SuiProvider;
|
|
1110
|
+
const base = yield* BaseProvider;
|
|
1111
|
+
const solana = yield* SolanaProvider;
|
|
1112
|
+
|
|
1113
|
+
return {
|
|
1114
|
+
transfer: (args) =>
|
|
1115
|
+
Effect.gen(function* () {
|
|
1116
|
+
// Route to correct chain based on tokenId metadata
|
|
1117
|
+
const token = yield* db.get(args.tokenId);
|
|
1118
|
+
|
|
1119
|
+
switch (token.metadata.blockchain) {
|
|
1120
|
+
case "sui": return yield* sui.transfer(args);
|
|
1121
|
+
case "base": return yield* base.transfer(args);
|
|
1122
|
+
case "solana": return yield* solana.transfer(args);
|
|
1123
|
+
}
|
|
1124
|
+
})
|
|
1125
|
+
};
|
|
1126
|
+
}),
|
|
1127
|
+
dependencies: [SuiProvider.Default, BaseProvider.Default, SolanaProvider.Default]
|
|
1128
|
+
}
|
|
1129
|
+
) {}
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
**Why Separate Providers Per Chain:**
|
|
1133
|
+
- Different APIs (Sui uses Move, Base uses EVM, Solana uses web3.js)
|
|
1134
|
+
- Different transaction models and gas fee structures
|
|
1135
|
+
- Type safety per chain (each has unique error types)
|
|
1136
|
+
- Easy to add new chains without modifying existing code
|
|
1137
|
+
- Users can choose preferred blockchain per token/NFT
|
|
1138
|
+
|
|
1139
|
+
All providers follow Effect.ts patterns:
|
|
1140
|
+
- Typed errors in signature
|
|
1141
|
+
- Automatic dependency injection
|
|
1142
|
+
- Composable operations
|
|
1143
|
+
- Built-in retry logic
|
|
1144
|
+
|
|
1145
|
+
See `docs/Service Providers.md` and `docs/Service Providers - New.md` for details.
|
|
1146
|
+
|
|
1147
|
+
---
|
|
1148
|
+
|
|
1149
|
+
## Why Functional Programming Enables Better AI Generation
|
|
1150
|
+
|
|
1151
|
+
### Problem: Imperative Code Is Unpredictable
|
|
1152
|
+
|
|
1153
|
+
**Imperative style (typical code):**
|
|
1154
|
+
```typescript
|
|
1155
|
+
async function purchaseTokens(userId, tokenId, amount) {
|
|
1156
|
+
// State mutation everywhere
|
|
1157
|
+
let payment = null;
|
|
1158
|
+
let tokens = null;
|
|
1159
|
+
let error = null;
|
|
1160
|
+
|
|
1161
|
+
try {
|
|
1162
|
+
payment = await stripe.charge(amount);
|
|
1163
|
+
tokens = await blockchain.mint(amount);
|
|
1164
|
+
await db.updateBalance(userId, tokens);
|
|
1165
|
+
} catch (e) {
|
|
1166
|
+
error = e;
|
|
1167
|
+
// Try to rollback? Maybe? Depends on where we failed
|
|
1168
|
+
if (payment) {
|
|
1169
|
+
await stripe.refund(payment.id);
|
|
1170
|
+
}
|
|
1171
|
+
if (tokens) {
|
|
1172
|
+
// Can we even rollback blockchain?
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// What state are we in? Unclear.
|
|
1177
|
+
}
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
**Problems for AI:**
|
|
1181
|
+
1. **Implicit state** - AI can't track where mutations happen
|
|
1182
|
+
2. **Error handling unclear** - Try/catch doesn't say what errors can occur
|
|
1183
|
+
3. **Partial failures complex** - Rollback logic is manual and error-prone
|
|
1184
|
+
4. **Hard to compose** - Can't easily combine with other functions
|
|
1185
|
+
5. **Testing difficult** - Need to mock global state
|
|
1186
|
+
|
|
1187
|
+
**AI generates buggy code because:**
|
|
1188
|
+
- Can't predict all state changes
|
|
1189
|
+
- Doesn't know what errors to handle
|
|
1190
|
+
- Misses edge cases in rollback logic
|
|
1191
|
+
- Creates tight coupling
|
|
1192
|
+
|
|
1193
|
+
### Solution: Functional Programming Is Predictable
|
|
1194
|
+
|
|
1195
|
+
**Functional style (Effect.ts):**
|
|
1196
|
+
```typescript
|
|
1197
|
+
const purchaseTokens = (
|
|
1198
|
+
userId: Id<"entities">,
|
|
1199
|
+
tokenId: Id<"entities">,
|
|
1200
|
+
amount: number
|
|
1201
|
+
): Effect.Effect<
|
|
1202
|
+
{ paymentId: string; tokens: number }, // Success type
|
|
1203
|
+
StripeError | BlockchainError | DatabaseError, // Error types (explicit!)
|
|
1204
|
+
TokenService // Dependencies (explicit!)
|
|
1205
|
+
> =>
|
|
1206
|
+
Effect.gen(function* () {
|
|
1207
|
+
const service = yield* TokenService;
|
|
1208
|
+
|
|
1209
|
+
// All operations must succeed together
|
|
1210
|
+
const [payment, tokens] = yield* Effect.all([
|
|
1211
|
+
service.charge(userId, amount),
|
|
1212
|
+
service.mint(tokenId, amount),
|
|
1213
|
+
]);
|
|
1214
|
+
|
|
1215
|
+
// Automatically rolls back on any failure
|
|
1216
|
+
yield* service.recordPurchase(userId, payment, tokens);
|
|
1217
|
+
|
|
1218
|
+
return { paymentId: payment.id, tokens };
|
|
1219
|
+
}).pipe(
|
|
1220
|
+
// Declarative error handling
|
|
1221
|
+
Effect.onError(() =>
|
|
1222
|
+
Effect.all([
|
|
1223
|
+
service.refund(payment.id),
|
|
1224
|
+
service.burn(tokens)
|
|
1225
|
+
])
|
|
1226
|
+
)
|
|
1227
|
+
);
|
|
1228
|
+
```
|
|
1229
|
+
|
|
1230
|
+
**Benefits for AI:**
|
|
1231
|
+
1. **Pure functions** - Same input → same output (predictable)
|
|
1232
|
+
2. **Typed errors** - AI knows exactly what can fail
|
|
1233
|
+
3. **Explicit dependencies** - AI sees what's needed
|
|
1234
|
+
4. **Automatic rollback** - Declarative, not manual
|
|
1235
|
+
5. **Composable** - AI can combine functions safely
|
|
1236
|
+
|
|
1237
|
+
**AI generates better code because:**
|
|
1238
|
+
- All inputs/outputs are in the type signature
|
|
1239
|
+
- Error cases are exhaustive in types
|
|
1240
|
+
- Dependencies are explicit
|
|
1241
|
+
- Rollback is automatic
|
|
1242
|
+
- Functions compose predictably
|
|
1243
|
+
|
|
1244
|
+
---
|
|
1245
|
+
|
|
1246
|
+
## Functional Programming Principles That Help AI
|
|
1247
|
+
|
|
1248
|
+
### 1. Pure Functions
|
|
1249
|
+
|
|
1250
|
+
**Pure function:**
|
|
1251
|
+
```typescript
|
|
1252
|
+
// ✅ Pure: Same input → same output, no side effects
|
|
1253
|
+
function calculateTokenPrice(
|
|
1254
|
+
supply: number,
|
|
1255
|
+
demand: number
|
|
1256
|
+
): number {
|
|
1257
|
+
return demand / supply;
|
|
1258
|
+
}
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
**Impure function:**
|
|
1262
|
+
```typescript
|
|
1263
|
+
// ❌ Impure: Depends on external state, has side effects
|
|
1264
|
+
let globalSupply = 1000000;
|
|
1265
|
+
|
|
1266
|
+
function calculateTokenPrice(demand: number): number {
|
|
1267
|
+
globalSupply -= 100; // Side effect!
|
|
1268
|
+
return demand / globalSupply; // Depends on mutable state!
|
|
1269
|
+
}
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
**Why AI prefers pure functions:**
|
|
1273
|
+
- AI can reason about behavior from signature alone
|
|
1274
|
+
- No hidden dependencies to track
|
|
1275
|
+
- No order-of-execution bugs
|
|
1276
|
+
- Can be moved/refactored safely
|
|
1277
|
+
- Easy to test (no setup needed)
|
|
1278
|
+
|
|
1279
|
+
### 2. Immutability
|
|
1280
|
+
|
|
1281
|
+
**Immutable:**
|
|
1282
|
+
```typescript
|
|
1283
|
+
// ✅ Immutable: Create new, don't modify
|
|
1284
|
+
const addToken = (
|
|
1285
|
+
balance: TokenBalance,
|
|
1286
|
+
amount: number
|
|
1287
|
+
): TokenBalance => ({
|
|
1288
|
+
...balance,
|
|
1289
|
+
amount: balance.amount + amount,
|
|
1290
|
+
updatedAt: Date.now()
|
|
1291
|
+
});
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
**Mutable:**
|
|
1295
|
+
```typescript
|
|
1296
|
+
// ❌ Mutable: Modify in place
|
|
1297
|
+
const addToken = (
|
|
1298
|
+
balance: TokenBalance,
|
|
1299
|
+
amount: number
|
|
1300
|
+
): void => {
|
|
1301
|
+
balance.amount += amount; // Mutation!
|
|
1302
|
+
balance.updatedAt = Date.now();
|
|
1303
|
+
};
|
|
1304
|
+
```
|
|
1305
|
+
|
|
1306
|
+
**Why AI prefers immutability:**
|
|
1307
|
+
- AI doesn't have to track where mutations occur
|
|
1308
|
+
- No aliasing bugs (two references to same object)
|
|
1309
|
+
- Can reason about state at any point in time
|
|
1310
|
+
- Easier to parallelize operations
|
|
1311
|
+
- Prevents accidental data corruption
|
|
1312
|
+
|
|
1313
|
+
### 3. Composition Over Inheritance
|
|
1314
|
+
|
|
1315
|
+
**Composition:**
|
|
1316
|
+
```typescript
|
|
1317
|
+
// ✅ Compose small functions
|
|
1318
|
+
const createClone = (creatorId: Id<"entities">) =>
|
|
1319
|
+
Effect.gen(function* () {
|
|
1320
|
+
const content = yield* fetchContent(creatorId);
|
|
1321
|
+
const voice = yield* cloneVoice(content);
|
|
1322
|
+
const personality = yield* extractPersonality(content);
|
|
1323
|
+
|
|
1324
|
+
return { voice, personality };
|
|
1325
|
+
});
|
|
1326
|
+
|
|
1327
|
+
// Each piece is independent, reusable
|
|
1328
|
+
```
|
|
1329
|
+
|
|
1330
|
+
**Inheritance:**
|
|
1331
|
+
```typescript
|
|
1332
|
+
// ❌ Inheritance hierarchy (rigid, complex)
|
|
1333
|
+
class BaseClone {
|
|
1334
|
+
constructor(protected creator: Creator) {}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
class VoiceClone extends BaseClone {
|
|
1338
|
+
async clone() { /* ... */ }
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
class PersonalityClone extends VoiceClone {
|
|
1342
|
+
async extract() { /* ... */ }
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// AI has to understand entire hierarchy
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
**Why AI prefers composition:**
|
|
1349
|
+
- Smaller, independent pieces
|
|
1350
|
+
- No need to understand inheritance chains
|
|
1351
|
+
- Can mix and match functionality
|
|
1352
|
+
- Easier to modify without breaking other parts
|
|
1353
|
+
- Clear data flow (input → process → output)
|
|
1354
|
+
|
|
1355
|
+
### 4. Typed Errors (Effect.ts)
|
|
1356
|
+
|
|
1357
|
+
**Typed errors:**
|
|
1358
|
+
```typescript
|
|
1359
|
+
// ✅ Errors in type signature
|
|
1360
|
+
const cloneVoice = (
|
|
1361
|
+
samples: string[]
|
|
1362
|
+
): Effect.Effect<
|
|
1363
|
+
VoiceId,
|
|
1364
|
+
InsufficientSamplesError | VoiceCloneFailedError, // Explicit!
|
|
1365
|
+
ElevenLabsProvider
|
|
1366
|
+
> => { /* ... */ }
|
|
1367
|
+
|
|
1368
|
+
// AI knows exactly what to catch
|
|
1369
|
+
Effect.catchTags({
|
|
1370
|
+
InsufficientSamplesError: (e) => askForMoreSamples(),
|
|
1371
|
+
VoiceCloneFailedError: (e) => useDefaultVoice()
|
|
1372
|
+
})
|
|
1373
|
+
```
|
|
1374
|
+
|
|
1375
|
+
**Generic errors:**
|
|
1376
|
+
```typescript
|
|
1377
|
+
// ❌ Generic error (AI doesn't know what can fail)
|
|
1378
|
+
async function cloneVoice(samples: string[]): Promise<VoiceId> {
|
|
1379
|
+
try {
|
|
1380
|
+
// What can go wrong? Who knows!
|
|
1381
|
+
return await elevenLabs.clone(samples);
|
|
1382
|
+
} catch (e) {
|
|
1383
|
+
// Lost all type information
|
|
1384
|
+
throw e;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
```
|
|
1388
|
+
|
|
1389
|
+
**Why AI prefers typed errors:**
|
|
1390
|
+
- Compiler enforces handling all error cases
|
|
1391
|
+
- AI can't forget to handle errors
|
|
1392
|
+
- Clear what errors are possible
|
|
1393
|
+
- Exhaustive pattern matching
|
|
1394
|
+
- No silent failures
|
|
1395
|
+
|
|
1396
|
+
### 5. Dependency Injection
|
|
1397
|
+
|
|
1398
|
+
**Dependency injection:**
|
|
1399
|
+
```typescript
|
|
1400
|
+
// ✅ Dependencies explicit
|
|
1401
|
+
class TokenService extends Effect.Service<TokenService>()(
|
|
1402
|
+
"TokenService",
|
|
1403
|
+
{
|
|
1404
|
+
effect: Effect.gen(function* () {
|
|
1405
|
+
const stripe = yield* StripeProvider;
|
|
1406
|
+
const blockchain = yield* BlockchainProvider;
|
|
1407
|
+
|
|
1408
|
+
return { /* methods */ };
|
|
1409
|
+
}),
|
|
1410
|
+
dependencies: [StripeProvider.Default, BlockchainProvider.Default]
|
|
1411
|
+
}
|
|
1412
|
+
) {}
|
|
1413
|
+
|
|
1414
|
+
// AI knows what's needed
|
|
1415
|
+
// AI can mock for tests
|
|
1416
|
+
```
|
|
1417
|
+
|
|
1418
|
+
**Global dependencies:**
|
|
1419
|
+
```typescript
|
|
1420
|
+
// ❌ Global imports (implicit dependencies)
|
|
1421
|
+
import { stripe } from '@/lib/stripe';
|
|
1422
|
+
import { blockchain } from '@/lib/blockchain';
|
|
1423
|
+
|
|
1424
|
+
async function purchaseTokens() {
|
|
1425
|
+
// AI doesn't know these are needed until runtime
|
|
1426
|
+
await stripe.charge();
|
|
1427
|
+
await blockchain.mint();
|
|
1428
|
+
}
|
|
1429
|
+
```
|
|
1430
|
+
|
|
1431
|
+
**Why AI prefers DI:**
|
|
1432
|
+
- All dependencies visible in type signature
|
|
1433
|
+
- Easy to mock for testing
|
|
1434
|
+
- Clear boundaries between modules
|
|
1435
|
+
- Can swap implementations easily
|
|
1436
|
+
- No hidden global state
|
|
1437
|
+
|
|
1438
|
+
---
|
|
1439
|
+
|
|
1440
|
+
## How This Scales With AI Code Generation
|
|
1441
|
+
|
|
1442
|
+
### At 100 Files
|
|
1443
|
+
|
|
1444
|
+
**Imperative codebase:**
|
|
1445
|
+
- AI generates code with implicit dependencies
|
|
1446
|
+
- Global state makes changes risky
|
|
1447
|
+
- Hard to predict what breaks
|
|
1448
|
+
- Tests are integration tests (slow, flaky)
|
|
1449
|
+
- Refactoring is dangerous
|
|
1450
|
+
|
|
1451
|
+
**Functional codebase (ONE):**
|
|
1452
|
+
- AI generates code with explicit dependencies
|
|
1453
|
+
- No global state to corrupt
|
|
1454
|
+
- Types catch breaking changes
|
|
1455
|
+
- Tests are unit tests (fast, reliable)
|
|
1456
|
+
- Refactoring is safe (types + tests)
|
|
1457
|
+
|
|
1458
|
+
### At 1,000 Files
|
|
1459
|
+
|
|
1460
|
+
**Imperative codebase:**
|
|
1461
|
+
- AI generates increasingly coupled code
|
|
1462
|
+
- Side effects everywhere
|
|
1463
|
+
- Debugging requires tracing through many files
|
|
1464
|
+
- Fear of changing anything
|
|
1465
|
+
- **Code quality degrades**
|
|
1466
|
+
|
|
1467
|
+
**Functional codebase (ONE):**
|
|
1468
|
+
- AI generates composable services
|
|
1469
|
+
- Pure functions with clear boundaries
|
|
1470
|
+
- Each function testable in isolation
|
|
1471
|
+
- Can change implementation without breaking interface
|
|
1472
|
+
- **Code quality improves** (later code uses earlier patterns)
|
|
1473
|
+
|
|
1474
|
+
### At 10,000 Files (Large Application)
|
|
1475
|
+
|
|
1476
|
+
**Imperative codebase:**
|
|
1477
|
+
- AI generates duplicate logic (doesn't recognize patterns)
|
|
1478
|
+
- State management is spaghetti
|
|
1479
|
+
- Technical debt compounds
|
|
1480
|
+
- **AI becomes a liability**
|
|
1481
|
+
|
|
1482
|
+
**Functional codebase (ONE):**
|
|
1483
|
+
- AI recognizes and reuses services
|
|
1484
|
+
- Services compose into higher-level services
|
|
1485
|
+
- Patterns are clear and consistent
|
|
1486
|
+
- **AI becomes more valuable** (understands architecture deeply)
|
|
1487
|
+
|
|
1488
|
+
---
|
|
1489
|
+
|
|
1490
|
+
## Concrete Example: Token Purchase Flow
|
|
1491
|
+
|
|
1492
|
+
### Step 1: User Clicks "Buy Tokens" (Frontend)
|
|
1493
|
+
|
|
1494
|
+
```tsx
|
|
1495
|
+
// src/components/features/tokens/TokenPurchase.tsx
|
|
1496
|
+
export function TokenPurchase({ tokenId }: { tokenId: Id<"entities"> }) {
|
|
1497
|
+
const purchase = useMutation(api.tokens.purchase);
|
|
1498
|
+
|
|
1499
|
+
return (
|
|
1500
|
+
<Button onClick={() => purchase({ tokenId, amount: 100 })}>
|
|
1501
|
+
Buy 100 Tokens
|
|
1502
|
+
</Button>
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
```
|
|
1506
|
+
|
|
1507
|
+
### Step 2: Convex Mutation Receives Request
|
|
1508
|
+
|
|
1509
|
+
```typescript
|
|
1510
|
+
// convex/mutations/tokens.ts
|
|
1511
|
+
export const purchase = confect.mutation({
|
|
1512
|
+
args: { tokenId: v.id("entities"), amount: v.number() },
|
|
1513
|
+
handler: (ctx, args) =>
|
|
1514
|
+
Effect.gen(function* () {
|
|
1515
|
+
const userId = yield* getUserId(ctx);
|
|
1516
|
+
const tokenService = yield* TokenService;
|
|
1517
|
+
|
|
1518
|
+
return yield* tokenService.purchase({
|
|
1519
|
+
userId,
|
|
1520
|
+
tokenId: args.tokenId,
|
|
1521
|
+
amount: args.amount
|
|
1522
|
+
});
|
|
1523
|
+
}).pipe(Effect.provide(MainLayer))
|
|
1524
|
+
});
|
|
1525
|
+
```
|
|
1526
|
+
|
|
1527
|
+
### Step 3: Effect.ts Service Orchestrates
|
|
1528
|
+
|
|
1529
|
+
```typescript
|
|
1530
|
+
// convex/services/tokens/purchase.ts
|
|
1531
|
+
export class TokenService extends Effect.Service<TokenService>()(
|
|
1532
|
+
"TokenService",
|
|
1533
|
+
{
|
|
1534
|
+
effect: Effect.gen(function* () {
|
|
1535
|
+
const db = yield* ConvexDatabase;
|
|
1536
|
+
const stripe = yield* StripeProvider; // FIAT payments only
|
|
1537
|
+
const sui = yield* SuiProvider; // Sui blockchain
|
|
1538
|
+
const base = yield* BaseProvider; // Base L2
|
|
1539
|
+
const solana = yield* SolanaProvider; // Solana
|
|
1540
|
+
|
|
1541
|
+
return {
|
|
1542
|
+
purchase: ({ userId, tokenId, amount, paymentMethod }) =>
|
|
1543
|
+
Effect.gen(function* () {
|
|
1544
|
+
// Get token metadata to determine blockchain
|
|
1545
|
+
const token = yield* db.get(tokenId);
|
|
1546
|
+
const blockchain = token.metadata.blockchain; // "sui" | "base" | "solana"
|
|
1547
|
+
|
|
1548
|
+
// Step 1: Process payment (FIAT via Stripe OR crypto direct)
|
|
1549
|
+
const payment = paymentMethod === "fiat"
|
|
1550
|
+
? yield* stripe.charge({
|
|
1551
|
+
amount: amount * 0.10, // $0.10 per token (fiat)
|
|
1552
|
+
currency: "usd"
|
|
1553
|
+
})
|
|
1554
|
+
: { method: "crypto", txHash: null }; // Crypto payment handled on-chain
|
|
1555
|
+
|
|
1556
|
+
// Step 2: Mint tokens on the correct blockchain
|
|
1557
|
+
const mintResult = yield* (
|
|
1558
|
+
blockchain === "sui" ? sui.mintToken({ amount, toAddress: userId }) :
|
|
1559
|
+
blockchain === "base" ? base.mintToken({ amount, toAddress: userId }) :
|
|
1560
|
+
blockchain === "solana" ? solana.mintToken({ amount, toAddress: userId }) :
|
|
1561
|
+
Effect.fail(new UnsupportedBlockchainError(blockchain))
|
|
1562
|
+
);
|
|
1563
|
+
|
|
1564
|
+
// Step 3: Record in database
|
|
1565
|
+
yield* db.insert("events", {
|
|
1566
|
+
entityId: tokenId,
|
|
1567
|
+
eventType: "tokens_purchased",
|
|
1568
|
+
timestamp: Date.now(),
|
|
1569
|
+
actorType: "user",
|
|
1570
|
+
actorId: userId,
|
|
1571
|
+
metadata: {
|
|
1572
|
+
amount,
|
|
1573
|
+
blockchain,
|
|
1574
|
+
paymentMethod,
|
|
1575
|
+
paymentId: payment.method === "crypto" ? null : payment.id,
|
|
1576
|
+
txHash: mintResult.txHash
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
|
|
1580
|
+
// Step 4: Update balance connection
|
|
1581
|
+
yield* db.upsert("connections", {
|
|
1582
|
+
fromEntityId: userId,
|
|
1583
|
+
toEntityId: tokenId,
|
|
1584
|
+
relationshipType: "holds_tokens",
|
|
1585
|
+
metadata: {
|
|
1586
|
+
balance: amount,
|
|
1587
|
+
blockchain,
|
|
1588
|
+
lastUpdated: Date.now()
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
return { success: true, amount, blockchain, txHash: mintResult.txHash };
|
|
1593
|
+
}).pipe(
|
|
1594
|
+
// Automatic rollback on any failure
|
|
1595
|
+
Effect.onError((error) =>
|
|
1596
|
+
Effect.gen(function* () {
|
|
1597
|
+
// Refund fiat payment if it was processed
|
|
1598
|
+
if (payment.method !== "crypto") {
|
|
1599
|
+
yield* stripe.refund(payment.id);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// Burn tokens on the correct blockchain
|
|
1603
|
+
if (mintResult) {
|
|
1604
|
+
yield* (
|
|
1605
|
+
blockchain === "sui" ? sui.burnToken({ amount, txHash: mintResult.txHash }) :
|
|
1606
|
+
blockchain === "base" ? base.burnToken({ amount, txHash: mintResult.txHash }) :
|
|
1607
|
+
blockchain === "solana" ? solana.burnToken({ amount, txHash: mintResult.txHash }) :
|
|
1608
|
+
Effect.succeed(null)
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
})
|
|
1612
|
+
)
|
|
1613
|
+
)
|
|
1614
|
+
};
|
|
1615
|
+
}),
|
|
1616
|
+
dependencies: [
|
|
1617
|
+
ConvexDatabase.Default,
|
|
1618
|
+
StripeProvider.Default, // Fiat only
|
|
1619
|
+
SuiProvider.Default, // Multi-chain
|
|
1620
|
+
BaseProvider.Default,
|
|
1621
|
+
SolanaProvider.Default
|
|
1622
|
+
]
|
|
1623
|
+
}
|
|
1624
|
+
) {}
|
|
1625
|
+
```
|
|
1626
|
+
|
|
1627
|
+
### Why This Is AI-Friendly
|
|
1628
|
+
|
|
1629
|
+
**AI can see:**
|
|
1630
|
+
1. **Inputs:** `userId`, `tokenId`, `amount`, `paymentMethod` (explicit)
|
|
1631
|
+
2. **Outputs:** `{ success: boolean, amount: number, blockchain: string, txHash: string }` (explicit)
|
|
1632
|
+
3. **Errors:** `StripeError | SuiError | BaseError | SolanaError | UnsupportedBlockchainError | DatabaseError` (explicit)
|
|
1633
|
+
4. **Dependencies:** `ConvexDatabase`, `StripeProvider`, `SuiProvider`, `BaseProvider`, `SolanaProvider` (explicit)
|
|
1634
|
+
5. **Side effects:** Fiat payment OR crypto payment, minting on specific blockchain, database writes (explicit)
|
|
1635
|
+
6. **Rollback:** Automatic if any step fails, chain-specific rollback (declarative)
|
|
1636
|
+
7. **Multi-chain routing:** Token metadata determines which blockchain to use (explicit)
|
|
1637
|
+
|
|
1638
|
+
**AI can generate:**
|
|
1639
|
+
- Tests with mocked services for each blockchain
|
|
1640
|
+
- Similar flows for other multi-chain operations
|
|
1641
|
+
- Error handling for each blockchain's unique errors
|
|
1642
|
+
- Chain-specific logging and monitoring
|
|
1643
|
+
- Rate limiting per blockchain
|
|
1644
|
+
- Retry logic with chain-specific strategies
|
|
1645
|
+
- New blockchain integrations following the same pattern
|
|
1646
|
+
|
|
1647
|
+
**AI cannot break:**
|
|
1648
|
+
- Type system prevents invalid states
|
|
1649
|
+
- Compiler catches missing error handling per chain
|
|
1650
|
+
- Dependencies are wired automatically
|
|
1651
|
+
- Rollback is automatic and chain-aware
|
|
1652
|
+
- Unsupported blockchains fail explicitly (not silently)
|
|
1653
|
+
- Fiat vs crypto payment paths are type-safe
|
|
1654
|
+
|
|
1655
|
+
**Multi-chain pattern benefits:**
|
|
1656
|
+
1. **Consistency:** Same interface for all blockchains
|
|
1657
|
+
2. **Type Safety:** Each chain has unique error types
|
|
1658
|
+
3. **Extensibility:** Add new chains without modifying existing code
|
|
1659
|
+
4. **Testing:** Mock individual chains independently
|
|
1660
|
+
5. **Observability:** Chain-specific tracing and metrics
|
|
1661
|
+
|
|
1662
|
+
---
|
|
1663
|
+
|
|
1664
|
+
## Testing With Functional Programming
|
|
1665
|
+
|
|
1666
|
+
### Unit Test (Service)
|
|
1667
|
+
|
|
1668
|
+
```typescript
|
|
1669
|
+
// tests/unit/services/token.test.ts
|
|
1670
|
+
import { Effect, Layer } from "effect";
|
|
1671
|
+
import { TokenService } from "@/convex/services/tokens/purchase";
|
|
1672
|
+
|
|
1673
|
+
describe("TokenService.purchase", () => {
|
|
1674
|
+
it("should purchase tokens successfully", async () => {
|
|
1675
|
+
// Mock dependencies
|
|
1676
|
+
const MockStripe = Layer.succeed(StripeProvider, {
|
|
1677
|
+
charge: () => Effect.succeed({ id: "pay_123" })
|
|
1678
|
+
});
|
|
1679
|
+
|
|
1680
|
+
const MockBlockchain = Layer.succeed(BlockchainProvider, {
|
|
1681
|
+
mint: () => Effect.succeed({ txHash: "0x456" })
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
const MockDB = Layer.succeed(ConvexDatabase, {
|
|
1685
|
+
insert: () => Effect.succeed("evt_789"),
|
|
1686
|
+
upsert: () => Effect.succeed("conn_012")
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
const TestLayer = Layer.mergeAll(MockStripe, MockBlockchain, MockDB);
|
|
1690
|
+
|
|
1691
|
+
// Run test
|
|
1692
|
+
const result = await Effect.runPromise(
|
|
1693
|
+
Effect.gen(function* () {
|
|
1694
|
+
const service = yield* TokenService;
|
|
1695
|
+
return yield* service.purchase({
|
|
1696
|
+
userId: "user-123",
|
|
1697
|
+
tokenId: "token-456",
|
|
1698
|
+
amount: 100
|
|
1699
|
+
});
|
|
1700
|
+
}).pipe(Effect.provide(TestLayer))
|
|
1701
|
+
);
|
|
1702
|
+
|
|
1703
|
+
expect(result.success).toBe(true);
|
|
1704
|
+
expect(result.amount).toBe(100);
|
|
1705
|
+
});
|
|
1706
|
+
|
|
1707
|
+
it("should rollback on payment failure", async () => {
|
|
1708
|
+
const MockStripe = Layer.succeed(StripeProvider, {
|
|
1709
|
+
charge: () => Effect.fail(new StripeError("Card declined"))
|
|
1710
|
+
});
|
|
1711
|
+
|
|
1712
|
+
// Test that blockchain.mint is NOT called
|
|
1713
|
+
const mintSpy = vi.fn();
|
|
1714
|
+
const MockBlockchain = Layer.succeed(BlockchainProvider, {
|
|
1715
|
+
mint: () => Effect.sync(mintSpy)
|
|
1716
|
+
});
|
|
1717
|
+
|
|
1718
|
+
const TestLayer = Layer.mergeAll(MockStripe, MockBlockchain);
|
|
1719
|
+
|
|
1720
|
+
await expect(
|
|
1721
|
+
Effect.runPromise(
|
|
1722
|
+
/* ... */.pipe(Effect.provide(TestLayer))
|
|
1723
|
+
)
|
|
1724
|
+
).rejects.toThrow("Card declined");
|
|
1725
|
+
|
|
1726
|
+
expect(mintSpy).not.toHaveBeenCalled();
|
|
1727
|
+
});
|
|
1728
|
+
});
|
|
1729
|
+
```
|
|
1730
|
+
|
|
1731
|
+
**AI can generate these tests because:**
|
|
1732
|
+
- Clear service interface
|
|
1733
|
+
- Easy to mock dependencies
|
|
1734
|
+
- Behavior is predictable
|
|
1735
|
+
- Error cases are explicit
|
|
1736
|
+
|
|
1737
|
+
---
|
|
1738
|
+
|
|
1739
|
+
## Summary: Why This Architecture Works for AI
|
|
1740
|
+
|
|
1741
|
+
### Traditional Approach (Fails at Scale)
|
|
1742
|
+
```
|
|
1743
|
+
Imperative code
|
|
1744
|
+
→ Hidden state
|
|
1745
|
+
→ Implicit errors
|
|
1746
|
+
→ Tight coupling
|
|
1747
|
+
→ AI generates bugs
|
|
1748
|
+
→ Code quality degrades
|
|
1749
|
+
→ AI becomes liability
|
|
1750
|
+
```
|
|
1751
|
+
|
|
1752
|
+
### ONE Approach (Improves at Scale)
|
|
1753
|
+
```
|
|
1754
|
+
Functional programming
|
|
1755
|
+
→ Pure functions
|
|
1756
|
+
→ Typed errors
|
|
1757
|
+
→ Explicit dependencies
|
|
1758
|
+
→ AI generates correct code
|
|
1759
|
+
→ Code quality improves
|
|
1760
|
+
→ AI becomes more valuable
|
|
1761
|
+
```
|
|
1762
|
+
|
|
1763
|
+
**The key insight:** AI is pattern matching. Functional programming creates consistent, explicit patterns that AI can recognize and replicate.
|
|
1764
|
+
|
|
1765
|
+
**The result:** Your 10,000-file codebase is EASIER to work with than your 100-file codebase because:
|
|
1766
|
+
1. AI learns patterns from existing code
|
|
1767
|
+
2. Types catch breaking changes automatically
|
|
1768
|
+
3. Services compose rather than duplicate
|
|
1769
|
+
4. Tests verify behavior mechanically
|
|
1770
|
+
5. Refactoring is safe and automated
|
|
1771
|
+
|
|
1772
|
+
**This is why larger codebases get BETTER with functional programming + AI, not worse.**
|
|
1773
|
+
|
|
1774
|
+
---
|
|
1775
|
+
|
|
1776
|
+
## Key Architectural Decisions Summary
|
|
1777
|
+
|
|
1778
|
+
### 1. Plain Convex Schema with 6-Dimension Ontology
|
|
1779
|
+
**Decision:** Use plain Convex `defineSchema` with 6 dimensions (organizations, people, things, connections, events, knowledge)
|
|
1780
|
+
**Rationale:**
|
|
1781
|
+
- Simpler mental model for AI agents
|
|
1782
|
+
- Organizations provide perfect multi-tenant isolation
|
|
1783
|
+
- People represented as things with role metadata (no duplicate tables)
|
|
1784
|
+
- No ORM abstraction layer to learn
|
|
1785
|
+
- Direct control over indexes and queries
|
|
1786
|
+
- Every dimension scoped to organization
|
|
1787
|
+
- Scales from children's apps to enterprise SaaS
|
|
1788
|
+
|
|
1789
|
+
### 2. Organizations as First-Class Dimension
|
|
1790
|
+
**Decision:** Every resource (thing, connection, event, knowledge) belongs to an organization
|
|
1791
|
+
**Rationale:**
|
|
1792
|
+
- Perfect data isolation for multi-tenancy
|
|
1793
|
+
- Clear ownership boundaries
|
|
1794
|
+
- Independent billing and quotas per org
|
|
1795
|
+
- Custom frontends per org
|
|
1796
|
+
- Platform-level services (shared infrastructure)
|
|
1797
|
+
|
|
1798
|
+
### 3. People as Authorization Layer
|
|
1799
|
+
**Decision:** People are things with role property (platform_owner, org_owner, org_user, customer)
|
|
1800
|
+
**Rationale:**
|
|
1801
|
+
- Every action has an actor (person)
|
|
1802
|
+
- Clear permission hierarchy
|
|
1803
|
+
- Roles define what actions are allowed
|
|
1804
|
+
- Org owners control their users
|
|
1805
|
+
- Platform owner can access everything (support/debugging)
|
|
1806
|
+
|
|
1807
|
+
### 4. Multi-Chain Blockchain Architecture
|
|
1808
|
+
**Decision:** Separate Effect.ts provider per blockchain (Sui, Base, Solana)
|
|
1809
|
+
**Rationale:**
|
|
1810
|
+
- Each chain has unique APIs and transaction models
|
|
1811
|
+
- Type safety per chain (unique error types)
|
|
1812
|
+
- Easy to add new chains without modifying existing code
|
|
1813
|
+
- Users can choose preferred blockchain per token/NFT
|
|
1814
|
+
- Chain-specific retry strategies and error handling
|
|
1815
|
+
|
|
1816
|
+
### 5. Stripe for FIAT Only
|
|
1817
|
+
**Decision:** Stripe handles USD/EUR/etc payments only, NOT crypto
|
|
1818
|
+
**Rationale:**
|
|
1819
|
+
- Clear separation of concerns (fiat vs crypto)
|
|
1820
|
+
- Blockchain providers handle all crypto transactions
|
|
1821
|
+
- Prevents confusion about payment routing
|
|
1822
|
+
- Simpler error handling (payment method determines provider)
|
|
1823
|
+
|
|
1824
|
+
### 6. Effect.ts 100% Coverage
|
|
1825
|
+
**Decision:** ALL business logic uses Effect.ts (no raw async/await)
|
|
1826
|
+
**Rationale:**
|
|
1827
|
+
- Consistent patterns across entire codebase
|
|
1828
|
+
- Typed errors everywhere (no try/catch)
|
|
1829
|
+
- Automatic dependency injection
|
|
1830
|
+
- Built-in retry, timeout, resource management
|
|
1831
|
+
- AI generates consistent code every time
|
|
1832
|
+
|
|
1833
|
+
### 7. 6-Dimension Ontology (Organizations + People + 4 Core Dimensions)
|
|
1834
|
+
**Decision:** Expand from 4 tables to 6 dimensions
|
|
1835
|
+
**Rationale:**
|
|
1836
|
+
- Organizations: Multi-tenant isolation boundary
|
|
1837
|
+
- People: Authorization and governance
|
|
1838
|
+
- Things: 66 entity types (what exists)
|
|
1839
|
+
- Connections: 25 relationship types (how they relate)
|
|
1840
|
+
- Events: 67 event types (what happened)
|
|
1841
|
+
- Knowledge: Vectors + labels (what it means)
|
|
1842
|
+
- Simple enough for children, powerful enough for enterprises
|
|
1843
|
+
- AI agents can reason about complete reality model
|
|
1844
|
+
|
|
1845
|
+
---
|
|
1846
|
+
|
|
1847
|
+
## 🎯 Benefits of the Three-Layer Architecture
|
|
1848
|
+
|
|
1849
|
+
### For Developers
|
|
1850
|
+
|
|
1851
|
+
**Frontend Developers:**
|
|
1852
|
+
- Work independently with Astro + React
|
|
1853
|
+
- Use Convex hooks for real-time data (no backend changes needed)
|
|
1854
|
+
- Call Hono API for complex operations (clear contracts)
|
|
1855
|
+
- Rapid prototyping with "vibe code"
|
|
1856
|
+
- Full TypeScript support with generated types
|
|
1857
|
+
|
|
1858
|
+
**Backend Developers:**
|
|
1859
|
+
- Focus on business logic in Effect.ts services
|
|
1860
|
+
- Clear separation between API layer (Hono) and data layer (Convex)
|
|
1861
|
+
- Easy to test (mock dependencies via Effect layers)
|
|
1862
|
+
- Composable services (combine small functions into larger ones)
|
|
1863
|
+
- Automatic retry, timeout, error handling
|
|
1864
|
+
|
|
1865
|
+
**Full-Stack Developers:**
|
|
1866
|
+
- Clear boundaries between layers
|
|
1867
|
+
- Easy to understand data flow (Frontend → Effect.ts → Backend)
|
|
1868
|
+
- Consistent patterns across entire stack
|
|
1869
|
+
- Type safety end-to-end (TypeScript + Effect.ts)
|
|
1870
|
+
|
|
1871
|
+
### For AI Code Generation
|
|
1872
|
+
|
|
1873
|
+
**Why This Architecture Works for AI:**
|
|
1874
|
+
|
|
1875
|
+
1. **Predictable Patterns:** Same structure for every feature (map to ontology → Effect.ts service → Hono route → React component)
|
|
1876
|
+
2. **Explicit Types:** AI knows exactly what inputs, outputs, errors, and dependencies are needed
|
|
1877
|
+
3. **Composable:** AI can combine existing services to create new features
|
|
1878
|
+
4. **Testable:** AI can generate tests by mocking Effect layers
|
|
1879
|
+
5. **Self-Improving:** Each new feature makes the next feature easier (AI learns patterns)
|
|
1880
|
+
|
|
1881
|
+
**Example: AI generates a new feature in minutes:**
|
|
1882
|
+
```
|
|
1883
|
+
1. Read docs/Ontology.md (understand 6-dimension model: organizations, people, things, connections, events, knowledge)
|
|
1884
|
+
2. Read docs/Frontend.md (understand Astro + React patterns)
|
|
1885
|
+
3. Read docs/Hono.md (understand Effect.ts service patterns)
|
|
1886
|
+
4. Generate Effect.ts service (pure business logic)
|
|
1887
|
+
5. Generate Hono route (thin wrapper)
|
|
1888
|
+
6. Generate Convex wrapper (confect bridge)
|
|
1889
|
+
7. Generate React component (uses Convex hooks + Hono API)
|
|
1890
|
+
8. Generate tests (mock Effect layers)
|
|
1891
|
+
9. Done! Feature is complete, type-safe, tested
|
|
1892
|
+
```
|
|
1893
|
+
|
|
1894
|
+
### For Multi-Tenancy
|
|
1895
|
+
|
|
1896
|
+
**Different orgs can customize their frontend:**
|
|
1897
|
+
- Each org has their own Astro deployment (unique branding, features)
|
|
1898
|
+
- All orgs share the same Hono API + Convex backend
|
|
1899
|
+
- Backend remains stable while frontends evolve independently
|
|
1900
|
+
- API contracts ensure compatibility
|
|
1901
|
+
|
|
1902
|
+
**Example:**
|
|
1903
|
+
```
|
|
1904
|
+
Org A: Marketing site with blog (Astro + shadcn/ui dark theme)
|
|
1905
|
+
Org B: E-commerce store (Astro + shadcn/ui + custom components)
|
|
1906
|
+
Org C: Dashboard app (Astro + custom charting library)
|
|
1907
|
+
|
|
1908
|
+
All three: Share same Hono API + Convex backend (auth, tokens, content)
|
|
1909
|
+
```
|
|
1910
|
+
|
|
1911
|
+
### For Performance
|
|
1912
|
+
|
|
1913
|
+
**Deployment Strategy:**
|
|
1914
|
+
```
|
|
1915
|
+
Frontend: Cloudflare Pages (global edge network)
|
|
1916
|
+
↓
|
|
1917
|
+
Hono API: Cloudflare Workers (edge compute, sub-100ms)
|
|
1918
|
+
↓
|
|
1919
|
+
Convex: Real-time database (global replication)
|
|
1920
|
+
```
|
|
1921
|
+
|
|
1922
|
+
**Result:**
|
|
1923
|
+
- Sub-100ms response times globally
|
|
1924
|
+
- Real-time data subscriptions via Convex
|
|
1925
|
+
- Static pages cached at the edge (Cloudflare Pages)
|
|
1926
|
+
- API routes execute at the edge (Cloudflare Workers)
|
|
1927
|
+
- Database queries optimized with indexes
|
|
1928
|
+
|
|
1929
|
+
## The Complete 6-Dimension Picture
|
|
1930
|
+
|
|
1931
|
+
**Example: User purchases a course**
|
|
1932
|
+
|
|
1933
|
+
Here's how all 6 dimensions work together in a real scenario:
|
|
1934
|
+
|
|
1935
|
+
```
|
|
1936
|
+
1. Organization → "fitnesspro" (Id<'organizations'>)
|
|
1937
|
+
└─ Multi-tenant boundary
|
|
1938
|
+
└─ Settings: allow purchases, payment methods
|
|
1939
|
+
|
|
1940
|
+
2. Person → "john@fitnesspro.com" (Id<'people'>)
|
|
1941
|
+
└─ Separate people table (NOT a thing!)
|
|
1942
|
+
└─ role: "customer"
|
|
1943
|
+
└─ organizationId: fitnesspro_id
|
|
1944
|
+
|
|
1945
|
+
3. Thing → "Fitness Fundamentals Course" (Id<'things'>)
|
|
1946
|
+
└─ type: "course"
|
|
1947
|
+
└─ organizationId: fitnesspro_id
|
|
1948
|
+
└─ properties: { price: 99, instructor: "Jane" }
|
|
1949
|
+
|
|
1950
|
+
4. Connection → Purchase (Id<'connections'>)
|
|
1951
|
+
└─ fromPersonId: john_person_id (NOT thingId!)
|
|
1952
|
+
└─ toThingId: course_thing_id
|
|
1953
|
+
└─ type: "purchased"
|
|
1954
|
+
└─ metadata: { amount: 99, method: "stripe" }
|
|
1955
|
+
|
|
1956
|
+
5. Event → "purchase_completed" (Id<'events'>)
|
|
1957
|
+
└─ actorId: john_person_id (Person ID - who did it)
|
|
1958
|
+
└─ targetId: connection_id (what happened)
|
|
1959
|
+
└─ organizationId: fitnesspro_id
|
|
1960
|
+
└─ metadata: { amount: 99, stripe_id: "ch_123" }
|
|
1961
|
+
|
|
1962
|
+
6. Knowledge → Purchase pattern (Id<'knowledge'>)
|
|
1963
|
+
└─ sourcePersonId: john_person_id
|
|
1964
|
+
└─ AI learns: John prefers fitness courses, buys on weekends
|
|
1965
|
+
└─ Can recommend similar courses
|
|
1966
|
+
```
|
|
1967
|
+
|
|
1968
|
+
**When the same person purchases from a different org:**
|
|
1969
|
+
|
|
1970
|
+
```
|
|
1971
|
+
1. Organization → "yoga-academy" (different org!)
|
|
1972
|
+
2. Person → Same John, but organizationId: yoga_academy_id
|
|
1973
|
+
3. Thing → "Beginner Yoga" (yoga-academy course)
|
|
1974
|
+
4. Connection → New purchase connection (yoga_academy scoped)
|
|
1975
|
+
5. Event → Logged to yoga-academy (perfect isolation)
|
|
1976
|
+
6. Knowledge → Separate yoga-academy knowledge (no cross-org leakage)
|
|
1977
|
+
```
|
|
1978
|
+
|
|
1979
|
+
**Key Benefits:**
|
|
1980
|
+
- ✅ **Organizations** isolate data (fitnesspro can't see yoga-academy)
|
|
1981
|
+
- ✅ **People** act across orgs (John can belong to multiple orgs)
|
|
1982
|
+
- ✅ **Things** are org-scoped (courses belong to specific orgs)
|
|
1983
|
+
- ✅ **Connections** link people → things (purchases, enrollments)
|
|
1984
|
+
- ✅ **Events** track all actions with actorId (complete audit trail)
|
|
1985
|
+
- ✅ **Knowledge** learns patterns (AI recommends based on behavior)
|
|
1986
|
+
|
|
1987
|
+
**DataProvider Makes It Backend-Agnostic:**
|
|
1988
|
+
|
|
1989
|
+
```typescript
|
|
1990
|
+
// Frontend code - works with ANY backend
|
|
1991
|
+
const program = Effect.gen(function* () {
|
|
1992
|
+
const provider = yield* DataProvider
|
|
1993
|
+
|
|
1994
|
+
// Purchase flow
|
|
1995
|
+
const person = yield* provider.people.get(userId)
|
|
1996
|
+
const course = yield* provider.things.get(courseId)
|
|
1997
|
+
|
|
1998
|
+
// Create purchase connection
|
|
1999
|
+
const purchaseId = yield* provider.connections.create({
|
|
2000
|
+
fromPersonId: person._id,
|
|
2001
|
+
toThingId: course._id,
|
|
2002
|
+
relationshipType: "purchased",
|
|
2003
|
+
organizationId: person.organizationId,
|
|
2004
|
+
metadata: { amount: 99, method: "stripe" }
|
|
2005
|
+
})
|
|
2006
|
+
|
|
2007
|
+
// Log event
|
|
2008
|
+
yield* provider.events.log({
|
|
2009
|
+
type: "purchase_completed",
|
|
2010
|
+
actorId: person._id,
|
|
2011
|
+
targetId: purchaseId,
|
|
2012
|
+
organizationId: person.organizationId,
|
|
2013
|
+
metadata: { amount: 99 }
|
|
2014
|
+
})
|
|
2015
|
+
|
|
2016
|
+
return { success: true, purchaseId }
|
|
2017
|
+
})
|
|
2018
|
+
|
|
2019
|
+
// Same code works with:
|
|
2020
|
+
// - ConvexProvider (real-time database)
|
|
2021
|
+
// - WordPressProvider (WooCommerce backend)
|
|
2022
|
+
// - SupabaseProvider (PostgreSQL database)
|
|
2023
|
+
// - NotionProvider (Notion databases)
|
|
2024
|
+
```
|
|
2025
|
+
|
|
2026
|
+
**This is why the architecture is beautiful:**
|
|
2027
|
+
- Frontend doesn't know which backend it's talking to
|
|
2028
|
+
- People are separate from things (clear authorization)
|
|
2029
|
+
- Everything is org-scoped (perfect multi-tenancy)
|
|
2030
|
+
- Events log who did what (complete audit trail)
|
|
2031
|
+
- Knowledge learns from behavior (AI gets smarter)
|
|
2032
|
+
- Effect.ts makes it all type-safe
|
|
2033
|
+
|
|
2034
|
+
---
|
|
2035
|
+
|
|
2036
|
+
## Next Steps for AI Agents
|
|
2037
|
+
|
|
2038
|
+
When implementing a new feature:
|
|
2039
|
+
|
|
2040
|
+
1. **Read the documentation:**
|
|
2041
|
+
- **docs/Frontend.md** - If building UI components or pages
|
|
2042
|
+
- **docs/Hono.md** - If building API routes or Effect.ts services
|
|
2043
|
+
- **docs/Architecture.md** - To understand how everything fits together
|
|
2044
|
+
- **docs/Ontology.md** - Map feature to 6 dimensions (organizations, people, things, connections, events, knowledge)
|
|
2045
|
+
|
|
2046
|
+
2. **Design the layers:**
|
|
2047
|
+
- **Frontend:** Astro page + React component (uses Convex hooks + Hono API)
|
|
2048
|
+
- **Glue:** Effect.ts service (pure business logic)
|
|
2049
|
+
- **Backend:** Hono route (thin wrapper) + Convex wrapper (confect bridge)
|
|
2050
|
+
|
|
2051
|
+
3. **Implement with patterns:**
|
|
2052
|
+
- 100% Effect.ts for business logic (NO async/await)
|
|
2053
|
+
- Typed errors with `_tag` pattern
|
|
2054
|
+
- Dependency injection via Effect layers
|
|
2055
|
+
- Automatic retry, timeout, rollback
|
|
2056
|
+
|
|
2057
|
+
4. **Test thoroughly:**
|
|
2058
|
+
- Unit tests for Effect.ts services (mock layers)
|
|
2059
|
+
- Integration tests for Hono routes
|
|
2060
|
+
- E2E tests for React components
|
|
2061
|
+
|
|
2062
|
+
5. **Document patterns:**
|
|
2063
|
+
- Add to `docs/Patterns.md` for future AI
|
|
2064
|
+
- Update `docs/Files.md` with new file locations
|
|
2065
|
+
|
|
2066
|
+
**Key Reminders:**
|
|
2067
|
+
- **Frontend Layer:** Astro + React, content collections, Convex hooks + Hono API client
|
|
2068
|
+
- **Glue Layer:** Effect.ts services (100% coverage), typed errors, DI
|
|
2069
|
+
- **Backend Layer:** Hono API routes, Convex database (6-dimension ontology), Better Auth
|
|
2070
|
+
- **6 Dimensions:** Organizations partition, People authorize, Things exist, Connections relate, Events record, Knowledge understands
|
|
2071
|
+
- Stripe = fiat only (NOT crypto)
|
|
2072
|
+
- Cloudflare = livestreaming only (NOT web hosting)
|
|
2073
|
+
- Plain Convex schema (NO Convex Ents)
|
|
2074
|
+
- Multi-chain providers (separate services per blockchain)
|
|
2075
|
+
- 25 connection types + 67 event types (optimized, generic)
|
|
2076
|
+
|
|
2077
|
+
**The Result:** Each feature makes the next feature easier because AI has more patterns to learn from, and the architecture ensures consistency across all layers.
|