Skip to content
acc-check-bounded-contexts logo

Bounded Contexts Analyzer

acc-check-bounded-contexts

Analyzes bounded context boundaries in DDD projects. Detects cross-context coupling, shared kernel violations, context mapping issues, and ubiquitous language inconsistencies. Generates context map diagrams and boundary recommendations.

SKILL.md

Full skill instructions

Bounded Contexts Analyzer

Overview

This skill analyzes PHP DDD projects for bounded context boundary issues, cross-context coupling, and context mapping violations.

Bounded Context Concepts

ConceptDefinitionViolation Indicator
Bounded ContextExplicit boundary with its own domain modelMissing namespace separation
Ubiquitous LanguageConsistent terminology within contextSame term, different meanings
Context MapRelationships between contextsUnclear dependencies
Anti-Corruption LayerTranslation between contextsDirect foreign model usage
Shared KernelDeliberately shared codeUnintentional sharing
Published LanguagePublic API contractsBreaking changes

Detection Patterns

Phase 1: Context Discovery

# Identify bounded contexts from directory structure
Glob: **/​src/​**/​Domain/​*
Glob: **/​src/​**/​Context/​*
Glob: **/​src/​**/​Bounded/​*
Glob: **/​src/​**/​Module/​*

# Namespace-based contexts
Grep: "namespace.*\\\\Domain\\\\|namespace.*\\\\Context\\\\" --glob "**/​*.php"

# Composer autoload namespaces
Read: composer.json (check autoload paths for context namespaces)

Context Indicators:

  • Top-level namespace under src/ (e.g., Order, User, Payment)
  • Explicit Domain/ subfolder per context
  • BoundedContext/ or Context/ folder structure

Phase 2: Cross-Context Coupling Detection

Direct Cross-Context Imports
# Find cross-context imports (most critical)
# Pattern: Context A importing from Context B's Domain layer

# Order context importing User domain
Grep: "use Order\\\\.*\\\\Domain" --glob "**/​User/​**/​*.php"
Grep: "use User\\\\.*\\\\Domain" --glob "**/​Order/​**/​*.php"

# General pattern: Domain layer importing another Domain
Grep: "use [A-Z][a-z]+\\\\Domain\\\\" --glob "**/​Domain/​**/​*.php"

# Direct entity references across contexts
Grep: "use.*\\\\Entity\\\\(?!.*\\\\self)" --glob "**/​Domain/​**/​*.php"
Foreign Aggregate References
# Aggregates referencing foreign entities directly
Grep: "private.*[A-Z][a-z]+Entity\|private readonly [A-Z][a-z]+" --glob "**/​Aggregate/​**/​*.php"

# Should use ID references only
# Good: private UserId $userId
# Bad: private User $user (from another context)

# Detect direct object references vs ID references
Grep: "\\$user[^I]|\\$order[^I]|\\$customer[^I]" --glob "**/​Domain/​**/​*.php"
Shared Repository Usage
# Repository from one context used in another
Grep: "UserRepositoryInterface" --glob "**/​Order/​**/​*.php"
Grep: "OrderRepositoryInterface" --glob "**/​User/​**/​*.php"

# Generic repository pattern violations
Grep: "RepositoryInterface" --glob "**/​*.php"
# Check if implementations span contexts

Phase 3: Shared Kernel Analysis

# Identify potential shared kernel (common code between contexts)
Glob: **/​Shared/​**/​*.php
Glob: **/​Common/​**/​*.php
Glob: **/​Core/​**/​*.php
Glob: **/​SharedKernel/​**/​*.php

# Find duplicated Value Objects across contexts
# Same class name in multiple contexts
Glob: **/​Domain/​**/​Email.php
Glob: **/​Domain/​**/​Money.php
Glob: **/​Domain/​**/​Address.php

# Shared events
Grep: "class.*Event.*implements|extends.*Event" --glob "**/​Shared/​**/​*.php"

Shared Kernel Rules:

  • Must be explicitly designated
  • Minimal and stable
  • Changes require agreement from all context owners
  • Should contain only Value Objects, not Entities

Phase 4: Context Map Relationships

Upstream/​Downstream Detection
# Event publishers (upstream)
Grep: "EventDispatcher|MessageBus|publish\(" --glob "**/​Domain/​**/​*.php"
Grep: "class.*Event\s*\{|final readonly class.*Event" --glob "**/​Domain/​**/​*.php"

# Event subscribers (downstream)
Grep: "EventSubscriber|MessageHandler|Listener" --glob "**/​*.php"
Grep: "function __invoke\(.*Event" --glob "**/​*.php"

# Check which context publishes and which subscribes
Customer/​Supplier Relationships
# API clients (customer role)
Grep: "ApiClient|HttpClient|RestClient" --glob "**/​Infrastructure/​**/​*.php"

