No description
  • Gleam 85.1%
  • Erlang 4.6%
  • Python 3.9%
  • Shell 3.3%
  • Dockerfile 1.3%
  • Other 1.8%
Find a file
beamologist 52bed361fc
All checks were successful
c4 model / c4-model-1 (push) Successful in 2s
c4 model / c4-model (push) Successful in 0s
Merge PR 4: the README without the GitHub Sponsors badge
2026-11-24 01:10:31 +01:00
.github/workflows ci: a guarded job calls a pinned copy, so no uses: names a repository the forge must fetch (images-to-forge, macula-io/martha#601) 2026-11-22 02:04:41 +01:00
architecture c4_model: a gleam model that claims neither a fleet row nor a box 2026-10-23 04:31:28 +02:00
assets c4_model: a gleam model that claims neither a fleet row nor a box 2026-10-23 04:31:28 +02:00
config The Erlang cookie stays on the box; distribution and epmd on loopback (PR 2 squashed) 2026-11-23 21:14:13 +01:00
priv/admin Port the full domain to Gleam: CMD desks, aggregates, PRJ, QRY, facade 2026-09-25 15:13:06 +02:00
scripts The Erlang cookie stays on the box; distribution and epmd on loopback (PR 2 squashed) 2026-11-23 21:14:13 +01:00
src mcl-bookclub-gleam opens its own store: mcl_om brings no reckon-db from 0.35 (mcl-om#10) 2026-09-29 17:02:48 +02:00
test mcl-bookclub-gleam opens its own store: mcl_om brings no reckon-db from 0.35 (mcl-om#10) 2026-09-29 17:02:48 +02:00
.gitignore Stop committing build output; the lint gate fetches elvis as a dependency 2026-09-26 06:15:01 +02:00
.tool-versions Scaffold the Gleam twin: gleam.toml with the estate's dep floors, toolchain pin, test wrapper 2026-09-25 14:50:50 +02:00
CHANGELOG.md Release 0.1.0: on mcl_om 0.37.6 and macula 13.5.0 2026-10-05 17:18:20 +02:00
Containerfile No crew member or lab box names in a public tree 2026-11-23 21:24:32 +01:00
gleam.toml c4_model: a gleam model that claims neither a fleet row nor a box 2026-10-23 04:31:28 +02:00
LICENSE README: the department layout, the boot order, the deviations, the wire contract 2026-09-25 16:07:07 +02:00
README.md README: add the Buy Me a Coffee badge 2026-11-23 22:19:50 +00:00
rebar.config The release carries no dev dependency 2026-09-26 06:36:33 +02:00
SECURITY.md SECURITY.md: response times, attachment and identity rules, drills (macula-io/macula#174) 2026-10-31 02:58:57 +01:00

mcl-bookclub-gleam

Buy Me a Coffee

The Bookclub-on-Mesh in Gleam: the third club on the mesh, a drop-in twin of mcl-bookclub (Erlang) and mcl-bookclub-phoenix (Elixir). Same org (mcl-bookclub), same fact topics, same procedure names — distinguishable on the wire only by node identity. This is the workspace's first Gleam edge service.

A book club kept as a reckon-db event store, with projections into sqlite, on the macula mesh through mcl_om (0.37 floor, the serving-station spread the many-club model needs; mcl-om#5).

The department layout

One Gleam OTP app, four department folders (the Erlang twin's division boundary is enforced by tests, not by the build; Gleam has no umbrella, so the single app follows that precedent):

src/mcl_bookclub_gleam/
  *.gleam                    the facade: the mcl_om service contract, the
                             get_bookclub_by_id handler, the three fact
                             emitters, the cowboy LAN admin, the supervisors
  host_bookclub/             CMD: nine desks, four aggregates, the party policy
  project_bookclub/          PRJ: the sqlite read-model store, eight projections
  query_bookclub/            QRY: the read-only query store, five query desks
  internal/                  bindings only (evoq, mesh, esqlite, cowboy, ...)
src/mcl_bookclub_gleam_ffi.erl
                             the Erlang edge: shapes Gleam cannot type

The facade owns everything that touches the mesh; the divisions import no mesh SDK (the boundary tests pin that — see below). Emitters live in the facade (the Phoenix twin's stricter boundary), not in host_bookclub.

Boot order (load-bearing)

mcl_om:boot/1 opens the reckon-db store and starts the evoq subscription — whose catch-up replay delivers to registered deliver-policy projections — before ServiceMod:start/1 fires. The twins get the ordering from their umbrella application order; this single app gets it from app.gleam: the division supervisors start first, then mcl_om:boot/1. The facade's own supervisor (admin + emitters) starts inside ServiceMod:start/1, after the replay — harmless for the skip-policy emitters.

Deviations from the twins, all deliberate

  • Stores are gleam_otp actors, not gen_servers. A NIF connection still belongs to the process that opened it (the actor owns it). health/0 probes them with a safe ping that cannot crash the caller (internal/health), because Gleam actors are not gen_servers.
  • data_dir/0 is a real charlist (dets/ra rejects binaries). Note that gleam_erlang's own charlist module stores a binary — the release path uses binary_to_list through the FFI.
  • Registered names are exact atoms. gleam_erlang's process.new_name/1 always appends a unique suffix, so the stores register under an exact atom via the FFI, and the health ping rides the actor's {Name, Message} subject envelope.
  • The release is assembled by rebar3's relx from gleam build output. Gleam owns compilation; scripts/release.sh stages a patched copy (mod entry in, test beams and the gleeunit dev dep out, every beam unioned into the modules list — gleam_otp/gleam_erlang ship beams their own .app files omit, which is an undef at boot otherwise) and rebar3 release assembles it. See rebar.config.

The wire contract (shared with the twins)

  • Org: mcl-bookclub. Capability: get_bookclub_by_id (mcl-bookclub/get_bookclub_by_id, auth => open).
  • The fact topics, one per fact kind, ids and names in the payload: bookclub/member/member_registered_v1, bookclub/book/book_procured_v1, bookclub/book/book_retired_v1.
  • Facts are read with mcl_om_wire:field/2 (Demon 65); text travels as CBOR text, booleans as 1/0.

Where dynamic.Dynamic lives, and why

Gleam is a typed language, and the domain is fully typed: commands, events, aggregate states and the QRY desks' results are all records. Dynamic appears in exactly three places, and each is a deliberate boundary:

  1. The evoq envelope. evoq hands the aggregate a map for execute/2 and apply/2 and the handler a map for handle_event/4 — atom keys in memory, binary keys from the store, {text, Bin} on the wire. Tolerance is part of the contract (Demon 65), so Payload = Dict(Dynamic, Dynamic) at that boundary, converted to typed values the moment a desk reads it.
  2. The sqlite cell. Rows are lists of cells; SQL NULL is the atom undefined. The QRY desks coerce each cell to a typed field (desk.cell_string, desk.cell_int, desk.cell_int_option) and return typed records, so Dynamic stops at the desk and reaches neither a facade nor the wire.
  3. The wire. mcl_om_wire:field/2 and facts.to_wire read and write wire-shaped terms; the facade converts between the typed desks and the wire in the handler it installs for a desk.

The alternative — modeling heterogeneous Erlang terms as Gleam types — would be a facade over a facade; the corpus's "no wrapper" convention says call Erlang directly, and the typed boundary above is where that call is contained.

Building and testing

# Everything is scoped: the ambient shell is OTP 29; the repos pin OTP 28.4.3
# and gleam 1.18.1 (see .tool-versions).
mise x erlang@28.4.3 gleam@1.18.1 -- gleam build
scripts/test.sh            # gleam test cannot pass a sys.config to erl; the
                           # wrapper loads config/test.sys.config and runs the
                           # generated test main
mise x erlang@28.4.3 gleam@1.18.1 -- gleam format --check .

scripts/test.sh runs the 91-test suite: desk tests against a real reckon-db store through evoq, projection and query-desk tests against the sqlite read model, the facade contract tests, and the boundary tests.

The boundary tests (the division wall)

  • No division source imports the mesh SDK (internal/mesh, macula, mcl_om, cowboy, esqlite).
  • No PRJ source spells a status literal — the readable names come from the status modules' flag maps (Demon 68).
  • The QRY desks' SELECT columns are all declared by the PRJ schema.

Release and deploy

Containerfile + .github/workflows/ci.yml mirror the twins: gates in the pinned macula-ci-gleam image, then the image, published as :main and :<sha> only. The realm grant is issued per org procedure, mcl-om's open info and get_limits among them; until it is, advertisement is refused with {provider_authorization, ...} and the node boots healthy, which is the honest pre-grant state.

A local release boot against the real mesh: scripts/local_boot.sh (health on MCL_HEALTH_PORT, admin UI on MCL_ADMIN_PORT).

Architecture

The C4 model is in architecture/README.md, with its diagrams drawn by architecture/c4_diagrams.py into assets/. Change the script, run it (python3 architecture/c4_diagrams.py), and look at the result before committing.

mcl-bookclub-gleam system context

License

Apache 2.0.