oneie 2.0.2 → 2.0.5
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 +725 -0
- package/LICENSE.md +84 -0
- package/README.md +489 -931
- package/folders.yaml +78 -17
- 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/agentkit.md +349 -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/copilotkit.md +1559 -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/CASCADE-2-BACKEND-AGNOSTIC.md +412 -0
- package/one/events/FEATURE-2-4-COMPLETE.md +302 -0
- package/one/events/FEATURE_2_3_COMPLETE.md +575 -0
- package/one/events/GROUPS-MIGRATION.md +625 -0
- package/one/events/INSTALL-TESTS.md +293 -0
- package/one/events/INTEGRATION-ARCHITECTURE.md +561 -0
- package/one/events/INTEGRATION-CHECKLIST.md +1234 -0
- package/one/events/INTEGRATION-ORCHESTRATION.md +2623 -0
- package/one/events/INTEGRATION-SUMMARY.md +653 -0
- package/one/events/MIGRATION-REPORT.md +435 -0
- package/one/events/MIGRATION.md +69 -0
- package/one/events/README-archived.md +519 -0
- package/one/events/TEST-SUMMARY.md +393 -0
- package/one/events/TESTS-QUICK-REF.md +262 -0
- package/one/events/events.md +545 -0
- package/one/groups/groups.md +543 -0
- package/one/groups/one.md +599 -0
- package/one/groups/revenue.md +673 -0
- package/one/groups/strategy.md +869 -0
- package/one/groups/vision.md +98 -0
- package/one/knowledge/CLOUDFLARE_ENV_SETUP.md +49 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-any-backend.md +1366 -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/docs/flow.md +0 -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 +2830 -0
- package/one/knowledge/ontology.md.backup +2822 -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/provider-creation-guide.md +1064 -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/knowledge/todo.md +251 -0
- package/one/license.md +84 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/things/CHECKLIST.md +356 -0
- package/one/things/ONE.md +510 -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/cli-code.md +652 -0
- package/one/things/cli/cli-compiler-code.md +652 -0
- package/one/things/cli/cli.md +1068 -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/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-1-dataprovider-interface.md +2358 -0
- package/one/things/features/2-2-config-system.md +3075 -0
- package/one/things/features/2-3-effectts-services.md +1498 -0
- package/one/things/features/2-4-react-hooks.md +2120 -0
- package/one/things/features/2-5-auth-migration.md +2046 -0
- package/one/things/features/2-6-dashboard-migration.md +1985 -0
- package/one/things/features/2-7-alternative-providers.md +2505 -0
- package/one/things/features/2-7-implementation-report.md +680 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/2-design.md +1738 -0
- package/one/things/features/2-tests.md +520 -0
- package/one/things/features/AUTH_HOOKS_IMPLEMENTATION.md +521 -0
- package/one/things/features/DECOUPLING.md +272 -0
- package/one/things/features/DEPLOYMENT.md +452 -0
- package/one/things/features/IMPLEMENTATION_SUMMARY.md +316 -0
- package/one/things/features/dataprovider-interface/1-tests.md +1522 -0
- package/one/things/features/improve.md +843 -0
- package/one/things/features/remove-convex-deps.md +45 -0
- package/one/things/features/top-features.md +79 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/ideas/2-backend-agnostic-frontend.md +384 -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/2-backend-agnostic-frontend.md +543 -0
- package/one/things/plans/3-groups.md +502 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/backend-agnostic-frontend.md +323 -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/deploy-to-cloudflare.md +581 -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/organizations-to-groups.md +705 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/release.md +432 -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/system.md +600 -0
- package/one/things/tests/2-1-dataprovider-interface.md +1144 -0
- package/one/things/tests/2-1-test-analysis.md +496 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/one/things/vision/elegant-interface.md +214 -0
- package/package.json +5 -2
|
@@ -0,0 +1,2458 @@
|
|
|
1
|
+
# Frontend-Backend Separation Plan
|
|
2
|
+
|
|
3
|
+
## Executive Summary
|
|
4
|
+
|
|
5
|
+
**Goal:** Transform the current tightly-coupled architecture into a fully headless, **backend-agnostic** architecture where:
|
|
6
|
+
|
|
7
|
+
- **Frontend:** Pure Astro/React UI with DataProvider interface (no backend dependency)
|
|
8
|
+
- **Backend:** ANY backend that implements the 6-dimension ontology (Convex, WordPress, Notion, Supabase, etc.)
|
|
9
|
+
- **Connection:** DataProvider interface - swap backends by changing ONE line
|
|
10
|
+
|
|
11
|
+
**Current State:**
|
|
12
|
+
|
|
13
|
+
- ✅ Frontend is **working** and connected to Convex backend
|
|
14
|
+
- ✅ Auth is functional with tests in `frontend/tests/auth/*`
|
|
15
|
+
- ✅ Direct Convex integration (using `useQuery`, `useMutation`, Convex hooks)
|
|
16
|
+
- ⚠️ Tightly coupled to Convex - can't swap to WordPress/Notion/Supabase
|
|
17
|
+
|
|
18
|
+
**Target State:**
|
|
19
|
+
|
|
20
|
+
- Frontend uses DataProvider interface
|
|
21
|
+
- Backend is pluggable - organizations can use Convex, their existing WordPress site, Notion databases, or any other backend
|
|
22
|
+
- Existing auth tests continue to pass
|
|
23
|
+
- All current functionality preserved while adding flexibility
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Important Context
|
|
28
|
+
|
|
29
|
+
**This is NOT a bug fix - this is a strategic enhancement.**
|
|
30
|
+
|
|
31
|
+
✅ **Current System Works:**
|
|
32
|
+
|
|
33
|
+
- Frontend successfully talks to Convex backend
|
|
34
|
+
- Auth is functional with passing tests
|
|
35
|
+
- All features operational
|
|
36
|
+
- No critical issues requiring immediate changes
|
|
37
|
+
|
|
38
|
+
⚠️ **Why Separate Now:**
|
|
39
|
+
|
|
40
|
+
- Add backend flexibility (support WordPress, Notion, Shopify, etc.)
|
|
41
|
+
- Enable multi-backend federation (auth in Convex, blog in WordPress, products in Shopify)
|
|
42
|
+
- Allow organizations to use existing infrastructure
|
|
43
|
+
- Remove Convex lock-in
|
|
44
|
+
|
|
45
|
+
**Migration Approach:**
|
|
46
|
+
|
|
47
|
+
- Zero downtime - wrap existing working functionality
|
|
48
|
+
- Preserve all existing tests (especially auth tests)
|
|
49
|
+
- Gradual page-by-page migration
|
|
50
|
+
- Can rollback at any phase
|
|
51
|
+
- No data migration required
|
|
52
|
+
|
|
53
|
+
**Priority:** Medium (strategic, not urgent)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Table of Contents
|
|
58
|
+
|
|
59
|
+
1. [Architecture Comparison](#architecture-comparison)
|
|
60
|
+
2. [Benefits of Separation](#benefits-of-separation)
|
|
61
|
+
3. [Migration Strategy](#migration-strategy)
|
|
62
|
+
4. [API Key Authentication](#api-key-authentication)
|
|
63
|
+
5. [File Structure Changes](#file-structure-changes)
|
|
64
|
+
6. [Implementation Steps](#implementation-steps)
|
|
65
|
+
7. [Testing Strategy](#testing-strategy)
|
|
66
|
+
8. [Deployment Changes](#deployment-changes)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Architecture Comparison
|
|
71
|
+
|
|
72
|
+
### Current Architecture (Working, but Coupled)
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
┌─────────────────────────────────────────────────────────┐
|
|
76
|
+
│ FRONTEND (Astro + React) │
|
|
77
|
+
│ ┌──────────────────────────────────────────────────┐ │
|
|
78
|
+
│ │ Pages & Components │ │
|
|
79
|
+
│ │ ├─ import { useQuery } from 'convex/react' │ │
|
|
80
|
+
│ │ ├─ import { api } from 'convex/_generated/api' │ │
|
|
81
|
+
│ │ └─ const data = useQuery(api.things.get) │ │
|
|
82
|
+
│ └──────────────────────────────────────────────────┘ │
|
|
83
|
+
│ │
|
|
84
|
+
│ frontend/convex/* (schema, mutations, queries) │
|
|
85
|
+
│ ↓ Direct WebSocket Connection (WORKING) │
|
|
86
|
+
│ │
|
|
87
|
+
│ frontend/tests/auth/* (Auth tests passing) │
|
|
88
|
+
└─────────────────────────────────────────────────────────┘
|
|
89
|
+
│
|
|
90
|
+
▼
|
|
91
|
+
┌───────────────────────┐
|
|
92
|
+
│ CONVEX BACKEND │
|
|
93
|
+
│ (Real-time DB) │
|
|
94
|
+
│ 6-Dimension Ontology │
|
|
95
|
+
└───────────────────────┘
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Status:** ✅ Working - Auth functional, tests passing
|
|
99
|
+
|
|
100
|
+
**Limitations (Not Bugs):**
|
|
101
|
+
|
|
102
|
+
- ⚠️ Frontend tightly coupled to Convex (works, but inflexible)
|
|
103
|
+
- ⚠️ Can't swap backend without rewriting frontend
|
|
104
|
+
- ⚠️ Organizations must use Convex (can't use existing WordPress/Notion)
|
|
105
|
+
- ⚠️ Hard to add mobile/desktop apps without Convex SDK
|
|
106
|
+
- ⚠️ No multi-backend support (can't federate data from Shopify/WordPress)
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### Target Architecture (Backend-Agnostic with 6-Dimension Ontology)
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
┌──────────────────────────────────────────────────────────┐
|
|
114
|
+
│ FRONTEND (Backend-Agnostic) │
|
|
115
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
116
|
+
│ │ Astro Pages + React Components │ │
|
|
117
|
+
│ │ - Renders UI from data │ │
|
|
118
|
+
│ │ - Calls DataProvider methods │ │
|
|
119
|
+
│ │ - NO backend-specific code │ │
|
|
120
|
+
│ └────────────────────────────────────────────────────┘ │
|
|
121
|
+
│ │
|
|
122
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
123
|
+
│ │ Effect.ts Services (Backend-Agnostic) │ │
|
|
124
|
+
│ │ - ThingService │ │
|
|
125
|
+
│ │ - ConnectionService │ │
|
|
126
|
+
│ │ - Uses DataProvider interface │ │
|
|
127
|
+
│ └────────────────────────────────────────────────────┘ │
|
|
128
|
+
│ │
|
|
129
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
130
|
+
│ │ DataProvider Interface (Universal API) │ │
|
|
131
|
+
│ │ organizations: { get, list, update } │ │
|
|
132
|
+
│ │ people: { get, list, create, update } │ │
|
|
133
|
+
│ │ things: { get, list, create, update, delete } │ │
|
|
134
|
+
│ │ connections: { create, getRelated, getCount } │ │
|
|
135
|
+
│ │ events: { log, query } │ │
|
|
136
|
+
│ │ knowledge: { embed, search } │ │
|
|
137
|
+
│ └────────────────────────────────────────────────────┘ │
|
|
138
|
+
└──────────────────────────────────────────────────────────┘
|
|
139
|
+
│
|
|
140
|
+
↓ Provider Implementation
|
|
141
|
+
┌──────────────────────────────────────────────────────────┐
|
|
142
|
+
│ BACKEND PROVIDERS (Choose One - ONE Line!) │
|
|
143
|
+
│ │
|
|
144
|
+
│ ┌─────────────────────────────────────────────┐ │
|
|
145
|
+
│ │ Option 1: ConvexProvider │ │
|
|
146
|
+
│ │ → Convex backend (real-time, serverless) │ │
|
|
147
|
+
│ └─────────────────────────────────────────────┘ │
|
|
148
|
+
│ │
|
|
149
|
+
│ ┌─────────────────────────────────────────────┐ │
|
|
150
|
+
│ │ Option 2: WordPressProvider │ │
|
|
151
|
+
│ │ → WordPress + WooCommerce (existing CMS) │ │
|
|
152
|
+
│ └─────────────────────────────────────────────┘ │
|
|
153
|
+
│ │
|
|
154
|
+
│ ┌─────────────────────────────────────────────┐ │
|
|
155
|
+
│ │ Option 3: NotionProvider │ │
|
|
156
|
+
│ │ → Notion databases as backend │ │
|
|
157
|
+
│ └─────────────────────────────────────────────┘ │
|
|
158
|
+
│ │
|
|
159
|
+
│ ┌─────────────────────────────────────────────┐ │
|
|
160
|
+
│ │ Option 4: SupabaseProvider │ │
|
|
161
|
+
│ │ → PostgreSQL + real-time (pgvector) │ │
|
|
162
|
+
│ └─────────────────────────────────────────────┘ │
|
|
163
|
+
│ │
|
|
164
|
+
│ ┌─────────────────────────────────────────────┐ │
|
|
165
|
+
│ │ Option 5: CustomProvider │ │
|
|
166
|
+
│ │ → Your own API/database │ │
|
|
167
|
+
│ └─────────────────────────────────────────────┘ │
|
|
168
|
+
│ │
|
|
169
|
+
│ All implement the same DataProvider interface │
|
|
170
|
+
└──────────────────────────────────────────────────────────┘
|
|
171
|
+
│
|
|
172
|
+
↓ Backend-Specific Implementation
|
|
173
|
+
┌──────────────────────────────────────────────────────────┐
|
|
174
|
+
│ ACTUAL BACKENDS (Examples) │
|
|
175
|
+
│ │
|
|
176
|
+
│ Convex: │
|
|
177
|
+
│ 6 tables → organizations, people, things, │
|
|
178
|
+
│ connections, events, knowledge │
|
|
179
|
+
│ │
|
|
180
|
+
│ WordPress: │
|
|
181
|
+
│ wp_posts, wp_users, wp_postmeta, wp_terms, etc. │
|
|
182
|
+
│ │
|
|
183
|
+
│ Notion: │
|
|
184
|
+
│ Databases, Pages, Relations │
|
|
185
|
+
│ │
|
|
186
|
+
│ Supabase: │
|
|
187
|
+
│ PostgreSQL tables with pgvector for knowledge │
|
|
188
|
+
│ │
|
|
189
|
+
│ Custom: │
|
|
190
|
+
│ Your own database schema │
|
|
191
|
+
└──────────────────────────────────────────────────────────┘
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Benefits:**
|
|
195
|
+
|
|
196
|
+
- ✅ **Backend-Agnostic:** Change backend by editing ONE line in config
|
|
197
|
+
- ✅ **Multi-Backend Support:** Organizations can use existing infrastructure (WordPress, Notion, etc.)
|
|
198
|
+
- ✅ **No Lock-In:** Not tied to Convex, any backend works
|
|
199
|
+
- ✅ **Progressive Migration:** Keep existing WordPress site, add ONE frontend gradually
|
|
200
|
+
- ✅ **Frontend Independence:** Rebuild UI without touching backend
|
|
201
|
+
- ✅ **6-Dimension Ontology:** Universal data model works with any backend
|
|
202
|
+
- ✅ **Effect.ts Services:** Type-safe, composable, testable operations
|
|
203
|
+
- ✅ **Multi-Platform:** Same backend serves web, mobile, desktop, CLI
|
|
204
|
+
- ✅ **Developer Choice:** Use the best backend for your organization's needs
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Understanding the 6-Dimension Ontology
|
|
209
|
+
|
|
210
|
+
**The ONE ontology models reality in six core dimensions:**
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
┌──────────────────────────────────────────────────────┐
|
|
214
|
+
│ 1. ORGANIZATIONS → Who owns this space? │
|
|
215
|
+
│ Multi-tenant isolation, perfect data boundaries │
|
|
216
|
+
└──────────────────────────────────────────────────────┘
|
|
217
|
+
↓
|
|
218
|
+
┌──────────────────────────────────────────────────────┐
|
|
219
|
+
│ 2. PEOPLE → Who can do what? │
|
|
220
|
+
│ Authorization, governance, human intent │
|
|
221
|
+
└──────────────────────────────────────────────────────┘
|
|
222
|
+
↓
|
|
223
|
+
┌──────────────────────────────────────────────────────┐
|
|
224
|
+
│ 3. THINGS → What exists? │
|
|
225
|
+
│ Domain entities (66 types) │
|
|
226
|
+
└──────────────────────────────────────────────────────┘
|
|
227
|
+
↓
|
|
228
|
+
┌──────────────────────────────────────────────────────┐
|
|
229
|
+
│ 4. CONNECTIONS → How do things relate? │
|
|
230
|
+
│ Relationships (25 types) │
|
|
231
|
+
└──────────────────────────────────────────────────────┘
|
|
232
|
+
↓
|
|
233
|
+
┌──────────────────────────────────────────────────────┐
|
|
234
|
+
│ 5. EVENTS → What happened? │
|
|
235
|
+
│ Audit trail, complete history (67 types) │
|
|
236
|
+
└──────────────────────────────────────────────────────┘
|
|
237
|
+
↓
|
|
238
|
+
┌──────────────────────────────────────────────────────┐
|
|
239
|
+
│ 6. KNOWLEDGE → What does it mean? │
|
|
240
|
+
│ AI intelligence, embeddings, RAG │
|
|
241
|
+
└──────────────────────────────────────────────────────┘
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Key Principle:** Every feature maps to these 6 dimensions. If you can't map it, you're thinking about it wrong.
|
|
245
|
+
|
|
246
|
+
### Example: User Creates a Course
|
|
247
|
+
|
|
248
|
+
**Organizations (Dimension 1):**
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
organizationId: "fitnesspro_123"; // All operations scoped here
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**People (Dimension 2):**
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// Separate people table (NOT things!)
|
|
258
|
+
{
|
|
259
|
+
_id: Id<'people'>,
|
|
260
|
+
email: "sarah@fitnesspro.com",
|
|
261
|
+
role: "org_owner", // Authorization level
|
|
262
|
+
organizationId: "fitnesspro_123"
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Things (Dimension 3):**
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
// Course is a thing
|
|
270
|
+
{
|
|
271
|
+
_id: Id<'things'>,
|
|
272
|
+
thingType: "course",
|
|
273
|
+
name: "Fitness Fundamentals",
|
|
274
|
+
organizationId: "fitnesspro_123",
|
|
275
|
+
properties: {
|
|
276
|
+
description: "...",
|
|
277
|
+
price: 99,
|
|
278
|
+
duration: "8 weeks"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Connections (Dimension 4):**
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
// Sarah owns the course
|
|
287
|
+
{
|
|
288
|
+
_id: Id<'connections'>,
|
|
289
|
+
fromPersonId: sarah_person_id, // Person ID (Dimension 2)!
|
|
290
|
+
toThingId: course_thing_id, // Thing ID (Dimension 3)
|
|
291
|
+
relationshipType: "owns",
|
|
292
|
+
organizationId: "fitnesspro_123"
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Events (Dimension 5):**
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// Log the creation
|
|
300
|
+
{
|
|
301
|
+
_id: Id<'events'>,
|
|
302
|
+
eventType: "course_created",
|
|
303
|
+
actorId: sarah_person_id, // Person who did it (REQUIRED)
|
|
304
|
+
targetId: course_thing_id, // What was created
|
|
305
|
+
organizationId: "fitnesspro_123",
|
|
306
|
+
timestamp: Date.now()
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Knowledge (Dimension 6):**
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// Embed course content for AI
|
|
314
|
+
{
|
|
315
|
+
_id: Id<'knowledge'>,
|
|
316
|
+
knowledgeType: "document",
|
|
317
|
+
text: "Fitness Fundamentals...",
|
|
318
|
+
embedding: [...], // 768-dim vector
|
|
319
|
+
sourceThingId: course_thing_id,
|
|
320
|
+
organizationId: "fitnesspro_123",
|
|
321
|
+
labels: ["course", "fitness", "beginner"]
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**Result:** One operation touches all 6 dimensions → complete context for AI agents.
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## Effect.ts + DataProvider Pattern
|
|
330
|
+
|
|
331
|
+
**The separation uses Effect.ts for type-safety and DataProvider for backend-agnosticism.**
|
|
332
|
+
|
|
333
|
+
### DataProvider Interface (Backend-Agnostic)
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// frontend/src/providers/DataProvider.ts
|
|
337
|
+
import { Effect, Context } from "effect";
|
|
338
|
+
|
|
339
|
+
// Universal interface ALL backends implement
|
|
340
|
+
export interface DataProvider {
|
|
341
|
+
// Dimension 1: Organizations
|
|
342
|
+
organizations: {
|
|
343
|
+
get: (id: string) => Effect.Effect<Organization, OrganizationNotFoundError>;
|
|
344
|
+
list: (params?: {
|
|
345
|
+
status?: string;
|
|
346
|
+
}) => Effect.Effect<Organization[], Error>;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// Dimension 2: People (separate from things!)
|
|
350
|
+
people: {
|
|
351
|
+
get: (id: string) => Effect.Effect<Person, PersonNotFoundError>;
|
|
352
|
+
list: (params: {
|
|
353
|
+
organizationId?: string;
|
|
354
|
+
role?: string;
|
|
355
|
+
}) => Effect.Effect<Person[], Error>;
|
|
356
|
+
create: (input: {
|
|
357
|
+
email: string;
|
|
358
|
+
displayName: string;
|
|
359
|
+
role: string;
|
|
360
|
+
organizationId: string;
|
|
361
|
+
}) => Effect.Effect<string, Error>;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// Dimension 3: Things
|
|
365
|
+
things: {
|
|
366
|
+
get: (id: string) => Effect.Effect<Thing, ThingNotFoundError>;
|
|
367
|
+
list: (params: {
|
|
368
|
+
type: ThingType;
|
|
369
|
+
organizationId?: string;
|
|
370
|
+
}) => Effect.Effect<Thing[], Error>;
|
|
371
|
+
create: (input: {
|
|
372
|
+
type: ThingType;
|
|
373
|
+
name: string;
|
|
374
|
+
organizationId: string;
|
|
375
|
+
properties: any;
|
|
376
|
+
}) => Effect.Effect<string, Error>;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// Dimension 4: Connections
|
|
380
|
+
connections: {
|
|
381
|
+
create: (input: {
|
|
382
|
+
fromPersonId?: string; // Can connect people
|
|
383
|
+
fromThingId?: string; // OR things
|
|
384
|
+
toThingId: string;
|
|
385
|
+
relationshipType: ConnectionType;
|
|
386
|
+
organizationId: string;
|
|
387
|
+
metadata?: any;
|
|
388
|
+
}) => Effect.Effect<string, Error>;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// Dimension 5: Events
|
|
392
|
+
events: {
|
|
393
|
+
log: (event: {
|
|
394
|
+
type: EventType;
|
|
395
|
+
actorId: string; // Always a Person ID!
|
|
396
|
+
targetId?: string;
|
|
397
|
+
organizationId: string;
|
|
398
|
+
metadata?: any;
|
|
399
|
+
}) => Effect.Effect<void, Error>;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// Dimension 6: Knowledge
|
|
403
|
+
knowledge: {
|
|
404
|
+
search: (params: {
|
|
405
|
+
query: string;
|
|
406
|
+
organizationId: string;
|
|
407
|
+
k?: number;
|
|
408
|
+
}) => Effect.Effect<KnowledgeChunk[], Error>;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export const DataProvider = Context.GenericTag<DataProvider>("DataProvider");
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
### Effect.ts Service Example
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
// backend/services/CourseService.ts
|
|
419
|
+
import { Effect } from "effect";
|
|
420
|
+
import { DataProvider } from "@/providers/DataProvider";
|
|
421
|
+
|
|
422
|
+
export class CourseService extends Effect.Service<CourseService>()(
|
|
423
|
+
"CourseService",
|
|
424
|
+
{
|
|
425
|
+
effect: Effect.gen(function* () {
|
|
426
|
+
const provider = yield* DataProvider;
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
// Create course → touches all 6 dimensions
|
|
430
|
+
create: (params: {
|
|
431
|
+
name: string;
|
|
432
|
+
creatorId: string;
|
|
433
|
+
organizationId: string;
|
|
434
|
+
properties: any;
|
|
435
|
+
}) =>
|
|
436
|
+
Effect.gen(function* () {
|
|
437
|
+
// 3. Create thing (course)
|
|
438
|
+
const courseId = yield* provider.things.create({
|
|
439
|
+
type: "course",
|
|
440
|
+
name: params.name,
|
|
441
|
+
organizationId: params.organizationId,
|
|
442
|
+
properties: params.properties,
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// 4. Create connection (person owns course)
|
|
446
|
+
yield* provider.connections.create({
|
|
447
|
+
fromPersonId: params.creatorId, // Person ID!
|
|
448
|
+
toThingId: courseId,
|
|
449
|
+
relationshipType: "owns",
|
|
450
|
+
organizationId: params.organizationId,
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// 5. Log event (course created)
|
|
454
|
+
yield* provider.events.log({
|
|
455
|
+
type: "course_created",
|
|
456
|
+
actorId: params.creatorId, // Person who did it
|
|
457
|
+
targetId: courseId,
|
|
458
|
+
organizationId: params.organizationId,
|
|
459
|
+
metadata: {
|
|
460
|
+
courseName: params.name,
|
|
461
|
+
creatorEmail: "sarah@fitnesspro.com",
|
|
462
|
+
},
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// 6. Embed for knowledge (AI can find it)
|
|
466
|
+
// (handled by background job)
|
|
467
|
+
|
|
468
|
+
return courseId;
|
|
469
|
+
}),
|
|
470
|
+
};
|
|
471
|
+
}),
|
|
472
|
+
dependencies: [DataProvider],
|
|
473
|
+
}
|
|
474
|
+
) {}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Frontend Usage (Backend-Agnostic)
|
|
478
|
+
|
|
479
|
+
```tsx
|
|
480
|
+
// frontend/src/components/CreateCourse.tsx
|
|
481
|
+
import { useEffectRunner } from "@/hooks/useEffectRunner";
|
|
482
|
+
import { CourseService } from "@/services/CourseService";
|
|
483
|
+
import { Effect } from "effect";
|
|
484
|
+
|
|
485
|
+
export function CreateCourseForm() {
|
|
486
|
+
const { run, loading } = useEffectRunner();
|
|
487
|
+
|
|
488
|
+
const handleSubmit = async (formData: CourseFormData) => {
|
|
489
|
+
// Define Effect program using CourseService
|
|
490
|
+
const program = Effect.gen(function* () {
|
|
491
|
+
const courseService = yield* CourseService;
|
|
492
|
+
|
|
493
|
+
// Create course → touches all 6 dimensions automatically
|
|
494
|
+
const courseId = yield* courseService.create({
|
|
495
|
+
name: formData.name,
|
|
496
|
+
creatorId: currentUser.id,
|
|
497
|
+
organizationId: currentOrg.id,
|
|
498
|
+
properties: {
|
|
499
|
+
description: formData.description,
|
|
500
|
+
price: formData.price,
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
return courseId;
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// Run program (frontend uses DataProvider)
|
|
508
|
+
const courseId = await run(program);
|
|
509
|
+
|
|
510
|
+
// Redirect to course page
|
|
511
|
+
navigate(`/courses/${courseId}`);
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
return <form onSubmit={handleSubmit}>...</form>;
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Backend Provider Implementations
|
|
519
|
+
|
|
520
|
+
**Convex Provider:**
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
// frontend/src/providers/convex/ConvexProvider.ts
|
|
524
|
+
import { Effect, Layer } from "effect";
|
|
525
|
+
import { ConvexHttpClient } from "convex/browser";
|
|
526
|
+
import { DataProvider } from "../DataProvider";
|
|
527
|
+
|
|
528
|
+
export class ConvexProvider implements DataProvider {
|
|
529
|
+
constructor(private client: ConvexHttpClient) {}
|
|
530
|
+
|
|
531
|
+
things = {
|
|
532
|
+
create: (input) =>
|
|
533
|
+
Effect.tryPromise({
|
|
534
|
+
try: () => this.client.mutation(api.things.create, input),
|
|
535
|
+
catch: (error) => new Error(String(error)),
|
|
536
|
+
}),
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
people = {
|
|
540
|
+
create: (input) =>
|
|
541
|
+
Effect.tryPromise({
|
|
542
|
+
try: () => this.client.mutation(api.people.create, input),
|
|
543
|
+
catch: (error) => new Error(String(error)),
|
|
544
|
+
}),
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
// ... other dimensions
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export const convexProvider = (config: { url: string }) =>
|
|
551
|
+
Layer.succeed(
|
|
552
|
+
DataProvider,
|
|
553
|
+
new ConvexProvider(new ConvexHttpClient(config.url))
|
|
554
|
+
);
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**Composite Provider (Multi-Backend):**
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
// frontend/src/providers/composite/CompositeProvider.ts
|
|
561
|
+
import { Effect, Layer } from "effect";
|
|
562
|
+
import { DataProvider } from "../DataProvider";
|
|
563
|
+
|
|
564
|
+
export class CompositeProvider implements DataProvider {
|
|
565
|
+
constructor(
|
|
566
|
+
private defaultProvider: DataProvider,
|
|
567
|
+
private routes: Map<ThingType, DataProvider>
|
|
568
|
+
) {}
|
|
569
|
+
|
|
570
|
+
// Route to appropriate provider based on thing type
|
|
571
|
+
private getProvider(type?: ThingType): DataProvider {
|
|
572
|
+
if (type && this.routes.has(type)) {
|
|
573
|
+
return this.routes.get(type)!;
|
|
574
|
+
}
|
|
575
|
+
return this.defaultProvider;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
things = {
|
|
579
|
+
get: (id: string) =>
|
|
580
|
+
Effect.gen(function* () {
|
|
581
|
+
// Fetch thing to determine type
|
|
582
|
+
const thing = yield* this.defaultProvider.things.get(id);
|
|
583
|
+
|
|
584
|
+
// Route to appropriate provider
|
|
585
|
+
const provider = this.getProvider(thing.type);
|
|
586
|
+
if (provider !== this.defaultProvider) {
|
|
587
|
+
return yield* provider.things.get(id);
|
|
588
|
+
}
|
|
589
|
+
return thing;
|
|
590
|
+
}),
|
|
591
|
+
|
|
592
|
+
list: (params: { type: ThingType; organizationId?: string }) =>
|
|
593
|
+
Effect.gen(function* () {
|
|
594
|
+
// Route based on thing type
|
|
595
|
+
const provider = this.getProvider(params.type);
|
|
596
|
+
return yield* provider.things.list(params);
|
|
597
|
+
}),
|
|
598
|
+
|
|
599
|
+
create: (input: {
|
|
600
|
+
type: ThingType;
|
|
601
|
+
name: string;
|
|
602
|
+
organizationId: string;
|
|
603
|
+
properties: any;
|
|
604
|
+
}) =>
|
|
605
|
+
Effect.gen(function* () {
|
|
606
|
+
// Route based on thing type
|
|
607
|
+
const provider = this.getProvider(input.type);
|
|
608
|
+
return yield* provider.things.create(input);
|
|
609
|
+
}),
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// Organizations, People, Events, Knowledge → always use default provider
|
|
613
|
+
organizations = this.defaultProvider.organizations;
|
|
614
|
+
people = this.defaultProvider.people;
|
|
615
|
+
connections = this.defaultProvider.connections;
|
|
616
|
+
events = this.defaultProvider.events;
|
|
617
|
+
knowledge = this.defaultProvider.knowledge;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export function compositeProvider(config: {
|
|
621
|
+
default: Layer<DataProvider>;
|
|
622
|
+
routes: Record<string, Layer<DataProvider> | "default">;
|
|
623
|
+
}) {
|
|
624
|
+
return Effect.gen(function* () {
|
|
625
|
+
// Resolve default provider
|
|
626
|
+
const defaultProvider = yield* Effect.provide(DataProvider, config.default);
|
|
627
|
+
|
|
628
|
+
// Resolve route providers
|
|
629
|
+
const routes = new Map<ThingType, DataProvider>();
|
|
630
|
+
for (const [type, providerConfig] of Object.entries(config.routes)) {
|
|
631
|
+
if (providerConfig === "default") {
|
|
632
|
+
routes.set(type as ThingType, defaultProvider);
|
|
633
|
+
} else {
|
|
634
|
+
const provider = yield* Effect.provide(DataProvider, providerConfig);
|
|
635
|
+
routes.set(type as ThingType, provider);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return new CompositeProvider(defaultProvider, routes);
|
|
640
|
+
}).pipe(Effect.map((provider) => Layer.succeed(DataProvider, provider)));
|
|
641
|
+
}
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
**Real-World Example:**
|
|
645
|
+
|
|
646
|
+
```typescript
|
|
647
|
+
// Auth & courses in Convex, blog in WordPress, products in Shopify
|
|
648
|
+
export default defineConfig({
|
|
649
|
+
integrations: [
|
|
650
|
+
one({
|
|
651
|
+
provider: compositeProvider({
|
|
652
|
+
default: convexProvider({ url: env.PUBLIC_CONVEX_URL }),
|
|
653
|
+
routes: {
|
|
654
|
+
blog_post: wordpressProvider({
|
|
655
|
+
url: "https://blog.yoursite.com",
|
|
656
|
+
apiKey: env.WP_API_KEY,
|
|
657
|
+
}),
|
|
658
|
+
product: shopifyProvider({
|
|
659
|
+
store: "yourstore.myshopify.com",
|
|
660
|
+
accessToken: env.SHOPIFY_ACCESS_TOKEN,
|
|
661
|
+
}),
|
|
662
|
+
},
|
|
663
|
+
}),
|
|
664
|
+
}),
|
|
665
|
+
],
|
|
666
|
+
});
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
**Benefits:**
|
|
670
|
+
|
|
671
|
+
- ✅ **Type-safe**: Compiler enforces all dimensions
|
|
672
|
+
- ✅ **Composable**: Services build on each other
|
|
673
|
+
- ✅ **Testable**: Mock layers, not databases
|
|
674
|
+
- ✅ **Backend-agnostic**: Change provider, not code
|
|
675
|
+
- ✅ **Multi-backend**: Use best backend for each data type
|
|
676
|
+
- ✅ **6-dimension aware**: Every operation properly scoped
|
|
677
|
+
|
|
678
|
+
---
|
|
679
|
+
|
|
680
|
+
## Benefits of Separation
|
|
681
|
+
|
|
682
|
+
### 1. Multi-Tenancy Support
|
|
683
|
+
|
|
684
|
+
**Before:**
|
|
685
|
+
|
|
686
|
+
```
|
|
687
|
+
Org A → Frontend A → Convex Deployment A
|
|
688
|
+
Org B → Frontend B → Convex Deployment B
|
|
689
|
+
Org C → Frontend C → Convex Deployment C
|
|
690
|
+
|
|
691
|
+
❌ 3 orgs = 3 Convex deployments (expensive, hard to manage)
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
**After:**
|
|
695
|
+
|
|
696
|
+
```
|
|
697
|
+
Org A → Frontend A ──┐
|
|
698
|
+
├→ Single Backend API → Single Convex Deployment
|
|
699
|
+
Org B → Frontend B ──┤ (with API key isolation)
|
|
700
|
+
│
|
|
701
|
+
Org C → Frontend C ──┘
|
|
702
|
+
|
|
703
|
+
✅ 3 orgs = 1 Convex deployment (cheap, centralized)
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
### 2. Backend Independence
|
|
707
|
+
|
|
708
|
+
**Before:**
|
|
709
|
+
|
|
710
|
+
- Frontend tightly coupled to Convex
|
|
711
|
+
- Can't switch to WordPress, Notion, Supabase, etc.
|
|
712
|
+
- Organizations must use Convex even if they have existing systems
|
|
713
|
+
- Must learn Convex SDK for every platform
|
|
714
|
+
|
|
715
|
+
❌ Locked into Convex
|
|
716
|
+
|
|
717
|
+
**After (Backend-Agnostic):**
|
|
718
|
+
|
|
719
|
+
- Frontend uses DataProvider interface
|
|
720
|
+
- Organizations can use:
|
|
721
|
+
- **Convex** (real-time, serverless)
|
|
722
|
+
- **WordPress** (existing CMS)
|
|
723
|
+
- **Notion** (databases as backend)
|
|
724
|
+
- **Supabase** (PostgreSQL + real-time)
|
|
725
|
+
- **Custom backend** (your own API)
|
|
726
|
+
- Change backend by editing ONE line in `astro.config.ts`
|
|
727
|
+
|
|
728
|
+
```typescript
|
|
729
|
+
// Swap backends - frontend code unchanged!
|
|
730
|
+
provider: convexProvider({ url: "..." });
|
|
731
|
+
// OR
|
|
732
|
+
provider: wordpressProvider({ url: "...", apiKey: "..." });
|
|
733
|
+
// OR
|
|
734
|
+
provider: notionProvider({ apiKey: "...", databaseId: "..." });
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
✅ Organizations use their existing infrastructure
|
|
738
|
+
|
|
739
|
+
### 3. Team Organization
|
|
740
|
+
|
|
741
|
+
**Before:**
|
|
742
|
+
|
|
743
|
+
```
|
|
744
|
+
Full-stack developer needs to know:
|
|
745
|
+
- Astro + React
|
|
746
|
+
- Convex-specific hooks and patterns
|
|
747
|
+
- Convex schema + queries/mutations/actions
|
|
748
|
+
- Effect.ts
|
|
749
|
+
- Business logic
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
**After (Backend-Agnostic):**
|
|
753
|
+
|
|
754
|
+
```
|
|
755
|
+
Frontend developer needs to know:
|
|
756
|
+
- Astro + React
|
|
757
|
+
- DataProvider interface (universal)
|
|
758
|
+
- Effect.ts services
|
|
759
|
+
|
|
760
|
+
Backend developer needs to know:
|
|
761
|
+
- Their chosen backend (WordPress, Convex, Notion, etc.)
|
|
762
|
+
- How to implement DataProvider for that backend
|
|
763
|
+
- 6-dimension ontology mapping
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
✅ Frontend devs don't learn backend-specific details
|
|
767
|
+
✅ Organizations can hire developers with their existing tech stack
|
|
768
|
+
✅ Clear separation of concerns
|
|
769
|
+
|
|
770
|
+
### 4. Progressive Migration & Flexibility
|
|
771
|
+
|
|
772
|
+
**Before:**
|
|
773
|
+
|
|
774
|
+
```
|
|
775
|
+
Organization has WordPress site with 10,000 posts
|
|
776
|
+
Want to use ONE frontend
|
|
777
|
+
Must migrate ALL data to Convex first
|
|
778
|
+
|
|
779
|
+
❌ Big-bang migration required
|
|
780
|
+
❌ Can't test gradually
|
|
781
|
+
❌ Risk losing SEO, existing integrations
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
**After (Backend-Agnostic):**
|
|
785
|
+
|
|
786
|
+
```
|
|
787
|
+
Organization keeps WordPress backend
|
|
788
|
+
Implements WordPressProvider (maps WP → 6-dimension ontology)
|
|
789
|
+
Deploys ONE frontend
|
|
790
|
+
Frontend talks to WordPress via DataProvider
|
|
791
|
+
|
|
792
|
+
✅ Zero data migration needed
|
|
793
|
+
✅ Keep existing WordPress admin, plugins, integrations
|
|
794
|
+
✅ Progressive: Start with one page, migrate gradually
|
|
795
|
+
✅ Test ONE frontend without touching backend
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
**Real-World Example:**
|
|
799
|
+
|
|
800
|
+
```typescript
|
|
801
|
+
// Week 1: Deploy ONE frontend with WordPress backend
|
|
802
|
+
provider: wordpressProvider({
|
|
803
|
+
url: "https://existing-site.com",
|
|
804
|
+
apiKey: env.WP_API_KEY,
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
// Week 50: Migrate to Convex when ready (ONE line change)
|
|
808
|
+
provider: convexProvider({
|
|
809
|
+
url: env.CONVEX_URL,
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
// Frontend code? UNCHANGED. No rewrite needed.
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
✅ Organizations control their migration timeline
|
|
816
|
+
✅ No forced backend choice
|
|
817
|
+
✅ Test frontend without backend risk
|
|
818
|
+
|
|
819
|
+
---
|
|
820
|
+
|
|
821
|
+
## Migration Strategy
|
|
822
|
+
|
|
823
|
+
### Phase 1: Create DataProvider Interface (Universal API)
|
|
824
|
+
|
|
825
|
+
**Goal:** Define the backend-agnostic interface that ALL providers must implement
|
|
826
|
+
|
|
827
|
+
**Tasks:**
|
|
828
|
+
|
|
829
|
+
1. Create `/frontend/src/providers/DataProvider.ts`
|
|
830
|
+
2. Define interfaces for 6 dimensions:
|
|
831
|
+
- `organizations: { get, list, update }`
|
|
832
|
+
- `people: { get, list, create, update, delete }`
|
|
833
|
+
- `things: { get, list, create, update, delete }`
|
|
834
|
+
- `connections: { create, getRelated, getCount, delete }`
|
|
835
|
+
- `events: { log, query }`
|
|
836
|
+
- `knowledge: { embed, search }`
|
|
837
|
+
3. Define error types (ThingNotFoundError, ConnectionCreateError, etc.)
|
|
838
|
+
4. Document interface with TypeScript types
|
|
839
|
+
|
|
840
|
+
**Timeline:** 2-3 days
|
|
841
|
+
|
|
842
|
+
**Risk:** None (just interface definition)
|
|
843
|
+
|
|
844
|
+
**Reference:** See `one/knowledge/ontology-frontend.md` for complete DataProvider interface
|
|
845
|
+
|
|
846
|
+
---
|
|
847
|
+
|
|
848
|
+
### Phase 2: Implement ConvexProvider (Wrap Existing Working Backend)
|
|
849
|
+
|
|
850
|
+
**Goal:** Wrap existing **working** Convex backend with DataProvider interface (NO functionality changes)
|
|
851
|
+
|
|
852
|
+
**Tasks:**
|
|
853
|
+
|
|
854
|
+
1. Create `/frontend/src/providers/convex/ConvexProvider.ts`
|
|
855
|
+
2. Implement DataProvider interface using Convex client:
|
|
856
|
+
```typescript
|
|
857
|
+
things.get(id) => client.query(api.queries.things.get, { id })
|
|
858
|
+
things.create(input) => client.mutation(api.mutations.things.create, input)
|
|
859
|
+
// etc. for all methods
|
|
860
|
+
```
|
|
861
|
+
3. Wrap Convex calls in Effect.ts for error handling
|
|
862
|
+
4. Create factory function: `convexProvider(config)`
|
|
863
|
+
5. Test provider in isolation
|
|
864
|
+
6. **Critical:** Run `frontend/tests/auth/*` - all tests must pass
|
|
865
|
+
|
|
866
|
+
**Timeline:** 3-5 days
|
|
867
|
+
|
|
868
|
+
**Risk:** Very Low (just wraps existing working Convex calls, no logic changes)
|
|
869
|
+
|
|
870
|
+
**Success Criteria:**
|
|
871
|
+
|
|
872
|
+
- ✅ ConvexProvider implements DataProvider interface fully
|
|
873
|
+
- ✅ All existing auth tests pass
|
|
874
|
+
- ✅ No functionality changes - just adds abstraction layer
|
|
875
|
+
|
|
876
|
+
---
|
|
877
|
+
|
|
878
|
+
### Phase 3: Create Effect.ts Service Layer
|
|
879
|
+
|
|
880
|
+
**Goal:** Build generic services that use DataProvider (backend-agnostic)
|
|
881
|
+
|
|
882
|
+
**Tasks:**
|
|
883
|
+
|
|
884
|
+
1. Create `/frontend/src/services/ThingService.ts` (generic, handles all 66 types)
|
|
885
|
+
2. Create `/frontend/src/services/ConnectionService.ts`
|
|
886
|
+
3. Create `/frontend/src/services/ClientLayer.ts` (dependency injection)
|
|
887
|
+
4. Services delegate to DataProvider:
|
|
888
|
+
```typescript
|
|
889
|
+
export class ThingService extends Effect.Service<ThingService>()({
|
|
890
|
+
effect: Effect.gen(function* () {
|
|
891
|
+
const provider = yield* DataProvider // Backend-agnostic!
|
|
892
|
+
return {
|
|
893
|
+
get: (id: string) => provider.things.get(id),
|
|
894
|
+
list: (type, orgId) => provider.things.list({ type, organizationId: orgId })
|
|
895
|
+
}
|
|
896
|
+
})
|
|
897
|
+
})
|
|
898
|
+
```
|
|
899
|
+
5. Create `useEffectRunner` hook for React integration
|
|
900
|
+
|
|
901
|
+
**Timeline:** 3-5 days
|
|
902
|
+
|
|
903
|
+
**Risk:** Low (services just delegate to provider)
|
|
904
|
+
|
|
905
|
+
---
|
|
906
|
+
|
|
907
|
+
### Phase 4: Configure Provider in astro.config.ts
|
|
908
|
+
|
|
909
|
+
**Goal:** Wire up ConvexProvider as the active backend
|
|
910
|
+
|
|
911
|
+
**Tasks:**
|
|
912
|
+
|
|
913
|
+
1. Update `astro.config.ts`:
|
|
914
|
+
|
|
915
|
+
```typescript
|
|
916
|
+
import { convexProvider } from "./src/providers/convex";
|
|
917
|
+
|
|
918
|
+
export default defineConfig({
|
|
919
|
+
integrations: [
|
|
920
|
+
react(),
|
|
921
|
+
one({
|
|
922
|
+
provider: convexProvider({
|
|
923
|
+
url: import.meta.env.PUBLIC_CONVEX_URL,
|
|
924
|
+
}),
|
|
925
|
+
}),
|
|
926
|
+
],
|
|
927
|
+
});
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
2. Test that services can access provider via Effect.ts layers
|
|
931
|
+
|
|
932
|
+
**Timeline:** 1 day
|
|
933
|
+
|
|
934
|
+
**Risk:** Low (configuration only)
|
|
935
|
+
|
|
936
|
+
---
|
|
937
|
+
|
|
938
|
+
### Phase 5: Migrate Frontend Components Gradually
|
|
939
|
+
|
|
940
|
+
**Goal:** Replace Convex hooks with Effect.ts services (page by page)
|
|
941
|
+
|
|
942
|
+
**Before:**
|
|
943
|
+
|
|
944
|
+
```tsx
|
|
945
|
+
import { useQuery } from "convex/react";
|
|
946
|
+
import { api } from "@/convex/_generated/api";
|
|
947
|
+
|
|
948
|
+
const courses = useQuery(api.queries.things.list, { type: "course" });
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
**After:**
|
|
952
|
+
|
|
953
|
+
```tsx
|
|
954
|
+
import { useEffectRunner } from "@/hooks/useEffectRunner";
|
|
955
|
+
import { ThingService } from "@/services/ThingService";
|
|
956
|
+
|
|
957
|
+
const { run, loading } = useEffectRunner();
|
|
958
|
+
const [courses, setCourses] = useState([]);
|
|
959
|
+
|
|
960
|
+
useEffect(() => {
|
|
961
|
+
const program = Effect.gen(function* () {
|
|
962
|
+
const thingService = yield* ThingService;
|
|
963
|
+
return yield* thingService.list("course", orgId);
|
|
964
|
+
});
|
|
965
|
+
run(program, { onSuccess: setCourses });
|
|
966
|
+
}, []);
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
**Migration Order:**
|
|
970
|
+
|
|
971
|
+
1. Low-traffic pages first (`/about`, `/blog`)
|
|
972
|
+
2. Medium-traffic pages (`/courses`, `/products`)
|
|
973
|
+
3. High-traffic pages (`/`, `/dashboard`)
|
|
974
|
+
4. Authentication pages last (highest risk)
|
|
975
|
+
|
|
976
|
+
**Critical - Auth Test Validation:**
|
|
977
|
+
|
|
978
|
+
```bash
|
|
979
|
+
# After migrating ANY page that touches auth
|
|
980
|
+
npm test frontend/tests/auth/
|
|
981
|
+
|
|
982
|
+
# If tests fail:
|
|
983
|
+
# 1. STOP migration
|
|
984
|
+
# 2. Debug the issue
|
|
985
|
+
# 3. Fix before continuing
|
|
986
|
+
# 4. Re-run tests until all pass
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
**Timeline:** 2-4 weeks (gradual, page by page)
|
|
990
|
+
|
|
991
|
+
**Risk:** Medium (test each page thoroughly before deploying)
|
|
992
|
+
|
|
993
|
+
**Safety Net:** Existing auth tests catch regressions immediately
|
|
994
|
+
|
|
995
|
+
---
|
|
996
|
+
|
|
997
|
+
### Phase 6: Remove Convex Dependencies from Frontend
|
|
998
|
+
|
|
999
|
+
**Goal:** Clean up frontend - no more direct Convex imports
|
|
1000
|
+
|
|
1001
|
+
**Tasks:**
|
|
1002
|
+
|
|
1003
|
+
1. Verify all pages use Effect.ts services (no direct Convex hooks)
|
|
1004
|
+
2. Remove `convex` from `frontend/package.json`
|
|
1005
|
+
3. Delete `frontend/convex/` directory (no longer needed)
|
|
1006
|
+
4. Update build process (no Convex codegen)
|
|
1007
|
+
5. Frontend is now backend-agnostic!
|
|
1008
|
+
|
|
1009
|
+
**Timeline:** 1-2 days
|
|
1010
|
+
|
|
1011
|
+
**Risk:** Low (if Phase 5 complete)
|
|
1012
|
+
|
|
1013
|
+
---
|
|
1014
|
+
|
|
1015
|
+
### Phase 7 (Optional): Add Alternative Backend Providers
|
|
1016
|
+
|
|
1017
|
+
**Goal:** Demonstrate backend flexibility - add WordPress, Notion, Supabase providers
|
|
1018
|
+
|
|
1019
|
+
**Example - WordPress Provider:**
|
|
1020
|
+
|
|
1021
|
+
```typescript
|
|
1022
|
+
// /frontend/src/providers/wordpress/WordPressProvider.ts
|
|
1023
|
+
export class WordPressProvider implements DataProvider {
|
|
1024
|
+
things = {
|
|
1025
|
+
get: (id) =>
|
|
1026
|
+
Effect.gen(function* () {
|
|
1027
|
+
const response = yield* Effect.tryPromise({
|
|
1028
|
+
try: () => fetch(`${this.baseUrl}/wp-json/wp/v2/posts/${id}`),
|
|
1029
|
+
catch: (error) => new Error(String(error)),
|
|
1030
|
+
});
|
|
1031
|
+
const post = yield* Effect.tryPromise({
|
|
1032
|
+
try: () => response.json(),
|
|
1033
|
+
catch: (error) => new Error(String(error)),
|
|
1034
|
+
});
|
|
1035
|
+
// Transform WordPress post → ONE thing
|
|
1036
|
+
return {
|
|
1037
|
+
_id: post.id.toString(),
|
|
1038
|
+
type: "post",
|
|
1039
|
+
name: post.title.rendered,
|
|
1040
|
+
properties: {
|
|
1041
|
+
content: post.content.rendered,
|
|
1042
|
+
publishedAt: post.date,
|
|
1043
|
+
},
|
|
1044
|
+
status: post.status,
|
|
1045
|
+
createdAt: new Date(post.date).getTime(),
|
|
1046
|
+
updatedAt: new Date(post.modified).getTime(),
|
|
1047
|
+
};
|
|
1048
|
+
}),
|
|
1049
|
+
};
|
|
1050
|
+
// ... implement other methods
|
|
1051
|
+
}
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
**Swap backends in config:**
|
|
1055
|
+
|
|
1056
|
+
```typescript
|
|
1057
|
+
// Change from Convex to WordPress - ONE line!
|
|
1058
|
+
export default defineConfig({
|
|
1059
|
+
integrations: [
|
|
1060
|
+
one({
|
|
1061
|
+
// provider: convexProvider({ url: "..." }) // OLD
|
|
1062
|
+
provider: wordpressProvider({
|
|
1063
|
+
// NEW
|
|
1064
|
+
url: "https://existing-site.com",
|
|
1065
|
+
apiKey: env.WP_API_KEY,
|
|
1066
|
+
}),
|
|
1067
|
+
}),
|
|
1068
|
+
],
|
|
1069
|
+
});
|
|
1070
|
+
```
|
|
1071
|
+
|
|
1072
|
+
**Timeline:** 1-2 weeks per provider
|
|
1073
|
+
|
|
1074
|
+
**Risk:** Low (doesn't affect existing Convex setup)
|
|
1075
|
+
|
|
1076
|
+
**Value:** Demonstrates TRUE backend-agnosticism
|
|
1077
|
+
|
|
1078
|
+
---
|
|
1079
|
+
|
|
1080
|
+
## Authentication (Provider-Specific)
|
|
1081
|
+
|
|
1082
|
+
**Key Concept:** Authentication is handled by each backend provider, not by the frontend.
|
|
1083
|
+
|
|
1084
|
+
### Authentication by Provider
|
|
1085
|
+
|
|
1086
|
+
**1. Convex Provider**
|
|
1087
|
+
|
|
1088
|
+
```typescript
|
|
1089
|
+
// Frontend reads from environment
|
|
1090
|
+
provider: convexProvider({
|
|
1091
|
+
url: import.meta.env.PUBLIC_CONVEX_URL,
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
// Backend: Better Auth handles sessions
|
|
1095
|
+
// Convex mutations check ctx.auth for user identity
|
|
1096
|
+
// No API keys needed (sessions + WebSocket auth)
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
**2. WordPress Provider**
|
|
1100
|
+
|
|
1101
|
+
```typescript
|
|
1102
|
+
// Frontend configured with WordPress API key
|
|
1103
|
+
provider: wordpressProvider({
|
|
1104
|
+
url: "https://yoursite.com",
|
|
1105
|
+
apiKey: import.meta.env.WP_API_KEY, // WordPress Application Password
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
// Backend: WordPress REST API validates the key
|
|
1109
|
+
// Provider adds Authorization header to all requests
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
**3. Notion Provider**
|
|
1113
|
+
|
|
1114
|
+
```typescript
|
|
1115
|
+
// Frontend configured with Notion integration token
|
|
1116
|
+
provider: notionProvider({
|
|
1117
|
+
apiKey: import.meta.env.NOTION_API_KEY, // Notion integration token
|
|
1118
|
+
databaseId: import.meta.env.NOTION_DB_ID,
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
// Backend: Notion API validates the integration token
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
**4. Supabase Provider**
|
|
1125
|
+
|
|
1126
|
+
```typescript
|
|
1127
|
+
// Frontend uses Supabase anon key + RLS
|
|
1128
|
+
provider: supabaseProvider({
|
|
1129
|
+
url: import.meta.env.PUBLIC_SUPABASE_URL,
|
|
1130
|
+
apiKey: import.meta.env.PUBLIC_SUPABASE_ANON_KEY,
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1133
|
+
// Backend: Supabase Row Level Security (RLS) enforces access control
|
|
1134
|
+
// User sessions managed by Supabase Auth
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
### Security Model
|
|
1138
|
+
|
|
1139
|
+
**Frontend:**
|
|
1140
|
+
|
|
1141
|
+
- Frontend stores provider config (URLs, public/anon keys)
|
|
1142
|
+
- NO secret keys in frontend
|
|
1143
|
+
- Authentication state managed by provider (sessions, tokens, etc.)
|
|
1144
|
+
|
|
1145
|
+
**Backend (Provider-Specific):**
|
|
1146
|
+
|
|
1147
|
+
- **Convex:** Better Auth sessions + JWT validation
|
|
1148
|
+
- **WordPress:** Application Passwords or OAuth
|
|
1149
|
+
- **Notion:** Integration tokens (server-side only)
|
|
1150
|
+
- **Supabase:** Row Level Security (RLS) + Auth
|
|
1151
|
+
|
|
1152
|
+
### Multi-Tenancy & Authorization
|
|
1153
|
+
|
|
1154
|
+
Each provider implements organization isolation differently:
|
|
1155
|
+
|
|
1156
|
+
**Convex:**
|
|
1157
|
+
|
|
1158
|
+
```typescript
|
|
1159
|
+
// Convex mutations enforce org scoping
|
|
1160
|
+
const courses = await ctx.db
|
|
1161
|
+
.query("things")
|
|
1162
|
+
.withIndex("by_type", (q) => q.eq("type", "course"))
|
|
1163
|
+
.filter((q) => q.eq(q.field("organizationId"), userOrgId))
|
|
1164
|
+
.collect();
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
**WordPress:**
|
|
1168
|
+
|
|
1169
|
+
```typescript
|
|
1170
|
+
// WordPress categories/taxonomies for org isolation
|
|
1171
|
+
// Or use multi-site for complete separation
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
**Notion:**
|
|
1175
|
+
|
|
1176
|
+
```typescript
|
|
1177
|
+
// Separate Notion databases per organization
|
|
1178
|
+
// Or use Notion's built-in sharing/permissions
|
|
1179
|
+
```
|
|
1180
|
+
|
|
1181
|
+
**Supabase:**
|
|
1182
|
+
|
|
1183
|
+
```typescript
|
|
1184
|
+
// Row Level Security (RLS) policies
|
|
1185
|
+
CREATE POLICY "Users can only see their org's data"
|
|
1186
|
+
ON things FOR SELECT
|
|
1187
|
+
USING (organizationId = auth.uid());
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1190
|
+
**Key Point:** Authorization logic lives in the BACKEND (provider implementation), not the frontend
|
|
1191
|
+
|
|
1192
|
+
---
|
|
1193
|
+
|
|
1194
|
+
## File Structure Changes
|
|
1195
|
+
|
|
1196
|
+
### Before (Coupled)
|
|
1197
|
+
|
|
1198
|
+
```
|
|
1199
|
+
frontend/
|
|
1200
|
+
├── convex/ # ❌ Tightly coupled to Convex
|
|
1201
|
+
│ ├── _generated/
|
|
1202
|
+
│ ├── mutations/
|
|
1203
|
+
│ ├── queries/
|
|
1204
|
+
│ ├── schema.ts
|
|
1205
|
+
│ └── http.ts
|
|
1206
|
+
├── src/
|
|
1207
|
+
│ ├── components/
|
|
1208
|
+
│ │ └── CourseCard.tsx # Uses useQuery(api.things.list)
|
|
1209
|
+
│ └── pages/
|
|
1210
|
+
│ └── courses/[id].astro # Uses ConvexHttpClient
|
|
1211
|
+
└── package.json # Includes "convex": "^1.x.x"
|
|
1212
|
+
|
|
1213
|
+
❌ Can't swap to WordPress, Notion, Supabase, etc.
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
### After (Backend-Agnostic)
|
|
1217
|
+
|
|
1218
|
+
```
|
|
1219
|
+
frontend/
|
|
1220
|
+
├── src/
|
|
1221
|
+
│ ├── providers/ # ✅ Backend provider implementations
|
|
1222
|
+
│ │ ├── DataProvider.ts # Universal interface (6 dimensions)
|
|
1223
|
+
│ │ ├── convex/
|
|
1224
|
+
│ │ │ ├── ConvexProvider.ts # Convex implementation
|
|
1225
|
+
│ │ │ └── index.ts
|
|
1226
|
+
│ │ ├── wordpress/ # Optional: WordPress implementation
|
|
1227
|
+
│ │ │ ├── WordPressProvider.ts
|
|
1228
|
+
│ │ │ └── index.ts
|
|
1229
|
+
│ │ ├── notion/ # Optional: Notion implementation
|
|
1230
|
+
│ │ │ ├── NotionProvider.ts
|
|
1231
|
+
│ │ │ └── index.ts
|
|
1232
|
+
│ │ └── supabase/ # Optional: Supabase implementation
|
|
1233
|
+
│ │ ├── SupabaseProvider.ts
|
|
1234
|
+
│ │ └── index.ts
|
|
1235
|
+
│ ├── services/ # ✅ Backend-agnostic services
|
|
1236
|
+
│ │ ├── ThingService.ts # Generic (handles all 66 types)
|
|
1237
|
+
│ │ ├── ConnectionService.ts # Generic connections
|
|
1238
|
+
│ │ └── ClientLayer.ts # Dependency injection
|
|
1239
|
+
│ ├── hooks/
|
|
1240
|
+
│ │ └── useEffectRunner.ts # ✅ Run Effect.ts in React
|
|
1241
|
+
│ ├── components/
|
|
1242
|
+
│ │ └── CourseCard.tsx # ✅ Uses ThingService (backend-agnostic)
|
|
1243
|
+
│ └── pages/
|
|
1244
|
+
│ └── courses/[id].astro # ✅ Uses ThingService (backend-agnostic)
|
|
1245
|
+
├── astro.config.ts # ✅ Configure provider (ONE line to swap!)
|
|
1246
|
+
├── .env # PUBLIC_CONVEX_URL or WP_API_KEY, etc.
|
|
1247
|
+
└── package.json # ✅ No Convex dependency (if using other backend)
|
|
1248
|
+
|
|
1249
|
+
✅ Swap backends by changing ONE line in astro.config.ts!
|
|
1250
|
+
✅ Organizations can use their existing infrastructure
|
|
1251
|
+
```
|
|
1252
|
+
|
|
1253
|
+
### Configuration Example (Single Provider)
|
|
1254
|
+
|
|
1255
|
+
```typescript
|
|
1256
|
+
// frontend/astro.config.ts
|
|
1257
|
+
|
|
1258
|
+
// Option 1: Use Convex for everything
|
|
1259
|
+
import { convexProvider } from "./src/providers/convex";
|
|
1260
|
+
export default defineConfig({
|
|
1261
|
+
integrations: [
|
|
1262
|
+
one({
|
|
1263
|
+
provider: convexProvider({ url: env.PUBLIC_CONVEX_URL }),
|
|
1264
|
+
}),
|
|
1265
|
+
],
|
|
1266
|
+
});
|
|
1267
|
+
|
|
1268
|
+
// Option 2: Use WordPress for everything (change ONE line!)
|
|
1269
|
+
import { wordpressProvider } from "./src/providers/wordpress";
|
|
1270
|
+
export default defineConfig({
|
|
1271
|
+
integrations: [
|
|
1272
|
+
one({
|
|
1273
|
+
provider: wordpressProvider({
|
|
1274
|
+
url: "https://yoursite.com",
|
|
1275
|
+
apiKey: env.WP_API_KEY,
|
|
1276
|
+
}),
|
|
1277
|
+
}),
|
|
1278
|
+
],
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
// Option 3: Use Notion for everything (change ONE line!)
|
|
1282
|
+
import { notionProvider } from "./src/providers/notion";
|
|
1283
|
+
export default defineConfig({
|
|
1284
|
+
integrations: [
|
|
1285
|
+
one({
|
|
1286
|
+
provider: notionProvider({
|
|
1287
|
+
apiKey: env.NOTION_API_KEY,
|
|
1288
|
+
databaseId: env.NOTION_DB_ID,
|
|
1289
|
+
}),
|
|
1290
|
+
}),
|
|
1291
|
+
],
|
|
1292
|
+
});
|
|
1293
|
+
```
|
|
1294
|
+
|
|
1295
|
+
### Configuration Example (Multi-Provider - Federated Data)
|
|
1296
|
+
|
|
1297
|
+
**Use case:** Auth from Convex, blog posts from WordPress, products from Shopify
|
|
1298
|
+
|
|
1299
|
+
```typescript
|
|
1300
|
+
// frontend/astro.config.ts
|
|
1301
|
+
import { compositeProvider } from "./src/providers/composite";
|
|
1302
|
+
import { convexProvider } from "./src/providers/convex";
|
|
1303
|
+
import { wordpressProvider } from "./src/providers/wordpress";
|
|
1304
|
+
import { shopifyProvider } from "./src/providers/shopify";
|
|
1305
|
+
|
|
1306
|
+
export default defineConfig({
|
|
1307
|
+
integrations: [
|
|
1308
|
+
one({
|
|
1309
|
+
provider: compositeProvider({
|
|
1310
|
+
// Default provider (fallback)
|
|
1311
|
+
default: convexProvider({
|
|
1312
|
+
url: env.PUBLIC_CONVEX_URL,
|
|
1313
|
+
}),
|
|
1314
|
+
|
|
1315
|
+
// Route specific thing types to specific providers
|
|
1316
|
+
routes: {
|
|
1317
|
+
// Auth & core data → Convex
|
|
1318
|
+
organizations: "default",
|
|
1319
|
+
people: "default",
|
|
1320
|
+
sessions: "default",
|
|
1321
|
+
|
|
1322
|
+
// Blog content → WordPress
|
|
1323
|
+
blog_post: wordpressProvider({
|
|
1324
|
+
url: "https://blog.yoursite.com",
|
|
1325
|
+
apiKey: env.WP_API_KEY,
|
|
1326
|
+
}),
|
|
1327
|
+
|
|
1328
|
+
// Products → Shopify
|
|
1329
|
+
product: shopifyProvider({
|
|
1330
|
+
store: "yourstore.myshopify.com",
|
|
1331
|
+
accessToken: env.SHOPIFY_ACCESS_TOKEN,
|
|
1332
|
+
}),
|
|
1333
|
+
digital_product: "product", // Use same as product
|
|
1334
|
+
|
|
1335
|
+
// Courses → Convex (default)
|
|
1336
|
+
course: "default",
|
|
1337
|
+
lesson: "default",
|
|
1338
|
+
},
|
|
1339
|
+
}),
|
|
1340
|
+
}),
|
|
1341
|
+
],
|
|
1342
|
+
});
|
|
1343
|
+
```
|
|
1344
|
+
|
|
1345
|
+
**How it works:**
|
|
1346
|
+
|
|
1347
|
+
```typescript
|
|
1348
|
+
// Frontend calls generic service
|
|
1349
|
+
const thingService = yield * ThingService;
|
|
1350
|
+
|
|
1351
|
+
// Service calls DataProvider
|
|
1352
|
+
const blogPost = yield * thingService.get(postId); // → WordPress
|
|
1353
|
+
const product = yield * thingService.get(productId); // → Shopify
|
|
1354
|
+
const course = yield * thingService.get(courseId); // → Convex
|
|
1355
|
+
|
|
1356
|
+
// CompositeProvider routes based on thing type
|
|
1357
|
+
// Frontend code doesn't change!
|
|
1358
|
+
```
|
|
1359
|
+
|
|
1360
|
+
**Benefits:**
|
|
1361
|
+
|
|
1362
|
+
- ✅ Use best backend for each data type
|
|
1363
|
+
- ✅ Keep existing WordPress blog - no migration
|
|
1364
|
+
- ✅ Pull products from Shopify in real-time
|
|
1365
|
+
- ✅ Auth/sessions in Convex (fast, real-time)
|
|
1366
|
+
- ✅ Frontend code unchanged - just reads things
|
|
1367
|
+
- ✅ Add/remove providers without touching components
|
|
1368
|
+
|
|
1369
|
+
### Advanced: Data Sync Strategies
|
|
1370
|
+
|
|
1371
|
+
**Strategy 1: Real-Time (Live Queries)**
|
|
1372
|
+
|
|
1373
|
+
```typescript
|
|
1374
|
+
// Products pulled live from Shopify on every request
|
|
1375
|
+
product: shopifyProvider({
|
|
1376
|
+
store: "yourstore.myshopify.com",
|
|
1377
|
+
accessToken: env.SHOPIFY_ACCESS_TOKEN,
|
|
1378
|
+
// No caching - always fresh
|
|
1379
|
+
});
|
|
1380
|
+
```
|
|
1381
|
+
|
|
1382
|
+
**Strategy 2: Import & Cache (Better Performance)**
|
|
1383
|
+
|
|
1384
|
+
```typescript
|
|
1385
|
+
// Import WordPress posts to Convex, sync periodically
|
|
1386
|
+
import { syncedProvider } from "./src/providers/synced";
|
|
1387
|
+
|
|
1388
|
+
provider: compositeProvider({
|
|
1389
|
+
default: convexProvider({ url: env.PUBLIC_CONVEX_URL }),
|
|
1390
|
+
routes: {
|
|
1391
|
+
// Blog posts synced from WordPress → stored in Convex
|
|
1392
|
+
blog_post: syncedProvider({
|
|
1393
|
+
source: wordpressProvider({
|
|
1394
|
+
url: "https://blog.yoursite.com",
|
|
1395
|
+
apiKey: env.WP_API_KEY,
|
|
1396
|
+
}),
|
|
1397
|
+
destination: "default", // Store in Convex
|
|
1398
|
+
syncInterval: "1 hour", // Sync every hour
|
|
1399
|
+
strategy: "incremental", // Only sync new/changed posts
|
|
1400
|
+
}),
|
|
1401
|
+
},
|
|
1402
|
+
});
|
|
1403
|
+
```
|
|
1404
|
+
|
|
1405
|
+
**Strategy 3: Federation (Query Multiple Backends)**
|
|
1406
|
+
|
|
1407
|
+
```typescript
|
|
1408
|
+
// Search across blog posts (WordPress) AND courses (Convex)
|
|
1409
|
+
const searchResults =
|
|
1410
|
+
yield *
|
|
1411
|
+
Effect.all(
|
|
1412
|
+
[
|
|
1413
|
+
thingService.list("blog_post", { filters: { query: "fitness" } }),
|
|
1414
|
+
thingService.list("course", { filters: { query: "fitness" } }),
|
|
1415
|
+
],
|
|
1416
|
+
{ concurrency: "unbounded" }
|
|
1417
|
+
);
|
|
1418
|
+
|
|
1419
|
+
// CompositeProvider queries both backends in parallel
|
|
1420
|
+
// Frontend merges results
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
**Strategy 4: Hybrid (Auth + Import)**
|
|
1424
|
+
|
|
1425
|
+
```typescript
|
|
1426
|
+
// Common pattern: Auth in Convex, content from external sources
|
|
1427
|
+
provider: compositeProvider({
|
|
1428
|
+
default: convexProvider({ url: env.PUBLIC_CONVEX_URL }),
|
|
1429
|
+
routes: {
|
|
1430
|
+
// WordPress posts imported to Convex (fast reads)
|
|
1431
|
+
blog_post: syncedProvider({
|
|
1432
|
+
source: wordpressProvider({ url: "...", apiKey: "..." }),
|
|
1433
|
+
destination: "default",
|
|
1434
|
+
syncInterval: "15 minutes",
|
|
1435
|
+
}),
|
|
1436
|
+
|
|
1437
|
+
// Shopify products live (always current pricing)
|
|
1438
|
+
product: shopifyProvider({
|
|
1439
|
+
store: "yourstore.myshopify.com",
|
|
1440
|
+
accessToken: env.SHOPIFY_ACCESS_TOKEN,
|
|
1441
|
+
}),
|
|
1442
|
+
|
|
1443
|
+
// Everything else (auth, courses, etc.) in Convex
|
|
1444
|
+
// Uses 'default' provider
|
|
1445
|
+
},
|
|
1446
|
+
});
|
|
1447
|
+
```
|
|
1448
|
+
|
|
1449
|
+
**Real-World Example: E-commerce Platform**
|
|
1450
|
+
|
|
1451
|
+
```typescript
|
|
1452
|
+
export default defineConfig({
|
|
1453
|
+
integrations: [
|
|
1454
|
+
one({
|
|
1455
|
+
provider: compositeProvider({
|
|
1456
|
+
// Core platform data in Convex
|
|
1457
|
+
default: convexProvider({ url: env.PUBLIC_CONVEX_URL }),
|
|
1458
|
+
|
|
1459
|
+
routes: {
|
|
1460
|
+
// Auth & users → Convex (real-time, fast)
|
|
1461
|
+
organizations: "default",
|
|
1462
|
+
people: "default",
|
|
1463
|
+
|
|
1464
|
+
// Products → Shopify (live pricing, inventory)
|
|
1465
|
+
product: shopifyProvider({
|
|
1466
|
+
store: env.SHOPIFY_STORE,
|
|
1467
|
+
accessToken: env.SHOPIFY_ACCESS_TOKEN,
|
|
1468
|
+
}),
|
|
1469
|
+
|
|
1470
|
+
// Blog → WordPress (existing content, no migration)
|
|
1471
|
+
blog_post: syncedProvider({
|
|
1472
|
+
source: wordpressProvider({
|
|
1473
|
+
url: env.WP_URL,
|
|
1474
|
+
apiKey: env.WP_API_KEY,
|
|
1475
|
+
}),
|
|
1476
|
+
destination: "default",
|
|
1477
|
+
syncInterval: "30 minutes",
|
|
1478
|
+
}),
|
|
1479
|
+
|
|
1480
|
+
// Courses → Convex (real-time progress tracking)
|
|
1481
|
+
course: "default",
|
|
1482
|
+
lesson: "default",
|
|
1483
|
+
|
|
1484
|
+
// Customer reviews → Import from Trustpilot/Google
|
|
1485
|
+
review: syncedProvider({
|
|
1486
|
+
source: trustpilotProvider({ businessId: env.TRUSTPILOT_ID }),
|
|
1487
|
+
destination: "default",
|
|
1488
|
+
syncInterval: "24 hours",
|
|
1489
|
+
}),
|
|
1490
|
+
},
|
|
1491
|
+
}),
|
|
1492
|
+
}),
|
|
1493
|
+
],
|
|
1494
|
+
});
|
|
1495
|
+
```
|
|
1496
|
+
|
|
1497
|
+
**Frontend Code (Unchanged!):**
|
|
1498
|
+
|
|
1499
|
+
```tsx
|
|
1500
|
+
// Component doesn't know or care about backend routing
|
|
1501
|
+
export function HomePage() {
|
|
1502
|
+
const { run } = useEffectRunner();
|
|
1503
|
+
const [data, setData] = useState(null);
|
|
1504
|
+
|
|
1505
|
+
useEffect(() => {
|
|
1506
|
+
const program = Effect.gen(function* () {
|
|
1507
|
+
const thingService = yield* ThingService;
|
|
1508
|
+
|
|
1509
|
+
// Fetches from multiple backends automatically
|
|
1510
|
+
const [products, posts, courses] = yield* Effect.all(
|
|
1511
|
+
[
|
|
1512
|
+
thingService.list("product", orgId), // → Shopify (live)
|
|
1513
|
+
thingService.list("blog_post", orgId), // → WordPress (cached)
|
|
1514
|
+
thingService.list("course", orgId), // → Convex (default)
|
|
1515
|
+
],
|
|
1516
|
+
{ concurrency: "unbounded" }
|
|
1517
|
+
);
|
|
1518
|
+
|
|
1519
|
+
return { products, posts, courses };
|
|
1520
|
+
});
|
|
1521
|
+
|
|
1522
|
+
run(program, { onSuccess: setData });
|
|
1523
|
+
}, []);
|
|
1524
|
+
|
|
1525
|
+
// Render federated data
|
|
1526
|
+
return (
|
|
1527
|
+
<div>
|
|
1528
|
+
<ProductGrid products={data?.products} />
|
|
1529
|
+
<BlogFeed posts={data?.posts} />
|
|
1530
|
+
<CourseList courses={data?.courses} />
|
|
1531
|
+
</div>
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
```
|
|
1535
|
+
|
|
1536
|
+
**Key Insights:**
|
|
1537
|
+
|
|
1538
|
+
- ✅ Frontend components don't change when adding/removing backends
|
|
1539
|
+
- ✅ Mix real-time and cached data based on needs
|
|
1540
|
+
- ✅ Organizations keep existing content management systems
|
|
1541
|
+
- ✅ Import external data (reviews, social proof) without manual copying
|
|
1542
|
+
- ✅ Route based on performance/cost tradeoffs (Shopify API calls vs Convex reads)
|
|
1543
|
+
|
|
1544
|
+
### Backend Stays Separate (No Changes Needed)
|
|
1545
|
+
|
|
1546
|
+
```
|
|
1547
|
+
backend/
|
|
1548
|
+
└── convex/ # Backend unchanged!
|
|
1549
|
+
├── queries/
|
|
1550
|
+
├── mutations/
|
|
1551
|
+
├── schema.ts # 6-dimension ontology
|
|
1552
|
+
└── http.ts
|
|
1553
|
+
|
|
1554
|
+
# OR use WordPress, Notion, Supabase - frontend doesn't care!
|
|
1555
|
+
```
|
|
1556
|
+
|
|
1557
|
+
---
|
|
1558
|
+
|
|
1559
|
+
## Implementation Steps
|
|
1560
|
+
|
|
1561
|
+
### Step 1: Create API Key Entity Type
|
|
1562
|
+
|
|
1563
|
+
**File: `backend/convex/schema.ts`**
|
|
1564
|
+
|
|
1565
|
+
Add to existing schema:
|
|
1566
|
+
|
|
1567
|
+
```typescript
|
|
1568
|
+
export default defineSchema({
|
|
1569
|
+
// ... existing entities table
|
|
1570
|
+
|
|
1571
|
+
entities: defineTable({
|
|
1572
|
+
type: v.string(), // Add "api_key" as new type
|
|
1573
|
+
name: v.string(),
|
|
1574
|
+
properties: v.any(),
|
|
1575
|
+
status: v.optional(
|
|
1576
|
+
v.union(
|
|
1577
|
+
v.literal("active"),
|
|
1578
|
+
v.literal("inactive"),
|
|
1579
|
+
v.literal("draft"),
|
|
1580
|
+
v.literal("published"),
|
|
1581
|
+
v.literal("archived"),
|
|
1582
|
+
v.literal("revoked") // ✅ Add for API keys
|
|
1583
|
+
)
|
|
1584
|
+
),
|
|
1585
|
+
createdAt: v.number(),
|
|
1586
|
+
updatedAt: v.number(),
|
|
1587
|
+
deletedAt: v.optional(v.number()),
|
|
1588
|
+
})
|
|
1589
|
+
.index("by_type", ["type"])
|
|
1590
|
+
.index("by_status", ["status"])
|
|
1591
|
+
.index("by_key_hash", ["properties.keyHash"]), // ✅ Add for fast lookup
|
|
1592
|
+
|
|
1593
|
+
// ... rest of schema
|
|
1594
|
+
});
|
|
1595
|
+
```
|
|
1596
|
+
|
|
1597
|
+
### Step 2: Create API Key Queries
|
|
1598
|
+
|
|
1599
|
+
**File: `backend/convex/queries/apiKeys.ts`**
|
|
1600
|
+
|
|
1601
|
+
```typescript
|
|
1602
|
+
import { query } from "../_generated/server";
|
|
1603
|
+
import { v } from "convex/values";
|
|
1604
|
+
|
|
1605
|
+
export const validate = query({
|
|
1606
|
+
args: { keyHash: v.string() },
|
|
1607
|
+
handler: async (ctx, args) => {
|
|
1608
|
+
const apiKey = await ctx.db
|
|
1609
|
+
.query("entities")
|
|
1610
|
+
.withIndex("by_key_hash", (q) => q.eq("properties.keyHash", args.keyHash))
|
|
1611
|
+
.filter((q) => q.eq(q.field("type"), "api_key"))
|
|
1612
|
+
.first();
|
|
1613
|
+
|
|
1614
|
+
return apiKey;
|
|
1615
|
+
},
|
|
1616
|
+
});
|
|
1617
|
+
|
|
1618
|
+
export const listByOrg = query({
|
|
1619
|
+
args: { orgId: v.string() },
|
|
1620
|
+
handler: async (ctx, args) => {
|
|
1621
|
+
const keys = await ctx.db
|
|
1622
|
+
.query("entities")
|
|
1623
|
+
.withIndex("by_type", (q) => q.eq("type", "api_key"))
|
|
1624
|
+
.filter((q) => q.eq(q.field("properties.orgId"), args.orgId))
|
|
1625
|
+
.collect();
|
|
1626
|
+
|
|
1627
|
+
// Don't return keyHash (security)
|
|
1628
|
+
return keys.map((key) => ({
|
|
1629
|
+
...key,
|
|
1630
|
+
properties: {
|
|
1631
|
+
...key.properties,
|
|
1632
|
+
keyHash: undefined, // Remove sensitive data
|
|
1633
|
+
},
|
|
1634
|
+
}));
|
|
1635
|
+
},
|
|
1636
|
+
});
|
|
1637
|
+
```
|
|
1638
|
+
|
|
1639
|
+
### Step 3: Create API Key Mutations
|
|
1640
|
+
|
|
1641
|
+
**File: `backend/convex/mutations/apiKeys.ts`**
|
|
1642
|
+
|
|
1643
|
+
```typescript
|
|
1644
|
+
import { mutation } from "../_generated/server";
|
|
1645
|
+
import { v } from "convex/values";
|
|
1646
|
+
import { createHash, randomBytes } from "crypto";
|
|
1647
|
+
|
|
1648
|
+
export const create = mutation({
|
|
1649
|
+
args: {
|
|
1650
|
+
orgId: v.string(),
|
|
1651
|
+
name: v.string(),
|
|
1652
|
+
scopes: v.array(v.string()),
|
|
1653
|
+
environment: v.union(v.literal("production"), v.literal("development")),
|
|
1654
|
+
},
|
|
1655
|
+
handler: async (ctx, args) => {
|
|
1656
|
+
// Generate random API key
|
|
1657
|
+
const prefix = args.environment === "production" ? "sk_live" : "sk_test";
|
|
1658
|
+
const random = randomBytes(18).toString("base64url");
|
|
1659
|
+
const apiKey = `${prefix}_${random}`;
|
|
1660
|
+
|
|
1661
|
+
// Hash the key for storage
|
|
1662
|
+
const keyHash = createHash("sha256").update(apiKey).digest("hex");
|
|
1663
|
+
const keyHint = apiKey.slice(-3);
|
|
1664
|
+
|
|
1665
|
+
// Create entity
|
|
1666
|
+
const keyId = await ctx.db.insert("entities", {
|
|
1667
|
+
type: "api_key",
|
|
1668
|
+
name: args.name,
|
|
1669
|
+
properties: {
|
|
1670
|
+
keyPrefix: prefix,
|
|
1671
|
+
keyHash,
|
|
1672
|
+
keyHint,
|
|
1673
|
+
orgId: args.orgId,
|
|
1674
|
+
scopes: args.scopes,
|
|
1675
|
+
rateLimit: {
|
|
1676
|
+
requests: 1000,
|
|
1677
|
+
period: 60,
|
|
1678
|
+
},
|
|
1679
|
+
environment: args.environment,
|
|
1680
|
+
lastUsedAt: null,
|
|
1681
|
+
},
|
|
1682
|
+
status: "active",
|
|
1683
|
+
createdAt: Date.now(),
|
|
1684
|
+
updatedAt: Date.now(),
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
// Return plaintext key ONLY this once
|
|
1688
|
+
return {
|
|
1689
|
+
id: keyId,
|
|
1690
|
+
apiKey, // ⚠️ Show user - never shown again!
|
|
1691
|
+
keyHint,
|
|
1692
|
+
};
|
|
1693
|
+
},
|
|
1694
|
+
});
|
|
1695
|
+
|
|
1696
|
+
export const revoke = mutation({
|
|
1697
|
+
args: { keyId: v.id("entities") },
|
|
1698
|
+
handler: async (ctx, args) => {
|
|
1699
|
+
await ctx.db.patch(args.keyId, {
|
|
1700
|
+
status: "revoked",
|
|
1701
|
+
updatedAt: Date.now(),
|
|
1702
|
+
});
|
|
1703
|
+
},
|
|
1704
|
+
});
|
|
1705
|
+
|
|
1706
|
+
export const updateLastUsed = mutation({
|
|
1707
|
+
args: { keyId: v.id("entities") },
|
|
1708
|
+
handler: async (ctx, args) => {
|
|
1709
|
+
const key = await ctx.db.get(args.keyId);
|
|
1710
|
+
if (!key) return;
|
|
1711
|
+
|
|
1712
|
+
await ctx.db.patch(args.keyId, {
|
|
1713
|
+
properties: {
|
|
1714
|
+
...key.properties,
|
|
1715
|
+
lastUsedAt: Date.now(),
|
|
1716
|
+
},
|
|
1717
|
+
updatedAt: Date.now(),
|
|
1718
|
+
});
|
|
1719
|
+
},
|
|
1720
|
+
});
|
|
1721
|
+
```
|
|
1722
|
+
|
|
1723
|
+
### Step 4: Create Hono API Backend
|
|
1724
|
+
|
|
1725
|
+
**File: `backend/api/index.ts`**
|
|
1726
|
+
|
|
1727
|
+
```typescript
|
|
1728
|
+
import { Hono } from "hono";
|
|
1729
|
+
import { cors } from "hono/cors";
|
|
1730
|
+
import { logger } from "hono/logger";
|
|
1731
|
+
import { validateApiKey } from "./middleware/auth";
|
|
1732
|
+
import tokensRoutes from "./routes/tokens";
|
|
1733
|
+
import agentsRoutes from "./routes/agents";
|
|
1734
|
+
import authRoutes from "./routes/auth";
|
|
1735
|
+
|
|
1736
|
+
const app = new Hono();
|
|
1737
|
+
|
|
1738
|
+
// Middleware
|
|
1739
|
+
app.use("*", logger());
|
|
1740
|
+
app.use(
|
|
1741
|
+
"/api/*",
|
|
1742
|
+
cors({
|
|
1743
|
+
origin: [
|
|
1744
|
+
"http://localhost:4321",
|
|
1745
|
+
"https://*.pages.dev",
|
|
1746
|
+
process.env.FRONTEND_URL || "",
|
|
1747
|
+
].filter(Boolean),
|
|
1748
|
+
credentials: true,
|
|
1749
|
+
})
|
|
1750
|
+
);
|
|
1751
|
+
|
|
1752
|
+
// Health check (no auth required)
|
|
1753
|
+
app.get("/health", (c) => c.json({ status: "ok" }));
|
|
1754
|
+
|
|
1755
|
+
// API routes (auth required)
|
|
1756
|
+
app.use("/api/*", validateApiKey);
|
|
1757
|
+
app.route("/api/v1/tokens", tokensRoutes);
|
|
1758
|
+
app.route("/api/v1/agents", agentsRoutes);
|
|
1759
|
+
app.route("/api/v1/auth", authRoutes);
|
|
1760
|
+
|
|
1761
|
+
// 404 handler
|
|
1762
|
+
app.notFound((c) => c.json({ error: "Not found" }, 404));
|
|
1763
|
+
|
|
1764
|
+
// Error handler
|
|
1765
|
+
app.onError((err, c) => {
|
|
1766
|
+
console.error(err);
|
|
1767
|
+
return c.json({ error: "Internal server error" }, 500);
|
|
1768
|
+
});
|
|
1769
|
+
|
|
1770
|
+
export default app;
|
|
1771
|
+
```
|
|
1772
|
+
|
|
1773
|
+
**File: `backend/api/routes/tokens.ts`**
|
|
1774
|
+
|
|
1775
|
+
```typescript
|
|
1776
|
+
import { Hono } from "hono";
|
|
1777
|
+
import { ConvexHttpClient } from "convex/browser";
|
|
1778
|
+
import { api } from "../../convex/_generated/api";
|
|
1779
|
+
|
|
1780
|
+
const app = new Hono();
|
|
1781
|
+
const convex = new ConvexHttpClient(process.env.CONVEX_URL!);
|
|
1782
|
+
|
|
1783
|
+
// GET /api/v1/tokens/:id
|
|
1784
|
+
app.get("/:id", async (c) => {
|
|
1785
|
+
const tokenId = c.req.param("id");
|
|
1786
|
+
const orgId = c.get("orgId"); // From API key middleware
|
|
1787
|
+
|
|
1788
|
+
const token = await convex.query(api.queries.entities.get, { id: tokenId });
|
|
1789
|
+
|
|
1790
|
+
if (!token || token.type !== "token") {
|
|
1791
|
+
return c.json({ error: "Token not found" }, 404);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
// Check ownership
|
|
1795
|
+
if (token.properties.orgId !== orgId) {
|
|
1796
|
+
return c.json({ error: "Unauthorized" }, 403);
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
return c.json(token);
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1802
|
+
// POST /api/v1/tokens/:id/purchase
|
|
1803
|
+
app.post("/:id/purchase", async (c) => {
|
|
1804
|
+
const tokenId = c.req.param("id");
|
|
1805
|
+
const { amount } = await c.req.json();
|
|
1806
|
+
const orgId = c.get("orgId");
|
|
1807
|
+
|
|
1808
|
+
// Call Convex mutation
|
|
1809
|
+
const result = await convex.mutation(api.mutations.tokens.purchase, {
|
|
1810
|
+
tokenId,
|
|
1811
|
+
amount,
|
|
1812
|
+
orgId,
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
return c.json(result);
|
|
1816
|
+
});
|
|
1817
|
+
|
|
1818
|
+
// Add more routes...
|
|
1819
|
+
|
|
1820
|
+
export default app;
|
|
1821
|
+
```
|
|
1822
|
+
|
|
1823
|
+
### Step 5: Create Frontend API Client
|
|
1824
|
+
|
|
1825
|
+
**File: `frontend/src/lib/api/client.ts`**
|
|
1826
|
+
|
|
1827
|
+
```typescript
|
|
1828
|
+
export class ApiError extends Error {
|
|
1829
|
+
constructor(message: string, public status: number) {
|
|
1830
|
+
super(message);
|
|
1831
|
+
this.name = "ApiError";
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
export class ApiClient {
|
|
1836
|
+
private baseUrl: string;
|
|
1837
|
+
private apiKey: string;
|
|
1838
|
+
|
|
1839
|
+
constructor(apiKey: string, baseUrl?: string) {
|
|
1840
|
+
this.apiKey = apiKey;
|
|
1841
|
+
this.baseUrl = baseUrl || import.meta.env.PUBLIC_API_URL;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
private async request<T>(
|
|
1845
|
+
endpoint: string,
|
|
1846
|
+
options: RequestInit = {}
|
|
1847
|
+
): Promise<T> {
|
|
1848
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
1849
|
+
|
|
1850
|
+
const response = await fetch(url, {
|
|
1851
|
+
...options,
|
|
1852
|
+
headers: {
|
|
1853
|
+
"Content-Type": "application/json",
|
|
1854
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
1855
|
+
...options.headers,
|
|
1856
|
+
},
|
|
1857
|
+
});
|
|
1858
|
+
|
|
1859
|
+
if (!response.ok) {
|
|
1860
|
+
const error = await response.json();
|
|
1861
|
+
throw new ApiError(error.error, response.status);
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
return response.json();
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
tokens = {
|
|
1868
|
+
get: (id: string) => this.request<Token>(`/api/v1/tokens/${id}`),
|
|
1869
|
+
|
|
1870
|
+
purchase: (id: string, amount: number) =>
|
|
1871
|
+
this.request<PurchaseResult>(`/api/v1/tokens/${id}/purchase`, {
|
|
1872
|
+
method: "POST",
|
|
1873
|
+
body: JSON.stringify({ amount }),
|
|
1874
|
+
}),
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1877
|
+
agents = {
|
|
1878
|
+
get: (id: string) => this.request<Agent>(`/api/v1/agents/${id}`),
|
|
1879
|
+
|
|
1880
|
+
list: () => this.request<Agent[]>("/api/v1/agents"),
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
// Singleton instance
|
|
1885
|
+
export const api = new ApiClient(import.meta.env.PUBLIC_API_KEY || "");
|
|
1886
|
+
```
|
|
1887
|
+
|
|
1888
|
+
### Step 6: Update Frontend Pages
|
|
1889
|
+
|
|
1890
|
+
**Before:**
|
|
1891
|
+
|
|
1892
|
+
```astro
|
|
1893
|
+
---
|
|
1894
|
+
// frontend/src/pages/tokens/[id].astro
|
|
1895
|
+
import { ConvexHttpClient } from "convex/browser";
|
|
1896
|
+
import { api as convexApi } from "@/convex/_generated/api";
|
|
1897
|
+
|
|
1898
|
+
const convex = new ConvexHttpClient(import.meta.env.PUBLIC_CONVEX_URL);
|
|
1899
|
+
const token = await convex.query(convexApi.entities.get, { id: Astro.params.id });
|
|
1900
|
+
---
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
**After:**
|
|
1904
|
+
|
|
1905
|
+
```astro
|
|
1906
|
+
---
|
|
1907
|
+
// frontend/src/pages/tokens/[id].astro
|
|
1908
|
+
import { api } from "@/lib/api/client";
|
|
1909
|
+
|
|
1910
|
+
const token = await api.tokens.get(Astro.params.id);
|
|
1911
|
+
---
|
|
1912
|
+
```
|
|
1913
|
+
|
|
1914
|
+
### Step 7: Remove Convex from Frontend
|
|
1915
|
+
|
|
1916
|
+
**Delete:**
|
|
1917
|
+
|
|
1918
|
+
```bash
|
|
1919
|
+
rm -rf frontend/convex/
|
|
1920
|
+
rm frontend/convex.config.ts
|
|
1921
|
+
```
|
|
1922
|
+
|
|
1923
|
+
**Update `package.json`:**
|
|
1924
|
+
|
|
1925
|
+
```diff
|
|
1926
|
+
{
|
|
1927
|
+
"dependencies": {
|
|
1928
|
+
- "convex": "^1.x.x",
|
|
1929
|
+
- "@convex-dev/resend": "^x.x.x",
|
|
1930
|
+
"astro": "^5.14.0"
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
```
|
|
1934
|
+
|
|
1935
|
+
---
|
|
1936
|
+
|
|
1937
|
+
## Testing Strategy
|
|
1938
|
+
|
|
1939
|
+
### 0. Preserve Existing Auth Tests (Critical)
|
|
1940
|
+
|
|
1941
|
+
**REQUIREMENT:** All tests in `frontend/tests/auth/*` must continue to pass throughout migration.
|
|
1942
|
+
|
|
1943
|
+
**Strategy:**
|
|
1944
|
+
|
|
1945
|
+
```typescript
|
|
1946
|
+
// Run existing auth tests after each phase
|
|
1947
|
+
npm test frontend/tests/auth/
|
|
1948
|
+
|
|
1949
|
+
// Tests must pass:
|
|
1950
|
+
// ✅ Signup flow
|
|
1951
|
+
// ✅ Signin flow
|
|
1952
|
+
// ✅ Session management
|
|
1953
|
+
// ✅ Password reset
|
|
1954
|
+
// ✅ Email verification
|
|
1955
|
+
// ✅ Role-based authorization
|
|
1956
|
+
```
|
|
1957
|
+
|
|
1958
|
+
**Migration Safety:**
|
|
1959
|
+
|
|
1960
|
+
1. **Phase 2 (ConvexProvider):** Run auth tests - should pass unchanged
|
|
1961
|
+
2. **Phase 3 (Service Layer):** Run auth tests - should pass with new services
|
|
1962
|
+
3. **Phase 5 (Component Migration):** Run auth tests after each page migration
|
|
1963
|
+
4. **Phase 6 (Remove Convex):** Run auth tests - final verification
|
|
1964
|
+
|
|
1965
|
+
**If auth tests fail at any phase:** STOP, investigate, fix before continuing.
|
|
1966
|
+
|
|
1967
|
+
---
|
|
1968
|
+
|
|
1969
|
+
### 1. Backend API Tests
|
|
1970
|
+
|
|
1971
|
+
```typescript
|
|
1972
|
+
// backend/api/__tests__/tokens.test.ts
|
|
1973
|
+
import { describe, it, expect } from "vitest";
|
|
1974
|
+
import app from "../index";
|
|
1975
|
+
|
|
1976
|
+
describe("Tokens API", () => {
|
|
1977
|
+
it("should require API key", async () => {
|
|
1978
|
+
const res = await app.request("/api/v1/tokens/123");
|
|
1979
|
+
expect(res.status).toBe(401);
|
|
1980
|
+
});
|
|
1981
|
+
|
|
1982
|
+
it("should fetch token with valid key", async () => {
|
|
1983
|
+
const res = await app.request("/api/v1/tokens/123", {
|
|
1984
|
+
headers: {
|
|
1985
|
+
Authorization: `Bearer ${process.env.TEST_API_KEY}`,
|
|
1986
|
+
},
|
|
1987
|
+
});
|
|
1988
|
+
expect(res.status).toBe(200);
|
|
1989
|
+
});
|
|
1990
|
+
|
|
1991
|
+
it("should enforce org isolation", async () => {
|
|
1992
|
+
const res = await app.request("/api/v1/tokens/org-b-token", {
|
|
1993
|
+
headers: {
|
|
1994
|
+
Authorization: `Bearer ${process.env.ORG_A_API_KEY}`,
|
|
1995
|
+
},
|
|
1996
|
+
});
|
|
1997
|
+
expect(res.status).toBe(403);
|
|
1998
|
+
});
|
|
1999
|
+
});
|
|
2000
|
+
```
|
|
2001
|
+
|
|
2002
|
+
### 2. Frontend Integration Tests
|
|
2003
|
+
|
|
2004
|
+
```typescript
|
|
2005
|
+
// frontend/src/lib/api/__tests__/client.test.ts
|
|
2006
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2007
|
+
import { ApiClient } from "../client";
|
|
2008
|
+
|
|
2009
|
+
describe("ApiClient", () => {
|
|
2010
|
+
it("should add Authorization header", async () => {
|
|
2011
|
+
const fetchMock = vi.fn().mockResolvedValue({
|
|
2012
|
+
ok: true,
|
|
2013
|
+
json: async () => ({ id: "123" }),
|
|
2014
|
+
});
|
|
2015
|
+
global.fetch = fetchMock;
|
|
2016
|
+
|
|
2017
|
+
const client = new ApiClient("sk_test_123");
|
|
2018
|
+
await client.tokens.get("123");
|
|
2019
|
+
|
|
2020
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
2021
|
+
expect.any(String),
|
|
2022
|
+
expect.objectContaining({
|
|
2023
|
+
headers: expect.objectContaining({
|
|
2024
|
+
Authorization: "Bearer sk_test_123",
|
|
2025
|
+
}),
|
|
2026
|
+
})
|
|
2027
|
+
);
|
|
2028
|
+
});
|
|
2029
|
+
|
|
2030
|
+
it("should throw ApiError on failure", async () => {
|
|
2031
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
2032
|
+
ok: false,
|
|
2033
|
+
status: 404,
|
|
2034
|
+
json: async () => ({ error: "Not found" }),
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
const client = new ApiClient("sk_test_123");
|
|
2038
|
+
await expect(client.tokens.get("999")).rejects.toThrow("Not found");
|
|
2039
|
+
});
|
|
2040
|
+
});
|
|
2041
|
+
```
|
|
2042
|
+
|
|
2043
|
+
---
|
|
2044
|
+
|
|
2045
|
+
## Deployment Changes
|
|
2046
|
+
|
|
2047
|
+
### Before (Coupled)
|
|
2048
|
+
|
|
2049
|
+
```
|
|
2050
|
+
1. Deploy frontend to Cloudflare Pages
|
|
2051
|
+
- Includes Convex SDK
|
|
2052
|
+
- WebSocket connection to Convex
|
|
2053
|
+
|
|
2054
|
+
2. Deploy Convex backend
|
|
2055
|
+
- convex deploy
|
|
2056
|
+
```
|
|
2057
|
+
|
|
2058
|
+
### After (Separated)
|
|
2059
|
+
|
|
2060
|
+
```
|
|
2061
|
+
1. Deploy backend API to Cloudflare Workers
|
|
2062
|
+
- cd backend/api
|
|
2063
|
+
- wrangler deploy
|
|
2064
|
+
- Output: https://api.yourdomain.com
|
|
2065
|
+
|
|
2066
|
+
2. Deploy Convex backend
|
|
2067
|
+
- cd backend/convex
|
|
2068
|
+
- convex deploy
|
|
2069
|
+
- Output: https://your-deployment.convex.cloud
|
|
2070
|
+
|
|
2071
|
+
3. Deploy frontend to Cloudflare Pages
|
|
2072
|
+
- cd frontend
|
|
2073
|
+
- Set env: PUBLIC_API_URL=https://api.yourdomain.com
|
|
2074
|
+
- Set env: PUBLIC_API_KEY=pk_live_xxx
|
|
2075
|
+
- Build and deploy
|
|
2076
|
+
```
|
|
2077
|
+
|
|
2078
|
+
### Environment Variables
|
|
2079
|
+
|
|
2080
|
+
**Backend (`backend/api/.env`):**
|
|
2081
|
+
|
|
2082
|
+
```bash
|
|
2083
|
+
CONVEX_URL=https://your-deployment.convex.cloud
|
|
2084
|
+
FRONTEND_URL=https://yourdomain.com
|
|
2085
|
+
```
|
|
2086
|
+
|
|
2087
|
+
**Frontend (`frontend/.env`):**
|
|
2088
|
+
|
|
2089
|
+
```bash
|
|
2090
|
+
PUBLIC_API_URL=https://api.yourdomain.com
|
|
2091
|
+
PUBLIC_API_KEY=pk_live_1234567890abcdef
|
|
2092
|
+
```
|
|
2093
|
+
|
|
2094
|
+
---
|
|
2095
|
+
|
|
2096
|
+
## Security Considerations
|
|
2097
|
+
|
|
2098
|
+
### 1. API Key Storage
|
|
2099
|
+
|
|
2100
|
+
**❌ Never:**
|
|
2101
|
+
|
|
2102
|
+
- Store API keys in git
|
|
2103
|
+
- Use secret keys (`sk_*`) in frontend
|
|
2104
|
+
- Log API keys in console
|
|
2105
|
+
- Return key hash in API responses
|
|
2106
|
+
|
|
2107
|
+
**✅ Always:**
|
|
2108
|
+
|
|
2109
|
+
- Use publishable keys (`pk_*`) in frontend
|
|
2110
|
+
- Use secret keys (`sk_*`) only in backend
|
|
2111
|
+
- Hash keys before storing (SHA-256)
|
|
2112
|
+
- Show plaintext key only once at creation
|
|
2113
|
+
- Rotate keys regularly
|
|
2114
|
+
|
|
2115
|
+
### 2. Rate Limiting
|
|
2116
|
+
|
|
2117
|
+
**Implementation:**
|
|
2118
|
+
|
|
2119
|
+
```typescript
|
|
2120
|
+
// backend/api/middleware/rateLimit.ts
|
|
2121
|
+
import { Context, Next } from "hono";
|
|
2122
|
+
|
|
2123
|
+
const rateLimitMap = new Map<string, { count: number; resetAt: number }>();
|
|
2124
|
+
|
|
2125
|
+
export async function rateLimit(c: Context, next: Next) {
|
|
2126
|
+
const keyId = c.get("apiKeyId");
|
|
2127
|
+
const limit = c.get("keyRateLimit");
|
|
2128
|
+
|
|
2129
|
+
const now = Date.now();
|
|
2130
|
+
const key = `rate_limit:${keyId}`;
|
|
2131
|
+
const current = rateLimitMap.get(key);
|
|
2132
|
+
|
|
2133
|
+
if (current && now < current.resetAt) {
|
|
2134
|
+
if (current.count >= limit.requests) {
|
|
2135
|
+
return c.json(
|
|
2136
|
+
{
|
|
2137
|
+
error: "Rate limit exceeded",
|
|
2138
|
+
resetAt: new Date(current.resetAt).toISOString(),
|
|
2139
|
+
},
|
|
2140
|
+
429
|
|
2141
|
+
);
|
|
2142
|
+
}
|
|
2143
|
+
current.count++;
|
|
2144
|
+
} else {
|
|
2145
|
+
rateLimitMap.set(key, {
|
|
2146
|
+
count: 1,
|
|
2147
|
+
resetAt: now + limit.period * 1000,
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
await next();
|
|
2152
|
+
}
|
|
2153
|
+
```
|
|
2154
|
+
|
|
2155
|
+
### 3. CORS Configuration
|
|
2156
|
+
|
|
2157
|
+
**Backend:**
|
|
2158
|
+
|
|
2159
|
+
```typescript
|
|
2160
|
+
app.use(
|
|
2161
|
+
"/api/*",
|
|
2162
|
+
cors({
|
|
2163
|
+
origin: (origin) => {
|
|
2164
|
+
// Allow specific domains
|
|
2165
|
+
const allowed = [
|
|
2166
|
+
"http://localhost:4321",
|
|
2167
|
+
"https://yourdomain.com",
|
|
2168
|
+
"https://*.pages.dev",
|
|
2169
|
+
];
|
|
2170
|
+
|
|
2171
|
+
return allowed.some((pattern) =>
|
|
2172
|
+
new RegExp(pattern.replace("*", ".*")).test(origin)
|
|
2173
|
+
)
|
|
2174
|
+
? origin
|
|
2175
|
+
: null;
|
|
2176
|
+
},
|
|
2177
|
+
credentials: true,
|
|
2178
|
+
})
|
|
2179
|
+
);
|
|
2180
|
+
```
|
|
2181
|
+
|
|
2182
|
+
---
|
|
2183
|
+
|
|
2184
|
+
## Migration Checklist
|
|
2185
|
+
|
|
2186
|
+
### Backend Setup
|
|
2187
|
+
|
|
2188
|
+
- [ ] Add `api_key` entity type to schema
|
|
2189
|
+
- [ ] Create API key queries in `backend/convex/queries/apiKeys.ts`
|
|
2190
|
+
- [ ] Create API key mutations in `backend/convex/mutations/apiKeys.ts`
|
|
2191
|
+
- [ ] Deploy schema changes to Convex
|
|
2192
|
+
- [ ] Create test API key via mutation
|
|
2193
|
+
- [ ] Create `backend/api/` directory structure
|
|
2194
|
+
- [ ] Implement Hono routes for all resources
|
|
2195
|
+
- [ ] Add API key validation middleware
|
|
2196
|
+
- [ ] Add rate limiting middleware
|
|
2197
|
+
- [ ] Add CORS middleware
|
|
2198
|
+
- [ ] Deploy API to Cloudflare Workers
|
|
2199
|
+
- [ ] Test all endpoints with Postman/curl
|
|
2200
|
+
- [ ] Set up monitoring and logging
|
|
2201
|
+
|
|
2202
|
+
### Frontend Setup
|
|
2203
|
+
|
|
2204
|
+
- [ ] Create `frontend/src/lib/api/client.ts`
|
|
2205
|
+
- [ ] Create `frontend/src/lib/api/types.ts`
|
|
2206
|
+
- [ ] Create `frontend/src/lib/api/errors.ts`
|
|
2207
|
+
- [ ] Add `PUBLIC_API_URL` to `.env`
|
|
2208
|
+
- [ ] Add `PUBLIC_API_KEY` to `.env`
|
|
2209
|
+
- [ ] Update 1 page to test API client
|
|
2210
|
+
- [ ] Verify API client works in development
|
|
2211
|
+
- [ ] Migrate all pages to use API client
|
|
2212
|
+
- [ ] Remove all Convex imports from components
|
|
2213
|
+
- [ ] Delete `frontend/convex/` directory
|
|
2214
|
+
- [ ] Remove Convex from `package.json`
|
|
2215
|
+
- [ ] Update build process
|
|
2216
|
+
- [ ] Test full frontend in production
|
|
2217
|
+
|
|
2218
|
+
### Documentation
|
|
2219
|
+
|
|
2220
|
+
- [ ] Update `CLAUDE.md` with new architecture
|
|
2221
|
+
- [ ] Document API endpoints (OpenAPI/Swagger)
|
|
2222
|
+
- [ ] Create API key management guide
|
|
2223
|
+
- [ ] Update deployment instructions
|
|
2224
|
+
- [ ] Create troubleshooting guide
|
|
2225
|
+
|
|
2226
|
+
---
|
|
2227
|
+
|
|
2228
|
+
## Rollback Plan
|
|
2229
|
+
|
|
2230
|
+
**Key Safety:** We're wrapping a working system, so rollback just means removing the wrapper.
|
|
2231
|
+
|
|
2232
|
+
If migration encounters issues, rollback is straightforward:
|
|
2233
|
+
|
|
2234
|
+
**Option 1: Gradual Rollback (Keep Both)**
|
|
2235
|
+
|
|
2236
|
+
```typescript
|
|
2237
|
+
// Keep both Convex hooks and Effect.ts services temporarily
|
|
2238
|
+
// Migrate page by page, test thoroughly
|
|
2239
|
+
|
|
2240
|
+
// Old page (still works)
|
|
2241
|
+
const courses = useQuery(api.queries.things.list, { type: "course" });
|
|
2242
|
+
|
|
2243
|
+
// New page (backend-agnostic)
|
|
2244
|
+
const program = Effect.gen(function* () {
|
|
2245
|
+
const thingService = yield* ThingService;
|
|
2246
|
+
return yield* thingService.list("course", orgId);
|
|
2247
|
+
});
|
|
2248
|
+
```
|
|
2249
|
+
|
|
2250
|
+
**Option 2: Quick Rollback (Revert Provider)**
|
|
2251
|
+
|
|
2252
|
+
```typescript
|
|
2253
|
+
// Change provider back to direct Convex hooks if needed
|
|
2254
|
+
// In astro.config.ts:
|
|
2255
|
+
provider: convexProvider({ url: env.PUBLIC_CONVEX_URL }); // Keep this working
|
|
2256
|
+
|
|
2257
|
+
// Frontend components still work with ConvexProvider
|
|
2258
|
+
// Just wraps the same Convex queries/mutations
|
|
2259
|
+
```
|
|
2260
|
+
|
|
2261
|
+
**Key Safety:**
|
|
2262
|
+
|
|
2263
|
+
- ConvexProvider just wraps existing Convex backend
|
|
2264
|
+
- No data migration needed
|
|
2265
|
+
- No backend changes required
|
|
2266
|
+
- Worst case: remove DataProvider layer, use Convex directly again
|
|
2267
|
+
|
|
2268
|
+
---
|
|
2269
|
+
|
|
2270
|
+
## Success Metrics
|
|
2271
|
+
|
|
2272
|
+
**Critical Requirements (Must Pass):**
|
|
2273
|
+
|
|
2274
|
+
- [ ] All existing auth tests in `frontend/tests/auth/*` pass
|
|
2275
|
+
- [ ] Auth functionality unchanged (signup, signin, sessions, password reset, etc.)
|
|
2276
|
+
- [ ] No regressions in user-facing features
|
|
2277
|
+
- [ ] Zero downtime during migration
|
|
2278
|
+
|
|
2279
|
+
**Technical Goals:**
|
|
2280
|
+
|
|
2281
|
+
- [ ] Frontend uses DataProvider interface (backend-agnostic)
|
|
2282
|
+
- [ ] Can swap from Convex → WordPress by changing ONE line
|
|
2283
|
+
- [ ] Can swap from WordPress → Notion by changing ONE line
|
|
2284
|
+
- [ ] Effect.ts services handle all 66 thing types generically
|
|
2285
|
+
- [ ] No direct backend imports in frontend components
|
|
2286
|
+
- [ ] Full type safety maintained with Effect.ts
|
|
2287
|
+
|
|
2288
|
+
**Backend Flexibility:**
|
|
2289
|
+
|
|
2290
|
+
- [ ] ConvexProvider fully implements DataProvider interface
|
|
2291
|
+
- [ ] Organizations can choose their preferred backend
|
|
2292
|
+
- [ ] At least 2 provider implementations working (e.g., Convex + WordPress)
|
|
2293
|
+
- [ ] Multi-tenancy works across all providers
|
|
2294
|
+
- [ ] Authorization enforced by backend (not frontend)
|
|
2295
|
+
|
|
2296
|
+
**Developer Experience:**
|
|
2297
|
+
|
|
2298
|
+
- [ ] Frontend developers don't need backend-specific knowledge
|
|
2299
|
+
- [ ] Adding new provider takes 1-2 weeks (not months)
|
|
2300
|
+
- [ ] Frontend components work unchanged when backend swaps
|
|
2301
|
+
- [ ] Clear documentation for implementing new providers
|
|
2302
|
+
- [ ] Effect.ts patterns are consistent and learnable
|
|
2303
|
+
|
|
2304
|
+
---
|
|
2305
|
+
|
|
2306
|
+
## Timeline
|
|
2307
|
+
|
|
2308
|
+
**Total Duration:** 4-6 weeks (Backend-Agnostic Approach)
|
|
2309
|
+
|
|
2310
|
+
**Week 1:** Define DataProvider interface + Implement ConvexProvider wrapper
|
|
2311
|
+
**Week 2:** Create Effect.ts service layer + useEffectRunner hook
|
|
2312
|
+
**Week 3-4:** Migrate frontend components to use services (page by page)
|
|
2313
|
+
**Week 5:** Remove direct Convex imports + Test thoroughly
|
|
2314
|
+
**Week 6 (Optional):** Add alternative provider (WordPress, Notion, etc.) to prove flexibility
|
|
2315
|
+
|
|
2316
|
+
**Comparison to Old Plan:**
|
|
2317
|
+
|
|
2318
|
+
- ✅ Faster (4-6 weeks vs 6-8 weeks)
|
|
2319
|
+
- ✅ Less risky (no REST API to build)
|
|
2320
|
+
- ✅ More value (true backend flexibility, not just REST)
|
|
2321
|
+
- ✅ Organizations can use existing infrastructure immediately
|
|
2322
|
+
|
|
2323
|
+
---
|
|
2324
|
+
|
|
2325
|
+
## Next Steps
|
|
2326
|
+
|
|
2327
|
+
1. **Review this plan** with team - focus on DataProvider pattern benefits
|
|
2328
|
+
2. **Study references:**
|
|
2329
|
+
- Read `one/knowledge/ontology-frontend.md` (DataProvider architecture)
|
|
2330
|
+
- Review Astro's content layer pattern (inspiration for DataProvider)
|
|
2331
|
+
- Understand Effect.ts basics (type-safe composable services)
|
|
2332
|
+
3. **Begin Phase 1:** Create DataProvider interface
|
|
2333
|
+
- Define the 6-dimension interface
|
|
2334
|
+
- Document expected behavior for each method
|
|
2335
|
+
- Define error types (ThingNotFoundError, etc.)
|
|
2336
|
+
4. **Begin Phase 2:** Implement ConvexProvider
|
|
2337
|
+
- Wrap existing Convex queries/mutations
|
|
2338
|
+
- Test provider in isolation
|
|
2339
|
+
- Verify no functionality lost
|
|
2340
|
+
|
|
2341
|
+
---
|
|
2342
|
+
|
|
2343
|
+
## When to Implement This Plan
|
|
2344
|
+
|
|
2345
|
+
**DO migrate when:**
|
|
2346
|
+
|
|
2347
|
+
- ✅ You need to support organizations with existing WordPress/Notion/Supabase infrastructure
|
|
2348
|
+
- ✅ You want to enable multi-backend federation (e.g., auth in Convex + blog in WordPress)
|
|
2349
|
+
- ✅ You're building mobile/desktop apps and want backend flexibility
|
|
2350
|
+
- ✅ You want to reduce Convex lock-in for customer acquisition
|
|
2351
|
+
- ✅ You have 4-6 weeks for strategic enhancement work
|
|
2352
|
+
|
|
2353
|
+
**DON'T migrate yet if:**
|
|
2354
|
+
|
|
2355
|
+
- ❌ You need to ship urgent features (migration is strategic, not urgent)
|
|
2356
|
+
- ❌ Current Convex integration is causing actual problems (it's not - it works)
|
|
2357
|
+
- ❌ You have less than 4 weeks available (rushed migration = bugs)
|
|
2358
|
+
- ❌ Auth tests aren't stable yet (fix tests first, then migrate)
|
|
2359
|
+
|
|
2360
|
+
**Current Recommendation:** Keep existing Convex integration until you have:
|
|
2361
|
+
|
|
2362
|
+
1. A concrete customer requesting WordPress/Notion/Supabase support
|
|
2363
|
+
2. 4-6 weeks of uninterrupted development time
|
|
2364
|
+
3. All existing auth tests passing reliably
|
|
2365
|
+
4. Clear business value from backend flexibility
|
|
2366
|
+
|
|
2367
|
+
**The current system works. Don't fix what isn't broken unless the strategic value justifies the effort.**
|
|
2368
|
+
|
|
2369
|
+
---
|
|
2370
|
+
|
|
2371
|
+
## Questions to Resolve
|
|
2372
|
+
|
|
2373
|
+
1. **Real-Time Support:** Should DataProvider interface include `subscriptions` methods? (Optional - not all backends support it)
|
|
2374
|
+
2. **Provider Discovery:** Should providers register themselves, or explicit imports?
|
|
2375
|
+
3. **Error Handling:** Standardize error types across all providers, or allow provider-specific errors?
|
|
2376
|
+
4. **Provider Versioning:** How to handle breaking changes in provider implementations?
|
|
2377
|
+
5. **Performance:** Should DataProvider support caching/batching at interface level?
|
|
2378
|
+
|
|
2379
|
+
---
|
|
2380
|
+
|
|
2381
|
+
## Conclusion
|
|
2382
|
+
|
|
2383
|
+
### Starting Point: Working System
|
|
2384
|
+
|
|
2385
|
+
**What we have today:**
|
|
2386
|
+
|
|
2387
|
+
- ✅ Frontend connected to Convex backend (working)
|
|
2388
|
+
- ✅ Auth fully functional with passing tests
|
|
2389
|
+
- ✅ Real-time updates via Convex WebSockets
|
|
2390
|
+
- ✅ 6-dimension ontology implemented
|
|
2391
|
+
- ✅ All features operational
|
|
2392
|
+
|
|
2393
|
+
**This is a solid foundation.** We're not fixing broken code - we're adding strategic capabilities.
|
|
2394
|
+
|
|
2395
|
+
### The Transformation
|
|
2396
|
+
|
|
2397
|
+
This **backend-agnostic separation** transforms ONE from a tightly-coupled (but working) monolith into a truly flexible platform where:
|
|
2398
|
+
|
|
2399
|
+
### Key Wins
|
|
2400
|
+
|
|
2401
|
+
**🎯 For Organizations:**
|
|
2402
|
+
|
|
2403
|
+
- ✅ Use your existing infrastructure (WordPress, Notion, Supabase, etc.)
|
|
2404
|
+
- ✅ No forced migration to Convex
|
|
2405
|
+
- ✅ Keep your existing admin tools, plugins, workflows
|
|
2406
|
+
- ✅ Test ONE frontend without backend risk
|
|
2407
|
+
- ✅ Migrate backend later if/when you want
|
|
2408
|
+
|
|
2409
|
+
**🎯 For Developers:**
|
|
2410
|
+
|
|
2411
|
+
- ✅ Frontend devs learn DataProvider interface once, work with any backend
|
|
2412
|
+
- ✅ Backend devs can use their preferred stack
|
|
2413
|
+
- ✅ No vendor lock-in
|
|
2414
|
+
- ✅ Effect.ts provides type-safe, composable operations
|
|
2415
|
+
- ✅ Clear separation: frontend renders, backend manages data
|
|
2416
|
+
|
|
2417
|
+
**🎯 For ONE Platform:**
|
|
2418
|
+
|
|
2419
|
+
- ✅ Serve organizations with diverse infrastructure needs
|
|
2420
|
+
- ✅ Prove the 6-dimension ontology is universal (works with ANY backend)
|
|
2421
|
+
- ✅ Attract organizations who would never adopt Convex
|
|
2422
|
+
- ✅ Position as frontend layer, not full-stack lock-in
|
|
2423
|
+
|
|
2424
|
+
### The Breakthrough
|
|
2425
|
+
|
|
2426
|
+
Instead of building a **REST API** (still Convex-specific), we built a **universal data interface**:
|
|
2427
|
+
|
|
2428
|
+
```
|
|
2429
|
+
OLD PLAN: Convex → Hono REST API → Frontend
|
|
2430
|
+
❌ Still coupled to Convex backend
|
|
2431
|
+
❌ REST API is just another layer to maintain
|
|
2432
|
+
|
|
2433
|
+
NEW PLAN: ANY Backend → DataProvider → Frontend
|
|
2434
|
+
✅ True backend flexibility
|
|
2435
|
+
✅ Organizations use existing infrastructure
|
|
2436
|
+
✅ Swap backends with ONE line change
|
|
2437
|
+
```
|
|
2438
|
+
|
|
2439
|
+
### Implementation Strategy
|
|
2440
|
+
|
|
2441
|
+
The key is **gradual migration** with **zero risk**:
|
|
2442
|
+
|
|
2443
|
+
1. **Week 1-2:** Create abstraction layer (DataProvider + ConvexProvider)
|
|
2444
|
+
2. **Week 3-4:** Migrate frontend page by page to use services
|
|
2445
|
+
3. **Week 5:** Remove direct backend imports
|
|
2446
|
+
4. **Week 6+:** Add alternative providers to prove flexibility
|
|
2447
|
+
|
|
2448
|
+
At every step, frontend still works. At every step, we can rollback. At every step, we add value.
|
|
2449
|
+
|
|
2450
|
+
### Read More
|
|
2451
|
+
|
|
2452
|
+
- **Full Architecture:** See `one/knowledge/ontology-frontend.md`
|
|
2453
|
+
- **6-Dimension Ontology:** See `one/knowledge/ontology.md`
|
|
2454
|
+
- **Effect.ts Integration:** Frontend guide shows complete patterns
|
|
2455
|
+
|
|
2456
|
+
---
|
|
2457
|
+
|
|
2458
|
+
**This is how you build a platform that serves everyone, not just one tech stack.**
|