CBRL Syntax
CBRL Syntax
Section titled “CBRL Syntax”CBRL (ContextBrew Requirements Language) is a structured DSL for writing formal, traceable requirements. This page provides the complete syntax reference.
Structure
Section titled “Structure”A CBRL file contains one or more REQUIREMENT blocks:
REQUIREMENT <id> TITLE "<title>" DESCRIPTION "<description>"
[ACCEPTANCE_CRITERIA] GIVEN <precondition> WHEN <action> THEN <expected result>
[TEST_CASE] NAME "<test name>" INPUT <field> = <value> EXPECTED <assertion>
[INVOLVES_AGGREGATE <aggregate-name>] [LINKED_STORY "<story-title>"] [@<aspect-name>]END_REQUIREMENTKeywords
Section titled “Keywords”REQUIREMENT / END_REQUIREMENT
Section titled “REQUIREMENT / END_REQUIREMENT”Defines a requirement block. The ID must be unique within the project and follow the pattern REQ-NNN:
REQUIREMENT REQ-001 ...END_REQUIREMENTA human-readable title for the requirement:
TITLE "User registration"DESCRIPTION
Section titled “DESCRIPTION”A detailed description of what the system must do:
DESCRIPTION "The system shall allow new users to register with email and password. Passwords must be at least 12 characters and contain a mix of letters, numbers, and symbols."ACCEPTANCE_CRITERIA
Section titled “ACCEPTANCE_CRITERIA”One or more criteria in Given/When/Then format. Each requirement can have multiple criteria:
ACCEPTANCE_CRITERIA GIVEN a new user with email "[email protected]" WHEN the user submits the registration form with a valid password THEN the user account is created and a verification email is sent
ACCEPTANCE_CRITERIA GIVEN an existing user with email "[email protected]" WHEN a new user tries to register with the same email THEN the system rejects the registration with a "duplicate email" errorTEST_CASE
Section titled “TEST_CASE”An explicit test definition with inputs and expected outcomes:
TEST_CASE NAME "Valid registration creates account" INPUT email = "[email protected]" INPUT password = "Str0ng!Pass#2026" EXPECTED user account exists with email "[email protected]" EXPECTED verification_email_sent = true
TEST_CASE NAME "Duplicate email rejected" INPUT email = "[email protected]" INPUT password = "Str0ng!Pass#2026" EXPECTED error with code "DUPLICATE_EMAIL"INVOLVES_AGGREGATE
Section titled “INVOLVES_AGGREGATE”Links the requirement to a DDD aggregate. Creates a traceability link:
INVOLVES_AGGREGATE UserINVOLVES_AGGREGATE EmailVerificationA requirement can involve multiple aggregates.
LINKED_STORY
Section titled “LINKED_STORY”Links the requirement to a USM story:
LINKED_STORY "User registration"Aspect Tags
Section titled “Aspect Tags”Aspects tag cross-cutting concerns. They generate additional test cases:
@security@audit@accessibility@performance@privacyMultiple aspects can be applied to a single requirement:
REQUIREMENT REQ-005 TITLE "User profile update" DESCRIPTION "Users can update their profile information" INVOLVES_AGGREGATE User @security @audit @privacyEND_REQUIREMENTValue Types
Section titled “Value Types”CBRL supports the following value types in INPUT and EXPECTED fields:
| Type | Syntax | Example |
|---|---|---|
| String | "value" |
"[email protected]" |
| Number | 123 or 3.14 |
42 |
| Boolean | true or false |
true |
| Null | null |
null |
| Reference | <field> |
user.id |
Comments
Section titled “Comments”Single-line comments start with #:
# This requirement covers the core registration flowREQUIREMENT REQ-001 TITLE "User registration" ...END_REQUIREMENTFull Example
Section titled “Full Example”REQUIREMENT REQ-010 TITLE "Order placement" DESCRIPTION "Customers can place orders containing multiple items. The system validates stock availability before confirming the order."
ACCEPTANCE_CRITERIA GIVEN a customer with items in their cart WHEN the customer submits the order THEN the order is created with status PENDING AND stock is reserved for each item
ACCEPTANCE_CRITERIA GIVEN an item with 0 stock WHEN the customer attempts to order that item THEN the system rejects the order with "OUT_OF_STOCK"
TEST_CASE NAME "Valid order creates pending order" INPUT customer_id = "cust-123" INPUT items = [{"book_id": "book-1", "quantity": 2}] EXPECTED order.status = "PENDING" EXPECTED order.total = calculated from item prices
TEST_CASE NAME "Out of stock item rejected" INPUT customer_id = "cust-123" INPUT items = [{"book_id": "book-out-of-stock", "quantity": 1}] EXPECTED error with code "OUT_OF_STOCK"
INVOLVES_AGGREGATE Order INVOLVES_AGGREGATE Book LINKED_STORY "Place order" @security @auditEND_REQUIREMENTNext Steps
Section titled “Next Steps”- CBRL Model to learn about editing CBRL in Context Studio
- DDD Model to define aggregates referenced in CBRL
- CLI Reference for CBRL CLI commands
