@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,770 @@
|
|
|
1
|
+
# Coupling and Cohesion -- Architecture Expertise Module
|
|
2
|
+
|
|
3
|
+
> Coupling measures the degree of interdependence between software modules; cohesion measures
|
|
4
|
+
> how strongly the elements within a single module belong together. Together they form the
|
|
5
|
+
> oldest and most empirically validated heuristic in software design: strive for low coupling
|
|
6
|
+
> between modules and high cohesion within them.
|
|
7
|
+
|
|
8
|
+
> **Category:** Foundation
|
|
9
|
+
> **Complexity:** Moderate
|
|
10
|
+
> **Applies when:** You are defining module boundaries, designing APIs, splitting or merging services, or evaluating whether a codebase is healthy enough to evolve safely.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## What This Is (and What It Isn't)
|
|
15
|
+
|
|
16
|
+
### Definitions
|
|
17
|
+
|
|
18
|
+
**Coupling** is the degree to which one module depends on the internals, behavior, or
|
|
19
|
+
identity of another module. High coupling means a change in module A forces a change in
|
|
20
|
+
module B. Low coupling means modules can evolve, deploy, and be tested independently.
|
|
21
|
+
|
|
22
|
+
**Cohesion** is the degree to which the elements inside a single module (functions, data
|
|
23
|
+
structures, classes) are related and work toward a single, well-defined responsibility.
|
|
24
|
+
High cohesion means everything in the module belongs together. Low cohesion means the
|
|
25
|
+
module is a grab-bag of unrelated concerns.
|
|
26
|
+
|
|
27
|
+
Larry Constantine and Edward Yourdon formalized these concepts in *Structured Design* (1979).
|
|
28
|
+
They remain the primary design-quality heuristics across paradigms: procedural, object-oriented,
|
|
29
|
+
functional, and service-oriented.
|
|
30
|
+
|
|
31
|
+
### Types of Coupling (Worst to Best)
|
|
32
|
+
|
|
33
|
+
The classical taxonomy orders coupling types from tightest (most harmful) to loosest (most
|
|
34
|
+
desirable):
|
|
35
|
+
|
|
36
|
+
| Type | Description | Example | Severity |
|
|
37
|
+
|------|-------------|---------|----------|
|
|
38
|
+
| **Content coupling** | Module A directly accesses or modifies the internals of module B (private fields, internal branches, memory locations). | A Ruby class reaching into another class via `instance_variable_get` to read a private field. | Critical |
|
|
39
|
+
| **Common coupling** | Multiple modules read/write the same global mutable state. | Two services writing to the same database table without coordination; multiple modules sharing a global config dictionary they all mutate. | High |
|
|
40
|
+
| **Control coupling** | Module A passes a flag or control parameter that tells module B *what to do* internally. | `render(data, format="pdf")` where the `format` flag controls branching inside `render`. | Moderate |
|
|
41
|
+
| **Stamp coupling** | Modules share a composite data structure but each uses only a subset of it. | Passing an entire `User` object to a function that only needs `user.email`. | Moderate |
|
|
42
|
+
| **Data coupling** | Modules communicate only through well-defined parameters, each of which is necessary. | `calculateTax(income, taxRate)` -- both parameters are needed, nothing extra is passed. | Low |
|
|
43
|
+
| **Message coupling** | Modules communicate only through messages (events, commands) with no knowledge of each other's identity. | An `OrderPlaced` event published to a message bus; any subscriber can react without the publisher knowing who they are. | Minimal |
|
|
44
|
+
|
|
45
|
+
### Types of Cohesion (Worst to Best)
|
|
46
|
+
|
|
47
|
+
| Type | Description | Example | Quality |
|
|
48
|
+
|------|-------------|---------|---------|
|
|
49
|
+
| **Coincidental** | Elements are grouped arbitrarily with no meaningful relationship. | A `Utilities` class containing `formatDate()`, `compressImage()`, and `sendEmail()`. | Worst |
|
|
50
|
+
| **Logical** | Elements perform similar *categories* of operations but are otherwise unrelated. | An `InputHandler` that reads from files, sockets, and stdin in the same module. | Poor |
|
|
51
|
+
| **Temporal** | Elements are grouped because they execute at the same time. | A `startup()` function that initializes the logger, opens the DB connection, and loads config. | Poor |
|
|
52
|
+
| **Procedural** | Elements are grouped because they follow a specific sequence of execution. | A module that validates input, then transforms it, then saves it, but these steps serve different business concerns. | Fair |
|
|
53
|
+
| **Communicational** | Elements operate on the same data or contribute to the same output. | A module that reads customer data, calculates their credit score, and generates a credit report -- all using the same customer record. | Good |
|
|
54
|
+
| **Sequential** | The output of one element is the input of the next, forming a data pipeline. | An ETL module where `extract()` feeds `transform()` feeds `load()`. | Good |
|
|
55
|
+
| **Functional** | Every element contributes to a single, well-defined task. Nothing is extraneous. | An `AuthenticationService` whose every method relates to authenticating users: `login()`, `logout()`, `verifyToken()`, `refreshToken()`. | Best |
|
|
56
|
+
|
|
57
|
+
### What It Is NOT
|
|
58
|
+
|
|
59
|
+
- **Not a binary choice.** Coupling is a spectrum, not a switch. The goal is not zero coupling
|
|
60
|
+
(that would mean modules never communicate) but *appropriate* coupling at the *right level*
|
|
61
|
+
of abstraction.
|
|
62
|
+
- **Not about the number of dependencies.** A module with 20 dependencies via narrow,
|
|
63
|
+
stable interfaces can be less coupled than a module with 2 dependencies via wide, volatile
|
|
64
|
+
internal APIs.
|
|
65
|
+
- **Not the same as DRY.** Eliminating duplication by sharing code can *increase* coupling.
|
|
66
|
+
Sometimes duplicating a small piece of logic across two modules is healthier than creating
|
|
67
|
+
a shared dependency between them (see "When NOT to Use It").
|
|
68
|
+
- **Not only about code.** Coupling exists in deployment pipelines, database schemas, team
|
|
69
|
+
structures (Conway's Law), and even release schedules. Cohesion applies to teams, APIs,
|
|
70
|
+
and data models, not just classes.
|
|
71
|
+
|
|
72
|
+
### Connascence: The Modern Refinement
|
|
73
|
+
|
|
74
|
+
Meilir Page-Jones extended the coupling concept with **connascence** -- a more granular
|
|
75
|
+
framework for classifying dependencies. Connascence evaluates three dimensions:
|
|
76
|
+
|
|
77
|
+
- **Strength:** How difficult is the dependency to refactor? (Name < Type < Meaning < Position < Algorithm < Execution < Timing < Value < Identity)
|
|
78
|
+
- **Locality:** How close are the coupled components in the codebase?
|
|
79
|
+
- **Degree:** How many components are affected?
|
|
80
|
+
|
|
81
|
+
The rule of thumb: prefer *weaker* connascence, keep *strong* connascence *local*, and reduce
|
|
82
|
+
the *degree* of any connascence. Connascence of Name (two modules agree on a function name)
|
|
83
|
+
is far cheaper than Connascence of Timing (two modules must execute in a precise temporal order).
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## When to Use It
|
|
88
|
+
|
|
89
|
+
Coupling and cohesion analysis is not situational -- it applies to every design decision. But
|
|
90
|
+
certain scenarios make it especially critical.
|
|
91
|
+
|
|
92
|
+
### 1. Service Boundary Definition
|
|
93
|
+
|
|
94
|
+
When decomposing a monolith or designing a new distributed system, coupling analysis determines
|
|
95
|
+
whether two capabilities should live in the same service or separate services.
|
|
96
|
+
|
|
97
|
+
**Evidence -- Netflix:** Netflix's migration from a monolithic Java application to 700+
|
|
98
|
+
microservices succeeded because each service was designed around a bounded context with its
|
|
99
|
+
own data store, eliminating shared database coupling. Each service manages its own data store,
|
|
100
|
+
so schema changes in the recommendation engine cannot break the billing service.
|
|
101
|
+
|
|
102
|
+
**Evidence -- Shopify:** Shopify chose a **modular monolith** over microservices specifically
|
|
103
|
+
because they determined that the coupling between their commerce components (catalog, checkout,
|
|
104
|
+
payments) was too high to justify network boundaries. Code handling different business processes
|
|
105
|
+
was reorganized into modules with enforced boundaries within a single deployable, avoiding
|
|
106
|
+
the latency and reliability costs of inter-service HTTP calls while still achieving logical
|
|
107
|
+
decoupling.
|
|
108
|
+
|
|
109
|
+
### 2. API and Interface Design
|
|
110
|
+
|
|
111
|
+
When designing public APIs, SDKs, or inter-module contracts, coupling analysis guides you
|
|
112
|
+
toward narrow, stable interfaces. The Interface Segregation Principle (ISP) is a direct
|
|
113
|
+
application: prefer many small, role-specific interfaces over one large general-purpose
|
|
114
|
+
interface.
|
|
115
|
+
|
|
116
|
+
**Evidence -- Stripe:** Stripe's API stability is legendary in the industry. They achieve
|
|
117
|
+
it through data coupling (pass only what is needed) and versioning that lets old consumers
|
|
118
|
+
keep working while new consumers get new capabilities. Their API never exposes internal
|
|
119
|
+
data structures (avoiding stamp coupling).
|
|
120
|
+
|
|
121
|
+
### 3. Database Schema Design
|
|
122
|
+
|
|
123
|
+
When multiple modules access the same database, coupling analysis determines whether tables
|
|
124
|
+
should be shared, replicated, or owned exclusively by one module.
|
|
125
|
+
|
|
126
|
+
**Evidence -- Capital One:** Capital One's engineering team documented that shared databases
|
|
127
|
+
are one of the most dangerous forms of coupling in microservices architectures. Their
|
|
128
|
+
recommendation: each service owns its data and exposes it only through APIs. Changes to one
|
|
129
|
+
service's schema cannot inadvertently break another service.
|
|
130
|
+
|
|
131
|
+
### 4. Team Topology and Organizational Design
|
|
132
|
+
|
|
133
|
+
Conway's Law states that system structure mirrors organizational structure. Coupling analysis
|
|
134
|
+
applied to team boundaries helps ensure that tightly coupled code is owned by the same team,
|
|
135
|
+
and loosely coupled code can be owned by independent teams.
|
|
136
|
+
|
|
137
|
+
**Evidence -- Spotify:** Spotify's squad-and-tribe model was designed so that each squad owned
|
|
138
|
+
a functionally cohesive service. However, over time, duplication of infrastructure and
|
|
139
|
+
inconsistency in developer experience created friction. Their solution was Backstage, an
|
|
140
|
+
internal developer portal that centralized service catalogs and documentation, providing a
|
|
141
|
+
shared platform layer (low coupling to individual squads, high cohesion within the platform).
|
|
142
|
+
|
|
143
|
+
### 5. Refactoring and Technical Debt Remediation
|
|
144
|
+
|
|
145
|
+
Coupling metrics (CBO, afferent/efferent coupling, LCOM4) are the primary indicators of
|
|
146
|
+
where refactoring will have the highest ROI. Modules with high coupling are the riskiest
|
|
147
|
+
to change and the most expensive to test.
|
|
148
|
+
|
|
149
|
+
**Evidence -- SonarQube/CodeScene studies:** Empirical studies across 13 open-source projects
|
|
150
|
+
found that bug-fix commits disproportionately touched high-coupling, low-cohesion modules.
|
|
151
|
+
The correlation between CBO (Coupling Between Objects) values above 14 and defect density
|
|
152
|
+
was statistically significant across all studied projects.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## When NOT to Use It
|
|
157
|
+
|
|
158
|
+
The pursuit of loose coupling can become a pathology of its own. Here are the cases where
|
|
159
|
+
decoupling is the wrong move.
|
|
160
|
+
|
|
161
|
+
### 1. Over-Decoupling: The Distributed Monolith
|
|
162
|
+
|
|
163
|
+
When teams decompose a system into too many services with too-fine boundaries, they replace
|
|
164
|
+
in-process function calls with network calls -- gaining all the failure modes of distributed
|
|
165
|
+
systems (latency, partial failure, serialization overhead) while retaining the coupling they
|
|
166
|
+
were trying to escape.
|
|
167
|
+
|
|
168
|
+
**Evidence -- Amazon Prime Video (2023):** Amazon's Prime Video team had built their
|
|
169
|
+
audio/video monitoring service as a distributed system using AWS Step Functions. The
|
|
170
|
+
components were architecturally decoupled but *operationally* coupled: the media converter
|
|
171
|
+
and defect detector had to exchange large volumes of data through S3. Moving to a single
|
|
172
|
+
process (monolith) reduced infrastructure costs by over 90% because in-process communication
|
|
173
|
+
eliminated the serialization, network transfer, and storage costs. The components were
|
|
174
|
+
inherently tightly coupled by data flow; forcing them apart created overhead without
|
|
175
|
+
independence.
|
|
176
|
+
|
|
177
|
+
### 2. The Nano-Service Anti-Pattern
|
|
178
|
+
|
|
179
|
+
Splitting a system into hundreds of tiny services where each encapsulates only a trivial
|
|
180
|
+
piece of functionality destroys cohesion at the service level while creating a web of
|
|
181
|
+
inter-service dependencies.
|
|
182
|
+
|
|
183
|
+
**Anti-pattern indicators:**
|
|
184
|
+
- Services with fewer than 3 API endpoints
|
|
185
|
+
- Services that cannot be tested without mocking 5+ other services
|
|
186
|
+
- A single user-facing operation requires orchestrating 10+ service calls
|
|
187
|
+
- Teams spend more time on inter-service coordination than on business logic
|
|
188
|
+
|
|
189
|
+
**Evidence -- Industry surveys:** The DesignGurus analysis of microservice anti-patterns found
|
|
190
|
+
that over-fragmented systems experience exponential growth in operational complexity:
|
|
191
|
+
orchestration, distributed transactions, service discovery, circuit breaking, and distributed
|
|
192
|
+
tracing all become mandatory infrastructure for trivially simple business operations.
|
|
193
|
+
|
|
194
|
+
### 3. Premature Abstraction for "Future Flexibility"
|
|
195
|
+
|
|
196
|
+
Introducing interfaces, abstract factories, dependency injection containers, and event buses
|
|
197
|
+
*before* there is a demonstrated need creates accidental complexity. Each abstraction layer is
|
|
198
|
+
a form of indirection that makes the code harder to trace, debug, and understand.
|
|
199
|
+
|
|
200
|
+
**Rule of thumb (Rule of Three):** Do not abstract until you have at least three concrete
|
|
201
|
+
implementations. Until then, the direct dependency is simpler and cheaper.
|
|
202
|
+
|
|
203
|
+
**Evidence:** Martin Fowler's guidance: "When you get a new requirement that applies to
|
|
204
|
+
only some of the existing code, duplication is cheaper than the wrong abstraction." Sandi
|
|
205
|
+
Metz formalized this as "duplication is far cheaper than the wrong abstraction" (2014).
|
|
206
|
+
|
|
207
|
+
### 4. When Performance Requires Tight Coupling
|
|
208
|
+
|
|
209
|
+
In-process function calls are 1,000x to 1,000,000x faster than cross-network calls. For
|
|
210
|
+
latency-sensitive paths (real-time rendering, high-frequency trading, game loops, ML inference
|
|
211
|
+
pipelines), decoupling across process or network boundaries is unacceptable.
|
|
212
|
+
|
|
213
|
+
**Evidence -- High-Performance Computing (AWS):** AWS's Well-Architected Framework explicitly
|
|
214
|
+
distinguishes tightly coupled HPC workloads (molecular dynamics, weather simulation, CFD)
|
|
215
|
+
that require shared-memory or high-speed interconnects from loosely coupled workloads
|
|
216
|
+
(parameter sweeps, Monte Carlo simulations) that can use message queues. Choosing the wrong
|
|
217
|
+
coupling model for HPC can degrade performance by orders of magnitude.
|
|
218
|
+
|
|
219
|
+
### 5. When DRY Creates Coupling
|
|
220
|
+
|
|
221
|
+
Extracting shared libraries to avoid code duplication between services creates a deployment
|
|
222
|
+
coupling: every service using the shared library must be updated, tested, and redeployed
|
|
223
|
+
when the library changes. This is especially dangerous for cross-cutting concerns like
|
|
224
|
+
serialization formats or data models.
|
|
225
|
+
|
|
226
|
+
**Evidence -- The "I Was Taught to Share" anti-pattern:** In microservices, sharing a common
|
|
227
|
+
library for domain models means that a change to the shared model requires coordinated
|
|
228
|
+
deployment of every consumer. The recommendation: duplicate the model in each service and
|
|
229
|
+
let each service's model evolve independently, using anti-corruption layers at the boundaries.
|
|
230
|
+
|
|
231
|
+
### 6. When Coupling Aligns with Team Structure
|
|
232
|
+
|
|
233
|
+
If a single team owns two modules that are naturally tightly coupled, forcing them apart into
|
|
234
|
+
separate services adds coordination overhead (API versioning, network reliability, separate
|
|
235
|
+
deployment pipelines) without organizational benefit. The coupling is managed implicitly by
|
|
236
|
+
the team's shared context.
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## How It Works
|
|
241
|
+
|
|
242
|
+
### Measuring Coupling
|
|
243
|
+
|
|
244
|
+
**Afferent Coupling (Ca):** The number of modules that depend *on* this module. High Ca
|
|
245
|
+
means the module is heavily used -- changes are risky because many consumers will be affected.
|
|
246
|
+
|
|
247
|
+
**Efferent Coupling (Ce):** The number of modules that this module depends *on*. High Ce
|
|
248
|
+
means the module has many dependencies -- it is fragile because changes in any dependency
|
|
249
|
+
can break it.
|
|
250
|
+
|
|
251
|
+
**Instability (I):** `I = Ce / (Ca + Ce)`. Ranges from 0 (maximally stable, many dependents,
|
|
252
|
+
few dependencies) to 1 (maximally unstable, few dependents, many dependencies). Robert C.
|
|
253
|
+
Martin's Stable Dependencies Principle says: depend in the direction of stability. Unstable
|
|
254
|
+
modules should depend on stable modules, not the reverse.
|
|
255
|
+
|
|
256
|
+
**Coupling Between Objects (CBO):** For OO systems, CBO counts the number of classes to
|
|
257
|
+
which a given class is coupled. SonarQube flags classes with CBO > 14 as high-risk.
|
|
258
|
+
|
|
259
|
+
**Distance from Main Sequence (D):** `D = |A + I - 1|` where A = abstractness (ratio of
|
|
260
|
+
abstract classes to total classes in a package). Packages near D=0 are in the "sweet spot";
|
|
261
|
+
packages near D=1 are in the "zone of pain" (too concrete and too stable) or the "zone of
|
|
262
|
+
uselessness" (too abstract and too unstable).
|
|
263
|
+
|
|
264
|
+
### Measuring Cohesion
|
|
265
|
+
|
|
266
|
+
**LCOM (Lack of Cohesion of Methods):** Several variants exist. LCOM4 builds a graph where
|
|
267
|
+
nodes are methods and edges connect methods that share instance variables. The number of
|
|
268
|
+
connected components is the LCOM4 value. LCOM4 = 1 means perfect cohesion; LCOM4 > 1 means
|
|
269
|
+
the class should probably be split into that many classes.
|
|
270
|
+
|
|
271
|
+
**Relational Cohesion (H):** `H = (R + 1) / N` where R = number of internal relationships
|
|
272
|
+
and N = number of types in the module. Values between 1.5 and 4.0 are considered healthy.
|
|
273
|
+
|
|
274
|
+
### Tools for Measurement
|
|
275
|
+
|
|
276
|
+
| Tool | Language Support | Key Metrics |
|
|
277
|
+
|------|-----------------|-------------|
|
|
278
|
+
| **SonarQube** | 30+ languages | CBO, LCOM, afferent/efferent coupling, cyclomatic complexity |
|
|
279
|
+
| **NDepend** | .NET | Instability, abstractness, distance from main sequence, coupling graph |
|
|
280
|
+
| **CodeScene** | Language-agnostic (git-based) | Temporal coupling (files that change together), hotspot analysis |
|
|
281
|
+
| **JDepend / JArchitect** | Java | Package-level coupling, dependency cycles |
|
|
282
|
+
| **Structure101** | Java, .NET, C++ | Architecture-level coupling, layering violations |
|
|
283
|
+
| **deptrac** | PHP | Layer and class coupling enforcement |
|
|
284
|
+
| **Madge** | JavaScript/TypeScript | Module dependency graphs, circular dependency detection |
|
|
285
|
+
|
|
286
|
+
### Interface Design Techniques for Loose Coupling
|
|
287
|
+
|
|
288
|
+
1. **Dependency Inversion Principle (DIP):** High-level modules depend on abstractions, not
|
|
289
|
+
concrete implementations. This is the single most effective technique for reducing coupling
|
|
290
|
+
in OO systems. Introduce an interface at the boundary; let both sides depend on the
|
|
291
|
+
interface rather than on each other.
|
|
292
|
+
|
|
293
|
+
2. **Event-Driven Architecture:** Replace synchronous call chains with asynchronous events.
|
|
294
|
+
The publisher does not know who subscribes. This converts control/stamp coupling into
|
|
295
|
+
message coupling.
|
|
296
|
+
|
|
297
|
+
3. **Anti-Corruption Layer (ACL):** When integrating with an external system whose API is
|
|
298
|
+
volatile or poorly designed, wrap it in a translation layer. Changes to the external
|
|
299
|
+
system are absorbed by the ACL, not propagated to your domain.
|
|
300
|
+
|
|
301
|
+
4. **API Gateway / Backend for Frontend (BFF):** In microservices, a gateway decouples
|
|
302
|
+
clients from internal service topology. Clients couple to the gateway; the gateway
|
|
303
|
+
couples to services. Adding or removing services does not change client code.
|
|
304
|
+
|
|
305
|
+
5. **Contract Testing:** Tools like Pact verify that the producer's API satisfies the
|
|
306
|
+
consumer's expectations without requiring end-to-end integration tests. This reduces
|
|
307
|
+
temporal coupling (you do not need both services running simultaneously to verify
|
|
308
|
+
compatibility).
|
|
309
|
+
|
|
310
|
+
### Module Boundary Heuristics
|
|
311
|
+
|
|
312
|
+
- **Information Hiding (Parnas, 1972):** Each module hides a design decision that is likely
|
|
313
|
+
to change. The interface exposes only what is stable.
|
|
314
|
+
- **Single Responsibility Principle:** A module should have one and only one reason to change.
|
|
315
|
+
If it has two reasons, it has two responsibilities and should be two modules.
|
|
316
|
+
- **Common Closure Principle:** Classes that change together belong together. This is the
|
|
317
|
+
package-level equivalent of SRP.
|
|
318
|
+
- **Common Reuse Principle:** Classes that are used together belong together. Do not force
|
|
319
|
+
consumers to depend on things they do not use.
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## Trade-Offs Matrix
|
|
324
|
+
|
|
325
|
+
| You Get | You Pay |
|
|
326
|
+
|---------|---------|
|
|
327
|
+
| Independent deployability of services | Network latency, serialization overhead, distributed failure modes |
|
|
328
|
+
| Independent team ownership | API versioning discipline, contract testing infrastructure |
|
|
329
|
+
| Technology heterogeneity (each service picks its own stack) | Operational complexity: multiple build systems, monitoring stacks, deployment pipelines |
|
|
330
|
+
| Isolated failure domains (one service crashes, others survive) | Distributed transaction complexity (sagas, eventual consistency) |
|
|
331
|
+
| Easier reasoning about individual modules | Harder reasoning about system-wide behavior and data consistency |
|
|
332
|
+
| Testability of individual modules in isolation | Integration test complexity; mocking explosion |
|
|
333
|
+
| Freedom to refactor internals without breaking consumers | Upfront cost of designing stable interfaces; risk of premature abstraction |
|
|
334
|
+
| Ability to scale services independently | Infrastructure overhead: container orchestration, service mesh, observability |
|
|
335
|
+
| Reduced blast radius of bugs | Increased surface area for integration bugs, data inconsistency |
|
|
336
|
+
| Higher cohesion within modules | Risk of duplicated logic across modules if taken too far |
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Evolution Path
|
|
341
|
+
|
|
342
|
+
### Stage 1: Monolith with No Boundaries
|
|
343
|
+
- Everything in one deployment unit
|
|
344
|
+
- Coupling is invisible -- any module can call any other module's internals
|
|
345
|
+
- Cohesion is accidental -- code is organized by technical layer (controllers, services, repos)
|
|
346
|
+
rather than by business capability
|
|
347
|
+
- **Signal to move on:** Changes require touching 5+ files across unrelated features; test
|
|
348
|
+
suite takes 30+ minutes; teams step on each other's code daily
|
|
349
|
+
|
|
350
|
+
### Stage 2: Modular Monolith
|
|
351
|
+
- Single deployment unit, but code is organized into modules with enforced boundaries
|
|
352
|
+
- Public API surfaces defined per module; private internals hidden behind access rules
|
|
353
|
+
- Database tables owned by modules (schema-level isolation or at least naming conventions)
|
|
354
|
+
- Shopify's architecture: modules enforced by custom linting rules in a single Rails app
|
|
355
|
+
- **Signal to move on:** Independent scaling requirements emerge; team count exceeds what
|
|
356
|
+
a single repo and deployment pipeline can support (typically 8-15 teams)
|
|
357
|
+
|
|
358
|
+
### Stage 3: Macroservices / Coarse-Grained Services
|
|
359
|
+
- 5-15 services, each owning a major business domain (orders, inventory, users, payments)
|
|
360
|
+
- Async communication via events for most cross-service workflows
|
|
361
|
+
- Synchronous APIs only for real-time queries
|
|
362
|
+
- **Signal to move on:** Individual services become monoliths themselves; sub-domains within
|
|
363
|
+
a service need independent scaling or deployment cadences
|
|
364
|
+
|
|
365
|
+
### Stage 4: Fine-Grained Microservices
|
|
366
|
+
- 50-500+ services, each owning a bounded context
|
|
367
|
+
- Full operational infrastructure: service mesh, distributed tracing, centralized logging,
|
|
368
|
+
contract testing, saga orchestration
|
|
369
|
+
- Netflix, Uber, and Amazon operate at this level -- but with platform teams providing
|
|
370
|
+
shared infrastructure to reduce per-service operational burden
|
|
371
|
+
- **Signal to reconsider:** Operational costs exceed feature-development costs; developer
|
|
372
|
+
productivity drops because every feature requires coordinating across 10+ services
|
|
373
|
+
|
|
374
|
+
### Stage 5: Selective Re-Consolidation
|
|
375
|
+
- Merge tightly coupled fine-grained services back into coarser units where the coupling
|
|
376
|
+
analysis warrants it
|
|
377
|
+
- Keep independent, high-scale services separate
|
|
378
|
+
- Amazon Prime Video's 2023 move is the canonical example of this stage
|
|
379
|
+
- **The mature insight:** The optimal architecture is not at either extreme; it is a
|
|
380
|
+
heterogeneous mix of coupling levels chosen per-boundary based on data, not dogma
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## Failure Modes
|
|
385
|
+
|
|
386
|
+
### 1. Distributed Monolith
|
|
387
|
+
**Symptoms:** All services must be deployed together; a change in one service requires
|
|
388
|
+
synchronized changes in 3+ other services; shared database with no schema ownership.
|
|
389
|
+
**Root cause:** Services were decomposed along technical layers (API service, business logic
|
|
390
|
+
service, data service) instead of business capabilities. The coupling was never addressed --
|
|
391
|
+
it was just made more expensive by adding network hops.
|
|
392
|
+
**Fix:** Re-analyze bounded contexts using domain-driven design; merge services that share
|
|
393
|
+
a domain; introduce anti-corruption layers at true domain boundaries.
|
|
394
|
+
|
|
395
|
+
### 2. God Module / God Class
|
|
396
|
+
**Symptoms:** One module has CBO > 30 and LCOM4 > 5; it contains 3,000+ lines; every feature
|
|
397
|
+
branch touches it; merge conflicts are daily.
|
|
398
|
+
**Root cause:** Insufficient attention to SRP; the module accumulated responsibilities over
|
|
399
|
+
years of "just add it here, it's easiest."
|
|
400
|
+
**Fix:** Identify responsibility clusters using LCOM4 analysis; extract each cluster into its
|
|
401
|
+
own module; define narrow interfaces between them.
|
|
402
|
+
|
|
403
|
+
### 3. Leaky Abstraction
|
|
404
|
+
**Symptoms:** Consumers of a module depend on its implementation details (specific exception
|
|
405
|
+
types, internal data formats, execution order). Changes to internals break consumers.
|
|
406
|
+
**Root cause:** The interface was designed by exposing existing internals rather than by
|
|
407
|
+
modeling the consumer's needs.
|
|
408
|
+
**Fix:** Redesign the interface from the consumer's perspective (consumer-driven contracts);
|
|
409
|
+
introduce an ACL if the internal model must differ from the public contract.
|
|
410
|
+
|
|
411
|
+
### 4. Coupling Through Data
|
|
412
|
+
**Symptoms:** Two services use the same database table; changes to a column break the other
|
|
413
|
+
service; data consistency requires distributed locks.
|
|
414
|
+
**Root cause:** Data ownership was never defined; the database was treated as an integration
|
|
415
|
+
mechanism rather than as a private implementation detail.
|
|
416
|
+
**Fix:** Assign table ownership to one service; other services access that data through APIs
|
|
417
|
+
or event streams (CDC -- Change Data Capture).
|
|
418
|
+
|
|
419
|
+
### 5. Coupling Through Time (Temporal Coupling)
|
|
420
|
+
**Symptoms:** System behavior depends on the order in which services process events; race
|
|
421
|
+
conditions appear under load; initialization order matters.
|
|
422
|
+
**Root cause:** Implicit assumptions about execution timing; synchronous call chains that
|
|
423
|
+
create cascading timeouts.
|
|
424
|
+
**Fix:** Design for idempotency and out-of-order processing; use event sourcing with explicit
|
|
425
|
+
ordering guarantees where needed; replace synchronous chains with choreography.
|
|
426
|
+
|
|
427
|
+
### 6. Accidental Coupling Through Shared Libraries
|
|
428
|
+
**Symptoms:** Updating a shared library requires redeploying 15 services; version conflicts
|
|
429
|
+
create dependency hell; teams avoid updating the library because of blast radius.
|
|
430
|
+
**Root cause:** A shared library was used to enforce DRY across service boundaries, creating
|
|
431
|
+
deployment coupling.
|
|
432
|
+
**Fix:** Inline the shared code into each service (accept duplication); or extract the shared
|
|
433
|
+
functionality into a standalone service with a stable API.
|
|
434
|
+
|
|
435
|
+
### 7. Test Coupling
|
|
436
|
+
**Symptoms:** Unit tests require extensive mocking of collaborators; integration test
|
|
437
|
+
environments are unreliable; test suites take hours.
|
|
438
|
+
**Root cause:** Production code has high coupling, and tests mirror that coupling. Alternatively,
|
|
439
|
+
tests are coupled to implementation details rather than behavior.
|
|
440
|
+
**Fix:** Refactor production code to reduce coupling; adopt contract testing (Pact) to
|
|
441
|
+
decouple service-level tests; test behavior through public interfaces, not internal methods.
|
|
442
|
+
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
## Technology Landscape
|
|
446
|
+
|
|
447
|
+
### Languages and Frameworks Supporting Loose Coupling
|
|
448
|
+
|
|
449
|
+
| Technology | Coupling Mechanisms | Cohesion Support |
|
|
450
|
+
|------------|-------------------|------------------|
|
|
451
|
+
| **Java (Spring)** | DI container, interface-based wiring, Spring Events | Package-private access, module system (JPMS since Java 9) |
|
|
452
|
+
| **C# (.NET)** | DI container, interface segregation, MediatR for CQRS | Internal access modifier, assembly-level boundaries |
|
|
453
|
+
| **TypeScript/Node** | ES modules, dependency injection (NestJS, InversifyJS) | Barrel exports controlling public surface |
|
|
454
|
+
| **Go** | Implicit interfaces, package-level encapsulation | Internal packages (unexported by convention) |
|
|
455
|
+
| **Rust** | Traits, module visibility (`pub`, `pub(crate)`) | Crate boundaries, strong ownership model |
|
|
456
|
+
| **Python** | Duck typing, ABC, dependency injection (injector, dependency-injector) | `__all__` exports, package structure |
|
|
457
|
+
| **Elixir/Erlang** | Actor model (processes), behaviours, message passing | OTP applications as cohesive units |
|
|
458
|
+
|
|
459
|
+
### Infrastructure for Decoupling
|
|
460
|
+
|
|
461
|
+
| Category | Tools | Purpose |
|
|
462
|
+
|----------|-------|---------|
|
|
463
|
+
| **Message Brokers** | Kafka, RabbitMQ, NATS, AWS SNS/SQS, Google Pub/Sub | Async event-driven decoupling between services |
|
|
464
|
+
| **API Gateways** | Kong, Envoy, AWS API Gateway, Traefik | Decouple clients from service topology |
|
|
465
|
+
| **Service Mesh** | Istio, Linkerd, Consul Connect | Decouple networking concerns from application code |
|
|
466
|
+
| **Schema Registry** | Confluent Schema Registry, AWS Glue | Decouple producers from consumers via versioned schemas |
|
|
467
|
+
| **Contract Testing** | Pact, Spring Cloud Contract | Decouple service testing from integration environments |
|
|
468
|
+
| **Feature Flags** | LaunchDarkly, Unleash, Flagsmith | Decouple deployment from release (temporal decoupling) |
|
|
469
|
+
| **CDC (Change Data Capture)** | Debezium, AWS DMS | Decouple data consumers from database internals |
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## Decision Tree
|
|
474
|
+
|
|
475
|
+
Use this decision tree when deciding how tightly or loosely to couple two components A and B.
|
|
476
|
+
|
|
477
|
+
```
|
|
478
|
+
START: Components A and B need to communicate.
|
|
479
|
+
|
|
480
|
+
1. Do A and B belong to the same bounded context / business capability?
|
|
481
|
+
|
|
|
482
|
+
+-- YES --> Do they share the same data model?
|
|
483
|
+
| |
|
|
484
|
+
| +-- YES --> Keep them in the same module/service.
|
|
485
|
+
| | Use in-process function calls (data coupling).
|
|
486
|
+
| | High cohesion achieved.
|
|
487
|
+
| |
|
|
488
|
+
| +-- NO --> Separate modules within the same service.
|
|
489
|
+
| Communicate via internal interfaces.
|
|
490
|
+
| Consider: will they ever need independent scaling?
|
|
491
|
+
| |
|
|
492
|
+
| +-- YES --> Plan for future extraction; define clean API now.
|
|
493
|
+
| +-- NO --> Keep co-located; enforce module boundaries with
|
|
494
|
+
| access modifiers / linting.
|
|
495
|
+
|
|
|
496
|
+
+-- NO --> 2. Do A and B need synchronous, real-time interaction?
|
|
497
|
+
|
|
|
498
|
+
+-- YES --> 3. Is the latency budget < 10ms?
|
|
499
|
+
| |
|
|
500
|
+
| +-- YES --> Keep in same process (tight coupling acceptable
|
|
501
|
+
| | for performance). Use interfaces for testability.
|
|
502
|
+
| |
|
|
503
|
+
| +-- NO --> Separate services with synchronous API.
|
|
504
|
+
| Use contract testing. Define SLAs.
|
|
505
|
+
| Consider circuit breakers for resilience.
|
|
506
|
+
|
|
|
507
|
+
+-- NO --> 4. Can the interaction be eventually consistent?
|
|
508
|
+
|
|
|
509
|
+
+-- YES --> Use async events (message coupling).
|
|
510
|
+
| Publisher emits domain events.
|
|
511
|
+
| Subscriber reacts independently.
|
|
512
|
+
| Loosest coupling achievable.
|
|
513
|
+
|
|
|
514
|
+
+-- NO --> 5. Is strong consistency required across A and B?
|
|
515
|
+
|
|
|
516
|
+
+-- YES --> Consider:
|
|
517
|
+
| a) Merge A and B into one service
|
|
518
|
+
| (accept tight coupling to get ACID).
|
|
519
|
+
| b) Use Saga pattern (accept complexity
|
|
520
|
+
| to keep services separate).
|
|
521
|
+
| Choose (a) unless independent scaling
|
|
522
|
+
| or team ownership requires (b).
|
|
523
|
+
|
|
|
524
|
+
+-- NO --> Re-examine requirements.
|
|
525
|
+
"Not eventually consistent but not
|
|
526
|
+
strongly consistent" usually means
|
|
527
|
+
the requirement is under-specified.
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Quick Coupling-Level Selector
|
|
531
|
+
|
|
532
|
+
| Situation | Recommended Coupling Level |
|
|
533
|
+
|-----------|--------------------------|
|
|
534
|
+
| Same team, same bounded context, same scaling needs | In-process (tight) |
|
|
535
|
+
| Same team, different bounded contexts | Module boundaries within monolith |
|
|
536
|
+
| Different teams, synchronous data needs | Service API with contract tests |
|
|
537
|
+
| Different teams, asynchronous workflows | Event-driven (message coupling) |
|
|
538
|
+
| Third-party integration | Anti-corruption layer + adapter pattern |
|
|
539
|
+
| Performance-critical inner loop | Direct coupling (no abstraction overhead) |
|
|
540
|
+
| Rapidly changing domain model | Duplicated models with ACL at boundary |
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
## Implementation Sketch
|
|
545
|
+
|
|
546
|
+
### Example: Refactoring from Common Coupling to Data Coupling
|
|
547
|
+
|
|
548
|
+
**Before (Common Coupling -- shared global state):**
|
|
549
|
+
```python
|
|
550
|
+
# Shared mutable global -- any module can read/write
|
|
551
|
+
app_state = {"user": None, "cart": [], "session_token": ""}
|
|
552
|
+
|
|
553
|
+
# Module A
|
|
554
|
+
def login(username, password):
|
|
555
|
+
app_state["user"] = authenticate(username, password)
|
|
556
|
+
app_state["session_token"] = generate_token()
|
|
557
|
+
|
|
558
|
+
# Module B
|
|
559
|
+
def add_to_cart(item):
|
|
560
|
+
if not app_state["user"]: # reads global state set by Module A
|
|
561
|
+
raise AuthError("Not logged in")
|
|
562
|
+
app_state["cart"].append(item)
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
**After (Data Coupling -- explicit parameters):**
|
|
566
|
+
```python
|
|
567
|
+
# Module A -- returns data, does not mutate globals
|
|
568
|
+
def login(username, password) -> Session:
|
|
569
|
+
user = authenticate(username, password)
|
|
570
|
+
token = generate_token(user)
|
|
571
|
+
return Session(user=user, token=token)
|
|
572
|
+
|
|
573
|
+
# Module B -- receives only what it needs
|
|
574
|
+
def add_to_cart(cart: Cart, item: Item, user: User) -> Cart:
|
|
575
|
+
if not user:
|
|
576
|
+
raise AuthError("Not logged in")
|
|
577
|
+
return cart.add(item)
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### Example: Refactoring from Control Coupling to Polymorphism
|
|
581
|
+
|
|
582
|
+
**Before (Control Coupling -- flag parameter):**
|
|
583
|
+
```typescript
|
|
584
|
+
function exportReport(data: ReportData, format: "pdf" | "csv" | "html"): Buffer {
|
|
585
|
+
if (format === "pdf") {
|
|
586
|
+
return renderPdf(data);
|
|
587
|
+
} else if (format === "csv") {
|
|
588
|
+
return renderCsv(data);
|
|
589
|
+
} else if (format === "html") {
|
|
590
|
+
return renderHtml(data);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
**After (Data Coupling via Strategy pattern):**
|
|
596
|
+
```typescript
|
|
597
|
+
interface ReportRenderer {
|
|
598
|
+
render(data: ReportData): Buffer;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
class PdfRenderer implements ReportRenderer {
|
|
602
|
+
render(data: ReportData): Buffer { /* ... */ }
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
class CsvRenderer implements ReportRenderer {
|
|
606
|
+
render(data: ReportData): Buffer { /* ... */ }
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function exportReport(data: ReportData, renderer: ReportRenderer): Buffer {
|
|
610
|
+
return renderer.render(data);
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### Example: Event-Driven Decoupling (Message Coupling)
|
|
615
|
+
|
|
616
|
+
**Before (Direct service-to-service call):**
|
|
617
|
+
```python
|
|
618
|
+
# OrderService directly calls InventoryService and NotificationService
|
|
619
|
+
class OrderService:
|
|
620
|
+
def place_order(self, order):
|
|
621
|
+
self.inventory_service.reserve(order.items) # synchronous
|
|
622
|
+
self.notification_service.send_confirmation(order) # synchronous
|
|
623
|
+
self.analytics_service.track_order(order) # synchronous
|
|
624
|
+
return order
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
**After (Event-driven -- publisher knows nothing about subscribers):**
|
|
628
|
+
```python
|
|
629
|
+
class OrderService:
|
|
630
|
+
def place_order(self, order):
|
|
631
|
+
order.status = "placed"
|
|
632
|
+
self.repository.save(order)
|
|
633
|
+
self.event_bus.publish(OrderPlaced(
|
|
634
|
+
order_id=order.id,
|
|
635
|
+
items=order.items,
|
|
636
|
+
customer_id=order.customer_id
|
|
637
|
+
))
|
|
638
|
+
return order
|
|
639
|
+
|
|
640
|
+
# Separate services subscribe independently:
|
|
641
|
+
# InventoryService subscribes to OrderPlaced -> reserves stock
|
|
642
|
+
# NotificationService subscribes to OrderPlaced -> sends email
|
|
643
|
+
# AnalyticsService subscribes to OrderPlaced -> tracks metrics
|
|
644
|
+
# OrderService has zero knowledge of any of these subscribers.
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
### Example: Anti-Corruption Layer for External System
|
|
648
|
+
|
|
649
|
+
```python
|
|
650
|
+
# External payment provider with volatile, poorly-designed API
|
|
651
|
+
class LegacyPaymentGateway:
|
|
652
|
+
def doPayment(self, amt, curr, crd_num, crd_exp, crd_cvv, merch_id, ...):
|
|
653
|
+
# 15 positional parameters, changes every quarter
|
|
654
|
+
...
|
|
655
|
+
|
|
656
|
+
# Anti-Corruption Layer -- translates between your domain and the external API
|
|
657
|
+
class PaymentAdapter:
|
|
658
|
+
def __init__(self, gateway: LegacyPaymentGateway):
|
|
659
|
+
self._gateway = gateway
|
|
660
|
+
|
|
661
|
+
def charge(self, payment: Payment) -> PaymentResult:
|
|
662
|
+
"""Clean interface your domain uses. Absorbs external API volatility."""
|
|
663
|
+
raw_result = self._gateway.doPayment(
|
|
664
|
+
amt=payment.amount.cents,
|
|
665
|
+
curr=payment.amount.currency.value,
|
|
666
|
+
crd_num=payment.card.number,
|
|
667
|
+
crd_exp=payment.card.expiry.strftime("%m/%y"),
|
|
668
|
+
crd_cvv=payment.card.cvv,
|
|
669
|
+
merch_id=self._merchant_id,
|
|
670
|
+
...
|
|
671
|
+
)
|
|
672
|
+
return PaymentResult.from_raw(raw_result)
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
### Architecture Fitness Functions for Coupling
|
|
676
|
+
|
|
677
|
+
Automate coupling checks in CI/CD to prevent regression:
|
|
678
|
+
|
|
679
|
+
```yaml
|
|
680
|
+
# Example: ArchUnit test (Java) -- enforce layering rules
|
|
681
|
+
architecture_rules:
|
|
682
|
+
- name: "No domain-to-infrastructure coupling"
|
|
683
|
+
rule: "classes in package '..domain..' should not depend on '..infrastructure..'"
|
|
684
|
+
|
|
685
|
+
- name: "No cross-module direct access"
|
|
686
|
+
rule: "classes in package '..orders.internal..' should only be accessed by '..orders..'"
|
|
687
|
+
|
|
688
|
+
- name: "Maximum CBO per class"
|
|
689
|
+
threshold: 14
|
|
690
|
+
tool: sonarqube
|
|
691
|
+
|
|
692
|
+
- name: "No circular dependencies between packages"
|
|
693
|
+
tool: jdepend
|
|
694
|
+
assertion: "cycles == 0"
|
|
695
|
+
|
|
696
|
+
- name: "LCOM4 per class"
|
|
697
|
+
threshold: 1
|
|
698
|
+
tool: sonarqube
|
|
699
|
+
note: "LCOM4 > 1 suggests class should be split"
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
## Cross-References
|
|
705
|
+
|
|
706
|
+
- **[separation-of-concerns](../foundations/separation-of-concerns.md):** The philosophical
|
|
707
|
+
foundation -- coupling/cohesion are the *measurable* manifestation of separation of concerns.
|
|
708
|
+
- **[microservices](../patterns/microservices.md):** Service boundaries are coupling boundaries;
|
|
709
|
+
microservices trade in-process coupling for network-level coupling.
|
|
710
|
+
- **[modular-monolith](../patterns/modular-monolith.md):** Achieves logical decoupling without
|
|
711
|
+
physical decoupling; Shopify's preferred approach for high-coupling domains.
|
|
712
|
+
- **[hexagonal-clean-architecture](../patterns/hexagonal-clean-architecture.md):** Ports and
|
|
713
|
+
adapters enforce dependency inversion, ensuring domain logic has zero coupling to
|
|
714
|
+
infrastructure.
|
|
715
|
+
- **[domain-driven-design](../patterns/domain-driven-design.md):** Bounded contexts are the
|
|
716
|
+
primary tool for identifying natural low-coupling seams in a system.
|
|
717
|
+
|
|
718
|
+
---
|
|
719
|
+
|
|
720
|
+
## Key Takeaways
|
|
721
|
+
|
|
722
|
+
1. **Coupling is a spectrum, not a binary.** The goal is not zero coupling but *appropriate*
|
|
723
|
+
coupling -- tight where performance or simplicity demands it, loose where independent
|
|
724
|
+
evolution or team autonomy matters.
|
|
725
|
+
|
|
726
|
+
2. **Cohesion is the other half.** Low coupling without high cohesion produces scattered
|
|
727
|
+
systems where related logic is spread across many modules. Always optimize both together.
|
|
728
|
+
|
|
729
|
+
3. **Measure, do not guess.** Tools like SonarQube, CodeScene, and NDepend provide objective
|
|
730
|
+
coupling/cohesion metrics. Use them as fitness functions in CI/CD to prevent regression.
|
|
731
|
+
|
|
732
|
+
4. **The most expensive coupling is invisible.** Database coupling, temporal coupling, and
|
|
733
|
+
deployment coupling are harder to detect than code-level coupling but cause more production
|
|
734
|
+
incidents.
|
|
735
|
+
|
|
736
|
+
5. **Duplication is sometimes cheaper than coupling.** When two services share a data model
|
|
737
|
+
via a library, they are deployment-coupled. Duplicating the model and translating at the
|
|
738
|
+
boundary may be the healthier choice.
|
|
739
|
+
|
|
740
|
+
6. **Amazon Prime Video's lesson:** The right answer is sometimes *more* coupling, not less.
|
|
741
|
+
When components share heavy data flows, putting them in the same process can reduce costs
|
|
742
|
+
by 90% compared to distributing them.
|
|
743
|
+
|
|
744
|
+
7. **Conway's Law is real.** Coupling between code should mirror coupling between teams. If
|
|
745
|
+
two teams must coordinate on every release, their code is effectively coupled regardless
|
|
746
|
+
of what the architecture diagram says.
|
|
747
|
+
|
|
748
|
+
---
|
|
749
|
+
|
|
750
|
+
*Researched: 2026-03-08 | Sources:*
|
|
751
|
+
- *[Coupling (Wikipedia)](https://en.wikipedia.org/wiki/Coupling_(computer_programming))*
|
|
752
|
+
- *[GeeksforGeeks: Coupling and Cohesion](https://www.geeksforgeeks.org/software-engineering/software-engineering-coupling-and-cohesion/)*
|
|
753
|
+
- *[ByteByteGo: Coupling and Cohesion Principles](https://blog.bytebytego.com/p/coupling-and-cohesion-the-two-principles)*
|
|
754
|
+
- *[Wix Engineering: Low Coupling, High Cohesion](https://medium.com/wix-engineering/what-exactly-does-low-coupling-high-cohesion-mean-9259e8225372)*
|
|
755
|
+
- *[CodeOpinion: Loosely Coupled Monolith 2025](https://codeopinion.com/loosely-coupled-monolith-software-architecture-2025-edition/)*
|
|
756
|
+
- *[Enterprise Craftsmanship: Cohesion and Coupling](https://enterprisecraftsmanship.com/posts/cohesion-coupling-difference/)*
|
|
757
|
+
- *[Capital One: Avoiding Coupling in Microservices](https://www.capitalone.com/tech/software-engineering/how-to-avoid-loose-coupled-microservices/)*
|
|
758
|
+
- *[Amazon Prime Video Monolith Case Study](https://devclass.com/2023/05/05/reduce-costs-by-90-by-moving-from-microservices-to-monolith-amazon-internal-case-study-raises-eyebrows/)*
|
|
759
|
+
- *[Shopify: Deconstructing the Monolith](https://shopify.engineering/deconstructing-monolith-designing-software-maximizes-developer-productivity)*
|
|
760
|
+
- *[Netflix Microservices Lessons (F5/NGINX)](https://www.f5.com/company/blog/nginx/microservices-at-netflix-architectural-best-practices)*
|
|
761
|
+
- *[Spotify Backstage and Squad Model](https://www.netguru.com/blog/scaling-microservices)*
|
|
762
|
+
- *[Google Monorepo Strategy](https://medium.com/@sohail_saifi/the-monorepo-strategy-that-scaled-google-to-2-billion-lines-of-code-cb3eb59f02d4)*
|
|
763
|
+
- *[Connascence (Wikipedia)](https://en.wikipedia.org/wiki/Connascence)*
|
|
764
|
+
- *[Beyond Basic Coupling: Understanding Connascence](https://medium.com/@mohamedsallam953/beyond-basic-coupling-understanding-connascence-to-build-truly-robust-systems-e3151999df94)*
|
|
765
|
+
- *[TechTarget: Software Coupling Metrics](https://www.techtarget.com/searchapparchitecture/tip/The-basics-of-software-coupling-metrics-and-concepts)*
|
|
766
|
+
- *[Codurance: Thoughts on Coupling](https://www.codurance.com/publications/software-creation/2016/07/25/thoughts-on-coupling-in-software-design)*
|
|
767
|
+
- *[DesignGurus: 10 Common Microservices Anti-Patterns](https://www.designgurus.io/blog/10-common-microservices-anti-patterns)*
|
|
768
|
+
- *[AWS Well-Architected: HPC Tightly Coupled Scenarios](https://docs.aws.amazon.com/wellarchitected/latest/high-performance-computing-lens/tightly-coupled-scenarios.html)*
|
|
769
|
+
- *[The Valuable Dev: Cohesion and Coupling Guide](https://thevaluable.dev/cohesion-coupling-guide-examples/)*
|
|
770
|
+
- *[Microservices Anti-Patterns: "I Was Taught to Share"](https://l-lin.github.io/architecture/microservice/microservices-antipatterns-and-pitfalls/microservices-antipatterns-and-pitfalls---i-was-taught-to-share-antipattern)*
|