@domainlang/language
v0.13.0
Published
Core language library for DomainLang - parse, validate, and query Domain-Driven Design models programmatically
Maintainers
Readme
@domainlang/language
Parse, validate, and query Domain-Driven Design models written in the .dlang language. This package is the foundation that the CLI and VS Code extension are built on — and you can build on it too.
Install
npm install @domainlang/languageQuick start
import { loadModelFromText } from '@domainlang/language/sdk';
const { query } = await loadModelFromText(`
Domain Sales {
vision: "Enable seamless commerce"
}
Team SalesTeam
Classification Core
bc OrderContext for Sales as Core by SalesTeam {
description: "Handles the order lifecycle"
}
`);
const coreContexts = query.boundedContexts()
.withClassification('Core')
.toArray();
console.log(coreContexts.map(ctx => ctx.name)); // ['OrderContext']That's it — five lines to parse a model and start querying. The SDK works in the browser, in Node.js, and inside Langium LSP integrations.
What you can do with it
Validate models programmatically. Run the same validation the VS Code extension uses, from Node.js scripts or CI pipelines.
Query anything in the model. The fluent query builder lets you filter bounded contexts by team, classification, or domain — with lazy evaluation and full type safety.
Build custom automation. Generate architecture reports, enforce naming conventions, sync models to wikis, or feed model data into dashboards.
API at a glance
| Function | Runtime | Purpose |
| --- | --- | --- |
| loadModelFromText(text) | Browser + Node.js | Parse DomainLang text in memory |
| loadModel(path, options?) | Node.js | Load and parse .dlang files |
| validateFile(path, options?) | Node.js | Validate a single file |
| validateWorkspace(dir) | Node.js | Validate an entire workspace |
| fromModel(model) | Browser + Node.js | Wrap an existing AST with query methods |
| fromDocument(document) | Browser + Node.js | Zero-copy wrapping for Langium documents |
Query examples
// Find all Core bounded contexts owned by a specific team
const contexts = query.boundedContexts()
.withTeam('PaymentsTeam')
.withClassification('Core')
.toArray();
// Find context maps that include a specific bounded context
const maps = query.contextMaps()
.containing('OrderContext')
.toArray();Node.js file loading and validation
import { loadModel, validateFile } from '@domainlang/language/sdk';
const { query } = await loadModel('./model.dlang', { workspaceDir: process.cwd() });
const result = await validateFile('./model.dlang', { workspaceDir: process.cwd() });
if (!result.valid) {
for (const err of result.errors) {
console.error(`${err.file}:${err.line}: ${err.message}`);
}
process.exit(1);
}Documentation
Related packages
- @domainlang/cli — terminal validation, queries, and dependency management.
- DomainLang for VS Code — syntax highlighting, IntelliSense, and real-time validation.
License
Apache-2.0
