Boundaries files and reports
A boundaries file is a JSON file of kind codegraph.boundaries/1: rules that say where the outside comes into the code (the inbound half) and where the code goes out to another system (the outbound half). It is data: names and patterns, each with a word of a closed vocabulary. Three reports of codegraph analyze apply it to a model: entrypoints, outbound and reach. Their rows are never stored: they are a function of the model and the rules, computed on each run.
This page is derived from packages/analyzer/src/boundaries/ (the file, the rules, the slice) and packages/cli/src/commands/boundaries-reports.ts (the reports). Every codegraph.boundaries/1 example on it is parsed by packages/cli/test/docs-boundaries.test.ts, and its three vocabulary tables are held equal to the analyzer’s constants by the same test.
A complete example
A Phoenix application: where requests, jobs and processes come in, and what the code does to its database and its mail service.
{
"kind": "codegraph.boundaries/1",
"name": "phoenix",
"lang": "ex",
"inbound": {
"supertypes": { "Oban.Worker": "internal event" },
"types": { "*Controller": "inbound request" },
"operations": { "perform": { "kind": "internal event", "why": "Oban calls perform/1 for each job" } },
"conventional": ["init", "handle_call"]
},
"outbound": {
"modules": { "Ecto.Repo": "database", "Swoosh.*": "mail" },
"effects": {
"Ecto.Repo": {
"insert*": "write", "update*": "write", "delete*": "write",
"get*": "read", "all*": "read", "one*": "read"
},
"Swoosh.*": { "deliver*": "send" }
}
}
}codegraph analyze app.jsonl --report entrypoints --boundaries phoenix.json
codegraph analyze app.jsonl --report outbound --boundaries phoenix.json
codegraph analyze app.jsonl --report reach --boundaries phoenix.json --from entries --via candidates --max-depth 4Every key
Every key but kind is optional, and every object is strict: an unknown key is refused with its path and the valid keys.
| Key | Value |
|---|---|
kind | "codegraph.boundaries/1", the only kind this build reads |
name | a name for the file, printed in each report’s header |
lang | the language it was written for (java, ex, …); a report on a model of another language prints a warning and still applies it |
proposal | { "digest": … }, written by boundaries propose: the sha256 of the file without this key, so an edit is noticed and the file never overwritten. No rule reads it |
inbound | the six maps of an M23 stack table, and concepts, below |
outbound | modules, types, effects and concepts, below |
Inbound: where the outside comes in
The maps of a stack table, read as entry-points.sql reads them, in three layers: a written mark (an annotation, a supertype), a name, the absence of a caller.
| Map | A key is | It finds | Layer |
|---|---|---|---|
annotations | an annotation’s name, exactly | whatever carries it, one row per use | annotation |
supertypes | the name of a type the framework calls, exactly | the uncalled operations of every type below it | supertype |
entries | an entity id | that entity, or the id alone when the model does not declare it | by hand |
types | a pattern on a type’s name (*Controller) | the uncalled operations of the types it matches | type name |
operations | an operation’s name, exactly | gives its kind to the uncalled operations of that name | no caller |
conventional | (a list) the names the language itself calls | nothing: those are left out of the no caller layer, unless operations names them | — |
An uncalled operation is one nothing in the model calls: not the target of an invocation, not a candidate of any edge, not an operation of a type below a called one with the same name and number of parameters, not a constructor, not a stub, and not written inside another operation. Every uncalled operation that no rule classifies is still a row, with no stimulus: unclassified.
A row found by two layers is printed under the stronger one, in the order of the table: annotation, supertype, by hand, type name, no caller — and last concept, from concepts.
Outbound: where the code goes out
| Map | A key is | It names |
|---|---|---|
modules | a name or a pattern | the stubs whose own name, or the name of any container above them, matches: the module as a person says it (Ecto.Repo in Elixir, org.springframework.jdbc.* in Java) |
types | a name or a pattern | the stubs whose type (the stub, or the nearest type above it) is named so (RestTemplate) |
effects | a key of modules or types | an object of member patterns, each with an effect: what a call of that member does to the system |
A row is an invocation or an access edge to a stub a rule names. A reference (a member named without being called) is not a crossing. The types rules are tried first, then the modules rules, each in file order: the first that matches files the edge. The effect is the first pattern of its stub’s effects, in file order, that matches the member the edge names (MM-6: insert/2 in Elixir, save in Java). When there is none, the row says why: no member (the edge names none: the extractor does not write members, or the call is not to a member) or no effect rule.
Concepts: rules over insights
inbound.concepts and outbound.concepts name what codegraph explain judged a type to be — the concept of its type record, as codegraph insights prints it — instead of a name or a mark the code carries:
{
"kind": "codegraph.boundaries/1",
"name": "petclinic",
"lang": "java",
"inbound": { "concepts": { "applicationService": "inbound request" } },
"outbound": { "concepts": { "repository": { "kind": "database", "why": "a Spring Data interface: the reads it declares are calls into the code, not into a stub" } } }
}| Map | A key is | It finds |
|---|---|---|
inbound.concepts | a concept, exactly as the store spells it | the uncalled operations of the types of that concept, as supertypes and types find theirs, in the layer concept, last: a row another layer classified wins |
outbound.concepts | a concept, exactly | each corpus type of that concept, as an adapter towards the system: one row per type, edge or no edge |
- The concept is explain’s word. A key is one of the concepts a type record takes —
boundedContext,module,interface,operation,command,query,reaction,entity,readOnlyEntity,aggregate,stateMachine,repository,event,valueType,enum,domainService,applicationService,infrastructureService,invariant,precondition,postcondition,agreement,reconciliation,notDomain,unknown— compared exactly; any other key is refused, with that list. No pattern, and noeffectson a concept: a concept row has no edge, hence no member. - Where the labels come from. The report opens
<model>.insights.dbbeside the first model, read-only (--insights FILEnames another): it never creates, migrates or writes a store, it is not blocked by a run in progress, and it reads the type records’ concept and nothing else. A label is an inference a model made, never a fact; nothing here writes it anywhere. - Without a store, not evaluated. With no store there, or one this build refuses (an older one, say), the concepts rules find no row and are counted as not evaluated, apart from the rules that found nothing; the report’s header and its rules say why. Every other row is the same with and without the store: a store only adds rows.
- Beside a
no callerrow. An uncalled operation of a labelled type keeps its unclassifiedno callerrow, and gains aconceptrow: the inventory shows both, the text report counts how many unclassified rows a concepts rule classifies, and the selector termentry:unclassifiedno longer matches it,entrydoes. - Where it earns its keep. On Spring PetClinic,
"applicationService": "inbound request"matches the controllers’ uncalled operations and adds no row: their@GetMappingand@PostMappingclassify them first. A concepts rule finds what no annotation, supertype or name says: a framework that wires by convention. - In a walk.
rule:inbound.concepts:applicationServiceand the other terms read the concept rows too; a walk whose selector names a concepts rule that cannot be evaluated is refused, since its complement would ask everything.
Values
A value is a word of the map’s vocabulary, or an object { "kind": word, "why": "one line" }. The why is for a person: it is printed in --json, never evaluated.
The kinds of stimulus, for the inbound maps:
| Stimulus |
|---|
inbound command |
inbound query |
inbound request |
external event |
internal event |
temporal |
lifecycle |
framework callback |
What each one means, with the annotations and supertypes to look for: Stimuli.
The kinds of system, for modules and types:
| System |
|---|
database |
cache |
broker |
http api |
filesystem |
mail |
object storage |
other service |
The effects, for effects:
| Effect |
|---|
read |
write |
send |
receive |
Patterns
In types, modules, the keys of types and modules named under effects, and the member patterns, * matches any run of characters, the name’s separators included: *Controller matches MyAppWeb.PageController, Swoosh.* matches Swoosh.Adapters.Local, insert* matches insert/2 and insert_all/3. Nothing else is special: ?, [ and ] are refused. annotations, supertypes, operations and conventional hold names, compared exactly.
An M23 stack table is a boundaries file
A file with no kind and the root keys of a stack table (stack, lang, annotations, supertypes, types, operations, conventional, entries) is read as inbound alone, stack as its name. The five shipped tables, plugin/references/stacks/, are read unchanged, and a header says so:
boundaries: plugin/references/stacks/spring.json — spring (java), an M23 stack table read as inbound aloneA key no stack table has (outbound, say) in a file without kind is refused, with the reason.
Rule names
Every rule has a stable name, which each row carries and each report counts by, and which the selector term rule:NAME takes (below).
| Rule | Name |
|---|---|
| an inbound key | inbound.MAP:KEY: inbound.annotations:GetMapping, inbound.types:*Controller, inbound.entries:java:com.acme/Batch.run() |
| a system | outbound.modules:Ecto.Repo, outbound.types:RestTemplate |
| an effect | outbound.effects:STUB>MEMBER: outbound.effects:Ecto.Repo>insert* |
| a concept | inbound.concepts:applicationService, outbound.concepts:repository |
The name splits at its first :, and an effect’s key at its first >. conventional is not a rule: it finds nothing. An unclassified row carries no rule.
In a selector
What a file finds is also a set of entities a walk can ask, through five selector terms (the selector table has their JSON form):
| Term | Matches |
|---|---|
entry | an entity of the inventory a rule classified |
entry:KIND | the same, of one kind of stimulus; entry:unclassified, a row no rule classifies |
outbound | an operation that writes an edge crossing to a stub an outbound rule names, or a type an outbound.concepts rule names |
outbound:KIND | the same, to one system kind |
rule:NAME | what one rule found: an inbound rule’s entries, an outbound or effect rule’s crossing operations |
walk and explain take the file with --boundaries FILE; without it, such a term is an error, never an empty match. A kind with a space is one quoted word on a command line, and rule: takes the whole rest as the name:
codegraph walk model.jsonl --src DIR --prompt "Which table does this write, and when?" \
--include 'rule:outbound.effects:Ecto.Repo>insert*' --boundaries boundaries.json --dry-run
codegraph walk model.jsonl --src DIR --prompt "Which use case does this serve?" \
--roots entries --boundaries plugin/references/stacks/spring.json --max-depth 2 --closure containers --estimateThe second asks only what lies within two calls of a classified entry point, and its estimate prices each depth first (reach).
Faults
The file is read and checked before any model is opened. Every fault is reported, each with its path and the words that would have been valid, and the command exits 2:
codegraph: --boundaries bad.json: 2 faults
inbound.types["*X"]: unknown kind of stimulus "inbound read"; valid: inbound command, inbound query, inbound request, external event, internal event, temporal, lifecycle, framework callback
outbound.modules["Repo"]: unknown system kind "db"; valid: database, cache, broker, http api, filesystem, mail, object storage, other serviceThe reports
The three reports read the base graph: every entity and every edge, stubs and every provenance included, nothing folded. --level, --internal-only, --declared-only and --top are refused with them. They print the same rows whether the model is read from model.jsonl or from its model.db. Each ends, in the text form, with the rules of its half and those that found nothing; --json prints every rule with matched (its rows before layer precedence) and rows (the rows that carry it).
--report entrypoints
One row per entry point and layer, in the order of entry-points.sql: layer, classified before unclassified, calls descending, entry.
| Column | |
|---|---|
entry | the entity, or the id an entries rule names |
kind | its kind; none for an entries id the model does not declare |
layer | annotation, supertype, by hand, type name, no caller, concept |
evidence | the annotation, the supertype, the pattern or the concept |
stimulus | the rule’s kind of stimulus; none: unclassified |
rule | the rule that found the row |
calls | the invocations the entity writes |
arguments | (--json) the annotation’s arguments |
On the five fixtures with a stack table, these rows are the rows of entry-points.sql with the same table, in its order: packages/cli/test/boundaries-oracle.test.ts holds them equal.
--report outbound
One row per call into a stub a rule names, by stub, member, caller and line.
| Column | |
|---|---|
system | the rule’s kind of system |
stub | the stub the edge reaches; none on a concept row |
member | the member the edge names, as written |
effect | the effect, or why there is none: no member, no effect rule, no edge (a concept row) |
from | the corpus entity that writes the edge, or the labelled type: the adapter |
anchor | where; the type’s own anchor on a concept row |
rule, effectRule | the rules that filed it |
A concept row comes after every edge row, by type; in --json its stub, member, effect, edge and provenance are null. With a concepts rule in the file, --json also carries insights (store, evaluated, reason, labelled) and each concepts rule its evaluated.
codegraph analyze petclinic.jsonl --report outbound --boundaries petclinic.json
codegraph analyze petclinic.jsonl --report outbound --boundaries petclinic.json --insights elsewhere/petclinic.insights.db--report reach
The forward slice: what can run when an entry point fires, with each entity’s breadth-first distance from the nearest start.
codegraph analyze app.jsonl --report reach --boundaries stack.json --from 'java:com.acme.order/Order.discount(int)'
codegraph analyze app.jsonl --report reach --boundaries stack.json --from entries --via dispatch --max-depth 3--from entriesstarts from every classified entry point that is an operation, at depth 0;--from IDfrom one entity.--viatakes the three stated inferences of Stimuli, each adding to the one before.facts: invocation and access edges of provenancedeclared, and an operation written inside a reached one (a lambda, a local function).candidates: + the edges of every other provenance, + the candidates an edge lists without choosing one.dispatch: + a call to an operation may run the operation of the same name and number of parameters in any type below its type (an upper bound).--max-depth Nstops N hops from the start.- A row marked external is a stub: where the slice leaves the code.
With --max-depth 20, the slice from one id is reach.sql’s with candidates=0 on facts and candidates=1 on dispatch, depth for depth, on every fixture.
Worked example: Phoenix, outbound
The outbound half of the example at the top, on the Elixir fixture, with :ets filed as a cache:
{
"kind": "codegraph.boundaries/1",
"name": "phoenix",
"lang": "ex",
"outbound": {
"modules": { "Ecto.Repo": "database", "ets": "cache" },
"effects": {
"Ecto.Repo": { "insert*": "write", "update*": "write", "delete*": "write", "get*": "read", "all*": "read", "one*": "read" },
"ets": { "insert*": "write", "delete*": "write", "lookup*": "read" }
}
}
}$ codegraph analyze fixtures/elixir/expected/model.jsonl --report outbound --boundaries phoenix.json
outbound: 5 edges cross to a stub a rule names — database 1, cache 4
SYSTEM STUB MEMBER EFFECT FROM ANCHOR
database ex:<deps>/Ecto%2ERepo - - (no member) ex:lib%2Facme_order%2Frepo.ex/AcmeOrder%2ERepo lib/acme_order/repo.ex:2
cache ex:<otp>/ets - - (no member) …/AcmeOrder%2EStock.available?#1 lib/acme_order/stock.ex:14
…
(Header and the rule columns trimmed.) The Ecto.Repo row is the use Ecto.Repo of AcmeOrder.Repo: the module that crosses, and the place every Repo.insert/2 of the application goes through. Every row says no member until the Elixir extractor writes the member of each call (MM-6); from then on :ets.lookup/2 reads read and :ets.delete/2 reads write, and the calls the effects do not name, :ets.new/2 and :ets.update_counter/4, say no effect rule.
Worked example: Spring
The shipped spring.json on spring-petclinic 500158f: --report entrypoints prints 55 rows, 32 by annotation (the 32 entry points of --report wiring, id for id), 6 by supertype and 17 with no caller, of which 16 are unclassified; the rows are entry-points.sql’s, in its order. An outbound half for a Spring application:
{
"kind": "codegraph.boundaries/1",
"name": "spring-outbound",
"lang": "java",
"outbound": {
"modules": {
"org.springframework.data.repository.*": "database",
"org.springframework.data.jpa.repository": "database",
"org.springframework.kafka.*": "broker",
"org.springframework.mail.*": "mail",
"javax.cache.*": "cache"
},
"types": { "JdbcTemplate": "database", "RestTemplate": "http api" },
"effects": {
"org.springframework.data.jpa.repository": { "save*": "write", "delete*": "write", "find*": "read" },
"JdbcTemplate": { "query*": "read", "update": "write", "batchUpdate": "write" },
"RestTemplate": { "get*": "read", "post*": "write", "put": "write", "delete": "write" }
}
}
}On PetClinic it files six rows: the cache, CacheConfiguration.cacheConfiguration() building a javax.cache MutableConfiguration, and five database writes, save and saveAndFlush on JpaRepository. Three things the run shows:
- A Spring Data repository is not a stub, but its library parent is.
OwnerRepositoryis an interface of the code that extendsJpaRepository:owners.findById(ownerId)reaches thefindByIdthat interface declares, an entity of the code, so no outbound row is written for it.owners.save(owner)(OwnerController.java:84) calls a method inherited from the stub; the extractor charges it toJpaRepository, the one library ancestor that could answer, as aderivedinvocation namingsave(the Java extractor’s ancestor rule), so the effect rule readswrite. The reads the repository declares itself stay calls into the code: afind*effect on the stub finds nothing on PetClinic. - Name the package the stub is in.
JpaRepositorylives inorg.springframework.data.jpa.repository, whichorg.springframework.data.repository.*does not cover: without the second line the five writes file no row. - A
modulespattern names a whole package.org.springframework.data.*would file the 13 calls intoPageandPageRequest, which are values a query returns, as database calls. Name the package that talks to the system, or the type.
See also
analyze · Stimuli and flows · Walk definitions and selectors · model.jsonl