Skip to content

Commit 7135505

Browse files
Merge pull request #53 from diffo-dev/51-livebook-and-improve-documentation
51 livebook and improve documentation
2 parents 390dcb3 + 8e50f6d commit 7135505

22 files changed

Lines changed: 1339 additions & 326 deletions

config/config.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ config :spark,
1616
:characteristics,
1717
:neo4j,
1818
:jason,
19-
:json_api,
2019
:outstanding,
2120
:actions,
2221
:state_machine,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
3+
4+
SPDX-License-Identifier: MIT
5+
6+
Auto-generated by `mix gen.api_docs`. Do not edit by hand.
7+
Regenerate after changing any domain's `code_interface` defines.
8+
-->
9+
10+
# Access Domain API
11+
12+
The Elixir function-call surface for each resource in the `DiffoExample.Access` domain. Generated from the `define` declarations in the domain's `resources do` block.
13+
14+
## Cable
15+
16+
| Function | Action | Arguments | Purpose |
17+
|---|---|---|---|
18+
| `assign_pair` | `:assign_pair` | `assignment` (struct) | relates the cable with an instance by assigning a pair |
19+
| `build_cable` | `:build` | `id`, `name`, `type`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new Cable resource instance for build |
20+
| `define_cable` | `:define` | `characteristic_value_updates` (list of term) | defines the cable |
21+
| `get_cable_by_id` | `:read` | `id` | read a service or resource instance |
22+
| `relate_cable` | `:relate` | `relationships` (list of struct) | relates the cable with other instances |
23+
24+
## Card
25+
26+
| Function | Action | Arguments | Purpose |
27+
|---|---|---|---|
28+
| `assign_port` | `:assign_port` | `assignment` (struct) | relates the card with an instance by assigning a port |
29+
| `build_card` | `:build` | `id`, `name`, `type`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new Card resource instance for build |
30+
| `define_card` | `:define` | `characteristic_value_updates` (list of term) | defines the card |
31+
| `get_card_by_id` | `:read` | `id` | read a service or resource instance |
32+
| `relate_card` | `:relate` | `relationships` (list of struct) | relates the card with other instances |
33+
34+
## DslAccess
35+
36+
| Function | Action | Arguments | Purpose |
37+
|---|---|---|---|
38+
| `design_dsl_result` | `:design_result` | `characteristic_value_updates` (list of term) | updates the DSL Access service with the design |
39+
| `get_dsl_by_id` | `:read` | `id` | read a service or resource instance |
40+
| `qualify_dsl` | `:qualify` | `id`, `name`, `type`, `which`, `places` (list of struct), `parties` (list of struct) | creates a new DSL Access service instance for qualification |
41+
| `qualify_dsl_result` | `:qualify_result` | `service_operating_status`, `places` (list of struct) | updates the DSL Access service with qualification result |
42+
43+
## Path
44+
45+
| Function | Action | Arguments | Purpose |
46+
|---|---|---|---|
47+
| `build_path` | `:build` | `id`, `name`, `type`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new Path resource instance for build |
48+
| `define_path` | `:define` | `characteristic_value_updates` (list of term) | defines the path |
49+
| `get_path_by_id` | `:read` | `id` | read a service or resource instance |
50+
| `relate_path` | `:relate` | `relationships` (list of struct) | relates the path with other instances |
51+
52+
## Shelf
53+
54+
| Function | Action | Arguments | Purpose |
55+
|---|---|---|---|
56+
| `assign_slot` | `:assign_slot` | `assignment` (struct) | relates the shelf with an instance by assigning a slot |
57+
| `build_shelf` | `:build` | `id`, `name`, `type`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new Shelf resource instance for build |
58+
| `define_shelf` | `:define` | `characteristic_value_updates` (list of term) | defines the shelf |
59+
| `get_shelf_by_id` | `:read` | `id` | read a service or resource instance |
60+
| `relate_shelf` | `:relate` | `relationships` (list of struct) | relates the shelf with cards |