# API providers (supplier role)
Grep: "Controller|Action|Endpoint" --glob "**/​Presentation/​**/​*.php"
Anti-Corruption Layer Detection
# ACL presence
Glob: **/​AntiCorruption/​**/​*.php
Glob: **/​ACL/​**/​*.php
Glob: **/​Adapter/​**/​*.php
Glob: **/​Translator/​**/​*.php

# Missing ACL (direct external model usage)
Grep: "use External\\\\|use ThirdParty\\\\|use Legacy\\\\" --glob "**/​Domain/​**/​*.php"

Phase 5: Ubiquitous Language Analysis

# Find same term with different meanings
# Example: "Account" in User context vs Payment context

# Find class with same name in different contexts
Glob: **/​User/​**/​Account.php
Glob: **/​Payment/​**/​Account.php
Glob: **/​Billing/​**/​Account.php

# Find similar entity names
Glob: **/​Domain/​**/​User.php
Glob: **/​Domain/​**/​Customer.php
Glob: **/​Domain/​**/​Client.php

# Inconsistent naming
Grep: "class Order|class Purchase|class Sale" --glob "**/​Domain/​**/​*.php"

Report Format

# Bounded Context Analysis Report

## Context Map

```mermaid
graph TB
    subgraph "Order Context"
        O_Domain[Domain]
        O_App[Application]
    end

    subgraph "User Context"
        U_Domain[Domain]
        U_App[Application]
    end

    subgraph "Payment Context"
        P_Domain[Domain]
        P_App[Application]
    end

    subgraph "Shared Kernel"
        SK[Money, Currency]
    end

    O_Domain -->|"uses ID only"| U_Domain
    O_Domain -->|"publishes events"| P_Domain
    O_Domain --> SK
    U_Domain --> SK
    P_Domain --> SK

Detected Contexts

ContextLocationEntitiesEventsDependencies
Ordersrc/​Order/58User (ID), Payment (event)
Usersrc/​User/34None
Paymentsrc/​Payment/46Order (event)
Sharedsrc/​Shared/00All contexts

Critical Issues

BC-001: Cross-Context Entity Reference

  • File: src/​Order/​Domain/​Entity/​Order.php:15
  • Issue: Direct reference to User entity instead of UserId
  • Code: private User $user (from User context)
  • Expected: private UserId $userId
  • Impact: Tight coupling, breaks context isolation
  • Refactoring: Replace with ID reference, use ACL if needed
  • Skills: acc-create-value-object (for UserId), acc-create-anti-corruption-layer

BC-002: Missing Anti-Corruption Layer

  • File: src/​Payment/​Infrastructure/​Gateway/​StripeGateway.php
  • Issue: Stripe models used directly in domain
  • Code: use Stripe\PaymentIntent;
  • Impact: External API changes affect domain
  • Refactoring: Create PaymentIntent adapter/​translator
  • Skills: acc-create-anti-corruption-layer

BC-003: Unintended Shared Kernel

  • Files:
    • src/​Order/​Domain/​ValueObject/​Address.php
    • src/​User/​Domain/​ValueObject/​Address.php
  • Issue: Duplicated Address VO without explicit sharing
  • Impact: Inconsistent behavior, maintenance burden
  • Refactoring: Either consolidate to Shared Kernel or differentiate
  • Skills: acc-create-value-object

Warning Issues

BC-004: Ambiguous Ubiquitous Language

  • Context 1: src/​User/ uses Account for user profile
  • Context 2: src/​Payment/ uses Account for financial account
  • Issue: Same term, different meanings
  • Refactoring: Rename to UserProfile and PaymentAccount

BC-005: Missing Published Language

  • Context: Order
  • Issue: No explicit contract for inter-context communication
  • Events published: 8
  • Documented: 0
  • Refactoring: Create event schema documentation

BC-006: Upstream Without Events

  • Context: User (upstream)
  • Downstream: Order, Payment (via direct queries)
  • Issue: Downstream contexts query User directly
  • Refactoring: User should publish events, downstreams react

Context Relationship Matrix

From \ ToOrderUserPaymentShared
Order-ID refEventsUses
User---Uses
PaymentQueriesQueries-Uses
Shared----

Legend:

  • ID ref: References only by ID (good)
  • Events: Async event communication (good)
  • Queries: Direct query (warning)
  • Uses: Shared kernel usage (acceptable)

Recommendations

Immediate Actions

  1. Replace direct entity references with ID Value Objects
  2. Add ACL for external service integrations

Short-term

  1. Document published language (event contracts)
  2. Consolidate or differentiate duplicated VOs

Long-term

  1. Consider event-driven communication between contexts
  2. Review shared kernel scope

## Context Integration Patterns

### Recommended Patterns

| Pattern | When to Use | Skills |
|---------|-------------|--------|
| ID Reference | Entity association across contexts | `acc-create-value-object` |
| Domain Events | Async communication | `acc-create-domain-event` |
| ACL | External systems, legacy | `acc-create-anti-corruption-layer` |
| Shared Kernel | Common VOs (Money, etc.) | `acc-create-value-object` |
| Published Language | Public contracts | Documentation |

### Anti-patterns

| Anti-pattern | Issue | Remediation |
|--------------|-------|-------------|
| Direct Entity Reference | Tight coupling | Use ID + resolve via query |
| Shared Entities | Ownership unclear | Split or explicit ownership |
| Cross-Context Repository | Boundary violation | Use events or ACL |
| Synchronous Cross-Context Calls | Temporal coupling | Use async events |

## Quick Analysis Commands

```bash
# Detect bounded contexts
echo "=== Bounded Contexts ===" && \
find src -maxdepth 2 -type d -name "Domain" && \
echo "=== Cross-Context Imports ===" && \
for ctx in $(find src -maxdepth 1 -type d | tail -n +2); do \
  name=$(basename $ctx); \
  grep -rn "use .*\\\\Domain\\\\" --include="*.php" "$ctx" | grep -v "use $name"; \
