← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Bounded Context (DDD)

architecture Advanced
debt(d7/e7/b7/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated=no, and while deptrac and phpstan are listed, they can only catch dependency violations after boundaries have been manually defined and encoded as rules — the original misuse (a single shared User model across billing/shipping/marketing) is invisible until a developer explicitly maps out the architecture. There is no automatic signal that bounded contexts are missing or wrong.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix says 'draw explicit boundaries around each domain model', but the common_mistakes describe a shared domain model used everywhere. Separating a single monolithic User or domain model into context-specific models touches every layer — persistence, services, APIs, contracts — across multiple files and components. This is well beyond a single-component fix.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). The choice of how to define bounded contexts shapes every subsequent domain model decision, team structure, integration pattern, and service boundary. applies_to covers both web and cli contexts broadly, and tags include microservices and architecture. Every change to a domain concept must respect the established boundaries, making this a persistent and wide-reaching structural commitment.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states the canonical wrong belief: that a bounded context maps one-to-one to a microservice. This contradicts how many developers arriving from microservices literature think about it, and the common_mistakes reinforce that teams routinely share models across contexts or create too-fine-grained services. The concept contradicts intuitions formed from adjacent but different design patterns.

About DEBT scoring →

Also Known As

DDD bounded context context boundary domain boundary

TL;DR

An explicit boundary within which a domain model and its ubiquitous language apply — the same term may mean different things in different contexts.

Explanation

A Bounded Context (Eric Evans) is the boundary within which a particular domain model is consistent and coherent. The same concept can exist in multiple contexts with different meanings — a Customer in the Sales context has different attributes and behaviour than a Customer in the Shipping context. Bounded Contexts map to separately deployable services in microservices, or to modules in a modular monolith. Context Maps describe the relationships between contexts: Shared Kernel, Customer/Supplier, Conformist, Anti-Corruption Layer, etc.

Diagram

flowchart TD
    subgraph Ordering
        O_CUST[Customer<br/>name, shippingAddress]
        O_ORDER[Order<br/>lines, total]
    end
    subgraph Billing
        B_CUST[Customer<br/>name, billingAddress]
        B_INV[Invoice<br/>amount, dueDate]
    end
    subgraph Shipping
        S_PARCEL[Parcel<br/>weight, trackingNo]
    end
    O_ORDER -->|integration event| B_INV
    O_ORDER -->|integration event| S_PARCEL
    INFO[Same word Customer means<br/>different things in each context]
style Ordering fill:#1f6feb,color:#fff
style Billing fill:#238636,color:#fff
style Shipping fill:#6e40c9,color:#fff

Common Misconception

A bounded context maps one-to-one to a microservice. A bounded context is a conceptual boundary in the domain model — a single service can contain multiple bounded contexts, and one bounded context can span multiple services. The mapping is a design decision, not a rule.

Why It Matters

A bounded context defines the boundary within which a domain model is internally consistent — the same word can mean different things in different contexts, and crossing contexts requires explicit translation.

Common Mistakes

  • One shared domain model across the entire application — changes to meet one context's needs break others.
  • Not mapping between contexts explicitly — assuming User in the billing context is the same as User in the shipping context.
  • Bounded contexts that are too small — a new microservice for every entity creates integration overhead without benefit.
  • Not documenting context maps — which contexts exist and how they relate is critical institutional knowledge.

Code Examples

✗ Vulnerable
// Shared User model doing too many jobs across contexts:
class User {
    // Auth context needs: id, email, passwordHash, roles
    // Billing context needs: id, name, billingAddress, paymentMethods
    // Shipping context needs: id, name, shippingAddresses
    // One class serving all — changes for billing break auth
}
✓ Fixed
// 'Customer' means different things in different contexts
// — model each separately rather than one bloated Customer class

// Sales context
namespace App\Sales;
class Customer { public string $name; public Money $creditLimit; }

// Support context
namespace App\Support;
class Customer { public string $name; public Ticket[] $openTickets; }

// Shipping context
namespace App\Shipping;
class Customer { public Address $shippingAddress; public string $preferredCarrier; }

// Contexts communicate via integration events, not shared objects
class CustomerRegistered { public function __construct(public int $id, public string $email) {} }

Added 15 Mar 2026
Edited 22 Mar 2026
Views 35
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 1 ping S 3 pings M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 2 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Perplexity 8 Amazonbot 7 Ahrefs 6 ChatGPT 3 Unknown AI 3 Google 3
crawler 28 crawler_json 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Draw explicit boundaries around each domain model — the same word (e.g. 'User') can mean different things in different bounded contexts; never share domain models across boundaries
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
Single User model used across billing shipping marketing; ubiquitous language not consistent within one area of the codebase
Auto-detectable: ✗ No deptrac phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update

✓ schema.org compliant