documentation/domains/_nbn_api.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
3+
4+
SPDX-License-Identifier: MIT
5+
6+
Auto-generated by `mix gen.api_docs`. Do not edit by hand.
7+
Regenerate after changing any domain's `code_interface` defines.
8+
-->
9+
10+
# NBN Domain API
11+
12+
The Elixir function-call surface for each resource in the `DiffoExample.Nbn` domain. Generated from the `define` declarations in the domain's `resources do` block.
13+
14+
## Avc
15+
16+
| Function | Action | Arguments | Purpose |
17+
|---|---|---|---|
18+
| `build_avc` | `:build` | `id`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new AVC resource instance |
19+
| `define_avc` | `:define` | `characteristic_value_updates` (list of term) | defines the AVC |
20+
| `get_avc_by_id` | `:read` | `id` | read a service or resource instance |
21+
| `relate_avc` | `:relate` | `relationships` (list of struct) | relates the AVC with other instances |
22+
23+
## Cvc
24+
25+
| Function | Action | Arguments | Purpose |
26+
|---|---|---|---|
27+
| `assign_cvlan` | `:assign_cvlan` | `assignment` (struct) | assigns a C-VLAN ID from the CVC pool to an AVC |
28+
| `build_cvc` | `:build` | `id`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new CVC resource instance |
29+
| `define_cvc` | `:define` | `characteristic_value_updates` (list of term) | defines the CVC |
30+
| `get_cvc_by_id` | `:read` | `id` | read a service or resource instance |
31+
| `relate_cvc` | `:relate` | `relationships` (list of struct) | relates the CVC with other instances (e.g. AVC aggregation, NNI Group termination) |
32+
33+
## NbnEthernet
34+
35+
| Function | Action | Arguments | Purpose |
36+
|---|---|---|---|
37+
| `build_nbn_ethernet` | `:build` | `id`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new NBN Ethernet access resource instance |
38+
| `define_nbn_ethernet` | `:define` | `characteristic_value_updates` (list of term) | defines the NBN Ethernet access |
39+
| `get_nbn_ethernet_by_id` | `:read` | `id` | read a service or resource instance |
40+
| `relate_nbn_ethernet` | `:relate` | `relationships` (list of struct) | relates the NBN Ethernet access with other instances (e.g. UNI) |
41+
42+
## Nni
43+
44+
| Function | Action | Arguments | Purpose |
45+
|---|---|---|---|
46+
| `build_nni` | `:build` | `id`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new NNI resource instance |
47+
| `define_nni` | `:define` | `characteristic_value_updates` (list of term) | defines the NNI |
48+
| `get_nni_by_id` | `:read` | `id` | read a service or resource instance |
49+
| `relate_nni` | `:relate` | `relationships` (list of struct) | relates the NNI with other instances (e.g. its parent NNI Group) |
50+
51+
## NniGroup
52+
53+
| Function | Action | Arguments | Purpose |
54+
|---|---|---|---|
55+
| `assign_svlan` | `:assign_svlan` | `assignment` (struct) | assigns an S-VLAN ID from the NNI Group pool to a CVC |
56+
| `build_nni_group` | `:build` | `id`, `name`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new NNI Group resource instance |
57+
| `define_nni_group` | `:define` | `characteristic_value_updates` (list of term) | defines the NNI Group |
58+
| `get_nni_group_by_id` | `:read` | `id` | read a service or resource instance |
59+
| `relate_nni_group` | `:relate` | `relationships` (list of struct) | relates the NNI Group with other instances (e.g. NNI resources it comprises) |
60+
61+
## Ntd
62+
63+
| Function | Action | Arguments | Purpose |
64+
|---|---|---|---|
65+
| `assign_port` | `:assign_port` | `assignment` (struct) | assigns a port from the NTD pool to a UNI |
66+
| `build_ntd` | `:build` | `id`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new NTD resource instance |
67+
| `define_ntd` | `:define` | `characteristic_value_updates` (list of term) | defines the NTD |
68+
| `get_ntd_by_id` | `:read` | `id` | read a service or resource instance |
69+
| `relate_ntd` | `:relate` | `relationships` (list of struct) | relates the NTD with other instances (e.g. UNI) |
70+
71+
## Rsp
72+
73+
| Function | Action | Arguments | Purpose |
74+
|---|---|---|---|
75+
| `activate_rsp` | `:activate` |||
76+
| `create_rsp` | `:build` | `name`, `short_name`, `id` ||
77+
| `deactivate_rsp` | `:deactivate` |||
78+
| `get_rsp_by_epid` | `:read` | `id` ||
79+
| `get_rsp_by_short_name` | `:read` | `short_name` ||
80+
| `list_rsps` | `:inventory` |||
81+
| `suspend_rsp` | `:suspend` |||
82+
83+
## Uni
84+
85+
| Function | Action | Arguments | Purpose |
86+
|---|---|---|---|
87+
| `build_uni` | `:build` | `id`, `which`, `relationships` (list of struct), `places` (list of struct), `parties` (list of struct) | creates a new UNI resource instance |
88+
| `define_uni` | `:define` | `characteristic_value_updates` (list of term) | defines the UNI |
89+
| `get_uni_by_id` | `:read` | `id` | read a service or resource instance |
90+
| `relate_uni` | `:relate` | `relationships` (list of struct) | relates the UNI with other instances (e.g. NTD, NBN Ethernet access) |

