Skip to content

SIM — Tutorial

This is the tutorial part of the SIM — System Integration guide. See also Short info and samples.

Choose two communicating participants and one interaction. State whether each participant is under your control.

Booking and Inventory need more than a line between boxes. They must agree what a request means, which participant supplies the answer and how to interpret it. “Check availability” may be a read with no reservation, while “hold a seat” changes state. Confusing the two creates a system that looks connected but makes an unsafe business assumption.

Name the consumer and provider, the payload’s meaning and the relevant constraints. A synchronous response tells the caller something within one interaction. An event communicates a fact to consumers that may process it later. These choices have different consequences for what the user can be promised immediately.

Suppose Booking calls a payment provider and receives no response before a timeout. It may not know whether the provider accepted the charge. A retry policy therefore needs more than a timer: the parties need an agreement on duplicate requests and how to recover the result. Record these assumptions alongside the contract rather than treating network failure as a decorative warning on the diagram.

Connect SIM to the other views at their boundaries. C4 places the services in the architecture, Context Map explains the strategic relationship and DDD supplies the business meaning of a successful operation. SIM concentrates on the interaction. A consistent model can support contract review and generated obligations, while deployment behavior still needs contract or integration tests under declared conditions.

The response is lost: what did the other service do?. A reservation request reaches Inventory; the return response disappears; a retry exposes the need for a stable request identity.

Pause and predict: Does a timeout prove that no seat was reserved?

This is the text storyboard for a proposed short illustrated film. The written walkthrough and exercises are available now; a published movie will be added after its scenes, captions and model references have been reviewed.

There is no model command — topologies are authored as .json files under .contextbrew/specs/ (schema: ctxbrew schema sim), or produced from code with ctxbrew ingest-sim. A User Service / Order Service example:

{
"kind": "sim-file",
"schemaVersion": "0.1.0",
"contexts": [
{
"kind": "system-context",
"id": "ctx-users",
"name": "User Service",
"contextKind": "service",
"description": "Handles authentication and user profiles",
"ownedAggregates": ["User"],
"ownedTables": ["users"]
},
{
"kind": "system-context",
"id": "ctx-orders",
"name": "Order Service",
"contextKind": "service",
"description": "Manages orders and order lifecycle",
"ownedAggregates": ["Order"],
"ownedTables": ["orders"]
},
{
"kind": "system-context",
"id": "ctx-payments",
"name": "Payment Service",
"contextKind": "service",
"description": "Processes payments and refunds",
"ownedAggregates": ["Payment"],
"ownedTables": ["payments"]
}
],
"edges": [
{
"kind": "dependency-edge",
"id": "edge-orders-payments",
"sourceContextId": "ctx-orders",
"targetContextId": "ctx-payments",
"edgeType": "synchronous",
"criticality": "critical",
"contractId": "contract-payment-api",
"description": "Order Service requests payment processing"
}
],
"contracts": [
{
"kind": "contract",
"id": "contract-payment-api",
"name": "Payment API",
"contractType": "api",
"schema": { "PaymentRequest": { "orderId": "uuid", "amount": "number" } },
"version": "1.0.0",
"status": "active"
}
],
"invariants": [
{
"kind": "cross-cutting-invariant",
"id": "inv-no-db-sharing",
"name": "No direct database access across services",
"expression": "no context reads or writes tables owned by another context",
"involvedContexts": ["ctx-orders", "ctx-payments"],
"severity": "error",
"category": "consistency"
}
]
}
Terminal window
ctxbrew sim validate .contextbrew/specs/sim.json # exit 1 on any error

The SIM canvas renders your service topology as a DAG:

  1. Services appear as labeled nodes with port and health indicators
  2. Synchronous connections shown as solid directed edges
  3. Asynchronous connections shown as dashed edges with event names
  4. Constraint violations highlighted in red
  5. Dependency cycles detected and flagged

When a service’s specification changes, SIM propagates the impact:

  1. A DDD aggregate change in “Order Service” is detected
  2. SIM traces all dependency edges from “Order Service”
  3. Downstream services (“Payment Service”, “Notification Service”) are flagged as affected
  4. Data contracts on affected edges are marked for review
  5. Integration tests for affected connections are regenerated

In practice you drive this with three commands: ctxbrew sim diff <before> <after> for the semantic change, ctxbrew validate-consistency --sim <file> --ddd <file> for the cross-model verdict, and ctxbrew neighbourhood <aggregate> for the bounded local graph around a node.

This prevents the common microservice problem of “we changed our API and broke three downstream services we did not know about.”

Terminal window
ctxbrew sim validate <file> # Parse the file; exit 1 on any error
ctxbrew sim stats <file> # Collection sizes (contexts, edges…)
ctxbrew sim export <file> # Canonical DSL (or --format json|yaml)
ctxbrew sim import <file> # Canonicalization pass
ctxbrew sim diff <before> <after> # Semantic diff (report only)
ctxbrew ingest-sim <path> # Scan a codebase → SIM file
ctxbrew validate-consistency --sim <f> # Cross-model verdict (blocking on critical/major)
ctxbrew schema sim # Print the normative JSON Schema

SIM imports Structurizr DSL — the C4 parser maps systems, containers, and relationships onto SIM contexts, dependency edges, and contracts. ctxbrew ingest-sim builds a SIM file by scanning an existing codebase for service boundaries. Outbound, the canonical JSON/DSL round-trip is lossless. Details: Import & Export.