Core language library for DomainLang - parse, validate, and query Domain-Driven Design models programmatically
npm install @domainlang/language

Core language library for DomainLang - a Domain-Driven Design modeling language built with Langium.
- 🔤 Parser - Full DomainLang grammar with error recovery
- ✅ Validation - Semantic validation for DDD best practices
- 🔗 Linking - Cross-reference resolution across files and packages
- 🔍 Model Query SDK - Programmatic access to DDD models with fluent queries
- 🌐 Browser Support - Works in Node.js and browser environments
``bash`
npm install @domainlang/language
`typescript
import { loadModelFromText } from '@domainlang/language/sdk';
const { query } = await loadModelFromText(
Domain Sales {
vision: "Enable seamless commerce"
}
bc OrderContext for Sales as Core by SalesTeam {
description: "Handles order lifecycle"
});
// Query bounded contexts
const coreContexts = query.boundedContexts()
.withClassification('Core')
.toArray();
console.log(coreContexts[0].name); // 'OrderContext'
`
`typescript
import { loadModel } from '@domainlang/language/sdk/loader-node';
const { model, query } = await loadModel('./my-model.dlang');
// Access domains
for (const domain of query.domains()) {
console.log(${domain.name}: ${domain.vision});`
}
| Function | Environment | Use Case |
| -------- | ----------- | -------- |
| loadModelFromText(text) | Browser & Node | Parse inline DSL text |loadModel(file)
| | Node.js only | Load from file system |fromDocument(doc)
| | LSP integration | Zero-copy from Langium document |fromModel(model)
| | Advanced | Direct AST wrapping |
The SDK provides fluent query builders with lazy evaluation:
`typescript
// Find all bounded contexts owned by a team
const teamContexts = query.boundedContexts()
.withTeam('PaymentsTeam')
.toArray();
// Get context maps containing specific contexts
const maps = query.contextMaps()
.containing('OrderContext')
.toArray();
`
`typescript
// Direct AST properties
const desc = boundedContext.description;
const vision = domain.vision;
// SDK-augmented properties (with precedence resolution)
const classification = boundedContext.effectiveClassification; // Header 'as' wins over body 'classification:'
const team = boundedContext.effectiveTeam; // Header 'by' wins over body 'team:'
`
DomainLang models Domain-Driven Design concepts:
`dlang
// Define domains with vision
Domain Sales {
vision: "Drive revenue through great customer experience"
}
// Bounded contexts with ownership
bc OrderContext for Sales as Core by SalesTeam {
description: "Order lifecycle management"
}
bc PaymentContext for Sales as Supporting by PaymentsTeam
// Context maps showing integrations
ContextMap SalesIntegration {
contains OrderContext, PaymentContext
[OHS,PL] OrderContext -> [CF] PaymentContext
}
`
| Path | Purpose |
| ---- | ------- |
| src/domain-lang.langium | Grammar definition |src/generated/
| | Auto-generated AST (do not edit) |src/validation/
| | Semantic validation rules |src/lsp/
| | LSP features (hover, completion, formatting) |src/sdk/
| | Model Query SDK |
- @domainlang/cli - Command-line interface
- DomainLang VS Code Extension - IDE support
- Getting Started
- Language Reference
- Quick Reference
- SDK Documentation
From the workspace root (dsl/domain-lang/):
`bashAfter editing the grammar
npm run langium:generate
Apache-2.0