documentation/domains/access.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
3+
4+
SPDX-License-Identifier: MIT
5+
-->
6+
7+
# The Access Domain
8+
9+
Access is a small **DSL service** domain — a single fictional telco delivering broadband over copper to its own customers. It models the service the telco sells (`DslAccess`) and the physical infrastructure it runs on (`Shelf`, `Card`, `Path`, `Cable`).
10+
11+
Use it as the warm-up. The pattern is small enough to hold in your head and rich enough to show every diffo modelling primitive you'll need. NBN (the second example) revisits the same primitives with multi-tenancy and a much longer delivery chain.
12+
13+
## What's in here
14+
15+
| Kind | Resource | Plays the role of |
16+
|---|---|---|
17+
| Service | `DslAccess` | the broadband product the telco sells to a subscriber |
18+
| Resource | `Shelf` | a DSLAM frame at the exchange — slots for line cards |
19+
| Resource | `Card` | a line card in a shelf slot — ports for customer paths |
20+
| Resource | `Path` | the physical/logical access path from the exchange to the customer |
21+
| Resource | `Cable` | a copper cable — carries pairs assigned to paths |
22+
23+
`Shelf`, `Card`, and `Cable` each declare a **pool**: `:slots`, `:ports`, `:pairs`. Other resources consume those pools by being assigned a value — a card takes a slot from a shelf, a path takes a port from a card and a pair from a cable.
24+
25+
## Topology
26+
27+
The downstream view (the assignment direction) is a stack:
28+
29+
```
30+
Shelf (slots pool) ─── Card (ports pool) ─── Path
31+
32+
Cable (pairs pool)
33+
```
34+
35+
A `Card` is **assigned a slot** from its `Shelf`; a `Path` is **assigned a port** from its `Card` and **assigned pairs** from `Cable`s along the route. The consuming resource names its upstream by the role it plays — `:shelf`, `:card`, `:cable` — and that name (`alias`) sits on the assignment record so the relationship can be walked from either side.
36+
37+
The `DslAccess` service stands in front of the resources. It's the *what we sell*; the resources are the *what makes it work*.
38+
39+
## Inheritance — bringing upstream context up
40+
41+
Every consumer can read characteristics from what it's part of, without copying:
42+
43+
- `Card.shelf` brings up the **`ShelfCharacteristic`** value of the shelf this card sits in (single-hop via `:shelf`).
44+
- `Path.card` brings up the card it's plugged into (single-hop via `:card`).
45+
- `Path.shelf` brings up the shelf — two-hop via `[:card, :shelf]`.
46+
- `Shelf.cards` brings up every card sitting in a slot (reverse direction).
47+
48+
These are derived live from the assignment graph; nothing is duplicated.
49+
50+
## Service lifecycle
51+
52+
`DslAccess` is a TMF service with a small state machine:
53+
54+
```
55+
:initial ── qualify_dsl_result ──▶ :feasibilityChecked ── design_dsl_result ──▶ :reserved
56+
```
57+
58+
Each transition is an Ash action. Each action shapes the JSON output — the service's `state` field reflects where you are.
59+
60+
## Scenario walk-through
61+
62+
The standard provisioning flow — set up the infrastructure, then qualify and design a service for a subscriber:
63+
64+
```elixir
65+
# 1. Exchange has a shelf with a slots pool
66+
{:ok, shelf} = Access.build_shelf!(%{name: "QDONC-0001", places: [exchange]})
67+
Access.define_shelf!(shelf, %{
68+
characteristic_value_updates: [
69+
shelf: [device_name: "QDONC-0001", family: :ISAM, model: "ISAM7330", technology: :DSLAM],
70+
slots: [first: 1, last: 10, assignable_type: "LineCard"]
71+
]
72+
})
73+
74+
# 2. A line card consumes a slot from the shelf — it names its upstream Shelf :shelf
75+
{:ok, card} = Access.build_card!(%{name: "line card 1"})
76+
Access.define_card!(card, %{
77+
characteristic_value_updates: [
78+
card: [family: :ISAM, model: "EBLT48", technology: :adsl2Plus],
79+
ports: [first: 1, last: 48, assignable_type: "ADSL2+"]
80+
]
81+
})
82+
Access.assign_slot!(shelf, %{
83+
assignment: %Assignment{assignee_id: card.id, alias: :shelf, operation: :auto_assign}
84+
})
85+
86+
# 3. The subscriber's path through copper to the exchange
87+
{:ok, path} = Access.build_path!(%{name: "82 Rathmullen", places: [customer_site, exchange]})
88+
Access.define_path!(path, %{
89+
characteristic_value_updates: [path: [technology: :copper, sections: 5]]
90+
})
91+
92+
# 4. Cables along the route — each one assigns a pair to the path
93+
Enum.each(cables, fn cable ->
94+
Access.assign_pair!(cable, %{
95+
assignment: %Assignment{assignee_id: path.id, alias: :cable, operation: :auto_assign}
96+
})
97+
end)
98+
99+
# 5. The card assigns a port to the path — the path names its upstream Card :card
100+
Access.assign_port!(card, %{
101+
assignment: %Assignment{assignee_id: path.id, alias: :card, operation: :auto_assign}
102+
})
103+
104+
# 6. Now sell the service. Qualify first (do we have feasibility at this address?)
105+
{:ok, dsl} = Access.qualify_dsl(%{parties: [customer, reseller], places: [customer_site]})
106+
{:ok, dsl} = Access.qualify_dsl_result(dsl, %{
107+
service_operating_status: :feasible,
108+
places: [esa]
109+
})
110+
111+
# 7. Design — set the service's characteristics. State goes to :reserved.
112+
{:ok, dsl} = Access.design_dsl_result(dsl, %{
113+
characteristic_value_updates: [
114+
dslam: [device_name: "QDONC0001", model: "ISAM7330"],
115+
aggregate_interface: [interface_name: "eth0", svlan_id: 3108],
116+
circuit: [cvlan_id: 82],
117+
line: [slot: 10, port: 5]
118+
]
119+
})
120+
```
121+
122+
Read the path's brought-up context to see inheritance working live:
123+
124+
```elixir
125+
{:ok, path} = Access.get_path_by_id(path.id, load: [:card, :shelf, :port])
126+
127+
path.card # ⇒ [%CardCharacteristic.Value{family: :ISAM, model: "EBLT48", ...}]
128+
path.shelf # ⇒ [%ShelfCharacteristic.Value{device_name: "QDONC-0001", ...}] (two-hop)
129+
path.port # ⇒ [1] (the port number this path was assigned)
130+
```
131+
132+
## Domain API reference
133+
134+
See [_access_api.md](_access_api.md) for the auto-generated table of every `code_interface` function on `DiffoExample.Access` — function name, action, arguments, purpose. Regenerated with `mix gen.api_docs`.
135+
136+
## What's underneath?
137+
138+
You've been using diffo's Provider primitives the whole time — **specifications**, **typed characteristics**, **pools**, **assignments**, **relationships**, **state machines**, and the **TMF JSON encoding** that surfaces them. None of those are bespoke to Access; they all come from the [Provider domain](provider.md), which is where to look next once you've internalised this scenario.
139+
140+
For a runnable walk-through of the scenario, open [diffo_example_access.livemd](diffo_example_access.livemd) in Livebook.

0 commit comments

Comments
 (0)