oneie 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +245 -0
- package/CLAUDE.md +534 -0
- package/README.md +61 -4
- package/one/.obsidian/app.json +1 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/workspace.json +211 -0
- package/one/connections/a2a.md +551 -0
- package/one/connections/acp.md +761 -0
- package/one/connections/acps.md +731 -0
- package/one/connections/agui.md +767 -0
- package/one/connections/any-backend.md +1702 -0
- package/one/connections/ap2.md +998 -0
- package/one/connections/api-docs.md +1891 -0
- package/one/connections/api.md +2190 -0
- package/one/connections/architecture-diagram.md +94 -0
- package/one/connections/communications.md +449 -0
- package/one/connections/connections.md +339 -0
- package/one/connections/cryptonetworks.md +781 -0
- package/one/connections/documentation.md +1120 -0
- package/one/connections/effect.md +279 -0
- package/one/connections/elizaos.md +1290 -0
- package/one/connections/inference.md +58 -0
- package/one/connections/kyc.md +632 -0
- package/one/connections/mcp.md +842 -0
- package/one/connections/membership.md +1152 -0
- package/one/connections/middleware.md +1067 -0
- package/one/connections/multitenant.md +1341 -0
- package/one/connections/n8n.md +1015 -0
- package/one/connections/patterns.md +89 -0
- package/one/connections/protocols.md +279 -0
- package/one/connections/relationships.md +107 -0
- package/one/connections/schema.md +587 -0
- package/one/connections/service-layer.md +550 -0
- package/one/connections/structure.md +0 -0
- package/one/connections/vectors.md +207 -0
- package/one/connections/wordpress.md +1302 -0
- package/one/connections/workflow-copy.md +905 -0
- package/one/connections/workflow-examples.md +741 -0
- package/one/connections/workflow.md +905 -0
- package/one/connections/workflows/delegation.md +885 -0
- package/one/connections/workflows/frontend.md +1037 -0
- package/one/connections/workflows/strategy.md +903 -0
- package/one/connections/workflows/tasks.md +698 -0
- package/one/connections/x402.md +1249 -0
- package/one/events/events.md +545 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-diagram.md +94 -0
- package/one/knowledge/architecture-frontend.md +930 -0
- package/one/knowledge/architecture.md +2077 -0
- package/one/knowledge/crypto.md +960 -0
- package/one/knowledge/dsl.md +1660 -0
- package/one/knowledge/files.md +2471 -0
- package/one/knowledge/frontend.md +1038 -0
- package/one/knowledge/hono.md +2109 -0
- package/one/knowledge/implementation-examples.md +2536 -0
- package/one/knowledge/inference-score.md +159 -0
- package/one/knowledge/knowledge.md +642 -0
- package/one/knowledge/language.md +980 -0
- package/one/knowledge/lessons-learned.md +70 -0
- package/one/knowledge/ontology-6-dimensions.md +0 -0
- package/one/knowledge/ontology-documentation.md +356 -0
- package/one/knowledge/ontology-engineering-specification.md +1292 -0
- package/one/knowledge/ontology-engineering.md +1652 -0
- package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
- package/one/knowledge/ontology-frontend-copy.md +753 -0
- package/one/knowledge/ontology-frontend-specifications.md +2188 -0
- package/one/knowledge/ontology-frontend.md +2427 -0
- package/one/knowledge/ontology-minimal.yaml +299 -0
- package/one/knowledge/ontology.md +2819 -0
- package/one/knowledge/ontology.yaml +1165 -0
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
- package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
- package/one/knowledge/patterns/backend/mutation-template.md +231 -0
- package/one/knowledge/patterns/backend/query-template.md +267 -0
- package/one/knowledge/patterns/backend/service-template.md +237 -0
- package/one/knowledge/patterns/design/component-architecture.md +399 -0
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
- package/one/knowledge/patterns/design/wireframe-template.md +216 -0
- package/one/knowledge/patterns/frontend/component-template.md +195 -0
- package/one/knowledge/patterns/frontend/form-template.md +276 -0
- package/one/knowledge/patterns/frontend/page-template.md +178 -0
- package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
- package/one/knowledge/patterns/test/technical-test-template.md +544 -0
- package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
- package/one/knowledge/patterns/test/user-flow-template.md +254 -0
- package/one/knowledge/quality-loop.md +401 -0
- package/one/knowledge/readme.md +131 -0
- package/one/knowledge/rules.md +626 -0
- package/one/knowledge/score.md +67 -0
- package/one/knowledge/specifications.md +855 -0
- package/one/knowledge/tags.md +130 -0
- package/one/organisation/one.md +599 -0
- package/one/organisation/organisation.md +438 -0
- package/one/organisation/revenue.md +673 -0
- package/one/organisation/strategy.md +869 -0
- package/one/organisation/vision.md +98 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/repomix-output.md +92634 -0
- package/one/things/agentkit.md +349 -0
- package/one/things/agents/agent-backend.md +1401 -0
- package/one/things/agents/agent-builder.md +955 -0
- package/one/things/agents/agent-clean.md +709 -0
- package/one/things/agents/agent-clone.md +1341 -0
- package/one/things/agents/agent-designer.md +2177 -0
- package/one/things/agents/agent-director.md +1508 -0
- package/one/things/agents/agent-documenter.md +1049 -0
- package/one/things/agents/agent-frontend.md +1119 -0
- package/one/things/agents/agent-integrator.md +1192 -0
- package/one/things/agents/agent-problem-solver.md +1379 -0
- package/one/things/agents/agent-quality.md +1353 -0
- package/one/things/agents/agent-sales.md +986 -0
- package/one/things/cascade/cascade.yaml +464 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
- package/one/things/cascade/docs/examples/readme.md +222 -0
- package/one/things/cascade/docs/getting-started.md +515 -0
- package/one/things/cascade/docs/workflow.md +1372 -0
- package/one/things/cascade/readme.md +336 -0
- package/one/things/cascade/templates/feature-template.md +267 -0
- package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
- package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
- package/one/things/claude/agents/analyst.md +483 -0
- package/one/things/claude/agents/architect.md +480 -0
- package/one/things/claude/agents/brand-identity-specialist.md +513 -0
- package/one/things/claude/agents/bstp-token-strategist.md +667 -0
- package/one/things/claude/agents/builder-repo.md +489 -0
- package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
- package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
- package/one/things/claude/agents/company-bullstamp-character.md +587 -0
- package/one/things/claude/agents/company-bullstamp-community.md +292 -0
- package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
- package/one/things/claude/agents/company-bullstamp-token.md +292 -0
- package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
- package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
- package/one/things/claude/agents/content-calendar-planner.md +448 -0
- package/one/things/claude/agents/content-chapter-formatter.md +488 -0
- package/one/things/claude/agents/content-formatter.md +546 -0
- package/one/things/claude/agents/content-hook-specialist.md +462 -0
- package/one/things/claude/agents/content-image-formatter.md +535 -0
- package/one/things/claude/agents/content-introduction-formatter.md +485 -0
- package/one/things/claude/agents/content-multiplication-engine.md +556 -0
- package/one/things/claude/agents/content-playbook-writer.md +448 -0
- package/one/things/claude/agents/content-team-manager.md +622 -0
- package/one/things/claude/agents/content-toc-formatter.md +522 -0
- package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
- package/one/things/claude/agents/core-manager.md +582 -0
- package/one/things/claude/agents/core-master.md +403 -0
- package/one/things/claude/agents/cross-functional-manager.md +471 -0
- package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
- package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
- package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
- package/one/things/claude/agents/crypto-community-analyst.md +298 -0
- package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
- package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
- package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
- package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
- package/one/things/claude/agents/crypto-market-researcher.md +292 -0
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
- package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
- package/one/things/claude/agents/crypto-team-manager.md +387 -0
- package/one/things/claude/agents/crypto-token-analyst.md +278 -0
- package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
- package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
- package/one/things/claude/agents/customer-journey-designer.md +481 -0
- package/one/things/claude/agents/customer-success-manager.md +581 -0
- package/one/things/claude/agents/dev.md +413 -0
- package/one/things/claude/agents/documenter.md +546 -0
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
- package/one/things/claude/agents/engagement-specialist.md +509 -0
- package/one/things/claude/agents/engineering-architect.md +387 -0
- package/one/things/claude/agents/engineering-business-analyst.md +537 -0
- package/one/things/claude/agents/engineering-developer.md +387 -0
- package/one/things/claude/agents/engineering-director.md +282 -0
- package/one/things/claude/agents/engineering-ingestor.md +649 -0
- package/one/things/claude/agents/engineering-product-manager.md +537 -0
- package/one/things/claude/agents/engineering-product-owner.md +537 -0
- package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
- package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
- package/one/things/claude/agents/engineering-team-manager.md +512 -0
- package/one/things/claude/agents/engineering-user-experience.md +387 -0
- package/one/things/claude/agents/framework-elevate-manager.md +294 -0
- package/one/things/claude/agents/improver.md +763 -0
- package/one/things/claude/agents/intelligence-team-manager.md +385 -0
- package/one/things/claude/agents/lead-capture-expert.md +466 -0
- package/one/things/claude/agents/lead-magnet-creator.md +453 -0
- package/one/things/claude/agents/market-research-analyst.md +412 -0
- package/one/things/claude/agents/marketing-brand-identity.md +314 -0
- package/one/things/claude/agents/marketing-content-hooks.md +450 -0
- package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
- package/one/things/claude/agents/marketing-content-poster.md +361 -0
- package/one/things/claude/agents/marketing-customer-journey.md +326 -0
- package/one/things/claude/agents/marketing-director.md +397 -0
- package/one/things/claude/agents/marketing-engagement.md +326 -0
- package/one/things/claude/agents/marketing-lead-capture.md +326 -0
- package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
- package/one/things/claude/agents/marketing-network-effects.md +326 -0
- package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
- package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
- package/one/things/claude/agents/marketing-team-manager.md +446 -0
- package/one/things/claude/agents/marketing-viral-growth.md +201 -0
- package/one/things/claude/agents/mission-commander.md +373 -0
- package/one/things/claude/agents/network-effect-analyst.md +587 -0
- package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
- package/one/things/claude/agents/npx.md +890 -0
- package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
- package/one/things/claude/agents/one-master.md +355 -0
- package/one/things/claude/agents/one-orchestrator.md +315 -0
- package/one/things/claude/agents/one.md +601 -0
- package/one/things/claude/agents/playbook-generator.md +503 -0
- package/one/things/claude/agents/pm.md +326 -0
- package/one/things/claude/agents/po.md +345 -0
- package/one/things/claude/agents/qa.md +336 -0
- package/one/things/claude/agents/research-foundation-analyst.md +307 -0
- package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
- package/one/things/claude/agents/research-market-analyst.md +307 -0
- package/one/things/claude/agents/research-team-manager.md +482 -0
- package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
- package/one/things/claude/agents/sales-team-manager.md +400 -0
- package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
- package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
- package/one/things/claude/agents/service-advocacy-manager.md +307 -0
- package/one/things/claude/agents/service-success-manager.md +307 -0
- package/one/things/claude/agents/service-team-manager.md +400 -0
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
- package/one/things/claude/agents/share-optimization-specialist.md +551 -0
- package/one/things/claude/agents/sm.md +327 -0
- package/one/things/claude/agents/story-teller.md +473 -0
- package/one/things/claude/agents/task-master.md +596 -0
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
- package/one/things/claude/agents/tester.md +556 -0
- package/one/things/claude/agents/the-bull-character-manager.md +580 -0
- package/one/things/claude/agents/tools-playbook-generator.md +489 -0
- package/one/things/claude/agents/turbo-repo-builder.md +316 -0
- package/one/things/claude/agents/upsell-strategist.md +480 -0
- package/one/things/claude/agents/ux-expert.md +335 -0
- package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
- package/one/things/claude/claude-code-hooks-development.json +21 -0
- package/one/things/claude/claude-code-hooks-production.json +21 -0
- package/one/things/claude/claude-code-hooks.json +25 -0
- package/one/things/claude/commands/agent.md +104 -0
- package/one/things/claude/commands/cascade-status.md +128 -0
- package/one/things/claude/commands/ingest.md +290 -0
- package/one/things/claude/commands/ingestor.md +136 -0
- package/one/things/claude/commands/mission.md +83 -0
- package/one/things/claude/commands/npx.md +133 -0
- package/one/things/claude/commands/one.md +440 -0
- package/one/things/claude/commands/quality-check.md +204 -0
- package/one/things/claude/commands/smart-route.md +220 -0
- package/one/things/claude/commands/start.md +121 -0
- package/one/things/claude/commands/story.md +83 -0
- package/one/things/claude/commands/task.md +173 -0
- package/one/things/claude/hook-bypass.json +32 -0
- package/one/things/claude/hooks/agent-hook-config.json +427 -0
- package/one/things/claude/hooks/agent-hook-manager.js +525 -0
- package/one/things/claude/hooks/agent-load-balancer.js +271 -0
- package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
- package/one/things/claude/hooks/build-hook.sh +156 -0
- package/one/things/claude/hooks/cascade-feedback.js +297 -0
- package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
- package/one/things/claude/hooks/cleanup-hook.sh +201 -0
- package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
- package/one/things/claude/hooks/file-organization-engine.js +427 -0
- package/one/things/claude/hooks/file-organization-hook.sh +80 -0
- package/one/things/claude/hooks/file-organization-monitor.js +269 -0
- package/one/things/claude/hooks/format-hook.sh +43 -0
- package/one/things/claude/hooks/hook-bypass.sh +293 -0
- package/one/things/claude/hooks/hook-config-manager.js +202 -0
- package/one/things/claude/hooks/hook-debouncer.sh +62 -0
- package/one/things/claude/hooks/hook-logger.sh +89 -0
- package/one/things/claude/hooks/hook-orchestrator.js +662 -0
- package/one/things/claude/hooks/hook-performance-report.js +120 -0
- package/one/things/claude/hooks/lint-hook.sh +140 -0
- package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
- package/one/things/claude/hooks/memory-optimizer.js +510 -0
- package/one/things/claude/hooks/notification-hook.sh +204 -0
- package/one/things/claude/hooks/ontology-compliance.js +394 -0
- package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
- package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
- package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
- package/one/things/claude/hooks/performance-metrics.json +25 -0
- package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
- package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
- package/one/things/claude/hooks/security-hook.sh +256 -0
- package/one/things/claude/hooks/simple-load-balancer.js +238 -0
- package/one/things/claude/hooks/startup-optimizer.js +625 -0
- package/one/things/claude/hooks/story-scoring-system.js +445 -0
- package/one/things/claude/hooks/story-validation-engine.js +473 -0
- package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
- package/one/things/claude/hooks/story-validation-hook.sh +145 -0
- package/one/things/claude/hooks/structure-synchronizer.js +194 -0
- package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
- package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
- package/one/things/claude/hooks/test-hook.sh +145 -0
- package/one/things/claude/hooks/test-story-validation.sh +170 -0
- package/one/things/claude/hooks/trinity-validation-system.js +392 -0
- package/one/things/claude/settings-local.json +86 -0
- package/one/things/cli-code.md +652 -0
- package/one/things/cli-compiler-code.md +652 -0
- package/one/things/cli.md +1045 -0
- package/one/things/components/card-shadcn.md +929 -0
- package/one/things/components/card.md +1050 -0
- package/one/things/components.md +1669 -0
- package/one/things/componets.md +4 -0
- package/one/things/copilotkit.md +1559 -0
- package/one/things/creator-diagram.md +166 -0
- package/one/things/examples/children/lemonade-stand.md +366 -0
- package/one/things/examples/enterprise/crm-saas.md +1429 -0
- package/one/things/features/1-1-agent-prompts/design.md +470 -0
- package/one/things/features/1-1-agent-prompts/tests.md +264 -0
- package/one/things/features/1-1-agent-prompts.md +486 -0
- package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/features/1-2-yaml-orchestrator.md +516 -0
- package/one/things/features/1-3-event-coordination/design.md +544 -0
- package/one/things/features/1-3-event-coordination/tests.md +223 -0
- package/one/things/features/1-3-event-coordination.md +508 -0
- package/one/things/features/1-4-knowledge-management/design.md +609 -0
- package/one/things/features/1-4-knowledge-management/tests.md +195 -0
- package/one/things/features/1-4-knowledge-management.md +577 -0
- package/one/things/features/1-5-quality-loops/design.md +797 -0
- package/one/things/features/1-5-quality-loops/tests.md +212 -0
- package/one/things/features/1-5-quality-loops.md +641 -0
- package/one/things/features/1-6-numbering-structure/design.md +610 -0
- package/one/things/features/1-6-numbering-structure/tests.md +213 -0
- package/one/things/features/1-6-numbering-structure.md +575 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/plans/1-create-workflow-status.md +555 -0
- package/one/things/plans/1-create-workflow.md +713 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
- package/one/things/plans/better-auth-any-backend.md +1852 -0
- package/one/things/plans/better-auth-available-features.md +235 -0
- package/one/things/plans/big-plan.md +38 -0
- package/one/things/plans/convex-better-auth.md +1109 -0
- package/one/things/plans/convex-on-off.md +389 -0
- package/one/things/plans/desktop.md +1121 -0
- package/one/things/plans/effect-components.md +1669 -0
- package/one/things/plans/effect.md +973 -0
- package/one/things/plans/email.md +953 -0
- package/one/things/plans/enhance-auth.md +1669 -0
- package/one/things/plans/install-components.md +198 -0
- package/one/things/plans/landing.md +728 -0
- package/one/things/plans/layout.md +205 -0
- package/one/things/plans/mail-backend.md +1308 -0
- package/one/things/plans/mail.md +2624 -0
- package/one/things/plans/next-features.md +83 -0
- package/one/things/plans/one.md +658 -0
- package/one/things/plans/ontology-6-dimensions.md +2216 -0
- package/one/things/plans/ontology-driven-strategy.md +866 -0
- package/one/things/plans/ontology-ui-approach.md +357 -0
- package/one/things/plans/open-agent.md +785 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/releases.md +809 -0
- package/one/things/plans/repos.md +76 -0
- package/one/things/plans/separate-copy-2.md +1293 -0
- package/one/things/plans/separate-copy-3.md +2458 -0
- package/one/things/plans/separate-copy.md +1293 -0
- package/one/things/plans/separate.md +1983 -0
- package/one/things/plans/shadcn-integration-summary.md +450 -0
- package/one/things/plans/sidebar.md +172 -0
- package/one/things/plans/small-fixes.md +5 -0
- package/one/things/plans/test-backend-connection.md +476 -0
- package/one/things/plans/workflow-files.md +1196 -0
- package/one/things/plans/workflow.md +1372 -0
- package/one/things/products/cascade-landing-page.md +737 -0
- package/one/things/products/cascade.md +1518 -0
- package/one/things/products/context-engineering.md +1427 -0
- package/one/things/products/onthology.md +0 -0
- package/one/things/products/ontology-ui-shadcn.md +1280 -0
- package/one/things/products/ontology-ui.md +1387 -0
- package/one/things/products/ontology.md +717 -0
- package/one/things/products/sdk.md +557 -0
- package/one/things/promptkit.md +903 -0
- package/one/things/service-providers-new.md +982 -0
- package/one/things/service-providers.md +1092 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/package.json +5 -2
|
@@ -0,0 +1,1341 @@
|
|
|
1
|
+
# Multitenant.md - Multi-Tenant Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
**Multi-tenancy** enables multiple organizations to use the ONE Platform while maintaining complete data isolation, custom branding, and independent configuration. This architecture leverages the 6-dimension ontology to provide:
|
|
6
|
+
|
|
7
|
+
1. **Organization Isolation**: Each org's data is completely separated
|
|
8
|
+
2. **Shared Infrastructure**: Single Hono API + Convex backend serves all orgs
|
|
9
|
+
3. **Custom Frontends**: Each org can deploy custom-branded Astro frontend
|
|
10
|
+
4. **Flexible Billing**: Per-org limits, quotas, and subscriptions
|
|
11
|
+
5. **Role-Based Access**: Granular permissions within each organization
|
|
12
|
+
|
|
13
|
+
**Key Principle:** Organizations are first-class entities in the ontology. All resources (tokens, agents, content) belong to an organization via connections.
|
|
14
|
+
|
|
15
|
+
## Architecture Vision
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
19
|
+
│ MULTI-TENANT FRONTENDS │
|
|
20
|
+
├─────────────────────────────────────────────────────────────┤
|
|
21
|
+
│ Org A Frontend Org B Frontend Org C Frontend │
|
|
22
|
+
│ orgA.oneie.com orgB.oneie.com orgC.oneie.com │
|
|
23
|
+
│ - Custom theme - Custom theme - Custom theme │
|
|
24
|
+
│ - Custom components - Custom layout - Mobile-first │
|
|
25
|
+
└────────────────┬─────────────────┬──────────────────┬────────┘
|
|
26
|
+
│ │ │
|
|
27
|
+
└────────┬────────┴──────────┬───────┘
|
|
28
|
+
│ Shared API │
|
|
29
|
+
▼ │
|
|
30
|
+
┌─────────────────────────────────────────────▼───────────────┐
|
|
31
|
+
│ SHARED HONO API BACKEND │
|
|
32
|
+
│ - Organization middleware (extract orgId from subdomain) │
|
|
33
|
+
│ - Role-based access control (RBAC) │
|
|
34
|
+
│ - Per-org rate limiting │
|
|
35
|
+
│ - Per-org billing/quotas │
|
|
36
|
+
└────────────────────────────┬─────────────────────────────────┘
|
|
37
|
+
│
|
|
38
|
+
▼
|
|
39
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
40
|
+
│ SHARED CONVEX BACKEND │
|
|
41
|
+
│ - All orgs in single database │
|
|
42
|
+
│ - Data filtered by orgId (automatic isolation) │
|
|
43
|
+
│ - Organizations table (entities with type: 'organization') │
|
|
44
|
+
│ - Connections: user→org, org→resources │
|
|
45
|
+
│ - Events: per-org activity tracking │
|
|
46
|
+
└─────────────────────────────────────────────────────────────┘
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Data Model (6-Dimension Ontology)
|
|
50
|
+
|
|
51
|
+
### Entities
|
|
52
|
+
|
|
53
|
+
**Organization Entity:**
|
|
54
|
+
```typescript
|
|
55
|
+
{
|
|
56
|
+
_id: "org_xyz",
|
|
57
|
+
type: "organization",
|
|
58
|
+
name: "Acme Corp",
|
|
59
|
+
properties: {
|
|
60
|
+
slug: "acme-corp", // Unique slug for subdomain
|
|
61
|
+
domain: "acme-corp.oneie.com", // Custom domain
|
|
62
|
+
plan: "pro", // Subscription tier
|
|
63
|
+
settings: {
|
|
64
|
+
branding: {
|
|
65
|
+
logo: "https://...",
|
|
66
|
+
primaryColor: "#FF5733",
|
|
67
|
+
theme: "dark"
|
|
68
|
+
},
|
|
69
|
+
features: {
|
|
70
|
+
aiClone: true,
|
|
71
|
+
tokenEconomy: true,
|
|
72
|
+
customDomain: true
|
|
73
|
+
},
|
|
74
|
+
limits: {
|
|
75
|
+
maxUsers: 100,
|
|
76
|
+
maxAgents: 10,
|
|
77
|
+
maxTokens: 1000000
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
billing: {
|
|
81
|
+
stripeCustomerId: "cus_xxx",
|
|
82
|
+
subscriptionId: "sub_xxx",
|
|
83
|
+
currentPeriodEnd: 1735689600000
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
status: "active",
|
|
87
|
+
createdAt: 1704067200000,
|
|
88
|
+
updatedAt: 1704067200000
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**User Entity (enhanced with org context):**
|
|
93
|
+
```typescript
|
|
94
|
+
{
|
|
95
|
+
_id: "user_abc",
|
|
96
|
+
type: "user",
|
|
97
|
+
name: "Sarah Johnson",
|
|
98
|
+
properties: {
|
|
99
|
+
email: "sarah@acmecorp.com",
|
|
100
|
+
role: "creator", // Global role
|
|
101
|
+
currentOrgId: "org_xyz" // Active organization
|
|
102
|
+
},
|
|
103
|
+
status: "active",
|
|
104
|
+
createdAt: 1704067200000,
|
|
105
|
+
updatedAt: 1704067200000
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Connections
|
|
110
|
+
|
|
111
|
+
**Organization Membership:**
|
|
112
|
+
```typescript
|
|
113
|
+
{
|
|
114
|
+
fromEntityId: "user_abc",
|
|
115
|
+
toEntityId: "org_xyz",
|
|
116
|
+
relationshipType: "member_of",
|
|
117
|
+
metadata: {
|
|
118
|
+
role: "admin", // Org-specific role: admin, member, viewer
|
|
119
|
+
permissions: [
|
|
120
|
+
"create_agents",
|
|
121
|
+
"manage_users",
|
|
122
|
+
"manage_billing"
|
|
123
|
+
],
|
|
124
|
+
joinedAt: 1704067200000,
|
|
125
|
+
invitedBy: "user_def"
|
|
126
|
+
},
|
|
127
|
+
createdAt: 1704067200000
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Resource Ownership (org owns resources):**
|
|
132
|
+
```typescript
|
|
133
|
+
// Organization → Token
|
|
134
|
+
{
|
|
135
|
+
fromEntityId: "org_xyz",
|
|
136
|
+
toEntityId: "token_123",
|
|
137
|
+
relationshipType: "owns",
|
|
138
|
+
createdAt: 1704067200000
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Organization → AI Clone
|
|
142
|
+
{
|
|
143
|
+
fromEntityId: "org_xyz",
|
|
144
|
+
toEntityId: "ai_clone_456",
|
|
145
|
+
relationshipType: "owns",
|
|
146
|
+
createdAt: 1704067200000
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Organization → Content
|
|
150
|
+
{
|
|
151
|
+
fromEntityId: "org_xyz",
|
|
152
|
+
toEntityId: "content_789",
|
|
153
|
+
relationshipType: "owns",
|
|
154
|
+
createdAt: 1704067200000
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**User-Resource Access (user accesses org resources):**
|
|
159
|
+
```typescript
|
|
160
|
+
// User → Resource (scoped to org)
|
|
161
|
+
{
|
|
162
|
+
fromEntityId: "user_abc",
|
|
163
|
+
toEntityId: "token_123",
|
|
164
|
+
relationshipType: "has_access",
|
|
165
|
+
metadata: {
|
|
166
|
+
orgId: "org_xyz", // Scoped to organization
|
|
167
|
+
accessLevel: "edit" // read, edit, admin
|
|
168
|
+
},
|
|
169
|
+
createdAt: 1704067200000
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Events
|
|
174
|
+
|
|
175
|
+
**Organization Events:**
|
|
176
|
+
```typescript
|
|
177
|
+
{
|
|
178
|
+
entityId: "org_xyz",
|
|
179
|
+
eventType: "organization_created",
|
|
180
|
+
timestamp: 1704067200000,
|
|
181
|
+
actorType: "user",
|
|
182
|
+
actorId: "user_abc",
|
|
183
|
+
metadata: {
|
|
184
|
+
plan: "pro",
|
|
185
|
+
source: "web"
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
{
|
|
190
|
+
entityId: "org_xyz",
|
|
191
|
+
eventType: "user_invited",
|
|
192
|
+
timestamp: 1704067200000,
|
|
193
|
+
actorType: "user",
|
|
194
|
+
actorId: "user_abc",
|
|
195
|
+
metadata: {
|
|
196
|
+
invitedUserId: "user_def",
|
|
197
|
+
role: "member",
|
|
198
|
+
email: "john@acmecorp.com"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
{
|
|
203
|
+
entityId: "org_xyz",
|
|
204
|
+
eventType: "plan_upgraded",
|
|
205
|
+
timestamp: 1704067200000,
|
|
206
|
+
actorType: "user",
|
|
207
|
+
actorId: "user_abc",
|
|
208
|
+
metadata: {
|
|
209
|
+
oldPlan: "starter",
|
|
210
|
+
newPlan: "pro",
|
|
211
|
+
price: 99
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**Resource Events (scoped to org):**
|
|
217
|
+
```typescript
|
|
218
|
+
{
|
|
219
|
+
entityId: "token_123",
|
|
220
|
+
eventType: "tokens_purchased",
|
|
221
|
+
timestamp: 1704067200000,
|
|
222
|
+
actorType: "user",
|
|
223
|
+
actorId: "user_abc",
|
|
224
|
+
metadata: {
|
|
225
|
+
orgId: "org_xyz", // Organization context
|
|
226
|
+
amount: 1000,
|
|
227
|
+
price: 100,
|
|
228
|
+
paymentId: "pay_xxx"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Tags
|
|
234
|
+
|
|
235
|
+
**Organization Tags:**
|
|
236
|
+
```typescript
|
|
237
|
+
{
|
|
238
|
+
name: "industry:saas",
|
|
239
|
+
category: "industry"
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
{
|
|
243
|
+
name: "size:enterprise",
|
|
244
|
+
category: "organization_size"
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Junction: organization → tags
|
|
248
|
+
{
|
|
249
|
+
entityId: "org_xyz",
|
|
250
|
+
tagId: "tag_industry_saas"
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Implementation Pattern
|
|
255
|
+
|
|
256
|
+
### 1. Organization Service (Effect.ts)
|
|
257
|
+
|
|
258
|
+
#### `convex/services/organizations/organization.ts`
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
import { Effect } from 'effect';
|
|
262
|
+
import { ConvexDatabase } from '../providers/convex';
|
|
263
|
+
import type { Id } from '../../_generated/dataModel';
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Organization business logic
|
|
267
|
+
* Handles org creation, membership, settings
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
// Tagged errors
|
|
271
|
+
export class OrganizationNotFoundError {
|
|
272
|
+
readonly _tag = 'OrganizationNotFoundError';
|
|
273
|
+
constructor(readonly orgId: string) {}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export class DuplicateSlugError {
|
|
277
|
+
readonly _tag = 'DuplicateSlugError';
|
|
278
|
+
constructor(readonly slug: string) {}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export class InsufficientPermissionsError {
|
|
282
|
+
readonly _tag = 'InsufficientPermissionsError';
|
|
283
|
+
constructor(readonly userId: string, readonly permission: string) {}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export class QuotaExceededError {
|
|
287
|
+
readonly _tag = 'QuotaExceededError';
|
|
288
|
+
constructor(readonly resource: string, readonly limit: number) {}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export class OrganizationService extends Effect.Service<OrganizationService>()(
|
|
292
|
+
'OrganizationService',
|
|
293
|
+
{
|
|
294
|
+
effect: Effect.gen(function* () {
|
|
295
|
+
const db = yield* ConvexDatabase;
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
/**
|
|
299
|
+
* Create new organization
|
|
300
|
+
*/
|
|
301
|
+
create: (args: {
|
|
302
|
+
name: string;
|
|
303
|
+
slug: string;
|
|
304
|
+
creatorId: Id<'entities'>;
|
|
305
|
+
plan?: string;
|
|
306
|
+
}) =>
|
|
307
|
+
Effect.gen(function* () {
|
|
308
|
+
// Validate slug uniqueness
|
|
309
|
+
const existing = yield* Effect.tryPromise(() =>
|
|
310
|
+
db.query('entities')
|
|
311
|
+
.withIndex('type_slug', (q) =>
|
|
312
|
+
q.eq('type', 'organization').eq('properties.slug', args.slug)
|
|
313
|
+
)
|
|
314
|
+
.first()
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
if (existing) {
|
|
318
|
+
return yield* Effect.fail(new DuplicateSlugError(args.slug));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Create organization entity
|
|
322
|
+
const orgId = yield* Effect.tryPromise(() =>
|
|
323
|
+
db.insert('entities', {
|
|
324
|
+
type: 'organization',
|
|
325
|
+
name: args.name,
|
|
326
|
+
properties: {
|
|
327
|
+
slug: args.slug,
|
|
328
|
+
domain: `${args.slug}.oneie.com`,
|
|
329
|
+
plan: args.plan || 'starter',
|
|
330
|
+
settings: {
|
|
331
|
+
branding: {
|
|
332
|
+
primaryColor: '#3B82F6',
|
|
333
|
+
theme: 'light',
|
|
334
|
+
},
|
|
335
|
+
features: {
|
|
336
|
+
aiClone: args.plan === 'pro' || args.plan === 'enterprise',
|
|
337
|
+
tokenEconomy: true,
|
|
338
|
+
customDomain: args.plan === 'enterprise',
|
|
339
|
+
},
|
|
340
|
+
limits: {
|
|
341
|
+
maxUsers: args.plan === 'enterprise' ? -1 : args.plan === 'pro' ? 100 : 10,
|
|
342
|
+
maxAgents: args.plan === 'enterprise' ? -1 : args.plan === 'pro' ? 10 : 3,
|
|
343
|
+
maxTokens: args.plan === 'enterprise' ? -1 : 1000000,
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
status: 'active',
|
|
348
|
+
createdAt: Date.now(),
|
|
349
|
+
updatedAt: Date.now(),
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// Add creator as admin
|
|
354
|
+
yield* Effect.tryPromise(() =>
|
|
355
|
+
db.insert('connections', {
|
|
356
|
+
fromEntityId: args.creatorId,
|
|
357
|
+
toEntityId: orgId,
|
|
358
|
+
relationshipType: 'member_of',
|
|
359
|
+
metadata: {
|
|
360
|
+
role: 'admin',
|
|
361
|
+
permissions: ['*'], // All permissions
|
|
362
|
+
joinedAt: Date.now(),
|
|
363
|
+
},
|
|
364
|
+
createdAt: Date.now(),
|
|
365
|
+
})
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// Log event
|
|
369
|
+
yield* Effect.tryPromise(() =>
|
|
370
|
+
db.insert('events', {
|
|
371
|
+
entityId: orgId,
|
|
372
|
+
eventType: 'organization_created',
|
|
373
|
+
timestamp: Date.now(),
|
|
374
|
+
actorType: 'user',
|
|
375
|
+
actorId: args.creatorId,
|
|
376
|
+
metadata: {
|
|
377
|
+
plan: args.plan || 'starter',
|
|
378
|
+
source: 'web',
|
|
379
|
+
},
|
|
380
|
+
})
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
return { orgId, slug: args.slug };
|
|
384
|
+
}),
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Add user to organization
|
|
388
|
+
*/
|
|
389
|
+
addMember: (args: {
|
|
390
|
+
orgId: Id<'entities'>;
|
|
391
|
+
userId: Id<'entities'>;
|
|
392
|
+
role: 'admin' | 'member' | 'viewer';
|
|
393
|
+
invitedBy: Id<'entities'>;
|
|
394
|
+
}) =>
|
|
395
|
+
Effect.gen(function* () {
|
|
396
|
+
// Check if inviter has permission
|
|
397
|
+
const inviterMembership = yield* Effect.tryPromise(() =>
|
|
398
|
+
db.query('connections')
|
|
399
|
+
.withIndex('from_type', (q) =>
|
|
400
|
+
q.eq('fromEntityId', args.invitedBy).eq('relationshipType', 'member_of')
|
|
401
|
+
)
|
|
402
|
+
.filter((q) => q.eq(q.field('toEntityId'), args.orgId))
|
|
403
|
+
.first()
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
if (!inviterMembership || inviterMembership.metadata?.role !== 'admin') {
|
|
407
|
+
return yield* Effect.fail(
|
|
408
|
+
new InsufficientPermissionsError(args.invitedBy, 'manage_users')
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Check org limits
|
|
413
|
+
const org = yield* Effect.tryPromise(() => db.get(args.orgId));
|
|
414
|
+
if (!org) {
|
|
415
|
+
return yield* Effect.fail(new OrganizationNotFoundError(args.orgId));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const memberCount = yield* Effect.tryPromise(() =>
|
|
419
|
+
db.query('connections')
|
|
420
|
+
.withIndex('to_type', (q) =>
|
|
421
|
+
q.eq('toEntityId', args.orgId).eq('relationshipType', 'member_of')
|
|
422
|
+
)
|
|
423
|
+
.collect()
|
|
424
|
+
).pipe(Effect.map((members) => members.length));
|
|
425
|
+
|
|
426
|
+
const maxUsers = org.properties.settings.limits.maxUsers;
|
|
427
|
+
if (maxUsers !== -1 && memberCount >= maxUsers) {
|
|
428
|
+
return yield* Effect.fail(new QuotaExceededError('users', maxUsers));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Add member
|
|
432
|
+
const permissions =
|
|
433
|
+
args.role === 'admin'
|
|
434
|
+
? ['*']
|
|
435
|
+
: args.role === 'member'
|
|
436
|
+
? ['create_agents', 'create_content', 'view_analytics']
|
|
437
|
+
: ['view_content'];
|
|
438
|
+
|
|
439
|
+
yield* Effect.tryPromise(() =>
|
|
440
|
+
db.insert('connections', {
|
|
441
|
+
fromEntityId: args.userId,
|
|
442
|
+
toEntityId: args.orgId,
|
|
443
|
+
relationshipType: 'member_of',
|
|
444
|
+
metadata: {
|
|
445
|
+
role: args.role,
|
|
446
|
+
permissions,
|
|
447
|
+
joinedAt: Date.now(),
|
|
448
|
+
invitedBy: args.invitedBy,
|
|
449
|
+
},
|
|
450
|
+
createdAt: Date.now(),
|
|
451
|
+
})
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
// Log event
|
|
455
|
+
yield* Effect.tryPromise(() =>
|
|
456
|
+
db.insert('events', {
|
|
457
|
+
entityId: args.orgId,
|
|
458
|
+
eventType: 'user_invited',
|
|
459
|
+
timestamp: Date.now(),
|
|
460
|
+
actorType: 'user',
|
|
461
|
+
actorId: args.invitedBy,
|
|
462
|
+
metadata: {
|
|
463
|
+
invitedUserId: args.userId,
|
|
464
|
+
role: args.role,
|
|
465
|
+
},
|
|
466
|
+
})
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
return { success: true };
|
|
470
|
+
}),
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Update organization settings
|
|
474
|
+
*/
|
|
475
|
+
updateSettings: (args: {
|
|
476
|
+
orgId: Id<'entities'>;
|
|
477
|
+
userId: Id<'entities'>;
|
|
478
|
+
settings: Record<string, any>;
|
|
479
|
+
}) =>
|
|
480
|
+
Effect.gen(function* () {
|
|
481
|
+
// Check permissions
|
|
482
|
+
const membership = yield* Effect.tryPromise(() =>
|
|
483
|
+
db.query('connections')
|
|
484
|
+
.withIndex('from_type', (q) =>
|
|
485
|
+
q.eq('fromEntityId', args.userId).eq('relationshipType', 'member_of')
|
|
486
|
+
)
|
|
487
|
+
.filter((q) => q.eq(q.field('toEntityId'), args.orgId))
|
|
488
|
+
.first()
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
if (!membership || membership.metadata?.role !== 'admin') {
|
|
492
|
+
return yield* Effect.fail(
|
|
493
|
+
new InsufficientPermissionsError(args.userId, 'manage_settings')
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Update org
|
|
498
|
+
const org = yield* Effect.tryPromise(() => db.get(args.orgId));
|
|
499
|
+
if (!org) {
|
|
500
|
+
return yield* Effect.fail(new OrganizationNotFoundError(args.orgId));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
yield* Effect.tryPromise(() =>
|
|
504
|
+
db.patch(args.orgId, {
|
|
505
|
+
properties: {
|
|
506
|
+
...org.properties,
|
|
507
|
+
settings: {
|
|
508
|
+
...org.properties.settings,
|
|
509
|
+
...args.settings,
|
|
510
|
+
},
|
|
511
|
+
},
|
|
512
|
+
updatedAt: Date.now(),
|
|
513
|
+
})
|
|
514
|
+
);
|
|
515
|
+
|
|
516
|
+
// Log event
|
|
517
|
+
yield* Effect.tryPromise(() =>
|
|
518
|
+
db.insert('events', {
|
|
519
|
+
entityId: args.orgId,
|
|
520
|
+
eventType: 'settings_updated',
|
|
521
|
+
timestamp: Date.now(),
|
|
522
|
+
actorType: 'user',
|
|
523
|
+
actorId: args.userId,
|
|
524
|
+
metadata: {
|
|
525
|
+
updatedFields: Object.keys(args.settings),
|
|
526
|
+
},
|
|
527
|
+
})
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
return { success: true };
|
|
531
|
+
}),
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Check if user has permission in org
|
|
535
|
+
*/
|
|
536
|
+
checkPermission: (args: {
|
|
537
|
+
userId: Id<'entities'>;
|
|
538
|
+
orgId: Id<'entities'>;
|
|
539
|
+
permission: string;
|
|
540
|
+
}) =>
|
|
541
|
+
Effect.gen(function* () {
|
|
542
|
+
const membership = yield* Effect.tryPromise(() =>
|
|
543
|
+
db.query('connections')
|
|
544
|
+
.withIndex('from_type', (q) =>
|
|
545
|
+
q.eq('fromEntityId', args.userId).eq('relationshipType', 'member_of')
|
|
546
|
+
)
|
|
547
|
+
.filter((q) => q.eq(q.field('toEntityId'), args.orgId))
|
|
548
|
+
.first()
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
if (!membership) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const permissions = membership.metadata?.permissions || [];
|
|
556
|
+
return permissions.includes('*') || permissions.includes(args.permission);
|
|
557
|
+
}),
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Get organization by slug
|
|
561
|
+
*/
|
|
562
|
+
getBySlug: (slug: string) =>
|
|
563
|
+
Effect.gen(function* () {
|
|
564
|
+
const org = yield* Effect.tryPromise(() =>
|
|
565
|
+
db.query('entities')
|
|
566
|
+
.withIndex('type_slug', (q) =>
|
|
567
|
+
q.eq('type', 'organization').eq('properties.slug', slug)
|
|
568
|
+
)
|
|
569
|
+
.first()
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
if (!org) {
|
|
573
|
+
return yield* Effect.fail(new OrganizationNotFoundError(slug));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return org;
|
|
577
|
+
}),
|
|
578
|
+
};
|
|
579
|
+
}),
|
|
580
|
+
dependencies: [ConvexDatabase.Default],
|
|
581
|
+
}
|
|
582
|
+
) {}
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### 2. Organization Middleware (Hono)
|
|
586
|
+
|
|
587
|
+
#### `api/src/middleware/organization.ts`
|
|
588
|
+
|
|
589
|
+
```typescript
|
|
590
|
+
import { Context } from 'hono';
|
|
591
|
+
import { ConvexHttpClient } from 'convex/browser';
|
|
592
|
+
import { api } from '../../../convex/_generated/api';
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Organization middleware
|
|
596
|
+
* Extracts orgId from subdomain or header
|
|
597
|
+
* Validates user membership
|
|
598
|
+
*/
|
|
599
|
+
|
|
600
|
+
export const organizationMiddleware = async (c: Context, next: Function) => {
|
|
601
|
+
const convex = new ConvexHttpClient(c.env.CONVEX_URL);
|
|
602
|
+
|
|
603
|
+
// Extract org slug from subdomain
|
|
604
|
+
const host = c.req.header('host') || '';
|
|
605
|
+
const subdomain = host.split('.')[0];
|
|
606
|
+
|
|
607
|
+
// Skip for main domain or API domain
|
|
608
|
+
if (subdomain === 'api' || subdomain === 'www' || !subdomain.includes('oneie')) {
|
|
609
|
+
// Try to get orgId from header (for API calls)
|
|
610
|
+
const orgId = c.req.header('x-organization-id');
|
|
611
|
+
if (orgId) {
|
|
612
|
+
c.set('orgId', orgId);
|
|
613
|
+
}
|
|
614
|
+
await next();
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
try {
|
|
619
|
+
// Get organization by slug
|
|
620
|
+
const org = await convex.query(api.queries.organizations.getBySlug, {
|
|
621
|
+
slug: subdomain,
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
if (!org) {
|
|
625
|
+
return c.json({ error: 'Organization not found' }, 404);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Check if org is active
|
|
629
|
+
if (org.status !== 'active') {
|
|
630
|
+
return c.json({ error: 'Organization is inactive' }, 403);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// Set org context
|
|
634
|
+
c.set('orgId', org._id);
|
|
635
|
+
c.set('org', org);
|
|
636
|
+
|
|
637
|
+
await next();
|
|
638
|
+
} catch (error) {
|
|
639
|
+
return c.json({ error: 'Invalid organization' }, 400);
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Permission middleware
|
|
645
|
+
* Checks if user has required permission in org
|
|
646
|
+
*/
|
|
647
|
+
export const requirePermission = (permission: string) => {
|
|
648
|
+
return async (c: Context, next: Function) => {
|
|
649
|
+
const orgId = c.get('orgId');
|
|
650
|
+
const session = c.get('session'); // Set by auth middleware
|
|
651
|
+
|
|
652
|
+
if (!orgId || !session) {
|
|
653
|
+
return c.json({ error: 'Unauthorized' }, 401);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const convex = new ConvexHttpClient(c.env.CONVEX_URL);
|
|
657
|
+
|
|
658
|
+
const hasPermission = await convex.query(
|
|
659
|
+
api.queries.organizations.checkPermission,
|
|
660
|
+
{
|
|
661
|
+
userId: session.user.id,
|
|
662
|
+
orgId,
|
|
663
|
+
permission,
|
|
664
|
+
}
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
if (!hasPermission) {
|
|
668
|
+
return c.json({ error: 'Insufficient permissions' }, 403);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
await next();
|
|
672
|
+
};
|
|
673
|
+
};
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
### 3. Organization Routes (Hono)
|
|
677
|
+
|
|
678
|
+
#### `api/src/routes/organizations.ts`
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
import { Hono } from 'hono';
|
|
682
|
+
import { Effect } from 'effect';
|
|
683
|
+
import { convexMiddleware, ConvexService } from '../services/convex';
|
|
684
|
+
import { OrganizationService } from '../../../convex/services/organizations/organization';
|
|
685
|
+
import { auth } from '../auth';
|
|
686
|
+
import { requirePermission } from '../middleware/organization';
|
|
687
|
+
|
|
688
|
+
const app = new Hono();
|
|
689
|
+
|
|
690
|
+
app.use('*', convexMiddleware);
|
|
691
|
+
|
|
692
|
+
// POST /api/organizations - Create organization
|
|
693
|
+
app.post('/', async (c) => {
|
|
694
|
+
const session = await auth(c.env).api.getSession({
|
|
695
|
+
headers: c.req.raw.headers,
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
if (!session) {
|
|
699
|
+
return c.json({ error: 'Unauthorized' }, 401);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const { name, slug, plan } = await c.req.json();
|
|
703
|
+
|
|
704
|
+
const convex = c.get('convex') as ConvexService;
|
|
705
|
+
const orgService = new OrganizationService();
|
|
706
|
+
|
|
707
|
+
const program = orgService.create({
|
|
708
|
+
name,
|
|
709
|
+
slug,
|
|
710
|
+
creatorId: session.user.id,
|
|
711
|
+
plan,
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
const result = await Effect.runPromise(
|
|
715
|
+
program.pipe(
|
|
716
|
+
Effect.catchAll((error) => {
|
|
717
|
+
if (error._tag === 'DuplicateSlugError') {
|
|
718
|
+
return Effect.succeed({
|
|
719
|
+
error: 'Slug already taken',
|
|
720
|
+
code: 'DUPLICATE_SLUG',
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
return Effect.succeed({ error: 'Failed to create organization' });
|
|
724
|
+
})
|
|
725
|
+
)
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
if ('error' in result) {
|
|
729
|
+
return c.json(result, 400);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
return c.json(result, 201);
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
// GET /api/organizations/:slug - Get organization
|
|
736
|
+
app.get('/:slug', async (c) => {
|
|
737
|
+
const convex = c.get('convex') as ConvexService;
|
|
738
|
+
const org = await convex.getOrganizationBySlug(c.req.param('slug'));
|
|
739
|
+
|
|
740
|
+
if (!org) {
|
|
741
|
+
return c.json({ error: 'Organization not found' }, 404);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
return c.json(org);
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// POST /api/organizations/:id/members - Add member
|
|
748
|
+
app.post('/:id/members', requirePermission('manage_users'), async (c) => {
|
|
749
|
+
const session = await auth(c.env).api.getSession({
|
|
750
|
+
headers: c.req.raw.headers,
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
const { userId, role } = await c.req.json();
|
|
754
|
+
|
|
755
|
+
const orgService = new OrganizationService();
|
|
756
|
+
const program = orgService.addMember({
|
|
757
|
+
orgId: c.req.param('id'),
|
|
758
|
+
userId,
|
|
759
|
+
role,
|
|
760
|
+
invitedBy: session.user.id,
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
const result = await Effect.runPromise(
|
|
764
|
+
program.pipe(
|
|
765
|
+
Effect.catchAll((error) => {
|
|
766
|
+
if (error._tag === 'QuotaExceededError') {
|
|
767
|
+
return Effect.succeed({
|
|
768
|
+
error: `User limit exceeded (${error.limit})`,
|
|
769
|
+
code: 'QUOTA_EXCEEDED',
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
if (error._tag === 'InsufficientPermissionsError') {
|
|
773
|
+
return Effect.succeed({
|
|
774
|
+
error: 'Insufficient permissions',
|
|
775
|
+
code: 'FORBIDDEN',
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
return Effect.succeed({ error: 'Failed to add member' });
|
|
779
|
+
})
|
|
780
|
+
)
|
|
781
|
+
);
|
|
782
|
+
|
|
783
|
+
if ('error' in result) {
|
|
784
|
+
return c.json(result, 400);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
return c.json(result);
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
// PATCH /api/organizations/:id/settings - Update settings
|
|
791
|
+
app.patch('/:id/settings', requirePermission('manage_settings'), async (c) => {
|
|
792
|
+
const session = await auth(c.env).api.getSession({
|
|
793
|
+
headers: c.req.raw.headers,
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
const settings = await c.req.json();
|
|
797
|
+
|
|
798
|
+
const orgService = new OrganizationService();
|
|
799
|
+
const program = orgService.updateSettings({
|
|
800
|
+
orgId: c.req.param('id'),
|
|
801
|
+
userId: session.user.id,
|
|
802
|
+
settings,
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
const result = await Effect.runPromise(program);
|
|
806
|
+
|
|
807
|
+
return c.json(result);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
export const organizationRoutes = app;
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
### 4. Scoped Queries (Convex)
|
|
814
|
+
|
|
815
|
+
#### `convex/queries/tokens.ts` (with org filtering)
|
|
816
|
+
|
|
817
|
+
```typescript
|
|
818
|
+
import { v } from 'convex/values';
|
|
819
|
+
import { query } from '../_generated/server';
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Token queries scoped to organization
|
|
823
|
+
*/
|
|
824
|
+
|
|
825
|
+
export const list = query({
|
|
826
|
+
args: {
|
|
827
|
+
orgId: v.id('entities'),
|
|
828
|
+
},
|
|
829
|
+
handler: async (ctx, args) => {
|
|
830
|
+
// Get tokens owned by organization
|
|
831
|
+
const orgTokens = await ctx.db
|
|
832
|
+
.query('connections')
|
|
833
|
+
.withIndex('from_type', (q) =>
|
|
834
|
+
q.eq('fromEntityId', args.orgId).eq('relationshipType', 'owns')
|
|
835
|
+
)
|
|
836
|
+
.collect();
|
|
837
|
+
|
|
838
|
+
const tokenIds = orgTokens
|
|
839
|
+
.map((c) => c.toEntityId)
|
|
840
|
+
.filter((id) => id !== undefined);
|
|
841
|
+
|
|
842
|
+
const tokens = await Promise.all(
|
|
843
|
+
tokenIds.map(async (id) => {
|
|
844
|
+
const entity = await ctx.db.get(id);
|
|
845
|
+
if (entity && entity.type === 'token') {
|
|
846
|
+
return entity;
|
|
847
|
+
}
|
|
848
|
+
return null;
|
|
849
|
+
})
|
|
850
|
+
);
|
|
851
|
+
|
|
852
|
+
return tokens.filter((t) => t !== null);
|
|
853
|
+
},
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
export const getBalance = query({
|
|
857
|
+
args: {
|
|
858
|
+
userId: v.id('entities'),
|
|
859
|
+
tokenId: v.id('entities'),
|
|
860
|
+
orgId: v.id('entities'),
|
|
861
|
+
},
|
|
862
|
+
handler: async (ctx, args) => {
|
|
863
|
+
// Verify token belongs to org
|
|
864
|
+
const ownership = await ctx.db
|
|
865
|
+
.query('connections')
|
|
866
|
+
.withIndex('from_to', (q) =>
|
|
867
|
+
q.eq('fromEntityId', args.orgId).eq('toEntityId', args.tokenId)
|
|
868
|
+
)
|
|
869
|
+
.filter((q) => q.eq(q.field('relationshipType'), 'owns'))
|
|
870
|
+
.first();
|
|
871
|
+
|
|
872
|
+
if (!ownership) {
|
|
873
|
+
throw new Error('Token does not belong to organization');
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Get user's balance
|
|
877
|
+
const connection = await ctx.db
|
|
878
|
+
.query('connections')
|
|
879
|
+
.withIndex('from_to', (q) =>
|
|
880
|
+
q.eq('fromEntityId', args.userId).eq('toEntityId', args.tokenId)
|
|
881
|
+
)
|
|
882
|
+
.filter((q) => q.eq(q.field('relationshipType'), 'holds_tokens'))
|
|
883
|
+
.first();
|
|
884
|
+
|
|
885
|
+
return connection?.metadata?.balance || 0;
|
|
886
|
+
},
|
|
887
|
+
});
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
### 5. Frontend: Organization Context
|
|
891
|
+
|
|
892
|
+
#### `src/lib/organization-context.tsx`
|
|
893
|
+
|
|
894
|
+
```typescript
|
|
895
|
+
import { createContext, useContext, ReactNode } from 'react';
|
|
896
|
+
import { useQuery } from 'convex/react';
|
|
897
|
+
import { api } from '@/convex/_generated/api';
|
|
898
|
+
import type { Id } from '@/convex/_generated/dataModel';
|
|
899
|
+
|
|
900
|
+
interface Organization {
|
|
901
|
+
_id: Id<'entities'>;
|
|
902
|
+
name: string;
|
|
903
|
+
slug: string;
|
|
904
|
+
settings: {
|
|
905
|
+
branding: {
|
|
906
|
+
logo?: string;
|
|
907
|
+
primaryColor: string;
|
|
908
|
+
theme: 'light' | 'dark';
|
|
909
|
+
};
|
|
910
|
+
features: Record<string, boolean>;
|
|
911
|
+
limits: Record<string, number>;
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
interface OrganizationContextType {
|
|
916
|
+
organization: Organization | null;
|
|
917
|
+
isLoading: boolean;
|
|
918
|
+
hasFeature: (feature: string) => boolean;
|
|
919
|
+
hasPermission: (permission: string) => boolean;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
const OrganizationContext = createContext<OrganizationContextType | null>(null);
|
|
923
|
+
|
|
924
|
+
export function OrganizationProvider({
|
|
925
|
+
children,
|
|
926
|
+
orgSlug,
|
|
927
|
+
}: {
|
|
928
|
+
children: ReactNode;
|
|
929
|
+
orgSlug: string;
|
|
930
|
+
}) {
|
|
931
|
+
const organization = useQuery(api.queries.organizations.getBySlug, {
|
|
932
|
+
slug: orgSlug,
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
const hasFeature = (feature: string) => {
|
|
936
|
+
return organization?.properties.settings.features[feature] || false;
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
const hasPermission = (permission: string) => {
|
|
940
|
+
// TODO: Check user's permissions in this org
|
|
941
|
+
return true;
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
return (
|
|
945
|
+
<OrganizationContext.Provider
|
|
946
|
+
value={{
|
|
947
|
+
organization: organization || null,
|
|
948
|
+
isLoading: organization === undefined,
|
|
949
|
+
hasFeature,
|
|
950
|
+
hasPermission,
|
|
951
|
+
}}
|
|
952
|
+
>
|
|
953
|
+
{children}
|
|
954
|
+
</OrganizationContext.Provider>
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
export function useOrganization() {
|
|
959
|
+
const context = useContext(OrganizationContext);
|
|
960
|
+
if (!context) {
|
|
961
|
+
throw new Error('useOrganization must be used within OrganizationProvider');
|
|
962
|
+
}
|
|
963
|
+
return context;
|
|
964
|
+
}
|
|
965
|
+
```
|
|
966
|
+
|
|
967
|
+
#### `src/pages/[org]/dashboard.astro`
|
|
968
|
+
|
|
969
|
+
```astro
|
|
970
|
+
---
|
|
971
|
+
import { ConvexHttpClient } from 'convex/browser';
|
|
972
|
+
import { api } from '@/convex/_generated/api';
|
|
973
|
+
import Layout from '@/layouts/Layout.astro';
|
|
974
|
+
import { OrganizationProvider } from '@/lib/organization-context';
|
|
975
|
+
import Dashboard from '@/components/dashboard/Dashboard';
|
|
976
|
+
|
|
977
|
+
// Extract org slug from URL
|
|
978
|
+
const orgSlug = Astro.params.org;
|
|
979
|
+
|
|
980
|
+
// Fetch org data server-side
|
|
981
|
+
const convex = new ConvexHttpClient(import.meta.env.PUBLIC_CONVEX_URL);
|
|
982
|
+
const org = await convex.query(api.queries.organizations.getBySlug, {
|
|
983
|
+
slug: orgSlug,
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
if (!org) {
|
|
987
|
+
return Astro.redirect('/404');
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// Apply org branding
|
|
991
|
+
const primaryColor = org.properties.settings.branding.primaryColor;
|
|
992
|
+
---
|
|
993
|
+
|
|
994
|
+
<Layout title={`${org.name} - Dashboard`}>
|
|
995
|
+
<style define:vars={{ primaryColor }}>
|
|
996
|
+
:root {
|
|
997
|
+
--color-primary: var(--primaryColor);
|
|
998
|
+
}
|
|
999
|
+
</style>
|
|
1000
|
+
|
|
1001
|
+
<OrganizationProvider client:load orgSlug={orgSlug}>
|
|
1002
|
+
<Dashboard client:load />
|
|
1003
|
+
</OrganizationProvider>
|
|
1004
|
+
</Layout>
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
### 6. Feature Gating
|
|
1008
|
+
|
|
1009
|
+
#### `src/components/features/FeatureGate.tsx`
|
|
1010
|
+
|
|
1011
|
+
```typescript
|
|
1012
|
+
import { useOrganization } from '@/lib/organization-context';
|
|
1013
|
+
import { Alert, AlertDescription } from '@/components/ui/alert';
|
|
1014
|
+
|
|
1015
|
+
interface FeatureGateProps {
|
|
1016
|
+
feature: string;
|
|
1017
|
+
children: React.ReactNode;
|
|
1018
|
+
fallback?: React.ReactNode;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
export function FeatureGate({ feature, children, fallback }: FeatureGateProps) {
|
|
1022
|
+
const { hasFeature, organization } = useOrganization();
|
|
1023
|
+
|
|
1024
|
+
if (!hasFeature(feature)) {
|
|
1025
|
+
return (
|
|
1026
|
+
fallback || (
|
|
1027
|
+
<Alert>
|
|
1028
|
+
<AlertDescription>
|
|
1029
|
+
This feature is not available on your current plan.
|
|
1030
|
+
<a href={`/${organization?.slug}/billing`} className="underline ml-1">
|
|
1031
|
+
Upgrade now
|
|
1032
|
+
</a>
|
|
1033
|
+
</AlertDescription>
|
|
1034
|
+
</Alert>
|
|
1035
|
+
)
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
return <>{children}</>;
|
|
1040
|
+
}
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
**Usage:**
|
|
1044
|
+
|
|
1045
|
+
```typescript
|
|
1046
|
+
import { FeatureGate } from '@/components/features/FeatureGate';
|
|
1047
|
+
import { AICloneCreator } from '@/components/ai-clone/AICloneCreator';
|
|
1048
|
+
|
|
1049
|
+
export function Dashboard() {
|
|
1050
|
+
return (
|
|
1051
|
+
<div>
|
|
1052
|
+
<h1>Dashboard</h1>
|
|
1053
|
+
|
|
1054
|
+
<FeatureGate feature="aiClone">
|
|
1055
|
+
<AICloneCreator />
|
|
1056
|
+
</FeatureGate>
|
|
1057
|
+
|
|
1058
|
+
<FeatureGate feature="customDomain">
|
|
1059
|
+
<CustomDomainSettings />
|
|
1060
|
+
</FeatureGate>
|
|
1061
|
+
</div>
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
```
|
|
1065
|
+
|
|
1066
|
+
## Subdomain Routing
|
|
1067
|
+
|
|
1068
|
+
### Cloudflare Pages Configuration
|
|
1069
|
+
|
|
1070
|
+
**`wrangler.toml`:**
|
|
1071
|
+
|
|
1072
|
+
```toml
|
|
1073
|
+
name = "oneie-frontend"
|
|
1074
|
+
compatibility_date = "2024-01-01"
|
|
1075
|
+
|
|
1076
|
+
[[routes]]
|
|
1077
|
+
pattern = "*.oneie.com/*"
|
|
1078
|
+
zone_name = "oneie.com"
|
|
1079
|
+
custom_domain = true
|
|
1080
|
+
|
|
1081
|
+
[env.production]
|
|
1082
|
+
routes = [
|
|
1083
|
+
{ pattern = "*.oneie.com/*", custom_domain = true }
|
|
1084
|
+
]
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
### Subdomain Extraction (Astro Middleware)
|
|
1088
|
+
|
|
1089
|
+
#### `src/middleware/organization.ts`
|
|
1090
|
+
|
|
1091
|
+
```typescript
|
|
1092
|
+
import { defineMiddleware } from 'astro:middleware';
|
|
1093
|
+
|
|
1094
|
+
export const onRequest = defineMiddleware(async (context, next) => {
|
|
1095
|
+
const host = context.request.headers.get('host') || '';
|
|
1096
|
+
const subdomain = host.split('.')[0];
|
|
1097
|
+
|
|
1098
|
+
// Skip main domain
|
|
1099
|
+
if (subdomain === 'www' || subdomain === 'oneie' || !host.includes('oneie.com')) {
|
|
1100
|
+
return next();
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// Store org slug in context
|
|
1104
|
+
context.locals.orgSlug = subdomain;
|
|
1105
|
+
|
|
1106
|
+
return next();
|
|
1107
|
+
});
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
**Usage in pages:**
|
|
1111
|
+
|
|
1112
|
+
```astro
|
|
1113
|
+
---
|
|
1114
|
+
const orgSlug = Astro.locals.orgSlug;
|
|
1115
|
+
---
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
## Billing & Quotas
|
|
1119
|
+
|
|
1120
|
+
### Plan Configuration
|
|
1121
|
+
|
|
1122
|
+
#### `convex/config/plans.ts`
|
|
1123
|
+
|
|
1124
|
+
```typescript
|
|
1125
|
+
export const PLANS = {
|
|
1126
|
+
starter: {
|
|
1127
|
+
name: 'Starter',
|
|
1128
|
+
price: 0,
|
|
1129
|
+
features: {
|
|
1130
|
+
aiClone: false,
|
|
1131
|
+
tokenEconomy: true,
|
|
1132
|
+
customDomain: false,
|
|
1133
|
+
analytics: 'basic',
|
|
1134
|
+
},
|
|
1135
|
+
limits: {
|
|
1136
|
+
maxUsers: 10,
|
|
1137
|
+
maxAgents: 3,
|
|
1138
|
+
maxTokens: 100000,
|
|
1139
|
+
maxContent: 100,
|
|
1140
|
+
},
|
|
1141
|
+
},
|
|
1142
|
+
pro: {
|
|
1143
|
+
name: 'Pro',
|
|
1144
|
+
price: 99,
|
|
1145
|
+
features: {
|
|
1146
|
+
aiClone: true,
|
|
1147
|
+
tokenEconomy: true,
|
|
1148
|
+
customDomain: false,
|
|
1149
|
+
analytics: 'advanced',
|
|
1150
|
+
},
|
|
1151
|
+
limits: {
|
|
1152
|
+
maxUsers: 100,
|
|
1153
|
+
maxAgents: 10,
|
|
1154
|
+
maxTokens: 1000000,
|
|
1155
|
+
maxContent: 1000,
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
enterprise: {
|
|
1159
|
+
name: 'Enterprise',
|
|
1160
|
+
price: 499,
|
|
1161
|
+
features: {
|
|
1162
|
+
aiClone: true,
|
|
1163
|
+
tokenEconomy: true,
|
|
1164
|
+
customDomain: true,
|
|
1165
|
+
analytics: 'custom',
|
|
1166
|
+
},
|
|
1167
|
+
limits: {
|
|
1168
|
+
maxUsers: -1, // Unlimited
|
|
1169
|
+
maxAgents: -1,
|
|
1170
|
+
maxTokens: -1,
|
|
1171
|
+
maxContent: -1,
|
|
1172
|
+
},
|
|
1173
|
+
},
|
|
1174
|
+
} as const;
|
|
1175
|
+
```
|
|
1176
|
+
|
|
1177
|
+
### Quota Checking
|
|
1178
|
+
|
|
1179
|
+
```typescript
|
|
1180
|
+
// In OrganizationService
|
|
1181
|
+
checkQuota: (args: {
|
|
1182
|
+
orgId: Id<'entities'>;
|
|
1183
|
+
resource: 'users' | 'agents' | 'tokens' | 'content';
|
|
1184
|
+
}) =>
|
|
1185
|
+
Effect.gen(function* () {
|
|
1186
|
+
const org = yield* Effect.tryPromise(() => db.get(args.orgId));
|
|
1187
|
+
if (!org) {
|
|
1188
|
+
return yield* Effect.fail(new OrganizationNotFoundError(args.orgId));
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
const limit = org.properties.settings.limits[`max${args.resource.charAt(0).toUpperCase() + args.resource.slice(1)}`];
|
|
1192
|
+
|
|
1193
|
+
// -1 means unlimited
|
|
1194
|
+
if (limit === -1) {
|
|
1195
|
+
return { allowed: true, limit: -1, current: 0 };
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// Count current usage
|
|
1199
|
+
const connections = yield* Effect.tryPromise(() =>
|
|
1200
|
+
db.query('connections')
|
|
1201
|
+
.withIndex('from_type', (q) =>
|
|
1202
|
+
q.eq('fromEntityId', args.orgId).eq('relationshipType', 'owns')
|
|
1203
|
+
)
|
|
1204
|
+
.collect()
|
|
1205
|
+
);
|
|
1206
|
+
|
|
1207
|
+
const current = connections.length;
|
|
1208
|
+
|
|
1209
|
+
if (current >= limit) {
|
|
1210
|
+
return yield* Effect.fail(new QuotaExceededError(args.resource, limit));
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
return { allowed: true, limit, current };
|
|
1214
|
+
})
|
|
1215
|
+
```
|
|
1216
|
+
|
|
1217
|
+
## Multi-Tenant Benefits
|
|
1218
|
+
|
|
1219
|
+
### 1. Data Isolation
|
|
1220
|
+
|
|
1221
|
+
✅ **Complete separation**: Each org's data is isolated via `orgId` filtering
|
|
1222
|
+
✅ **No cross-contamination**: Users can't access other orgs' resources
|
|
1223
|
+
✅ **Audit trail**: All events tagged with `orgId`
|
|
1224
|
+
|
|
1225
|
+
### 2. Customization
|
|
1226
|
+
|
|
1227
|
+
✅ **Custom branding**: Logo, colors, theme per org
|
|
1228
|
+
✅ **Feature flags**: Enable/disable features per org
|
|
1229
|
+
✅ **Custom domains**: `acme-corp.oneie.com` or `app.acmecorp.com`
|
|
1230
|
+
|
|
1231
|
+
### 3. Scalability
|
|
1232
|
+
|
|
1233
|
+
✅ **Shared infrastructure**: Single API + database serves all orgs
|
|
1234
|
+
✅ **Independent deployments**: Each org can have custom frontend
|
|
1235
|
+
✅ **Cost efficiency**: Shared backend reduces operational costs
|
|
1236
|
+
|
|
1237
|
+
### 4. Flexibility
|
|
1238
|
+
|
|
1239
|
+
✅ **Per-org billing**: Different plans, pricing, quotas
|
|
1240
|
+
✅ **Role-based access**: Granular permissions within each org
|
|
1241
|
+
✅ **Multi-org users**: Users can belong to multiple organizations
|
|
1242
|
+
|
|
1243
|
+
## Migration from Single-Tenant
|
|
1244
|
+
|
|
1245
|
+
### Phase 1: Add Organization Entity
|
|
1246
|
+
|
|
1247
|
+
1. Create `organization` entity type in schema
|
|
1248
|
+
2. Create default organization for existing users
|
|
1249
|
+
3. Add `member_of` connections for all users
|
|
1250
|
+
|
|
1251
|
+
### Phase 2: Add Organization Ownership
|
|
1252
|
+
|
|
1253
|
+
1. Add `owns` connections: organization → resources
|
|
1254
|
+
2. Update all resource creation to set ownership
|
|
1255
|
+
3. Migrate existing resources to default org
|
|
1256
|
+
|
|
1257
|
+
### Phase 3: Add Organization Filtering
|
|
1258
|
+
|
|
1259
|
+
1. Update all queries to filter by `orgId`
|
|
1260
|
+
2. Add organization middleware to Hono
|
|
1261
|
+
3. Add organization context to frontend
|
|
1262
|
+
|
|
1263
|
+
### Phase 4: Enable Multi-Tenancy
|
|
1264
|
+
|
|
1265
|
+
1. Add subdomain routing
|
|
1266
|
+
2. Enable custom branding per org
|
|
1267
|
+
3. Add billing/quota system
|
|
1268
|
+
4. Launch multi-org support
|
|
1269
|
+
|
|
1270
|
+
## Best Practices
|
|
1271
|
+
|
|
1272
|
+
### 1. Always Filter by orgId
|
|
1273
|
+
|
|
1274
|
+
```typescript
|
|
1275
|
+
// ❌ Bad: No org filtering
|
|
1276
|
+
const tokens = await ctx.db.query('entities').filter((q) => q.eq(q.field('type'), 'token')).collect();
|
|
1277
|
+
|
|
1278
|
+
// ✅ Good: Filtered by org
|
|
1279
|
+
const orgTokens = await ctx.db
|
|
1280
|
+
.query('connections')
|
|
1281
|
+
.withIndex('from_type', (q) =>
|
|
1282
|
+
q.eq('fromEntityId', orgId).eq('relationshipType', 'owns')
|
|
1283
|
+
)
|
|
1284
|
+
.collect();
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1287
|
+
### 2. Check Permissions
|
|
1288
|
+
|
|
1289
|
+
```typescript
|
|
1290
|
+
// ❌ Bad: No permission check
|
|
1291
|
+
app.delete('/api/agents/:id', async (c) => {
|
|
1292
|
+
await convex.deleteAgent(c.req.param('id'));
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
// ✅ Good: Permission check
|
|
1296
|
+
app.delete('/api/agents/:id', requirePermission('delete_agents'), async (c) => {
|
|
1297
|
+
await convex.deleteAgent(c.req.param('id'));
|
|
1298
|
+
});
|
|
1299
|
+
```
|
|
1300
|
+
|
|
1301
|
+
### 3. Respect Quotas
|
|
1302
|
+
|
|
1303
|
+
```typescript
|
|
1304
|
+
// ✅ Always check quotas before creating resources
|
|
1305
|
+
const quota = await orgService.checkQuota({ orgId, resource: 'agents' });
|
|
1306
|
+
if (!quota.allowed) {
|
|
1307
|
+
throw new QuotaExceededError('agents', quota.limit);
|
|
1308
|
+
}
|
|
1309
|
+
```
|
|
1310
|
+
|
|
1311
|
+
### 4. Log Organization Events
|
|
1312
|
+
|
|
1313
|
+
```typescript
|
|
1314
|
+
// ✅ All significant actions should be logged with orgId
|
|
1315
|
+
await ctx.db.insert('events', {
|
|
1316
|
+
entityId: agentId,
|
|
1317
|
+
eventType: 'agent_created',
|
|
1318
|
+
timestamp: Date.now(),
|
|
1319
|
+
actorType: 'user',
|
|
1320
|
+
actorId: userId,
|
|
1321
|
+
metadata: {
|
|
1322
|
+
orgId, // Include organization context
|
|
1323
|
+
agentType: 'ai_clone',
|
|
1324
|
+
},
|
|
1325
|
+
});
|
|
1326
|
+
```
|
|
1327
|
+
|
|
1328
|
+
## Next Steps
|
|
1329
|
+
|
|
1330
|
+
1. Add `organization` entity type to schema
|
|
1331
|
+
2. Create OrganizationService (Effect.ts)
|
|
1332
|
+
3. Add organization middleware to Hono
|
|
1333
|
+
4. Implement subdomain routing
|
|
1334
|
+
5. Add organization context to frontend
|
|
1335
|
+
6. Implement feature gating
|
|
1336
|
+
7. Add billing/subscription system
|
|
1337
|
+
8. Enable custom domains
|
|
1338
|
+
9. Migrate existing users to default org
|
|
1339
|
+
10. Launch multi-tenant support
|
|
1340
|
+
|
|
1341
|
+
**Result:** A fully multi-tenant platform where organizations have complete data isolation, custom branding, and flexible billing, all powered by the 6-dimension ontology.
|