blockmine 1.20.0 → 1.22.0
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/.claude/agents/README.md +469 -0
- package/.claude/agents/auth-route-debugger.md +118 -0
- package/.claude/agents/auth-route-tester.md +93 -0
- package/.claude/agents/auto-error-resolver.md +97 -0
- package/.claude/agents/build-optimizer.md +236 -0
- package/.claude/agents/code-architecture-reviewer.md +83 -0
- package/.claude/agents/code-refactor-master.md +94 -0
- package/.claude/agents/cost-optimizer.md +134 -0
- package/.claude/agents/deployment-orchestrator.md +113 -0
- package/.claude/agents/documentation-architect.md +82 -0
- package/.claude/agents/frontend-error-fixer.md +77 -0
- package/.claude/agents/iac-code-generator.md +71 -0
- package/.claude/agents/incident-responder.md +346 -0
- package/.claude/agents/infrastructure-architect.md +31 -0
- package/.claude/agents/kubernetes-specialist.md +56 -0
- package/.claude/agents/migration-planner.md +181 -0
- package/.claude/agents/network-architect.md +196 -0
- package/.claude/agents/plan-reviewer.md +52 -0
- package/.claude/agents/refactor-planner.md +63 -0
- package/.claude/agents/security-scanner.md +102 -0
- package/.claude/agents/web-research-specialist.md +78 -0
- package/.claude/commands/cost-analysis.md +315 -0
- package/.claude/commands/dev-docs-update.md +55 -0
- package/.claude/commands/dev-docs.md +51 -0
- package/.claude/commands/incident-debug.md +247 -0
- package/.claude/commands/infra-plan.md +81 -0
- package/.claude/commands/migration-plan.md +478 -0
- package/.claude/commands/route-research-for-testing.md +37 -0
- package/.claude/commands/security-review.md +66 -0
- package/.claude/hooks/CONFIG.md +448 -0
- package/.claude/hooks/README.md +163 -0
- package/.claude/hooks/SKILL_ACTIVATION_COMPLETE.md +226 -0
- package/.claude/hooks/WINDOWS_HOOKS_README.md +151 -0
- package/.claude/hooks/add-skill-activation-banners.ts +132 -0
- package/.claude/hooks/comprehensive-skill-test.ts +1315 -0
- package/.claude/hooks/error-handling-reminder.sh +12 -0
- package/.claude/hooks/error-handling-reminder.ts +222 -0
- package/.claude/hooks/k8s-manifest-validator.sh +56 -0
- package/.claude/hooks/package-lock.json +556 -0
- package/.claude/hooks/package.json +16 -0
- package/.claude/hooks/post-tool-use-tracker.ps1 +174 -0
- package/.claude/hooks/post-tool-use-tracker.sh +183 -0
- package/.claude/hooks/security-policy-check.sh +247 -0
- package/.claude/hooks/skill-activation-prompt.ps1 +10 -0
- package/.claude/hooks/skill-activation-prompt.sh +10 -0
- package/.claude/hooks/skill-activation-prompt.ts +141 -0
- package/.claude/hooks/stop-build-check-enhanced.sh +130 -0
- package/.claude/hooks/terraform-validator.sh +53 -0
- package/.claude/hooks/test-input.json +7 -0
- package/.claude/hooks/test-skill-activation.ts +427 -0
- package/.claude/hooks/trigger-build-resolver.sh +79 -0
- package/.claude/hooks/tsc-check.sh +173 -0
- package/.claude/hooks/tsconfig.json +19 -0
- package/.claude/settings.json +55 -0
- package/.claude/settings.local.json +28 -3
- package/.claude/skills/README.md +507 -0
- package/.claude/skills/api-engineering/SKILL.md +63 -0
- package/.claude/skills/api-engineering/resources/api-versioning.md +88 -0
- package/.claude/skills/api-engineering/resources/graphql-patterns.md +106 -0
- package/.claude/skills/api-engineering/resources/rate-limiting.md +118 -0
- package/.claude/skills/api-engineering/resources/rest-api-design.md +105 -0
- package/.claude/skills/backend-dev-guidelines/SKILL.md +306 -0
- package/.claude/skills/backend-dev-guidelines/resources/architecture-overview.md +451 -0
- package/.claude/skills/backend-dev-guidelines/resources/async-and-errors.md +307 -0
- package/.claude/skills/backend-dev-guidelines/resources/complete-examples.md +638 -0
- package/.claude/skills/backend-dev-guidelines/resources/configuration.md +275 -0
- package/.claude/skills/backend-dev-guidelines/resources/database-patterns.md +224 -0
- package/.claude/skills/backend-dev-guidelines/resources/middleware-guide.md +213 -0
- package/.claude/skills/backend-dev-guidelines/resources/routing-and-controllers.md +756 -0
- package/.claude/skills/backend-dev-guidelines/resources/sentry-and-monitoring.md +336 -0
- package/.claude/skills/backend-dev-guidelines/resources/services-and-repositories.md +789 -0
- package/.claude/skills/backend-dev-guidelines/resources/testing-guide.md +235 -0
- package/.claude/skills/backend-dev-guidelines/resources/validation-patterns.md +754 -0
- package/.claude/skills/budget-and-cost-management/SKILL.md +850 -0
- package/.claude/skills/build-engineering/SKILL.md +431 -0
- package/.claude/skills/build-engineering/resources/artifact-repositories.md +72 -0
- package/.claude/skills/build-engineering/resources/build-caching.md +96 -0
- package/.claude/skills/build-engineering/resources/build-pipelines.md +105 -0
- package/.claude/skills/build-engineering/resources/build-security.md +95 -0
- package/.claude/skills/build-engineering/resources/build-systems.md +389 -0
- package/.claude/skills/build-engineering/resources/compilation-optimization.md +201 -0
- package/.claude/skills/build-engineering/resources/dependency-management.md +73 -0
- package/.claude/skills/build-engineering/resources/monorepo-builds.md +110 -0
- package/.claude/skills/build-engineering/resources/performance-optimization.md +113 -0
- package/.claude/skills/build-engineering/resources/reproducible-builds.md +82 -0
- package/.claude/skills/cloud-engineering/SKILL.md +675 -0
- package/.claude/skills/cloud-engineering/resources/aws-patterns.md +742 -0
- package/.claude/skills/cloud-engineering/resources/azure-patterns.md +714 -0
- package/.claude/skills/cloud-engineering/resources/cleared-cloud-environments.md +987 -0
- package/.claude/skills/cloud-engineering/resources/cloud-cost-optimization.md +757 -0
- package/.claude/skills/cloud-engineering/resources/cloud-networking.md +1058 -0
- package/.claude/skills/cloud-engineering/resources/cloud-security-tools.md +1530 -0
- package/.claude/skills/cloud-engineering/resources/cloud-security.md +990 -0
- package/.claude/skills/cloud-engineering/resources/gcp-patterns.md +758 -0
- package/.claude/skills/cloud-engineering/resources/migration-strategies.md +820 -0
- package/.claude/skills/cloud-engineering/resources/multi-cloud-strategies.md +670 -0
- package/.claude/skills/cloud-engineering/resources/oci-patterns.md +1198 -0
- package/.claude/skills/cloud-engineering/resources/serverless-patterns.md +795 -0
- package/.claude/skills/cloud-engineering/resources/well-architected-frameworks.md +966 -0
- package/.claude/skills/cybersecurity/SKILL.md +409 -0
- package/.claude/skills/cybersecurity/resources/security-architecture.md +266 -0
- package/.claude/skills/database-engineering/SKILL.md +61 -0
- package/.claude/skills/database-engineering/resources/backup-and-recovery.md +72 -0
- package/.claude/skills/database-engineering/resources/database-replication.md +63 -0
- package/.claude/skills/database-engineering/resources/postgresql-fundamentals.md +70 -0
- package/.claude/skills/database-engineering/resources/query-optimization.md +68 -0
- package/.claude/skills/devsecops/SKILL.md +374 -0
- package/.claude/skills/devsecops/resources/ci-cd-security.md +204 -0
- package/.claude/skills/devsecops/resources/compliance-automation.md +530 -0
- package/.claude/skills/devsecops/resources/compliance-frameworks.md +2322 -0
- package/.claude/skills/devsecops/resources/container-security.md +915 -0
- package/.claude/skills/devsecops/resources/cspm-integration.md +1440 -0
- package/.claude/skills/devsecops/resources/policy-enforcement.md +619 -0
- package/.claude/skills/devsecops/resources/secrets-management.md +755 -0
- package/.claude/skills/devsecops/resources/security-monitoring.md +146 -0
- package/.claude/skills/devsecops/resources/security-scanning.md +887 -0
- package/.claude/skills/devsecops/resources/security-testing.md +203 -0
- package/.claude/skills/devsecops/resources/supply-chain-security.md +518 -0
- package/.claude/skills/devsecops/resources/vulnerability-management.md +481 -0
- package/.claude/skills/devsecops/resources/zero-trust-architecture.md +177 -0
- package/.claude/skills/documentation-as-code/SKILL.md +323 -0
- package/.claude/skills/documentation-as-code/resources/api-documentation.md +90 -0
- package/.claude/skills/documentation-as-code/resources/changelog-management.md +79 -0
- package/.claude/skills/documentation-as-code/resources/diagram-generation.md +44 -0
- package/.claude/skills/documentation-as-code/resources/docs-as-code-workflow.md +99 -0
- package/.claude/skills/documentation-as-code/resources/documentation-automation.md +68 -0
- package/.claude/skills/documentation-as-code/resources/documentation-sites.md +79 -0
- package/.claude/skills/documentation-as-code/resources/markdown-best-practices.md +162 -0
- package/.claude/skills/documentation-as-code/resources/openapi-specification.md +77 -0
- package/.claude/skills/documentation-as-code/resources/readme-engineering.md +60 -0
- package/.claude/skills/documentation-as-code/resources/technical-writing-guide.md +202 -0
- package/.claude/skills/engineering-management/SKILL.md +356 -0
- package/.claude/skills/engineering-management/resources/career-ladders.md +609 -0
- package/.claude/skills/engineering-management/resources/hiring-and-assessment.md +555 -0
- package/.claude/skills/engineering-management/resources/one-on-one-guides.md +609 -0
- package/.claude/skills/engineering-management/resources/resource-planning.md +557 -0
- package/.claude/skills/engineering-management/resources/team-organization-patterns.md +491 -0
- package/.claude/skills/engineering-management/resources/technical-interviews.md +474 -0
- package/.claude/skills/engineering-operations-management/SKILL.md +817 -0
- package/.claude/skills/error-tracking/SKILL.md +379 -0
- package/.claude/skills/frontend-dev-guidelines/SKILL.md +403 -0
- package/.claude/skills/frontend-dev-guidelines/resources/common-patterns.md +331 -0
- package/.claude/skills/frontend-dev-guidelines/resources/complete-examples.md +872 -0
- package/.claude/skills/frontend-dev-guidelines/resources/component-patterns.md +502 -0
- package/.claude/skills/frontend-dev-guidelines/resources/data-fetching.md +767 -0
- package/.claude/skills/frontend-dev-guidelines/resources/file-organization.md +502 -0
- package/.claude/skills/frontend-dev-guidelines/resources/loading-and-error-states.md +501 -0
- package/.claude/skills/frontend-dev-guidelines/resources/performance.md +406 -0
- package/.claude/skills/frontend-dev-guidelines/resources/routing-guide.md +364 -0
- package/.claude/skills/frontend-dev-guidelines/resources/styling-guide.md +428 -0
- package/.claude/skills/frontend-dev-guidelines/resources/typescript-standards.md +418 -0
- package/.claude/skills/general-it-engineering/SKILL.md +393 -0
- package/.claude/skills/general-it-engineering/resources/asset-management.md +712 -0
- package/.claude/skills/general-it-engineering/resources/automation-orchestration.md +817 -0
- package/.claude/skills/general-it-engineering/resources/business-continuity.md +786 -0
- package/.claude/skills/general-it-engineering/resources/change-management.md +715 -0
- package/.claude/skills/general-it-engineering/resources/enterprise-monitoring.md +729 -0
- package/.claude/skills/general-it-engineering/resources/help-desk-operations.md +738 -0
- package/.claude/skills/general-it-engineering/resources/incident-service-management.md +834 -0
- package/.claude/skills/general-it-engineering/resources/it-governance.md +753 -0
- package/.claude/skills/general-it-engineering/resources/itil-framework.md +503 -0
- package/.claude/skills/general-it-engineering/resources/service-management.md +669 -0
- package/.claude/skills/infrastructure-architecture/SKILL.md +328 -0
- package/.claude/skills/infrastructure-architecture/resources/architecture-decision-records.md +505 -0
- package/.claude/skills/infrastructure-architecture/resources/architecture-patterns.md +528 -0
- package/.claude/skills/infrastructure-architecture/resources/capacity-planning.md +453 -0
- package/.claude/skills/infrastructure-architecture/resources/cleared-environment-architecture.md +773 -0
- package/.claude/skills/infrastructure-architecture/resources/cost-architecture.md +499 -0
- package/.claude/skills/infrastructure-architecture/resources/data-architecture.md +501 -0
- package/.claude/skills/infrastructure-architecture/resources/disaster-recovery.md +535 -0
- package/.claude/skills/infrastructure-architecture/resources/migration-architecture.md +512 -0
- package/.claude/skills/infrastructure-architecture/resources/multi-region-design.md +608 -0
- package/.claude/skills/infrastructure-architecture/resources/reference-architectures.md +562 -0
- package/.claude/skills/infrastructure-architecture/resources/security-architecture.md +538 -0
- package/.claude/skills/infrastructure-architecture/resources/system-design-principles.md +489 -0
- package/.claude/skills/infrastructure-architecture/resources/workload-classification.md +1000 -0
- package/.claude/skills/infrastructure-strategy/SKILL.md +924 -0
- package/.claude/skills/network-engineering/SKILL.md +385 -0
- package/.claude/skills/network-engineering/resources/dns-management.md +738 -0
- package/.claude/skills/network-engineering/resources/load-balancing.md +820 -0
- package/.claude/skills/network-engineering/resources/network-architecture.md +546 -0
- package/.claude/skills/network-engineering/resources/network-security.md +921 -0
- package/.claude/skills/network-engineering/resources/network-troubleshooting.md +749 -0
- package/.claude/skills/network-engineering/resources/routing-switching.md +373 -0
- package/.claude/skills/network-engineering/resources/sdn-networking.md +695 -0
- package/.claude/skills/network-engineering/resources/service-mesh-networking.md +777 -0
- package/.claude/skills/network-engineering/resources/tcp-ip-protocols.md +444 -0
- package/.claude/skills/network-engineering/resources/vpn-connectivity.md +672 -0
- package/.claude/skills/observability-engineering/SKILL.md +101 -0
- package/.claude/skills/observability-engineering/resources/apm-tools.md +97 -0
- package/.claude/skills/observability-engineering/resources/correlation-strategies.md +87 -0
- package/.claude/skills/observability-engineering/resources/distributed-tracing.md +98 -0
- package/.claude/skills/observability-engineering/resources/logs-aggregation.md +118 -0
- package/.claude/skills/observability-engineering/resources/observability-cost-optimization.md +141 -0
- package/.claude/skills/observability-engineering/resources/opentelemetry.md +110 -0
- package/.claude/skills/platform-engineering/SKILL.md +555 -0
- package/.claude/skills/platform-engineering/resources/architecture-overview.md +600 -0
- package/.claude/skills/platform-engineering/resources/container-orchestration.md +916 -0
- package/.claude/skills/platform-engineering/resources/cost-optimization.md +634 -0
- package/.claude/skills/platform-engineering/resources/developer-platforms.md +670 -0
- package/.claude/skills/platform-engineering/resources/gitops-automation.md +650 -0
- package/.claude/skills/platform-engineering/resources/infrastructure-as-code.md +778 -0
- package/.claude/skills/platform-engineering/resources/infrastructure-standards.md +708 -0
- package/.claude/skills/platform-engineering/resources/multi-tenancy.md +602 -0
- package/.claude/skills/platform-engineering/resources/platform-security.md +711 -0
- package/.claude/skills/platform-engineering/resources/resource-management.md +592 -0
- package/.claude/skills/platform-engineering/resources/service-mesh.md +628 -0
- package/.claude/skills/release-engineering/SKILL.md +393 -0
- package/.claude/skills/release-engineering/resources/artifact-management.md +108 -0
- package/.claude/skills/release-engineering/resources/build-optimization.md +84 -0
- package/.claude/skills/release-engineering/resources/ci-cd-pipelines.md +411 -0
- package/.claude/skills/release-engineering/resources/deployment-strategies.md +197 -0
- package/.claude/skills/release-engineering/resources/pipeline-security.md +62 -0
- package/.claude/skills/release-engineering/resources/progressive-delivery.md +83 -0
- package/.claude/skills/release-engineering/resources/release-automation.md +68 -0
- package/.claude/skills/release-engineering/resources/release-orchestration.md +77 -0
- package/.claude/skills/release-engineering/resources/rollback-strategies.md +66 -0
- package/.claude/skills/release-engineering/resources/versioning-strategies.md +59 -0
- package/.claude/skills/route-tester/SKILL.md +392 -0
- package/.claude/skills/skill-developer/ADVANCED.md +197 -0
- package/.claude/skills/skill-developer/HOOK_MECHANISMS.md +306 -0
- package/.claude/skills/skill-developer/PATTERNS_LIBRARY.md +152 -0
- package/.claude/skills/skill-developer/SKILL.md +430 -0
- package/.claude/skills/skill-developer/SKILL_RULES_REFERENCE.md +315 -0
- package/.claude/skills/skill-developer/TRIGGER_TYPES.md +305 -0
- package/.claude/skills/skill-developer/TROUBLESHOOTING.md +514 -0
- package/.claude/skills/skill-rules.json +2940 -0
- package/.claude/skills/sre/SKILL.md +464 -0
- package/.claude/skills/sre/resources/alerting-best-practices.md +282 -0
- package/.claude/skills/sre/resources/capacity-planning.md +226 -0
- package/.claude/skills/sre/resources/chaos-engineering.md +193 -0
- package/.claude/skills/sre/resources/disaster-recovery.md +232 -0
- package/.claude/skills/sre/resources/incident-management.md +436 -0
- package/.claude/skills/sre/resources/observability-stack.md +240 -0
- package/.claude/skills/sre/resources/on-call-runbooks.md +167 -0
- package/.claude/skills/sre/resources/performance-optimization.md +108 -0
- package/.claude/skills/sre/resources/reliability-patterns.md +183 -0
- package/.claude/skills/sre/resources/slo-sli-sla.md +464 -0
- package/.claude/skills/sre/resources/toil-reduction.md +145 -0
- package/.claude/skills/systems-engineering/SKILL.md +648 -0
- package/.claude/skills/systems-engineering/resources/automation-patterns.md +771 -0
- package/.claude/skills/systems-engineering/resources/configuration-management.md +998 -0
- package/.claude/skills/systems-engineering/resources/linux-administration.md +672 -0
- package/.claude/skills/systems-engineering/resources/networking-fundamentals.md +982 -0
- package/.claude/skills/systems-engineering/resources/performance-tuning.md +871 -0
- package/.claude/skills/systems-engineering/resources/powershell-scripting.md +482 -0
- package/.claude/skills/systems-engineering/resources/security-hardening.md +739 -0
- package/.claude/skills/systems-engineering/resources/shell-scripting.md +915 -0
- package/.claude/skills/systems-engineering/resources/storage-management.md +628 -0
- package/.claude/skills/systems-engineering/resources/system-monitoring.md +787 -0
- package/.claude/skills/systems-engineering/resources/troubleshooting-guide.md +753 -0
- package/.claude/skills/systems-engineering/resources/windows-administration.md +738 -0
- package/.claude/skills/technical-leadership/SKILL.md +728 -0
- package/CHANGELOG.md +90 -39
- package/README.md +94 -0
- package/backend/docs/SECRETS_DOCUMENTATION.md +327 -0
- package/backend/jest.config.js +59 -0
- package/backend/package-lock.json +6129 -0
- package/backend/package.json +16 -4
- package/backend/prisma/migrations/20251026104609_add_websocket_api/migration.sql +33 -0
- package/backend/prisma/schema.prisma +33 -0
- package/backend/src/__tests__/core/DependencyService.test.js +336 -0
- package/backend/src/__tests__/core/UserService.test.js +875 -0
- package/backend/src/__tests__/repositories/BaseRepository.test.js +146 -0
- package/backend/src/__tests__/repositories/BotRepository.test.js +118 -0
- package/backend/src/__tests__/repositories/CommandRepository.test.js +132 -0
- package/backend/src/__tests__/repositories/EventGraphRepository.test.js +93 -0
- package/backend/src/__tests__/repositories/GroupRepository.test.js +155 -0
- package/backend/src/__tests__/repositories/PermissionRepository.test.js +130 -0
- package/backend/src/__tests__/repositories/PluginRepository.test.js +107 -0
- package/backend/src/__tests__/repositories/ServerRepository.test.js +80 -0
- package/backend/src/__tests__/repositories/UserRepository.test.js +128 -0
- package/backend/src/__tests__/secretsFilter.test.js +425 -0
- package/backend/src/__tests__/services/BotLifecycleService.test.js +411 -0
- package/backend/src/__tests__/services/BotProcessManager.test.js +285 -0
- package/backend/src/__tests__/services/CacheManager.test.js +125 -0
- package/backend/src/__tests__/services/CommandExecutionService.test.js +460 -0
- package/backend/src/__tests__/services/ResourceMonitorService.test.js +207 -0
- package/backend/src/__tests__/services/TelemetryService.test.js +291 -0
- package/backend/src/__tests__/setup.js +25 -0
- package/backend/src/api/routes/apiKeys.js +181 -0
- package/backend/src/api/routes/bots.js +49 -7
- package/backend/src/api/routes/plugins.js +2 -1
- package/backend/src/api/routes/system.js +174 -0
- package/backend/src/container.js +82 -0
- package/backend/src/core/BotManager.js +142 -871
- package/backend/src/core/BotManager.old.js +1093 -0
- package/backend/src/core/BotProcess.js +1092 -850
- package/backend/src/core/BreakLoopSignal.js +8 -0
- package/backend/src/core/EventGraphManager.js +280 -193
- package/backend/src/core/GraphExecutionEngine.js +321 -928
- package/backend/src/core/MessageQueue.js +27 -6
- package/backend/src/core/NodeRegistry.js +37 -991
- package/backend/src/core/PluginManager.js +62 -12
- package/backend/src/core/PrismaService.js +32 -0
- package/backend/src/core/UserService.js +3 -3
- package/backend/src/core/__tests__/PrismaService.test.js +24 -0
- package/backend/src/core/commands/README.md +305 -0
- package/backend/src/core/commands/dev.js +13 -7
- package/backend/src/core/commands/ping.js +10 -4
- package/backend/src/core/commands/whois.js +63 -0
- package/backend/src/core/config/validation.js +27 -0
- package/backend/src/core/constants/graphTypes.js +21 -0
- package/backend/src/core/node-registries/actions.js +132 -0
- package/backend/src/core/node-registries/arrays.js +137 -0
- package/backend/src/core/node-registries/bot.js +23 -0
- package/backend/src/core/node-registries/data.js +290 -0
- package/backend/src/core/node-registries/debug.js +26 -0
- package/backend/src/core/node-registries/events.js +187 -0
- package/backend/src/core/node-registries/flow.js +139 -0
- package/backend/src/core/node-registries/logic.js +45 -0
- package/backend/src/core/node-registries/math.js +42 -0
- package/backend/src/core/node-registries/objects.js +98 -0
- package/backend/src/core/node-registries/strings.js +153 -0
- package/backend/src/core/node-registries/time.js +113 -0
- package/backend/src/core/node-registries/users.js +79 -0
- package/backend/src/core/nodes/actions/bot_look_at.js +36 -0
- package/backend/src/core/nodes/actions/bot_set_variable.js +32 -0
- package/backend/src/core/nodes/actions/http_request.js +98 -0
- package/backend/src/core/nodes/actions/send_log.js +28 -0
- package/backend/src/core/nodes/actions/send_message.js +32 -0
- package/backend/src/core/nodes/actions/send_websocket_response.js +33 -0
- package/backend/src/core/nodes/arrays/add_element.js +23 -0
- package/backend/src/core/nodes/arrays/contains.js +40 -0
- package/backend/src/core/nodes/arrays/find_index.js +23 -0
- package/backend/src/core/nodes/arrays/get_by_index.js +23 -0
- package/backend/src/core/nodes/arrays/get_next.js +35 -0
- package/backend/src/core/nodes/arrays/get_random_element.js +32 -0
- package/backend/src/core/nodes/arrays/remove_by_index.js +30 -0
- package/backend/src/core/nodes/bot/get_position.js +20 -0
- package/backend/src/core/nodes/data/array_literal.js +31 -0
- package/backend/src/core/nodes/data/boolean_literal.js +21 -0
- package/backend/src/core/nodes/data/cast.js +42 -0
- package/backend/src/core/nodes/data/datetime_literal.js +27 -0
- package/backend/src/core/nodes/data/entity_info.js +69 -0
- package/backend/src/core/nodes/data/get_argument.js +23 -0
- package/backend/src/core/nodes/data/get_bot_look.js +14 -0
- package/backend/src/core/nodes/data/get_entity_field.js +18 -0
- package/backend/src/core/nodes/data/get_nearby_entities.js +32 -0
- package/backend/src/core/nodes/data/get_nearby_players.js +64 -0
- package/backend/src/core/nodes/data/get_server_players.js +18 -0
- package/backend/src/core/nodes/data/get_user_field.js +40 -0
- package/backend/src/core/nodes/data/get_variable.js +23 -0
- package/backend/src/core/nodes/data/length.js +25 -0
- package/backend/src/core/nodes/data/make_object.js +31 -0
- package/backend/src/core/nodes/data/number_literal.js +21 -0
- package/backend/src/core/nodes/data/string_literal.js +34 -0
- package/backend/src/core/nodes/data/type_check.js +53 -0
- package/backend/src/core/nodes/debug/log.js +16 -0
- package/backend/src/core/nodes/flow/branch.js +15 -0
- package/backend/src/core/nodes/flow/break.js +14 -0
- package/backend/src/core/nodes/flow/delay.js +43 -0
- package/backend/src/core/nodes/flow/for_each.js +39 -0
- package/backend/src/core/nodes/flow/sequence.js +16 -0
- package/backend/src/core/nodes/flow/switch.js +47 -0
- package/backend/src/core/nodes/flow/while.js +64 -0
- package/backend/src/core/nodes/logic/__tests__/compare.test.js +83 -0
- package/backend/src/core/nodes/logic/compare.js +33 -0
- package/backend/src/core/nodes/logic/operation.js +35 -0
- package/backend/src/core/nodes/math/__tests__/operation.test.js +65 -0
- package/backend/src/core/nodes/math/operation.js +31 -0
- package/backend/src/core/nodes/math/random_number.js +43 -0
- package/backend/src/core/nodes/objects/create.js +40 -0
- package/backend/src/core/nodes/objects/delete.js +26 -0
- package/backend/src/core/nodes/objects/get.js +23 -0
- package/backend/src/core/nodes/objects/has_key.js +30 -0
- package/backend/src/core/nodes/objects/set.js +27 -0
- package/backend/src/core/nodes/strings/__tests__/concat.test.js +89 -0
- package/backend/src/core/nodes/strings/concat.js +27 -0
- package/backend/src/core/nodes/strings/contains.js +41 -0
- package/backend/src/core/nodes/strings/ends_with.js +43 -0
- package/backend/src/core/nodes/strings/equals.js +36 -0
- package/backend/src/core/nodes/strings/length.js +36 -0
- package/backend/src/core/nodes/strings/matches.js +39 -0
- package/backend/src/core/nodes/strings/split.js +37 -0
- package/backend/src/core/nodes/strings/starts_with.js +43 -0
- package/backend/src/core/nodes/time/__tests__/now.test.js +24 -0
- package/backend/src/core/nodes/time/add.js +33 -0
- package/backend/src/core/nodes/time/compare.js +35 -0
- package/backend/src/core/nodes/time/diff.js +29 -0
- package/backend/src/core/nodes/time/format.js +32 -0
- package/backend/src/core/nodes/time/now.js +18 -0
- package/backend/src/core/nodes/users/check_blacklist.js +37 -0
- package/backend/src/core/nodes/users/get_groups.js +36 -0
- package/backend/src/core/nodes/users/get_permissions.js +36 -0
- package/backend/src/core/nodes/users/set_blacklist.js +37 -0
- package/backend/src/core/services/BotLifecycleService.js +596 -0
- package/backend/src/core/services/BotProcessManager.js +163 -0
- package/backend/src/core/services/CacheManager.js +111 -0
- package/backend/src/core/services/CommandExecutionService.js +351 -0
- package/backend/src/core/services/ResourceMonitorService.js +90 -0
- package/backend/src/core/services/TelemetryService.js +124 -0
- package/backend/src/core/services/ValidationService.js +132 -0
- package/backend/src/core/services/__tests__/ValidationService.test.js +148 -0
- package/backend/src/core/services.js +20 -5
- package/backend/src/core/system/CommandContext.js +84 -0
- package/backend/src/core/system/Transport.js +78 -0
- package/backend/src/core/utils/__tests__/jsonParser.test.js +44 -0
- package/backend/src/core/utils/jsonParser.js +18 -0
- package/backend/src/core/utils/secretsFilter.js +262 -0
- package/backend/src/core/utils/variableParser.js +89 -0
- package/backend/src/core/validation/__tests__/nodeSchemas.test.js +175 -0
- package/backend/src/core/validation/nodeSchemas.js +112 -0
- package/backend/src/lib/prisma.js +2 -4
- package/backend/src/real-time/botApi/handlers/commandHandlers.js +28 -0
- package/backend/src/real-time/botApi/handlers/graphHandlers.js +99 -0
- package/backend/src/real-time/botApi/handlers/graphWebSocketHandlers.js +147 -0
- package/backend/src/real-time/botApi/handlers/index.js +43 -0
- package/backend/src/real-time/botApi/handlers/messageHandlers.js +66 -0
- package/backend/src/real-time/botApi/handlers/statusHandlers.js +17 -0
- package/backend/src/real-time/botApi/handlers/userHandlers.js +141 -0
- package/backend/src/real-time/botApi/index.js +40 -0
- package/backend/src/real-time/botApi/middleware.js +79 -0
- package/backend/src/real-time/botApi/utils.js +54 -0
- package/backend/src/real-time/socketHandler.js +6 -2
- package/backend/src/repositories/BaseRepository.js +43 -0
- package/backend/src/repositories/BotRepository.js +42 -0
- package/backend/src/repositories/CommandRepository.js +53 -0
- package/backend/src/repositories/EventGraphRepository.js +40 -0
- package/backend/src/repositories/GroupRepository.js +69 -0
- package/backend/src/repositories/PermissionRepository.js +48 -0
- package/backend/src/repositories/PluginRepository.js +42 -0
- package/backend/src/repositories/ServerRepository.js +27 -0
- package/backend/src/repositories/UserRepository.js +48 -0
- package/backend/src/server.js +3 -0
- package/backend/src/test-refactor.js +85 -0
- package/frontend/dist/assets/index-CfTo92bP.css +1 -0
- package/frontend/dist/assets/index-CiFD5X9Z.js +8344 -0
- package/frontend/dist/index.html +2 -2
- package/frontend/package.json +1 -5
- package/package.json +2 -1
- package/frontend/dist/assets/index-BFd7YoAj.css +0 -1
- package/frontend/dist/assets/index-CMMutadc.js +0 -8352
- package/nul +0 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
# Data Architecture
|
|
2
|
+
|
|
3
|
+
Guide to data modeling, storage selection, caching strategies, and data flow design.
|
|
4
|
+
|
|
5
|
+
## Data Flow Patterns
|
|
6
|
+
|
|
7
|
+
### Request-Response (Synchronous)
|
|
8
|
+
```
|
|
9
|
+
Client → API → Database → API → Client
|
|
10
|
+
Fast, simple, but coupled
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Event-Driven (Asynchronous)
|
|
14
|
+
```
|
|
15
|
+
Service A → Event Bus → Service B
|
|
16
|
+
↘→ Service C
|
|
17
|
+
↘→ Service D
|
|
18
|
+
|
|
19
|
+
Decoupled, scalable, eventual consistency
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Change Data Capture (CDC)
|
|
23
|
+
```
|
|
24
|
+
Database → CDC Tool (Debezium) → Event Stream → Consumers
|
|
25
|
+
Real-time data replication without application changes
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Storage Selection
|
|
29
|
+
|
|
30
|
+
### Relational Databases (PostgreSQL, MySQL)
|
|
31
|
+
|
|
32
|
+
**Use When:**
|
|
33
|
+
- Structured data with relationships
|
|
34
|
+
- ACID transactions required
|
|
35
|
+
- Complex queries (JOIN, aggregate)
|
|
36
|
+
- Data integrity critical
|
|
37
|
+
|
|
38
|
+
**Example:**
|
|
39
|
+
```sql
|
|
40
|
+
-- E-commerce: Users, Orders, Products
|
|
41
|
+
CREATE TABLE users (
|
|
42
|
+
id SERIAL PRIMARY KEY,
|
|
43
|
+
email VARCHAR UNIQUE NOT NULL
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
CREATE TABLE orders (
|
|
47
|
+
id SERIAL PRIMARY KEY,
|
|
48
|
+
user_id INT REFERENCES users(id),
|
|
49
|
+
total DECIMAL(10,2) NOT NULL,
|
|
50
|
+
created_at TIMESTAMP DEFAULT NOW()
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
CREATE TABLE order_items (
|
|
54
|
+
order_id INT REFERENCES orders(id),
|
|
55
|
+
product_id INT REFERENCES products(id),
|
|
56
|
+
quantity INT NOT NULL,
|
|
57
|
+
PRIMARY KEY (order_id, product_id)
|
|
58
|
+
);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Pros:** ✅ Strong consistency, ✅ Complex queries
|
|
62
|
+
**Cons:** ❌ Vertical scaling limits, ❌ Schema rigidity
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### Document Databases (MongoDB, DynamoDB)
|
|
67
|
+
|
|
68
|
+
**Use When:**
|
|
69
|
+
- Flexible/evolving schema
|
|
70
|
+
- Nested/hierarchical data
|
|
71
|
+
- High write throughput
|
|
72
|
+
- Simple queries (by ID, single table)
|
|
73
|
+
|
|
74
|
+
**Example:**
|
|
75
|
+
```javascript
|
|
76
|
+
// User profile with nested data
|
|
77
|
+
{
|
|
78
|
+
_id: "user-123",
|
|
79
|
+
email: "john@example.com",
|
|
80
|
+
profile: {
|
|
81
|
+
firstName: "John",
|
|
82
|
+
lastName: "Doe",
|
|
83
|
+
addresses: [
|
|
84
|
+
{ type: "home", city: "NYC", zip: "10001" },
|
|
85
|
+
{ type: "work", city: "SF", zip: "94102" }
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
preferences: {
|
|
89
|
+
newsletter: true,
|
|
90
|
+
theme: "dark"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Pros:** ✅ Flexible schema, ✅ Horizontal scaling
|
|
96
|
+
**Cons:** ❌ No JOIN support, ❌ Eventual consistency (some)
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### Key-Value Stores (Redis, Memcached)
|
|
101
|
+
|
|
102
|
+
**Use When:**
|
|
103
|
+
- Caching
|
|
104
|
+
- Session storage
|
|
105
|
+
- Rate limiting
|
|
106
|
+
- Real-time leaderboards
|
|
107
|
+
|
|
108
|
+
**Example:**
|
|
109
|
+
```typescript
|
|
110
|
+
// Session storage
|
|
111
|
+
await redis.set('session:abc123', JSON.stringify(session), 'EX', 3600);
|
|
112
|
+
|
|
113
|
+
// Rate limiting
|
|
114
|
+
const key = `rate-limit:${userId}`;
|
|
115
|
+
const count = await redis.incr(key);
|
|
116
|
+
if (count === 1) await redis.expire(key, 60); // 1 minute window
|
|
117
|
+
if (count > 100) throw new Error('Rate limit exceeded');
|
|
118
|
+
|
|
119
|
+
// Leaderboard
|
|
120
|
+
await redis.zadd('leaderboard', score, userId);
|
|
121
|
+
const top10 = await redis.zrevrange('leaderboard', 0, 9, 'WITHSCORES');
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Pros:** ✅ Ultra-fast (<1ms), ✅ Simple
|
|
125
|
+
**Cons:** ❌ Limited query capabilities, ❌ In-memory (volatile)
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### Object Storage (S3, GCS, Azure Blob)
|
|
130
|
+
|
|
131
|
+
**Use When:**
|
|
132
|
+
- Files, images, videos
|
|
133
|
+
- Backups, archives
|
|
134
|
+
- Data lakes
|
|
135
|
+
- Static website hosting
|
|
136
|
+
|
|
137
|
+
**Example:**
|
|
138
|
+
```typescript
|
|
139
|
+
// Upload file
|
|
140
|
+
await s3.putObject({
|
|
141
|
+
Bucket: 'user-uploads',
|
|
142
|
+
Key: `avatars/${userId}.jpg`,
|
|
143
|
+
Body: fileBuffer,
|
|
144
|
+
ContentType: 'image/jpeg'
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Serve via CloudFront CDN
|
|
148
|
+
const url = `https://cdn.example.com/avatars/${userId}.jpg`;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Pros:** ✅ Unlimited storage, ✅ Cheap, ✅ Durable (11 9s)
|
|
152
|
+
**Cons:** ❌ Not for structured data, ❌ Eventually consistent
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
### Time-Series Databases (InfluxDB, TimescaleDB)
|
|
157
|
+
|
|
158
|
+
**Use When:**
|
|
159
|
+
- Metrics, logs, events
|
|
160
|
+
- IoT sensor data
|
|
161
|
+
- Financial tick data
|
|
162
|
+
- Monitoring data
|
|
163
|
+
|
|
164
|
+
**Example:**
|
|
165
|
+
```sql
|
|
166
|
+
-- TimescaleDB (PostgreSQL extension)
|
|
167
|
+
CREATE TABLE metrics (
|
|
168
|
+
time TIMESTAMPTZ NOT NULL,
|
|
169
|
+
host TEXT NOT NULL,
|
|
170
|
+
cpu_usage DOUBLE PRECISION,
|
|
171
|
+
memory_usage DOUBLE PRECISION
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
SELECT create_hypertable('metrics', 'time');
|
|
175
|
+
|
|
176
|
+
-- Query: Average CPU by host, last 1 hour
|
|
177
|
+
SELECT host, AVG(cpu_usage)
|
|
178
|
+
FROM metrics
|
|
179
|
+
WHERE time > NOW() - INTERVAL '1 hour'
|
|
180
|
+
GROUP BY host;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**Pros:** ✅ Optimized for time-range queries, ✅ Compression
|
|
184
|
+
**Cons:** ❌ Specialized use case
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### Search Engines (Elasticsearch, Algolia)
|
|
189
|
+
|
|
190
|
+
**Use When:**
|
|
191
|
+
- Full-text search
|
|
192
|
+
- Fuzzy matching
|
|
193
|
+
- Faceted search
|
|
194
|
+
- Analytics/aggregations
|
|
195
|
+
|
|
196
|
+
**Example:**
|
|
197
|
+
```javascript
|
|
198
|
+
// Index document
|
|
199
|
+
await es.index({
|
|
200
|
+
index: 'products',
|
|
201
|
+
id: 'product-123',
|
|
202
|
+
body: {
|
|
203
|
+
name: 'Wireless Headphones',
|
|
204
|
+
description: 'High-quality Bluetooth headphones',
|
|
205
|
+
price: 99.99,
|
|
206
|
+
category: 'Electronics'
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Search with fuzzy matching
|
|
211
|
+
const results = await es.search({
|
|
212
|
+
index: 'products',
|
|
213
|
+
body: {
|
|
214
|
+
query: {
|
|
215
|
+
multi_match: {
|
|
216
|
+
query: 'hedphones', // Typo
|
|
217
|
+
fields: ['name', 'description'],
|
|
218
|
+
fuzziness: 'AUTO'
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Pros:** ✅ Powerful search, ✅ Fast
|
|
226
|
+
**Cons:** ❌ Not for primary data, ❌ Eventual consistency
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Storage Selection Matrix
|
|
231
|
+
|
|
232
|
+
| Use Case | Recommended | Alternative |
|
|
233
|
+
|----------|-------------|-------------|
|
|
234
|
+
| User accounts, orders | PostgreSQL | MySQL |
|
|
235
|
+
| Product catalog | PostgreSQL | MongoDB (if flexible schema) |
|
|
236
|
+
| Session storage | Redis | Memcached |
|
|
237
|
+
| File uploads | S3 | GCS, Azure Blob |
|
|
238
|
+
| Metrics/logs | InfluxDB | TimescaleDB, Prometheus |
|
|
239
|
+
| Full-text search | Elasticsearch | Algolia (managed) |
|
|
240
|
+
| Cache | Redis | Memcached |
|
|
241
|
+
| Real-time analytics | ClickHouse | BigQuery (batch) |
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Caching Strategies
|
|
246
|
+
|
|
247
|
+
### Cache-Aside (Lazy Loading)
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
async function getUser(userId) {
|
|
251
|
+
// 1. Try cache
|
|
252
|
+
let user = await cache.get(`user:${userId}`);
|
|
253
|
+
if (user) return JSON.parse(user); // Cache hit
|
|
254
|
+
|
|
255
|
+
// 2. Cache miss - fetch from DB
|
|
256
|
+
user = await db.users.findUnique({ where: { id: userId } });
|
|
257
|
+
|
|
258
|
+
// 3. Populate cache
|
|
259
|
+
await cache.set(`user:${userId}`, JSON.stringify(user), 'EX', 3600);
|
|
260
|
+
|
|
261
|
+
return user;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Pros:** ✅ Only cache what's needed
|
|
266
|
+
**Cons:** ❌ First request slow (cache miss)
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### Write-Through
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
async function updateUser(userId, data) {
|
|
274
|
+
// 1. Update database
|
|
275
|
+
const user = await db.users.update({
|
|
276
|
+
where: { id: userId },
|
|
277
|
+
data
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// 2. Update cache immediately
|
|
281
|
+
await cache.set(`user:${userId}`, JSON.stringify(user), 'EX', 3600);
|
|
282
|
+
|
|
283
|
+
return user;
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Pros:** ✅ Cache always fresh
|
|
288
|
+
**Cons:** ❌ Write latency (2 operations)
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
### Write-Behind (Write-Back)
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
async function updateUser(userId, data) {
|
|
296
|
+
// 1. Update cache immediately
|
|
297
|
+
await cache.set(`user:${userId}`, JSON.stringify(data));
|
|
298
|
+
|
|
299
|
+
// 2. Async write to database (background)
|
|
300
|
+
queue.publish('user-updates', { userId, data });
|
|
301
|
+
|
|
302
|
+
return data;
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**Pros:** ✅ Fast writes
|
|
307
|
+
**Cons:** ❌ Risk of data loss, ❌ Complexity
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Data Consistency Patterns
|
|
312
|
+
|
|
313
|
+
### Strong Consistency
|
|
314
|
+
```
|
|
315
|
+
Write → Wait for all replicas → Success
|
|
316
|
+
All reads see latest write immediately
|
|
317
|
+
Use: Banking, inventory
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Eventual Consistency
|
|
321
|
+
```
|
|
322
|
+
Write → Primary → Success
|
|
323
|
+
Replicate to secondaries asynchronously
|
|
324
|
+
Reads may see stale data temporarily
|
|
325
|
+
Use: Social media, profiles
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Read-Your-Writes Consistency
|
|
329
|
+
```
|
|
330
|
+
After writing, read from same source (primary)
|
|
331
|
+
User sees their own writes immediately
|
|
332
|
+
Others may still see stale data
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// Read-your-writes pattern
|
|
337
|
+
async function updateProfile(userId, data) {
|
|
338
|
+
await primaryDB.users.update({ where: { id: userId }, data });
|
|
339
|
+
|
|
340
|
+
// Read from primary (not replica) to guarantee consistency
|
|
341
|
+
return await primaryDB.users.findUnique({ where: { id: userId } });
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Data Partitioning (Sharding)
|
|
348
|
+
|
|
349
|
+
### Horizontal Sharding
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
Split data by rows across multiple databases
|
|
353
|
+
|
|
354
|
+
User sharding by user_id:
|
|
355
|
+
Shard 1: users 0-999
|
|
356
|
+
Shard 2: users 1000-1999
|
|
357
|
+
Shard 3: users 2000-2999
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
function getShardForUser(userId) {
|
|
362
|
+
const shardCount = 4;
|
|
363
|
+
const shardId = userId % shardCount;
|
|
364
|
+
return shards[shardId];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function getUserOrders(userId) {
|
|
368
|
+
const shard = getShardForUser(userId);
|
|
369
|
+
return await shard.query('SELECT * FROM orders WHERE user_id = ?', [userId]);
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**Pros:** ✅ Unlimited scaling
|
|
374
|
+
**Cons:** ❌ Cross-shard queries difficult, ❌ Rebalancing complex
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
### Vertical Partitioning
|
|
379
|
+
|
|
380
|
+
```
|
|
381
|
+
Split data by columns
|
|
382
|
+
|
|
383
|
+
Users table split:
|
|
384
|
+
- Hot data: user_id, email, name (frequently accessed)
|
|
385
|
+
- Cold data: settings, preferences (rarely accessed)
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Data Replication
|
|
391
|
+
|
|
392
|
+
### Leader-Follower (Primary-Replica)
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
Primary (Writes) → Followers (Reads)
|
|
396
|
+
|
|
397
|
+
1 Primary, N Followers
|
|
398
|
+
Writes go to primary
|
|
399
|
+
Reads can use any follower
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
// Write to primary
|
|
404
|
+
await primary.users.update({ where: { id: 1 }, data });
|
|
405
|
+
|
|
406
|
+
// Read from replica (load balancing)
|
|
407
|
+
const users = await replica.users.findMany();
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
### Multi-Leader
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
Multiple primaries accept writes
|
|
416
|
+
Conflict resolution required
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**Conflict Resolution:**
|
|
420
|
+
- Last-write-wins (lossy)
|
|
421
|
+
- Version vectors
|
|
422
|
+
- CRDTs (Conflict-free Replicated Data Types)
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## Change Data Capture (CDC)
|
|
427
|
+
|
|
428
|
+
```
|
|
429
|
+
Database → Debezium → Kafka → Consumers
|
|
430
|
+
|
|
431
|
+
Real-time data pipeline without app changes
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
```yaml
|
|
435
|
+
# Debezium connector for PostgreSQL
|
|
436
|
+
{
|
|
437
|
+
"name": "postgres-connector",
|
|
438
|
+
"config": {
|
|
439
|
+
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
|
|
440
|
+
"database.hostname": "postgres",
|
|
441
|
+
"database.port": "5432",
|
|
442
|
+
"database.user": "debezium",
|
|
443
|
+
"database.dbname": "mydb",
|
|
444
|
+
"table.include.list": "public.users,public.orders",
|
|
445
|
+
"topic.prefix": "cdc"
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
**Use Cases:**
|
|
451
|
+
- Real-time search index updates
|
|
452
|
+
- Data warehouse sync
|
|
453
|
+
- Event-driven microservices
|
|
454
|
+
- Audit logging
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## Data Modeling Best Practices
|
|
459
|
+
|
|
460
|
+
### 1. Design for Query Patterns
|
|
461
|
+
```
|
|
462
|
+
Know your queries first, then design schema
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### 2. Denormalize for Performance
|
|
466
|
+
```
|
|
467
|
+
Trade storage for speed in read-heavy systems
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### 3. Use Appropriate Data Types
|
|
471
|
+
```sql
|
|
472
|
+
-- ✅ Correct
|
|
473
|
+
timestamp TIMESTAMPTZ -- Timezone-aware
|
|
474
|
+
price DECIMAL(10,2) -- Exact (no floating point errors)
|
|
475
|
+
|
|
476
|
+
-- ❌ Wrong
|
|
477
|
+
timestamp INT -- Unix epoch (no timezone)
|
|
478
|
+
price FLOAT -- Rounding errors
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### 4. Index Strategically
|
|
482
|
+
```sql
|
|
483
|
+
-- Index frequently queried columns
|
|
484
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
485
|
+
CREATE INDEX idx_orders_user_created ON orders(user_id, created_at);
|
|
486
|
+
|
|
487
|
+
-- But don't over-index (slows writes)
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### 5. Avoid Premature Optimization
|
|
491
|
+
```
|
|
492
|
+
Start simple (single database)
|
|
493
|
+
Scale when metrics show need
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
**Related Resources:**
|
|
499
|
+
- architecture-patterns.md - Event-driven, CQRS patterns
|
|
500
|
+
- system-design-principles.md - CAP theorem, consistency
|
|
501
|
+
- capacity-planning.md - Database sizing
|