done && \
echo "=== Shared Kernel ===" && \
find src -type d -name "Shared" -o -name "Common" -o -name "Core"

Integration

Works with:

  • acc-ddd-auditor — Domain model quality
  • acc-structural-auditor — Layer violations
  • acc-ddd-generator — Generate missing components

References

  • "Domain-Driven Design" (Eric Evans) — Chapter 14: Context Mapping
  • "Implementing Domain-Driven Design" (Vaughn Vernon) — Chapter 3: Context Maps
  • Strategic DDD patterns documentation

More skills from diegosouzapw

accessibility logo
diegosouzapw/awesome-omni-skill

accessibility

Accessibility guidelines for VS Code features — covers accessibility help dialogs, accessible views, verbosity settings, accessibility signals, ARIA alerts/status announcements, keyboard navigation, and ARIA labels/roles. Applies to both new interactive UI surfaces and updates to existing feature...

62 1
View
mermaid-diagrams logo
diegosouzapw/awesome-omni-skill

mermaid-diagrams

Mermaid diagram creation for flowcharts, sequences, ERDs, and more. Generate diagrams from text in markdown files. Use for documentation, architecture diagrams, and visual representations. Triggers on mermaid, flowchart, sequence diagram, ERD, entity relationship, gantt chart, pie chart, class di...

62 1
View
tauri2-react-rust logo
diegosouzapw/awesome-omni-skill

tauri2-react-rust

Guides development of cross-platform desktop apps with Tauri 2, TypeScript, React, and Rust. Use when building Tauri apps, implementing IPC, designing Rust backend or TypeScript/React frontend, when researching or cloning a website (open site, snapshot elements), when verifying local dev or built...

62 1
View
fp-ts-errors logo
diegosouzapw/awesome-omni-skill

fp-ts-errors

Handle errors as values using fp-ts Either and TaskEither for cleaner, more predictable TypeScript code. Use when implementing error handling patterns with fp-ts.

62 0
View
ring:pre-dev-research logo
diegosouzapw/awesome-omni-skill

ring:pre-dev-research

Gate 0 research phase for pre-dev workflow. Dispatches 3 parallel research agents to gather codebase patterns, external best practices, and framework documentation BEFORE creating PRD/TRD. Outputs research.md with file:line references.

62 0
View
create-assistant logo
diegosouzapw/awesome-omni-skill

create-assistant

Create and configure Vapi voice AI assistants with models, voices, transcribers, tools, hooks, and advanced settings. Use when building voice agents, phone bots, customer support assistants, or any conversational AI that handles phone or web calls.

62 0
View
codex-headless logo
diegosouzapw/awesome-omni-skill

codex-headless

Delegiere Aufgaben an OpenAI Codex CLI im Headless-Mode. Nutzt ChatGPT Subscription (KEIN API Key). Nur Workspace-Zugriff, KEIN System-Zugriff. Auto-Accept mit --full-auto. Web-Recherche mit --search.

62 0
View
social-media-scheduler logo
diegosouzapw/awesome-omni-skill

social-media-scheduler

Generate a full week of social media content for any topic. Outputs platform-optimized posts for Twitter/X, LinkedIn, and Instagram with hashtags and posting times.

62 0
View
Data Privacy Compliance logo
diegosouzapw/awesome-omni-skill

Data Privacy Compliance

Data privacy and regulatory compliance specialist for GDPR, CCPA, HIPAA, and international data protection laws. Use when implementing privacy controls, conducting data protection impact assessments, ensuring regulatory compliance, or managing data subject rights. Expert in consent management, da...

62 0
View
triple-review logo
diegosouzapw/awesome-omni-skill

triple-review

Reviews a task using the TRIPLE protocol, as the review agent.

62 0
View
Tech Stack & Architecture Decision logo
diegosouzapw/awesome-omni-skill

Tech Stack & Architecture Decision

Define and document the technology stack and architecture decisions for a project. Use when the user needs to choose a tech stack, make architecture decisions, define infrastructure choices, or document technology selections. Triggers on requests like "define the tech stack", "choose technologies...

62 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View