@wazir-dev/cli 1.0.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/AGENTS.md +111 -0
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +101 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/assets/composition-engine.mmd +34 -0
- package/assets/demo-script.sh +17 -0
- package/assets/logo-dark.svg +14 -0
- package/assets/logo.svg +14 -0
- package/assets/pipeline.mmd +39 -0
- package/assets/record-demo.sh +51 -0
- package/docs/README.md +51 -0
- package/docs/adapters/context-mode.md +60 -0
- package/docs/concepts/architecture.md +87 -0
- package/docs/concepts/artifact-model.md +60 -0
- package/docs/concepts/composition-engine.md +36 -0
- package/docs/concepts/indexing-and-recall.md +160 -0
- package/docs/concepts/observability.md +41 -0
- package/docs/concepts/roles-and-workflows.md +59 -0
- package/docs/concepts/terminology-policy.md +27 -0
- package/docs/getting-started/01-installation.md +78 -0
- package/docs/getting-started/02-first-run.md +102 -0
- package/docs/getting-started/03-adding-to-project.md +15 -0
- package/docs/getting-started/04-host-setup.md +15 -0
- package/docs/guides/ci-integration.md +15 -0
- package/docs/guides/creating-skills.md +15 -0
- package/docs/guides/expertise-module-authoring.md +15 -0
- package/docs/guides/hook-development.md +15 -0
- package/docs/guides/memory-and-learnings.md +34 -0
- package/docs/guides/multi-host-export.md +15 -0
- package/docs/guides/troubleshooting.md +101 -0
- package/docs/guides/writing-custom-roles.md +15 -0
- package/docs/plans/2026-03-15-cli-pipeline-integration-design.md +592 -0
- package/docs/plans/2026-03-15-cli-pipeline-integration-plan.md +598 -0
- package/docs/plans/2026-03-15-docs-enforcement-plan.md +238 -0
- package/docs/readmes/INDEX.md +99 -0
- package/docs/readmes/features/expertise/README.md +171 -0
- package/docs/readmes/features/exports/README.md +222 -0
- package/docs/readmes/features/hooks/README.md +103 -0
- package/docs/readmes/features/hooks/loop-cap-guard.md +133 -0
- package/docs/readmes/features/hooks/post-tool-capture.md +121 -0
- package/docs/readmes/features/hooks/post-tool-lint.md +130 -0
- package/docs/readmes/features/hooks/pre-compact-summary.md +122 -0
- package/docs/readmes/features/hooks/pre-tool-capture-route.md +100 -0
- package/docs/readmes/features/hooks/protected-path-write-guard.md +128 -0
- package/docs/readmes/features/hooks/session-start.md +119 -0
- package/docs/readmes/features/hooks/stop-handoff-harvest.md +125 -0
- package/docs/readmes/features/roles/README.md +157 -0
- package/docs/readmes/features/roles/clarifier.md +152 -0
- package/docs/readmes/features/roles/content-author.md +190 -0
- package/docs/readmes/features/roles/designer.md +193 -0
- package/docs/readmes/features/roles/executor.md +184 -0
- package/docs/readmes/features/roles/learner.md +210 -0
- package/docs/readmes/features/roles/planner.md +182 -0
- package/docs/readmes/features/roles/researcher.md +164 -0
- package/docs/readmes/features/roles/reviewer.md +184 -0
- package/docs/readmes/features/roles/specifier.md +162 -0
- package/docs/readmes/features/roles/verifier.md +215 -0
- package/docs/readmes/features/schemas/README.md +178 -0
- package/docs/readmes/features/skills/README.md +63 -0
- package/docs/readmes/features/skills/brainstorming.md +96 -0
- package/docs/readmes/features/skills/debugging.md +148 -0
- package/docs/readmes/features/skills/design.md +120 -0
- package/docs/readmes/features/skills/prepare-next.md +109 -0
- package/docs/readmes/features/skills/run-audit.md +159 -0
- package/docs/readmes/features/skills/scan-project.md +109 -0
- package/docs/readmes/features/skills/self-audit.md +176 -0
- package/docs/readmes/features/skills/tdd.md +137 -0
- package/docs/readmes/features/skills/using-skills.md +92 -0
- package/docs/readmes/features/skills/verification.md +120 -0
- package/docs/readmes/features/skills/writing-plans.md +104 -0
- package/docs/readmes/features/tooling/README.md +320 -0
- package/docs/readmes/features/workflows/README.md +186 -0
- package/docs/readmes/features/workflows/author.md +181 -0
- package/docs/readmes/features/workflows/clarify.md +154 -0
- package/docs/readmes/features/workflows/design-review.md +171 -0
- package/docs/readmes/features/workflows/design.md +169 -0
- package/docs/readmes/features/workflows/discover.md +162 -0
- package/docs/readmes/features/workflows/execute.md +173 -0
- package/docs/readmes/features/workflows/learn.md +167 -0
- package/docs/readmes/features/workflows/plan-review.md +165 -0
- package/docs/readmes/features/workflows/plan.md +170 -0
- package/docs/readmes/features/workflows/prepare-next.md +167 -0
- package/docs/readmes/features/workflows/review.md +169 -0
- package/docs/readmes/features/workflows/run-audit.md +191 -0
- package/docs/readmes/features/workflows/spec-challenge.md +159 -0
- package/docs/readmes/features/workflows/specify.md +160 -0
- package/docs/readmes/features/workflows/verify.md +177 -0
- package/docs/readmes/packages/README.md +50 -0
- package/docs/readmes/packages/ajv.md +117 -0
- package/docs/readmes/packages/context-mode.md +118 -0
- package/docs/readmes/packages/gray-matter.md +116 -0
- package/docs/readmes/packages/node-test.md +137 -0
- package/docs/readmes/packages/yaml.md +112 -0
- package/docs/reference/configuration-reference.md +159 -0
- package/docs/reference/expertise-index.md +52 -0
- package/docs/reference/git-flow.md +43 -0
- package/docs/reference/hooks.md +87 -0
- package/docs/reference/host-exports.md +50 -0
- package/docs/reference/launch-checklist.md +172 -0
- package/docs/reference/marketplace-listings.md +76 -0
- package/docs/reference/release-process.md +34 -0
- package/docs/reference/roles-reference.md +77 -0
- package/docs/reference/skills.md +33 -0
- package/docs/reference/templates.md +29 -0
- package/docs/reference/tooling-cli.md +94 -0
- package/docs/truth-claims.yaml +222 -0
- package/expertise/PROGRESS.md +63 -0
- package/expertise/README.md +18 -0
- package/expertise/antipatterns/PROGRESS.md +56 -0
- package/expertise/antipatterns/backend/api-design-antipatterns.md +1271 -0
- package/expertise/antipatterns/backend/auth-antipatterns.md +1195 -0
- package/expertise/antipatterns/backend/caching-antipatterns.md +622 -0
- package/expertise/antipatterns/backend/database-antipatterns.md +1038 -0
- package/expertise/antipatterns/backend/index.md +24 -0
- package/expertise/antipatterns/backend/microservices-antipatterns.md +850 -0
- package/expertise/antipatterns/code/architecture-antipatterns.md +919 -0
- package/expertise/antipatterns/code/async-antipatterns.md +622 -0
- package/expertise/antipatterns/code/code-smells.md +1186 -0
- package/expertise/antipatterns/code/dependency-antipatterns.md +1209 -0
- package/expertise/antipatterns/code/error-handling-antipatterns.md +1360 -0
- package/expertise/antipatterns/code/index.md +27 -0
- package/expertise/antipatterns/code/naming-and-abstraction.md +1118 -0
- package/expertise/antipatterns/code/state-management-antipatterns.md +1076 -0
- package/expertise/antipatterns/code/testing-antipatterns.md +1053 -0
- package/expertise/antipatterns/design/accessibility-antipatterns.md +1136 -0
- package/expertise/antipatterns/design/dark-patterns.md +1121 -0
- package/expertise/antipatterns/design/index.md +22 -0
- package/expertise/antipatterns/design/ui-antipatterns.md +1202 -0
- package/expertise/antipatterns/design/ux-antipatterns.md +680 -0
- package/expertise/antipatterns/frontend/css-layout-antipatterns.md +691 -0
- package/expertise/antipatterns/frontend/flutter-antipatterns.md +1827 -0
- package/expertise/antipatterns/frontend/index.md +23 -0
- package/expertise/antipatterns/frontend/mobile-antipatterns.md +573 -0
- package/expertise/antipatterns/frontend/react-antipatterns.md +1128 -0
- package/expertise/antipatterns/frontend/spa-antipatterns.md +1235 -0
- package/expertise/antipatterns/index.md +31 -0
- package/expertise/antipatterns/performance/index.md +20 -0
- package/expertise/antipatterns/performance/performance-antipatterns.md +1013 -0
- package/expertise/antipatterns/performance/premature-optimization.md +623 -0
- package/expertise/antipatterns/performance/scaling-antipatterns.md +785 -0
- package/expertise/antipatterns/process/ai-coding-antipatterns.md +853 -0
- package/expertise/antipatterns/process/code-review-antipatterns.md +656 -0
- package/expertise/antipatterns/process/deployment-antipatterns.md +920 -0
- package/expertise/antipatterns/process/index.md +23 -0
- package/expertise/antipatterns/process/technical-debt-antipatterns.md +647 -0
- package/expertise/antipatterns/security/index.md +20 -0
- package/expertise/antipatterns/security/secrets-antipatterns.md +849 -0
- package/expertise/antipatterns/security/security-theater.md +843 -0
- package/expertise/antipatterns/security/vulnerability-patterns.md +801 -0
- package/expertise/architecture/PROGRESS.md +70 -0
- package/expertise/architecture/data/caching-architecture.md +671 -0
- package/expertise/architecture/data/data-consistency.md +574 -0
- package/expertise/architecture/data/data-modeling.md +536 -0
- package/expertise/architecture/data/event-streams-and-queues.md +634 -0
- package/expertise/architecture/data/index.md +25 -0
- package/expertise/architecture/data/search-architecture.md +663 -0
- package/expertise/architecture/data/sql-vs-nosql.md +708 -0
- package/expertise/architecture/decisions/architecture-decision-records.md +640 -0
- package/expertise/architecture/decisions/build-vs-buy.md +616 -0
- package/expertise/architecture/decisions/index.md +23 -0
- package/expertise/architecture/decisions/monolith-to-microservices.md +790 -0
- package/expertise/architecture/decisions/technology-selection.md +616 -0
- package/expertise/architecture/distributed/cap-theorem-and-tradeoffs.md +800 -0
- package/expertise/architecture/distributed/circuit-breaker-bulkhead.md +741 -0
- package/expertise/architecture/distributed/consensus-and-coordination.md +796 -0
- package/expertise/architecture/distributed/distributed-systems-fundamentals.md +564 -0
- package/expertise/architecture/distributed/idempotency-and-retry.md +796 -0
- package/expertise/architecture/distributed/index.md +25 -0
- package/expertise/architecture/distributed/saga-pattern.md +797 -0
- package/expertise/architecture/foundations/architectural-thinking.md +460 -0
- package/expertise/architecture/foundations/coupling-and-cohesion.md +770 -0
- package/expertise/architecture/foundations/design-principles-solid.md +649 -0
- package/expertise/architecture/foundations/domain-driven-design.md +719 -0
- package/expertise/architecture/foundations/index.md +25 -0
- package/expertise/architecture/foundations/separation-of-concerns.md +472 -0
- package/expertise/architecture/foundations/twelve-factor-app.md +797 -0
- package/expertise/architecture/index.md +34 -0
- package/expertise/architecture/integration/api-design-graphql.md +638 -0
- package/expertise/architecture/integration/api-design-grpc.md +804 -0
- package/expertise/architecture/integration/api-design-rest.md +892 -0
- package/expertise/architecture/integration/index.md +25 -0
- package/expertise/architecture/integration/third-party-integration.md +795 -0
- package/expertise/architecture/integration/webhooks-and-callbacks.md +1152 -0
- package/expertise/architecture/integration/websockets-realtime.md +791 -0
- package/expertise/architecture/mobile-architecture/index.md +22 -0
- package/expertise/architecture/mobile-architecture/mobile-app-architecture.md +780 -0
- package/expertise/architecture/mobile-architecture/mobile-backend-for-frontend.md +670 -0
- package/expertise/architecture/mobile-architecture/offline-first.md +719 -0
- package/expertise/architecture/mobile-architecture/push-and-sync.md +782 -0
- package/expertise/architecture/patterns/cqrs-event-sourcing.md +717 -0
- package/expertise/architecture/patterns/event-driven.md +797 -0
- package/expertise/architecture/patterns/hexagonal-clean-architecture.md +870 -0
- package/expertise/architecture/patterns/index.md +27 -0
- package/expertise/architecture/patterns/layered-architecture.md +736 -0
- package/expertise/architecture/patterns/microservices.md +753 -0
- package/expertise/architecture/patterns/modular-monolith.md +692 -0
- package/expertise/architecture/patterns/monolith.md +626 -0
- package/expertise/architecture/patterns/plugin-architecture.md +735 -0
- package/expertise/architecture/patterns/serverless.md +780 -0
- package/expertise/architecture/scaling/database-scaling.md +615 -0
- package/expertise/architecture/scaling/feature-flags-and-rollouts.md +757 -0
- package/expertise/architecture/scaling/horizontal-vs-vertical.md +606 -0
- package/expertise/architecture/scaling/index.md +24 -0
- package/expertise/architecture/scaling/multi-tenancy.md +800 -0
- package/expertise/architecture/scaling/stateless-design.md +787 -0
- package/expertise/backend/embedded-firmware.md +625 -0
- package/expertise/backend/go.md +853 -0
- package/expertise/backend/index.md +24 -0
- package/expertise/backend/java-spring.md +448 -0
- package/expertise/backend/node-typescript.md +625 -0
- package/expertise/backend/python-fastapi.md +724 -0
- package/expertise/backend/rust.md +458 -0
- package/expertise/backend/solidity.md +711 -0
- package/expertise/composition-map.yaml +443 -0
- package/expertise/content/foundations/content-modeling.md +395 -0
- package/expertise/content/foundations/editorial-standards.md +449 -0
- package/expertise/content/foundations/index.md +24 -0
- package/expertise/content/foundations/microcopy.md +455 -0
- package/expertise/content/foundations/terminology-governance.md +509 -0
- package/expertise/content/index.md +34 -0
- package/expertise/content/patterns/accessibility-copy.md +518 -0
- package/expertise/content/patterns/index.md +24 -0
- package/expertise/content/patterns/notification-content.md +433 -0
- package/expertise/content/patterns/sample-content.md +486 -0
- package/expertise/content/patterns/state-copy.md +439 -0
- package/expertise/design/PROGRESS.md +58 -0
- package/expertise/design/disciplines/dark-mode-theming.md +577 -0
- package/expertise/design/disciplines/design-systems.md +595 -0
- package/expertise/design/disciplines/index.md +25 -0
- package/expertise/design/disciplines/information-architecture.md +800 -0
- package/expertise/design/disciplines/interaction-design.md +788 -0
- package/expertise/design/disciplines/responsive-design.md +552 -0
- package/expertise/design/disciplines/usability-testing.md +516 -0
- package/expertise/design/disciplines/user-research.md +792 -0
- package/expertise/design/foundations/accessibility-design.md +796 -0
- package/expertise/design/foundations/color-theory.md +797 -0
- package/expertise/design/foundations/iconography.md +795 -0
- package/expertise/design/foundations/index.md +26 -0
- package/expertise/design/foundations/motion-and-animation.md +653 -0
- package/expertise/design/foundations/rtl-design.md +585 -0
- package/expertise/design/foundations/spacing-and-layout.md +607 -0
- package/expertise/design/foundations/typography.md +800 -0
- package/expertise/design/foundations/visual-hierarchy.md +761 -0
- package/expertise/design/index.md +32 -0
- package/expertise/design/patterns/authentication-flows.md +474 -0
- package/expertise/design/patterns/content-consumption.md +789 -0
- package/expertise/design/patterns/data-display.md +618 -0
- package/expertise/design/patterns/e-commerce.md +1494 -0
- package/expertise/design/patterns/feedback-and-states.md +642 -0
- package/expertise/design/patterns/forms-and-input.md +819 -0
- package/expertise/design/patterns/gamification.md +801 -0
- package/expertise/design/patterns/index.md +31 -0
- package/expertise/design/patterns/microinteractions.md +449 -0
- package/expertise/design/patterns/navigation.md +800 -0
- package/expertise/design/patterns/notifications.md +705 -0
- package/expertise/design/patterns/onboarding.md +700 -0
- package/expertise/design/patterns/search-and-filter.md +601 -0
- package/expertise/design/patterns/settings-and-preferences.md +768 -0
- package/expertise/design/patterns/social-and-community.md +748 -0
- package/expertise/design/platforms/desktop-native.md +612 -0
- package/expertise/design/platforms/index.md +25 -0
- package/expertise/design/platforms/mobile-android.md +825 -0
- package/expertise/design/platforms/mobile-cross-platform.md +983 -0
- package/expertise/design/platforms/mobile-ios.md +699 -0
- package/expertise/design/platforms/tablet.md +794 -0
- package/expertise/design/platforms/web-dashboard.md +790 -0
- package/expertise/design/platforms/web-responsive.md +550 -0
- package/expertise/design/psychology/behavioral-nudges.md +449 -0
- package/expertise/design/psychology/cognitive-load.md +1191 -0
- package/expertise/design/psychology/error-psychology.md +778 -0
- package/expertise/design/psychology/index.md +22 -0
- package/expertise/design/psychology/persuasive-design.md +736 -0
- package/expertise/design/psychology/user-mental-models.md +623 -0
- package/expertise/design/tooling/open-pencil.md +266 -0
- package/expertise/frontend/angular.md +1073 -0
- package/expertise/frontend/desktop-electron.md +546 -0
- package/expertise/frontend/flutter.md +782 -0
- package/expertise/frontend/index.md +27 -0
- package/expertise/frontend/native-android.md +409 -0
- package/expertise/frontend/native-ios.md +490 -0
- package/expertise/frontend/react-native.md +1160 -0
- package/expertise/frontend/react.md +808 -0
- package/expertise/frontend/vue.md +1089 -0
- package/expertise/humanize/domain-rules-code.md +79 -0
- package/expertise/humanize/domain-rules-content.md +67 -0
- package/expertise/humanize/domain-rules-technical-docs.md +56 -0
- package/expertise/humanize/index.md +35 -0
- package/expertise/humanize/self-audit-checklist.md +87 -0
- package/expertise/humanize/sentence-patterns.md +218 -0
- package/expertise/humanize/vocabulary-blacklist.md +105 -0
- package/expertise/i18n/PROGRESS.md +65 -0
- package/expertise/i18n/advanced/accessibility-and-i18n.md +28 -0
- package/expertise/i18n/advanced/bidirectional-text-algorithm.md +38 -0
- package/expertise/i18n/advanced/complex-scripts.md +30 -0
- package/expertise/i18n/advanced/performance-and-i18n.md +27 -0
- package/expertise/i18n/advanced/testing-i18n.md +28 -0
- package/expertise/i18n/content/content-adaptation.md +23 -0
- package/expertise/i18n/content/locale-specific-formatting.md +23 -0
- package/expertise/i18n/content/machine-translation-integration.md +28 -0
- package/expertise/i18n/content/translation-management.md +29 -0
- package/expertise/i18n/foundations/date-time-calendars.md +67 -0
- package/expertise/i18n/foundations/i18n-architecture.md +272 -0
- package/expertise/i18n/foundations/locale-and-language-tags.md +79 -0
- package/expertise/i18n/foundations/numbers-currency-units.md +61 -0
- package/expertise/i18n/foundations/pluralization-and-gender.md +109 -0
- package/expertise/i18n/foundations/string-externalization.md +236 -0
- package/expertise/i18n/foundations/text-direction-bidi.md +241 -0
- package/expertise/i18n/foundations/unicode-and-encoding.md +86 -0
- package/expertise/i18n/index.md +38 -0
- package/expertise/i18n/platform/backend-i18n.md +31 -0
- package/expertise/i18n/platform/flutter-i18n.md +148 -0
- package/expertise/i18n/platform/native-android-i18n.md +36 -0
- package/expertise/i18n/platform/native-ios-i18n.md +36 -0
- package/expertise/i18n/platform/react-i18n.md +103 -0
- package/expertise/i18n/platform/web-css-i18n.md +81 -0
- package/expertise/i18n/rtl/arabic-specific.md +175 -0
- package/expertise/i18n/rtl/hebrew-specific.md +149 -0
- package/expertise/i18n/rtl/rtl-animations-and-transitions.md +111 -0
- package/expertise/i18n/rtl/rtl-forms-and-input.md +161 -0
- package/expertise/i18n/rtl/rtl-fundamentals.md +211 -0
- package/expertise/i18n/rtl/rtl-icons-and-images.md +181 -0
- package/expertise/i18n/rtl/rtl-layout-mirroring.md +252 -0
- package/expertise/i18n/rtl/rtl-navigation-and-gestures.md +107 -0
- package/expertise/i18n/rtl/rtl-testing-and-qa.md +147 -0
- package/expertise/i18n/rtl/rtl-typography.md +160 -0
- package/expertise/index.md +113 -0
- package/expertise/index.yaml +216 -0
- package/expertise/infrastructure/cloud-aws.md +597 -0
- package/expertise/infrastructure/cloud-gcp.md +599 -0
- package/expertise/infrastructure/cybersecurity.md +816 -0
- package/expertise/infrastructure/database-mongodb.md +447 -0
- package/expertise/infrastructure/database-postgres.md +400 -0
- package/expertise/infrastructure/devops-cicd.md +787 -0
- package/expertise/infrastructure/index.md +27 -0
- package/expertise/performance/PROGRESS.md +50 -0
- package/expertise/performance/backend/api-latency.md +1204 -0
- package/expertise/performance/backend/background-jobs.md +506 -0
- package/expertise/performance/backend/connection-pooling.md +1209 -0
- package/expertise/performance/backend/database-query-optimization.md +515 -0
- package/expertise/performance/backend/index.md +23 -0
- package/expertise/performance/backend/rate-limiting-and-throttling.md +971 -0
- package/expertise/performance/foundations/algorithmic-complexity.md +954 -0
- package/expertise/performance/foundations/caching-strategies.md +489 -0
- package/expertise/performance/foundations/concurrency-and-parallelism.md +847 -0
- package/expertise/performance/foundations/index.md +24 -0
- package/expertise/performance/foundations/measuring-and-profiling.md +440 -0
- package/expertise/performance/foundations/memory-management.md +964 -0
- package/expertise/performance/foundations/performance-budgets.md +1314 -0
- package/expertise/performance/index.md +31 -0
- package/expertise/performance/infrastructure/auto-scaling.md +1059 -0
- package/expertise/performance/infrastructure/cdn-and-edge.md +1081 -0
- package/expertise/performance/infrastructure/index.md +22 -0
- package/expertise/performance/infrastructure/load-balancing.md +1081 -0
- package/expertise/performance/infrastructure/observability.md +1079 -0
- package/expertise/performance/mobile/index.md +23 -0
- package/expertise/performance/mobile/mobile-animations.md +544 -0
- package/expertise/performance/mobile/mobile-memory-battery.md +416 -0
- package/expertise/performance/mobile/mobile-network.md +452 -0
- package/expertise/performance/mobile/mobile-rendering.md +599 -0
- package/expertise/performance/mobile/mobile-startup-time.md +505 -0
- package/expertise/performance/platform-specific/flutter-performance.md +647 -0
- package/expertise/performance/platform-specific/index.md +22 -0
- package/expertise/performance/platform-specific/node-performance.md +1307 -0
- package/expertise/performance/platform-specific/postgres-performance.md +1366 -0
- package/expertise/performance/platform-specific/react-performance.md +1403 -0
- package/expertise/performance/web/bundle-optimization.md +1239 -0
- package/expertise/performance/web/image-and-media.md +636 -0
- package/expertise/performance/web/index.md +24 -0
- package/expertise/performance/web/network-optimization.md +1133 -0
- package/expertise/performance/web/rendering-performance.md +1098 -0
- package/expertise/performance/web/ssr-and-hydration.md +918 -0
- package/expertise/performance/web/web-vitals.md +1374 -0
- package/expertise/quality/accessibility.md +985 -0
- package/expertise/quality/evidence-based-verification.md +499 -0
- package/expertise/quality/index.md +24 -0
- package/expertise/quality/ml-model-audit.md +614 -0
- package/expertise/quality/performance.md +600 -0
- package/expertise/quality/testing-api.md +891 -0
- package/expertise/quality/testing-mobile.md +496 -0
- package/expertise/quality/testing-web.md +849 -0
- package/expertise/security/PROGRESS.md +54 -0
- package/expertise/security/agentic-identity.md +540 -0
- package/expertise/security/compliance-frameworks.md +601 -0
- package/expertise/security/data/data-encryption.md +364 -0
- package/expertise/security/data/data-privacy-gdpr.md +692 -0
- package/expertise/security/data/database-security.md +1171 -0
- package/expertise/security/data/index.md +22 -0
- package/expertise/security/data/pii-handling.md +531 -0
- package/expertise/security/foundations/authentication.md +1041 -0
- package/expertise/security/foundations/authorization.md +603 -0
- package/expertise/security/foundations/cryptography.md +1001 -0
- package/expertise/security/foundations/index.md +25 -0
- package/expertise/security/foundations/owasp-top-10.md +1354 -0
- package/expertise/security/foundations/secrets-management.md +1217 -0
- package/expertise/security/foundations/secure-sdlc.md +700 -0
- package/expertise/security/foundations/supply-chain-security.md +698 -0
- package/expertise/security/index.md +31 -0
- package/expertise/security/infrastructure/cloud-security-aws.md +1296 -0
- package/expertise/security/infrastructure/cloud-security-gcp.md +1376 -0
- package/expertise/security/infrastructure/container-security.md +721 -0
- package/expertise/security/infrastructure/incident-response.md +1295 -0
- package/expertise/security/infrastructure/index.md +24 -0
- package/expertise/security/infrastructure/logging-and-monitoring.md +1618 -0
- package/expertise/security/infrastructure/network-security.md +1337 -0
- package/expertise/security/mobile/index.md +23 -0
- package/expertise/security/mobile/mobile-android-security.md +1218 -0
- package/expertise/security/mobile/mobile-binary-protection.md +1229 -0
- package/expertise/security/mobile/mobile-data-storage.md +1265 -0
- package/expertise/security/mobile/mobile-ios-security.md +1401 -0
- package/expertise/security/mobile/mobile-network-security.md +1520 -0
- package/expertise/security/smart-contract-security.md +594 -0
- package/expertise/security/testing/index.md +22 -0
- package/expertise/security/testing/penetration-testing.md +1258 -0
- package/expertise/security/testing/security-code-review.md +1765 -0
- package/expertise/security/testing/threat-modeling.md +1074 -0
- package/expertise/security/testing/vulnerability-scanning.md +1062 -0
- package/expertise/security/web/api-security.md +586 -0
- package/expertise/security/web/cors-and-headers.md +433 -0
- package/expertise/security/web/csrf.md +562 -0
- package/expertise/security/web/file-upload.md +1477 -0
- package/expertise/security/web/index.md +25 -0
- package/expertise/security/web/injection.md +1375 -0
- package/expertise/security/web/session-management.md +1101 -0
- package/expertise/security/web/xss.md +1158 -0
- package/exports/README.md +17 -0
- package/exports/hosts/claude/.claude/agents/clarifier.md +42 -0
- package/exports/hosts/claude/.claude/agents/content-author.md +63 -0
- package/exports/hosts/claude/.claude/agents/designer.md +55 -0
- package/exports/hosts/claude/.claude/agents/executor.md +55 -0
- package/exports/hosts/claude/.claude/agents/learner.md +51 -0
- package/exports/hosts/claude/.claude/agents/planner.md +53 -0
- package/exports/hosts/claude/.claude/agents/researcher.md +43 -0
- package/exports/hosts/claude/.claude/agents/reviewer.md +54 -0
- package/exports/hosts/claude/.claude/agents/specifier.md +47 -0
- package/exports/hosts/claude/.claude/agents/verifier.md +71 -0
- package/exports/hosts/claude/.claude/commands/author.md +42 -0
- package/exports/hosts/claude/.claude/commands/clarify.md +38 -0
- package/exports/hosts/claude/.claude/commands/design-review.md +46 -0
- package/exports/hosts/claude/.claude/commands/design.md +44 -0
- package/exports/hosts/claude/.claude/commands/discover.md +37 -0
- package/exports/hosts/claude/.claude/commands/execute.md +48 -0
- package/exports/hosts/claude/.claude/commands/learn.md +38 -0
- package/exports/hosts/claude/.claude/commands/plan-review.md +42 -0
- package/exports/hosts/claude/.claude/commands/plan.md +39 -0
- package/exports/hosts/claude/.claude/commands/prepare-next.md +37 -0
- package/exports/hosts/claude/.claude/commands/review.md +40 -0
- package/exports/hosts/claude/.claude/commands/run-audit.md +41 -0
- package/exports/hosts/claude/.claude/commands/spec-challenge.md +41 -0
- package/exports/hosts/claude/.claude/commands/specify.md +38 -0
- package/exports/hosts/claude/.claude/commands/verify.md +37 -0
- package/exports/hosts/claude/.claude/settings.json +34 -0
- package/exports/hosts/claude/CLAUDE.md +19 -0
- package/exports/hosts/claude/export.manifest.json +38 -0
- package/exports/hosts/claude/host-package.json +67 -0
- package/exports/hosts/codex/AGENTS.md +19 -0
- package/exports/hosts/codex/export.manifest.json +38 -0
- package/exports/hosts/codex/host-package.json +41 -0
- package/exports/hosts/cursor/.cursor/hooks.json +16 -0
- package/exports/hosts/cursor/.cursor/rules/wazir-core.mdc +19 -0
- package/exports/hosts/cursor/export.manifest.json +38 -0
- package/exports/hosts/cursor/host-package.json +42 -0
- package/exports/hosts/gemini/GEMINI.md +19 -0
- package/exports/hosts/gemini/export.manifest.json +38 -0
- package/exports/hosts/gemini/host-package.json +41 -0
- package/hooks/README.md +18 -0
- package/hooks/definitions/loop_cap_guard.yaml +21 -0
- package/hooks/definitions/post_tool_capture.yaml +24 -0
- package/hooks/definitions/pre_compact_summary.yaml +19 -0
- package/hooks/definitions/pre_tool_capture_route.yaml +19 -0
- package/hooks/definitions/protected_path_write_guard.yaml +19 -0
- package/hooks/definitions/session_start.yaml +19 -0
- package/hooks/definitions/stop_handoff_harvest.yaml +20 -0
- package/hooks/loop-cap-guard +17 -0
- package/hooks/post-tool-lint +36 -0
- package/hooks/protected-path-write-guard +17 -0
- package/hooks/session-start +41 -0
- package/llms-full.txt +2355 -0
- package/llms.txt +43 -0
- package/package.json +79 -0
- package/roles/README.md +20 -0
- package/roles/clarifier.md +42 -0
- package/roles/content-author.md +63 -0
- package/roles/designer.md +55 -0
- package/roles/executor.md +55 -0
- package/roles/learner.md +51 -0
- package/roles/planner.md +53 -0
- package/roles/researcher.md +43 -0
- package/roles/reviewer.md +54 -0
- package/roles/specifier.md +47 -0
- package/roles/verifier.md +71 -0
- package/schemas/README.md +24 -0
- package/schemas/accepted-learning.schema.json +20 -0
- package/schemas/author-artifact.schema.json +156 -0
- package/schemas/clarification.schema.json +19 -0
- package/schemas/design-artifact.schema.json +80 -0
- package/schemas/docs-claim.schema.json +18 -0
- package/schemas/export-manifest.schema.json +20 -0
- package/schemas/hook.schema.json +67 -0
- package/schemas/host-export-package.schema.json +18 -0
- package/schemas/implementation-plan.schema.json +19 -0
- package/schemas/proposed-learning.schema.json +19 -0
- package/schemas/research.schema.json +18 -0
- package/schemas/review.schema.json +29 -0
- package/schemas/run-manifest.schema.json +18 -0
- package/schemas/spec-challenge.schema.json +18 -0
- package/schemas/spec.schema.json +20 -0
- package/schemas/usage.schema.json +102 -0
- package/schemas/verification-proof.schema.json +29 -0
- package/schemas/wazir-manifest.schema.json +173 -0
- package/skills/README.md +40 -0
- package/skills/brainstorming/SKILL.md +77 -0
- package/skills/debugging/SKILL.md +50 -0
- package/skills/design/SKILL.md +61 -0
- package/skills/dispatching-parallel-agents/SKILL.md +128 -0
- package/skills/executing-plans/SKILL.md +70 -0
- package/skills/finishing-a-development-branch/SKILL.md +169 -0
- package/skills/humanize/SKILL.md +123 -0
- package/skills/init-pipeline/SKILL.md +124 -0
- package/skills/prepare-next/SKILL.md +20 -0
- package/skills/receiving-code-review/SKILL.md +123 -0
- package/skills/requesting-code-review/SKILL.md +105 -0
- package/skills/requesting-code-review/code-reviewer.md +108 -0
- package/skills/run-audit/SKILL.md +197 -0
- package/skills/scan-project/SKILL.md +41 -0
- package/skills/self-audit/SKILL.md +153 -0
- package/skills/subagent-driven-development/SKILL.md +154 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
- package/skills/subagent-driven-development/implementer-prompt.md +102 -0
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/skills/tdd/SKILL.md +23 -0
- package/skills/using-git-worktrees/SKILL.md +163 -0
- package/skills/using-skills/SKILL.md +95 -0
- package/skills/verification/SKILL.md +22 -0
- package/skills/wazir/SKILL.md +463 -0
- package/skills/writing-plans/SKILL.md +30 -0
- package/skills/writing-skills/SKILL.md +157 -0
- package/skills/writing-skills/anthropic-best-practices.md +122 -0
- package/skills/writing-skills/persuasion-principles.md +50 -0
- package/templates/README.md +20 -0
- package/templates/artifacts/README.md +10 -0
- package/templates/artifacts/accepted-learning.md +19 -0
- package/templates/artifacts/accepted-learning.template.json +12 -0
- package/templates/artifacts/author.md +74 -0
- package/templates/artifacts/author.template.json +19 -0
- package/templates/artifacts/clarification.md +21 -0
- package/templates/artifacts/clarification.template.json +12 -0
- package/templates/artifacts/execute-notes.md +19 -0
- package/templates/artifacts/implementation-plan.md +21 -0
- package/templates/artifacts/implementation-plan.template.json +11 -0
- package/templates/artifacts/learning-proposal.md +19 -0
- package/templates/artifacts/next-run-handoff.md +21 -0
- package/templates/artifacts/plan-review.md +19 -0
- package/templates/artifacts/proposed-learning.template.json +12 -0
- package/templates/artifacts/research.md +21 -0
- package/templates/artifacts/research.template.json +12 -0
- package/templates/artifacts/review-findings.md +19 -0
- package/templates/artifacts/review.template.json +11 -0
- package/templates/artifacts/run-manifest.template.json +8 -0
- package/templates/artifacts/spec-challenge.md +19 -0
- package/templates/artifacts/spec-challenge.template.json +11 -0
- package/templates/artifacts/spec.md +21 -0
- package/templates/artifacts/spec.template.json +12 -0
- package/templates/artifacts/verification-proof.md +19 -0
- package/templates/artifacts/verification-proof.template.json +11 -0
- package/templates/examples/accepted-learning.example.json +14 -0
- package/templates/examples/author.example.json +152 -0
- package/templates/examples/clarification.example.json +15 -0
- package/templates/examples/docs-claim.example.json +8 -0
- package/templates/examples/export-manifest.example.json +7 -0
- package/templates/examples/host-export-package.example.json +11 -0
- package/templates/examples/implementation-plan.example.json +17 -0
- package/templates/examples/proposed-learning.example.json +13 -0
- package/templates/examples/research.example.json +15 -0
- package/templates/examples/research.example.md +6 -0
- package/templates/examples/review.example.json +17 -0
- package/templates/examples/run-manifest.example.json +9 -0
- package/templates/examples/spec-challenge.example.json +14 -0
- package/templates/examples/spec.example.json +21 -0
- package/templates/examples/verification-proof.example.json +21 -0
- package/templates/examples/wazir-manifest.example.yaml +65 -0
- package/templates/task-definition-schema.md +99 -0
- package/tooling/README.md +20 -0
- package/tooling/src/adapters/context-mode.js +50 -0
- package/tooling/src/capture/command.js +376 -0
- package/tooling/src/capture/store.js +99 -0
- package/tooling/src/capture/usage.js +270 -0
- package/tooling/src/checks/branches.js +50 -0
- package/tooling/src/checks/brand-truth.js +110 -0
- package/tooling/src/checks/changelog.js +231 -0
- package/tooling/src/checks/command-registry.js +36 -0
- package/tooling/src/checks/commits.js +102 -0
- package/tooling/src/checks/docs-drift.js +103 -0
- package/tooling/src/checks/docs-truth.js +201 -0
- package/tooling/src/checks/runtime-surface.js +156 -0
- package/tooling/src/cli.js +116 -0
- package/tooling/src/command-options.js +56 -0
- package/tooling/src/commands/validate.js +320 -0
- package/tooling/src/doctor/command.js +91 -0
- package/tooling/src/export/command.js +77 -0
- package/tooling/src/export/compiler.js +498 -0
- package/tooling/src/guards/loop-cap-guard.js +52 -0
- package/tooling/src/guards/protected-path-write-guard.js +67 -0
- package/tooling/src/index/command.js +152 -0
- package/tooling/src/index/storage.js +1061 -0
- package/tooling/src/index/summarizers.js +261 -0
- package/tooling/src/loaders.js +18 -0
- package/tooling/src/project-root.js +22 -0
- package/tooling/src/recall/command.js +225 -0
- package/tooling/src/schema-validator.js +30 -0
- package/tooling/src/state-root.js +40 -0
- package/tooling/src/status/command.js +71 -0
- package/wazir.manifest.yaml +135 -0
- package/workflows/README.md +19 -0
- package/workflows/author.md +42 -0
- package/workflows/clarify.md +38 -0
- package/workflows/design-review.md +46 -0
- package/workflows/design.md +44 -0
- package/workflows/discover.md +37 -0
- package/workflows/execute.md +48 -0
- package/workflows/learn.md +38 -0
- package/workflows/plan-review.md +42 -0
- package/workflows/plan.md +39 -0
- package/workflows/prepare-next.md +37 -0
- package/workflows/review.md +40 -0
- package/workflows/run-audit.md +41 -0
- package/workflows/spec-challenge.md +41 -0
- package/workflows/specify.md +38 -0
- package/workflows/verify.md +37 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
# MongoDB -- Expertise Module
|
|
2
|
+
|
|
3
|
+
> A MongoDB specialist designs, implements, and operates document-oriented databases using MongoDB (8.x+).
|
|
4
|
+
> Scope covers schema design, indexing, query optimization, replication, sharding, security hardening,
|
|
5
|
+
> and operational excellence for both Atlas-managed and self-hosted deployments.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Core Patterns & Conventions
|
|
10
|
+
|
|
11
|
+
### Schema Design Patterns
|
|
12
|
+
|
|
13
|
+
**Fundamental principle:** Data that is accessed together should be stored together.
|
|
14
|
+
|
|
15
|
+
- **Embedding:** Use for one-to-few relationships where nested data is tightly coupled to the parent and always retrieved together (e.g., addresses inside a user document).
|
|
16
|
+
- **Referencing:** Use when related data is large, unbounded, accessed independently, or shared across parents.
|
|
17
|
+
- **Polymorphic pattern:** Store documents with different shapes in one collection, distinguished by a discriminator field (`type: "movie"` vs `type: "tvshow"`). Ideal for product catalogs with variable attributes.
|
|
18
|
+
- **Bucket pattern:** Group time-series/event data into fixed-size buckets (one doc per sensor per hour). Reduces document count dramatically for IoT, metrics, and logging.
|
|
19
|
+
- **Computed pattern:** Pre-compute frequently read values (averages, counts) during writes. Suited for dashboards and leaderboards where reads vastly outnumber writes.
|
|
20
|
+
- **Outlier pattern:** Flag rare documents that violate cardinality assumptions (`has_overflow: true`) and store overflow in a secondary collection.
|
|
21
|
+
- **Subset pattern:** Embed frequently accessed fields; store cold data in a separate collection. Keeps working set small.
|
|
22
|
+
|
|
23
|
+
### Collection Naming Conventions
|
|
24
|
+
|
|
25
|
+
- Lowercase, plural nouns: `users`, `orders`, `productReviews`.
|
|
26
|
+
- Dot-notation for logical grouping: `analytics.pageViews`, `analytics.sessions`.
|
|
27
|
+
- Avoid `system.*` prefix (reserved by MongoDB internals).
|
|
28
|
+
|
|
29
|
+
### Index Strategies
|
|
30
|
+
|
|
31
|
+
- **Compound indexes:** Follow ESR rule -- Equality fields first, Sort fields second, Range fields last.
|
|
32
|
+
- **Multikey indexes:** Auto-created on array fields; each element generates a separate entry. Keep arrays bounded.
|
|
33
|
+
- **Text indexes:** Legacy full-text search, one per collection. Prefer Atlas Search for production.
|
|
34
|
+
- **Atlas Search:** Lucene-based full-text + vector search. MongoDB 8.0+ adds search to Community Edition.
|
|
35
|
+
- **Partial indexes:** Index only documents matching a filter, reducing size and write overhead.
|
|
36
|
+
- **Wildcard indexes:** For unpredictable document shapes. Avoid on high-write workloads.
|
|
37
|
+
- **TTL indexes:** Auto-delete documents after a duration. Ideal for sessions and tokens.
|
|
38
|
+
|
|
39
|
+
### Aggregation Pipeline Patterns
|
|
40
|
+
|
|
41
|
+
- Place `$match` and `$project` early to reduce the working set.
|
|
42
|
+
- Use `$lookup` for left-outer joins (MongoDB 8.0+: works in transactions on sharded collections).
|
|
43
|
+
- Use `$facet` for multi-dimensional aggregations in one pass.
|
|
44
|
+
- Use `$merge`/`$out` to materialize results for downstream consumption.
|
|
45
|
+
- Avoid `$unwind` on large arrays -- prefer `$filter` to work with arrays in-place.
|
|
46
|
+
|
|
47
|
+
### Transaction Patterns (Multi-Document ACID)
|
|
48
|
+
|
|
49
|
+
Supported across replica sets (since 4.0) and sharded clusters (since 4.2). Best practices:
|
|
50
|
+
- Keep transactions under 60 seconds (`transactionLifetimeLimitSeconds`).
|
|
51
|
+
- Use `readConcern: "snapshot"` and `writeConcern: { w: "majority" }`.
|
|
52
|
+
- Use `session.withTransaction()` for automatic retry on `TransientTransactionError`.
|
|
53
|
+
- Design schema to minimize multi-document transaction needs -- embed where possible.
|
|
54
|
+
|
|
55
|
+
### Connection Management
|
|
56
|
+
|
|
57
|
+
- Create **one MongoClient per process** and reuse it. Each client maintains its own pool.
|
|
58
|
+
- Default `maxPoolSize`: 100. Tune `minPoolSize`, `maxIdleTimeMS`, `waitQueueTimeoutMS`.
|
|
59
|
+
- Use `mongodb+srv://` with Atlas for DNS seedlist discovery and failover.
|
|
60
|
+
- Enable `retryWrites: true` and `retryReads: true` (defaults since 4.2+).
|
|
61
|
+
|
|
62
|
+
### Data Modeling for Relationships
|
|
63
|
+
|
|
64
|
+
- **One-to-Few (N < ~20):** Embed children in the parent.
|
|
65
|
+
- **One-to-Many (moderate N):** Array of references in parent, or parent ref in each child.
|
|
66
|
+
- **One-to-Squillions (unbounded N):** Always reference. Never embed unbounded arrays.
|
|
67
|
+
- **Many-to-Many:** Array of references or a dedicated junction collection.
|
|
68
|
+
- **Tree structures:** Parent refs, child refs, materialized paths, or `$graphLookup` for recursive traversal.
|
|
69
|
+
|
|
70
|
+
### Change Streams
|
|
71
|
+
|
|
72
|
+
Real-time subscription to data changes, built on the oplog (write-ahead log). Key properties:
|
|
73
|
+
- **Resumable** via `resumeToken` for crash recovery.
|
|
74
|
+
- **Filterable** using aggregation pipeline stages server-side.
|
|
75
|
+
- **Pre/post images** (MongoDB 6.0+): `fullDocumentBeforeChange` captures state before modification.
|
|
76
|
+
- **Use cases:** Cache invalidation, real-time dashboards, ETL pipelines, event-driven microservices.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Anti-Patterns & Pitfalls
|
|
81
|
+
|
|
82
|
+
### 1. Unbounded Array Growth
|
|
83
|
+
Continuously pushing to arrays risks the 16 MB BSON limit. Large arrays force MongoDB to rewrite the entire document on every append, degrading write performance and bloating memory.
|
|
84
|
+
|
|
85
|
+
### 2. Bloated Documents
|
|
86
|
+
Storing everything in one document (Base64 images, full logs) forces MongoDB to load megabytes into the WiredTiger cache per read, evicting other documents and tanking performance.
|
|
87
|
+
|
|
88
|
+
### 3. Using MongoDB as a Relational Database
|
|
89
|
+
Over-normalizing into separate collections with `$lookup` joins replicates SQL patterns without SQL's join optimizer. Leads to N+1 query patterns and negates MongoDB's document model strength.
|
|
90
|
+
|
|
91
|
+
### 4. Missing Indexes (Collection Scans)
|
|
92
|
+
Queries without indexes trigger `COLLSCAN` -- reading every document. On 10M documents, that is 10M reads per query. Performance degrades linearly with collection size.
|
|
93
|
+
|
|
94
|
+
### 5. Too Many Indexes
|
|
95
|
+
Each index consumes RAM, slows writes (every mutation updates all indexes), and increases storage. Collections with 15+ indexes on write-heavy workloads see 2-3x slower writes. Use `$indexStats` to drop unused indexes.
|
|
96
|
+
|
|
97
|
+
### 6. Case-Sensitive Queries Without Collation
|
|
98
|
+
`$regex: /^john$/i` bypasses indexes. Fix: use case-insensitive collation on the collection or index.
|
|
99
|
+
|
|
100
|
+
### 7. No Schema Validation
|
|
101
|
+
Without validators, applications write malformed documents and typo-ed fields, causing silent data corruption. Define `$jsonSchema` validators on all collections.
|
|
102
|
+
|
|
103
|
+
### 8. Default Write Concern (`w: 1`)
|
|
104
|
+
Writes acknowledged by the primary only; lost if primary fails before replication. Use `w: "majority"` for critical data.
|
|
105
|
+
|
|
106
|
+
### 9. Misusing Read Preferences
|
|
107
|
+
All reads to primary creates a bottleneck. Reads from secondaries may return stale data. Use `primaryPreferred` for general workloads, `secondary` only for analytics tolerating staleness.
|
|
108
|
+
|
|
109
|
+
### 10. Storing Large Files in Documents
|
|
110
|
+
Files over a few hundred KB waste working set memory and hit the 16 MB limit. Use GridFS or store files in S3 with metadata/URLs in MongoDB.
|
|
111
|
+
|
|
112
|
+
### 11. String Dates Instead of BSON Date
|
|
113
|
+
Storing dates as strings prevents range queries, date operators, and TTL indexes. Always use `new Date()` / `ISODate()`.
|
|
114
|
+
|
|
115
|
+
### 12. Poor Shard Key Selection
|
|
116
|
+
Monotonically increasing keys (e.g., `ObjectId`) route all writes to one shard. Choose high-cardinality, evenly distributed keys. Changing shard keys post-deployment is expensive even with MongoDB 8.0+ unshard support.
|
|
117
|
+
|
|
118
|
+
### 13. New MongoClient Per Request
|
|
119
|
+
Exhausts connection limits (`~1 MB per connection` server-side), causing `connection pool exhausted` errors. Common in serverless without connection reuse.
|
|
120
|
+
|
|
121
|
+
### 14. Using `$where` / Server-Side JavaScript
|
|
122
|
+
Executes JS on the server for every scanned document, bypassing indexes. Orders of magnitude slower and opens NoSQL injection attack surface.
|
|
123
|
+
|
|
124
|
+
### 15. Deploying Without Replica Sets
|
|
125
|
+
Standalone `mongod` has no failover, no oplog, no change streams, and no transactions. Even in dev, use a single-node replica set.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Testing Strategy
|
|
130
|
+
|
|
131
|
+
### Approaches
|
|
132
|
+
1. **Unit tests:** Mock the database layer. Test business logic in isolation.
|
|
133
|
+
2. **Integration tests:** Run against a real/in-memory MongoDB. Validate validators, indexes, pipelines.
|
|
134
|
+
3. **Contract tests:** Verify app code and schema validators agree on document structure.
|
|
135
|
+
4. **Performance tests:** Run queries against production-like volumes. Use `explain()` to verify index usage.
|
|
136
|
+
|
|
137
|
+
### Testcontainers (Java, .NET, Node.js, Python, Go)
|
|
138
|
+
```java
|
|
139
|
+
@Testcontainers
|
|
140
|
+
class OrderRepositoryTest {
|
|
141
|
+
@Container
|
|
142
|
+
static MongoDBContainer mongo = new MongoDBContainer("mongo:8.0");
|
|
143
|
+
@BeforeAll
|
|
144
|
+
static void setup() { String uri = mongo.getReplicaSetUrl(); }
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
Match container version to production. Supports replica sets for transaction testing.
|
|
148
|
+
|
|
149
|
+
### mongodb-memory-server (Node.js/TypeScript)
|
|
150
|
+
Lightweight in-process `mongod` (~7 MB) without Docker:
|
|
151
|
+
```typescript
|
|
152
|
+
const mongoServer = await MongoMemoryServer.create({ binary: { version: "8.0.0" } });
|
|
153
|
+
await mongoose.connect(mongoServer.getUri());
|
|
154
|
+
// afterEach: clear collections for isolation
|
|
155
|
+
// afterAll: disconnect + stop
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Data Seeding
|
|
159
|
+
- Use factory functions (`createTestUser()`) over static JSON fixtures.
|
|
160
|
+
- Libraries: `fishery` (TS), `factory-boy` (Python). Seed with `bulkWrite` for speed.
|
|
161
|
+
|
|
162
|
+
### Migration Testing
|
|
163
|
+
- Version changes with `migrate-mongo` (Node.js). Test forward and rollback in CI.
|
|
164
|
+
- Validate against anonymized production data snapshots.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Performance Considerations
|
|
169
|
+
|
|
170
|
+
### Query Optimization
|
|
171
|
+
- Use `explain("executionStats")`: look for `IXSCAN` vs `COLLSCAN`, check `totalDocsExamined` vs `nReturned`.
|
|
172
|
+
- **Covered queries:** When filter, projection, and sort are all in a single index, MongoDB returns from the index without disk reads -- the fastest query path.
|
|
173
|
+
|
|
174
|
+
### Index Optimization
|
|
175
|
+
- **Index intersection** exists but compound indexes almost always outperform it.
|
|
176
|
+
- **Partial indexes** reduce size by indexing only matching documents.
|
|
177
|
+
- **Wildcard indexes** (`{ "attrs.$**": 1 }`) for unpredictable field names.
|
|
178
|
+
- Monitor index size via `db.collection.stats()`. Indexes exceeding available RAM cause dramatic slowdowns.
|
|
179
|
+
|
|
180
|
+
### Working Set & Memory
|
|
181
|
+
- Working set should fit in WiredTiger cache (default: 50% RAM - 1 GB).
|
|
182
|
+
- Monitor: `db.serverStatus().wiredTiger.cache`. Alert if cache hit ratio < 95%.
|
|
183
|
+
|
|
184
|
+
### Sharding
|
|
185
|
+
**Shard key criteria:** High cardinality, low frequency, non-monotonic, present in most queries.
|
|
186
|
+
- **Hashed sharding:** Even write distribution, no range queries on shard key.
|
|
187
|
+
- **Ranged sharding:** Supports range queries, risks hotspots with monotonic keys.
|
|
188
|
+
- **Zone sharding:** Pin data to shards by region or classification.
|
|
189
|
+
|
|
190
|
+
### Read/Write Concern Tradeoffs
|
|
191
|
+
|
|
192
|
+
| Concern | Durability | Latency | Use Case |
|
|
193
|
+
|---------|-----------|---------|----------|
|
|
194
|
+
| `w: 1` | Primary only | Fastest | Non-critical logs |
|
|
195
|
+
| `w: "majority"` | Replicated | Moderate | Financial data |
|
|
196
|
+
| `readConcern: "majority"` | Committed | Moderate | Consistent reads |
|
|
197
|
+
| `readConcern: "linearizable"` | Strongest | Highest | Distributed consensus |
|
|
198
|
+
|
|
199
|
+
### Atlas Performance Advisor
|
|
200
|
+
Analyzes slow queries (>100ms), recommends indexes, identifies unused indexes and schema anti-patterns.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Security Considerations
|
|
205
|
+
|
|
206
|
+
### Authentication
|
|
207
|
+
- **SCRAM-SHA-256** (default): Username/password. Rotate regularly.
|
|
208
|
+
- **X.509:** Mutual TLS for machine-to-machine auth.
|
|
209
|
+
- **LDAP/AD:** Centralized enterprise authentication.
|
|
210
|
+
- **AWS IAM:** Available on Atlas.
|
|
211
|
+
|
|
212
|
+
### Role-Based Access Control
|
|
213
|
+
- Enable auth (`security.authorization: enabled`). Principle of least privilege.
|
|
214
|
+
- Built-in roles: `read`, `readWrite`, `dbAdmin`, `clusterAdmin`. Create custom roles for fine-grained access.
|
|
215
|
+
- Never use `root` for application connections.
|
|
216
|
+
|
|
217
|
+
### Field-Level Encryption
|
|
218
|
+
- **CSFLE:** Encrypts fields client-side before transmission. Deterministic (equality queries) or random encryption. Key management via AWS KMS, Azure Key Vault, GCP KMS. Mongoose 8.15+ native support.
|
|
219
|
+
- **Queryable Encryption (QE):** Supports equality (7.0+) and range queries (8.0+) on encrypted fields. Preferred for new applications. Cannot mix with CSFLE on the same collection.
|
|
220
|
+
|
|
221
|
+
### Network Security
|
|
222
|
+
- Enable TLS for all communication (`net.tls.mode: requireTLS`).
|
|
223
|
+
- Atlas: use VPC peering or AWS PrivateLink. Restrict via IP access lists.
|
|
224
|
+
- Never bind to `0.0.0.0` without firewall rules.
|
|
225
|
+
|
|
226
|
+
### Audit Logging
|
|
227
|
+
Enable `auditLog.destination: file` (Enterprise/Atlas). Route to SIEM for SOC 2, HIPAA, PCI-DSS compliance.
|
|
228
|
+
|
|
229
|
+
### NoSQL Injection Prevention
|
|
230
|
+
- Never concatenate user input into queries. Cast to expected types: `String(req.body.username)`.
|
|
231
|
+
- Use `express-mongo-sanitize` to strip `$`-prefixed keys.
|
|
232
|
+
- Disable server-side JS: `security.javascriptEnabled: false`.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Integration Patterns
|
|
237
|
+
|
|
238
|
+
### Driver Patterns
|
|
239
|
+
```javascript
|
|
240
|
+
// Node.js (mongodb 6.x+) -- reuse one client across all requests
|
|
241
|
+
const client = new MongoClient(uri, { maxPoolSize: 50, retryWrites: true, w: "majority" });
|
|
242
|
+
```
|
|
243
|
+
```python
|
|
244
|
+
# Python (PyMongo 4.x+)
|
|
245
|
+
client = MongoClient(uri, maxPoolSize=50, retryWrites=True, w="majority")
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Mongoose vs. Native Driver
|
|
249
|
+
|
|
250
|
+
| Aspect | Mongoose 8.x+ | Native Driver |
|
|
251
|
+
|--------|---------------|---------------|
|
|
252
|
+
| Schema enforcement | Built-in types + validation | Manual JSON Schema |
|
|
253
|
+
| Middleware hooks | `pre`/`post` save, validate | Not available |
|
|
254
|
+
| Performance | ~2x slower for basic ops | Baseline |
|
|
255
|
+
| Aggregation | Leaky abstraction | First-class |
|
|
256
|
+
|
|
257
|
+
**Use Mongoose** for complex domain models with validation and hooks. **Use native driver** for high-throughput microservices, aggregation-heavy workloads, and serverless (cold start sensitivity).
|
|
258
|
+
|
|
259
|
+
### Atlas Search Integration
|
|
260
|
+
```javascript
|
|
261
|
+
const results = await collection.aggregate([
|
|
262
|
+
{ $search: { index: "default", compound: {
|
|
263
|
+
must: [{ text: { query: "wireless headphones", path: "title" } }],
|
|
264
|
+
filter: [{ range: { path: "price", gte: 20, lte: 200 } }]
|
|
265
|
+
}}},
|
|
266
|
+
{ $limit: 20 },
|
|
267
|
+
{ $project: { title: 1, price: 1, score: { $meta: "searchScore" } } }
|
|
268
|
+
]).toArray();
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Atlas Triggers
|
|
272
|
+
- **Database triggers:** Respond to CRUD events. Forward to AWS EventBridge or run functions.
|
|
273
|
+
- **Scheduled triggers:** Cron-based periodic tasks.
|
|
274
|
+
- Note: Atlas Functions deprecated late 2025 in favor of AWS Lambda / Azure Functions.
|
|
275
|
+
|
|
276
|
+
### Change Streams for Event-Driven Architecture
|
|
277
|
+
Pattern: change stream -> Kafka/RabbitMQ -> downstream consumers. Persist `resumeToken` for crash recovery. Use `fullDocumentBeforeChange` (6.0+) for audit trails.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## DevOps & Deployment
|
|
282
|
+
|
|
283
|
+
### Atlas vs. Self-Managed
|
|
284
|
+
|
|
285
|
+
| Aspect | Atlas | Self-Managed |
|
|
286
|
+
|--------|-------|-------------|
|
|
287
|
+
| Setup | Minutes (UI/CLI/Terraform) | Hours to days |
|
|
288
|
+
| Maintenance | Automated patches + upgrades | Manual upgrades + OS patches |
|
|
289
|
+
| Backup | Continuous with PIT recovery | mongodump, oplog, or Percona Backup |
|
|
290
|
+
| Cost at scale | Higher | Lower (factor in ops team cost) |
|
|
291
|
+
| Compliance | SOC 2, HIPAA, PCI-DSS ready | DIY |
|
|
292
|
+
|
|
293
|
+
### Replica Set Configuration
|
|
294
|
+
- Minimum 3 members (1 primary + 2 secondaries) for failover.
|
|
295
|
+
- Use `priority: 0` for hidden secondaries dedicated to analytics/backups.
|
|
296
|
+
- Use `votes: 0` for cross-region DR nodes.
|
|
297
|
+
|
|
298
|
+
### Backup Strategies
|
|
299
|
+
- **Atlas:** Automated continuous backup with PIT recovery.
|
|
300
|
+
- **mongodump:** Use `--oplog` for consistency. Run against secondaries. Suitable for < 100 GB.
|
|
301
|
+
- **Filesystem snapshots:** Fastest for large datasets. Requires atomic capture of data + journal.
|
|
302
|
+
- **Percona Backup (PBM):** Open-source, physical/logical backups, S3 storage.
|
|
303
|
+
- **Test restores monthly.** Monitor backup jobs; silent failures are common.
|
|
304
|
+
|
|
305
|
+
### Monitoring
|
|
306
|
+
Key metrics: opcounters, replication lag (alert > 10s), connections, WiredTiger cache ratio, lock contention, read/write tickets.
|
|
307
|
+
Tools: `mongostat`, `mongotop`, Atlas Performance Panel, Prometheus + `mongodb_exporter`, Datadog.
|
|
308
|
+
|
|
309
|
+
### Version Upgrades
|
|
310
|
+
Upgrade secondaries first, step down primary, upgrade last. Set `featureCompatibilityVersion` incrementally.
|
|
311
|
+
MongoDB 8.0: 25% better throughput, 54% faster bulk inserts, range queries on encrypted fields, cross-collection `bulkWrite`.
|
|
312
|
+
|
|
313
|
+
### Docker for Development
|
|
314
|
+
```yaml
|
|
315
|
+
services:
|
|
316
|
+
mongodb:
|
|
317
|
+
image: mongo:8.0
|
|
318
|
+
command: ["--replSet", "rs0", "--bind_ip_all"]
|
|
319
|
+
ports: ["27017:27017"]
|
|
320
|
+
volumes: [mongo-data:/data/db]
|
|
321
|
+
mongo-init:
|
|
322
|
+
image: mongo:8.0
|
|
323
|
+
depends_on: { mongodb: { condition: service_healthy } }
|
|
324
|
+
entrypoint: mongosh --host mongodb --eval "rs.initiate({ _id:'rs0', members:[{_id:0,host:'mongodb:27017'}] })"
|
|
325
|
+
restart: "no"
|
|
326
|
+
volumes:
|
|
327
|
+
mongo-data:
|
|
328
|
+
```
|
|
329
|
+
Always use a replica set in dev for transactions, change streams, and full feature access.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Decision Trees
|
|
334
|
+
|
|
335
|
+
### 1. MongoDB vs. PostgreSQL
|
|
336
|
+
```
|
|
337
|
+
Flexible/evolving schema with variable document shapes?
|
|
338
|
+
YES -> Deep nesting / hierarchical? -> YES: MongoDB
|
|
339
|
+
-> NO: Could JSONB work? -> YES: PostgreSQL
|
|
340
|
+
-> NO: MongoDB
|
|
341
|
+
NO -> Complex multi-table JOINs needed? -> YES: PostgreSQL
|
|
342
|
+
-> Write-heavy (IoT, logs, time-series)? -> YES: MongoDB (sharding + buckets)
|
|
343
|
+
-> Heavy ACID across many entities? -> YES: PostgreSQL
|
|
344
|
+
-> Otherwise: choose based on team expertise
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### 2. Embedding vs. Referencing
|
|
348
|
+
```
|
|
349
|
+
Data always accessed with parent?
|
|
350
|
+
YES -> Cardinality bounded (< ~100)? -> Updated independently? -> YES: Reference
|
|
351
|
+
-> NO: EMBED
|
|
352
|
+
-> Unbounded? -> REFERENCE (16MB limit)
|
|
353
|
+
-> Bounded but large -> Subset pattern
|
|
354
|
+
NO -> Shared across parents? -> YES: REFERENCE (avoid duplication)
|
|
355
|
+
-> Accessed independently -> REFERENCE
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### 3. Atlas vs. Self-Hosted
|
|
359
|
+
```
|
|
360
|
+
Dedicated DB ops team? -> NO: Atlas
|
|
361
|
+
-> YES -> Budget-constrained? -> YES: Self-hosted
|
|
362
|
+
-> Multi-region with minimal config? -> YES: Atlas
|
|
363
|
+
-> Air-gapped / strict data residency? -> YES: Self-hosted
|
|
364
|
+
-> Startup / rapid prototyping? -> YES: Atlas (free tier)
|
|
365
|
+
-> Otherwise: evaluate TCO including ops staff
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Code Examples
|
|
371
|
+
|
|
372
|
+
### 1. Schema Validation (mongosh)
|
|
373
|
+
```javascript
|
|
374
|
+
db.createCollection("products", { validator: { $jsonSchema: {
|
|
375
|
+
bsonType: "object",
|
|
376
|
+
required: ["name", "price", "category", "createdAt"],
|
|
377
|
+
properties: {
|
|
378
|
+
name: { bsonType: "string", minLength: 1, maxLength: 200 },
|
|
379
|
+
price: { bsonType: "decimal", minimum: 0 },
|
|
380
|
+
category: { enum: ["electronics", "clothing", "books", "home"] },
|
|
381
|
+
tags: { bsonType: "array", maxItems: 20, items: { bsonType: "string" } },
|
|
382
|
+
specs: { bsonType: "object" },
|
|
383
|
+
createdAt: { bsonType: "date" }
|
|
384
|
+
}
|
|
385
|
+
}}, validationLevel: "strict", validationAction: "error" });
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### 2. Index Creation (ESR Rule)
|
|
389
|
+
```javascript
|
|
390
|
+
// Query: active orders for user, sorted by date, with date range
|
|
391
|
+
// ESR: Equality (userId, status) -> Sort (createdAt) -> Range (covered by createdAt)
|
|
392
|
+
db.orders.createIndex({ userId: 1, status: 1, createdAt: -1 }, { name: "idx_user_status_date" });
|
|
393
|
+
// Partial index: exclude archived orders
|
|
394
|
+
db.orders.createIndex({ userId: 1, createdAt: -1 },
|
|
395
|
+
{ partialFilterExpression: { status: { $ne: "archived" } } });
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### 3. Aggregation Pipeline
|
|
399
|
+
```javascript
|
|
400
|
+
const revenue = await db.collection("orders").aggregate([
|
|
401
|
+
{ $match: { status: "completed", completedAt: { $gte: new Date("2026-01-01"), $lt: new Date("2026-04-01") } } },
|
|
402
|
+
{ $unwind: "$items" },
|
|
403
|
+
{ $group: { _id: "$items.category", total: { $sum: "$items.totalPrice" }, count: { $sum: 1 } } },
|
|
404
|
+
{ $sort: { total: -1 } },
|
|
405
|
+
{ $project: { category: "$_id", total: { $round: ["$total", 2] }, count: 1, _id: 0 } }
|
|
406
|
+
]).toArray();
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### 4. Transaction with Auto-Retry (Node.js)
|
|
410
|
+
```javascript
|
|
411
|
+
async function transferFunds(client, fromId, toId, amount) {
|
|
412
|
+
const session = client.startSession();
|
|
413
|
+
try {
|
|
414
|
+
await session.withTransaction(async () => {
|
|
415
|
+
const accts = client.db("bank").collection("accounts");
|
|
416
|
+
const src = await accts.findOneAndUpdate(
|
|
417
|
+
{ _id: fromId, balance: { $gte: amount } },
|
|
418
|
+
{ $inc: { balance: -amount } }, { session, returnDocument: "after" });
|
|
419
|
+
if (!src) throw new Error("Insufficient funds");
|
|
420
|
+
await accts.updateOne({ _id: toId }, { $inc: { balance: amount } }, { session });
|
|
421
|
+
await client.db("bank").collection("transfers").insertOne(
|
|
422
|
+
{ from: fromId, to: toId, amount, timestamp: new Date() }, { session });
|
|
423
|
+
}, { readConcern: { level: "snapshot" }, writeConcern: { w: "majority" } });
|
|
424
|
+
} finally { session.endSession(); }
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### 5. Change Stream with Resume Token
|
|
429
|
+
```javascript
|
|
430
|
+
async function watchOrders(db) {
|
|
431
|
+
const tokens = db.collection("resumeTokens");
|
|
432
|
+
const saved = await tokens.findOne({ _id: "orders-watcher" });
|
|
433
|
+
const opts = { fullDocument: "updateLookup", ...(saved?.token && { resumeAfter: saved.token }) };
|
|
434
|
+
const stream = db.collection("orders").watch(
|
|
435
|
+
[{ $match: { operationType: { $in: ["insert", "update"] } } }], opts);
|
|
436
|
+
stream.on("change", async (evt) => {
|
|
437
|
+
console.log(`Order ${evt.fullDocument._id}: ${evt.operationType}`);
|
|
438
|
+
await tokens.updateOne({ _id: "orders-watcher" },
|
|
439
|
+
{ $set: { token: evt._id, updatedAt: new Date() } }, { upsert: true });
|
|
440
|
+
});
|
|
441
|
+
stream.on("error", () => setTimeout(() => watchOrders(db), 5000));
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
*Researched: 2026-03-07 | Sources: [MongoDB Official Docs](https://www.mongodb.com/docs/manual/), [MongoDB Schema Design Best Practices](https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/), [MongoDB Building With Patterns](https://www.mongodb.com/company/blog/building-with-patterns-a-summary), [Schema Design Anti-Patterns](https://www.mongodb.com/docs/manual/data-modeling/design-antipatterns/), [MongoDB 8.0 Release Notes](https://www.mongodb.com/docs/manual/release-notes/8.0/), [Performance Best Practices](https://www.mongodb.com/resources/products/capabilities/performance-best-practices), [CSFLE Docs](https://www.mongodb.com/docs/manual/core/csfle/), [Queryable Encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption/about-qe-csfle/), [Mongoose QE/CSFLE](https://www.mongodb.com/company/blog/product-release-announcements/mongoose-now-natively-supports-qe-csfle), [Connection Pools](https://www.mongodb.com/docs/manual/administration/connection-pool-overview/), [Change Streams](https://www.mongodb.com/docs/manual/changestreams/), [Testcontainers MongoDB](https://testcontainers.com/modules/mongodb/), [mongodb-memory-server](https://blog.appsignal.com/2025/06/18/testing-mongodb-in-node-with-the-mongodb-memory-server.html), [Percona Sharding](https://www.percona.com/blog/when-should-i-enable-mongodb-sharding/), [Backup Best Practices](https://www.percona.com/blog/mongodb-backup-best-practices/), [Atlas vs Self-Hosted](https://thedbadmin.com/blog/mongodb-atlas-vs-self-hosted-comparison), [MongoDB vs PostgreSQL 2026](https://thesoftwarescout.com/mongodb-vs-postgresql-2026-which-database-should-you-choose/)*
|