factory/shape-access-control (0.1.0)
Installation
{
"repositories": [{
"type": "composer",
"url": " "
}
]
}composer config repositories.bmiadmin composer composer require factory/shape-access-control:0.1.0About this package
factory/shape-access-control
The gate, as a shape: sites, their units and the people at them, visitor passes held on the
server, and a gate that admits against them. Generic on purpose. Boma, a residential estate, is
the first product (platform/blueprint/config/products.php, 'shape' => 'access-control'), and
the next gate or visitor product is a row of data, not a fork.
Status: Phase 1, the gate core (section 4), is built and tested (2026-10-08). It is not yet
published or deployed. This file was agreed with the app as a contract before any code, and it is
the server's word. Where products/boma/API.md (the app's draft) differs, this file holds, and
the differences are listed at the end.
Composed by the console application (platform/console/application). That is what serves the
staging API (saas-staging, staging-api.bm-e-industrie.com), and by the founder's ruling of
2026-10-04 the console hosts the modules; it already loads factory/auth the same way. The
blueprint runs on no host today, but it can compose this shape like any other. Either way, the
shape answers under its own segment, /api/access. shape-booking owns a bare
/api/bookings, and two modules claiming one path is the collision CompositionTest exists to
stop.
1. The boundary: what binds every route
-
Identity and tenant.
api,factory.auth,factory.scope. The tenant is the token's product (Boma's slug), never a header. Reads addfactory.can:orders.read. Writes addfactory.can:orders.writeandthrottle:factory-writes. Shapes ride theorders.*boundary, so this adds no new ability to the kernel. -
The shape gate. A token whose product's shape does not include
access-controlgets 404 on every route here. A product that never asked for gates cannot create one by calling the URL. -
The site is the inner boundary. One product holds many estates, and the kernel's
project_adminsees all of them: that role is the operator, never an estate's committee. So every route but the list is/api/access/sites/{site}/…, and the caller must hold an active membership at that site. A caller without one gets 404, not 403, so a site's existence is not confirmed to strangers. -
Site roles are this shape's data (
acc_members.site_role):Site role Kernel role App May residentcustomer Resident their own unit: passes, walk-ins to answer, their household, their unit's log lines guardstaff Guard the gate: the queue (visitor, kind, party, unit label only), verify, check-in, check-out, refuse, walk-ins. Never a resident's name or phone number committeecustomer Committee the estate whole: units, members, every pass, the full log and its export, the weekly brief The operator (
project_adminorplatform_admin) creates sites and appoints each site's first committee. A binary opens onme.site_role, never on the kernel role. -
A state changes only by a verb. No route accepts a state. An illegal move answers 422
{ok: false, message}, as every shape does.ApiResponse::fail,postJsonand the rest read it that way. -
Every change writes its audit row in the same transaction (
AuditLog::record, the kernel'saudit_entrieschain), and one row in this shape's ownacc_events. The log the app reads isacc_events: per site, redacted per role. The audit chain is the tamper-evident record and is never read back to an app. -
Wire format. Times are epoch milliseconds in
*_at_ms, as in every shape, kept to the second (milliseconds sent are not stored), andstatus_timestampsis an object of state → time. Money is*_minorpluscurrency. Ids are ULIDs. Wire names for kinds, states and reasons are the app's own (apps/boma/lib/data/models.dart).
2. The data (acc_ prefix)
| Table | Holds |
|---|---|
acc_sites |
an estate: name, timezone |
acc_units |
a door in it: label (the JSON key the app reads), block |
acc_members |
one person at one site: user_ref, site_role, unit_id (residents), active |
acc_passes |
the permission: unit, kind, visitor, party_size, code, state, the window, the repeat, origin (household or gate), who issued and who answered |
acc_visits |
one arrival under a pass: arrived, checked in, checked out, refused, guard, device |
acc_events |
the log: action, reason, pass, unit, actor, device, at |
Every row carries product_slug (BelongsToProduct: no product bound, no rows).
3. The pass, held on the server
requested ──answer(yes)──▶ at_gate ──check-in──▶ checked_in ──check-out──▶ checked_out
│ ▲ │
└─answer(no)─▶ denied │ └─refuse─▶ denied
│
approved ──verify(code)──────┘ approved ──withdraw──▶ withdrawn
approved ──window over──▶ expired
- A household's pass is born
approved, with a six-charactercodefromABCDEFGHJKLMNPQRSTUVWXYZ23456789, unique among the site's open passes. - A walk-in is born
requested(logged by a guard, no code). Its own household or the committee answers. The guard who logged it cannot: 403. - Recurring help (gap 1): a pass may carry
repeat: {days, until_at_ms}, with days as ISO weekdays 1–7, and the window then reads as a daily time span. The pass staysapprovedacross its days, and each day's arrival is a visit.usedmeans "already admitted today" for a recurring pass, "already admitted" for a single one. - Expiry is applied when a pass is read or verified, and by a sweep every five minutes, so the queue never shows a pass whose window has closed.
- Verify refuses with one reason, every refusal is logged, and a run of bad codes is there to
read:
unknown_code,too_early,expired,used,declined,withdrawn,guard, andwrong_unit(gap 2: the guard sends the unit the visitor names, and a pass for another unit is refused, not shown).
4. Phase 1 routes: the gate core
All under /api/access. Reads need orders.read, writes orders.write. R resident,
G guard, C committee, Op operator.
Sites and people
GET /sites(anyone with a membership) →[{id, name, timezone, units[], me: {site_role, unit}}]. A list, because a guard may work two estates. A resident sees their own unit; a guard and the committee see every unit's{id, label, block}.POST /sites{name, timezone?} (Op) → 201.POST /sites/{site}/units{label, block?} (Op, C) → 201.GET /sites/{site}/members(C) → people withsite_role,unitandactive.POST /sites/{site}/members{phone, site_role, unit_id?} (Op, C) → 201. The person must have signed in to the product once. Otherwise 422not_a_user_yet, and the app can say "ask them to install the app first".PATCH /sites/{site}/members/{member}{site_role?, unit_id?, active?} (C).- Your household (gap 5):
GET /sites/{site}/household(R) → the residents of their own unit.POST /sites/{site}/household{phone} (R) adds a resident to their own unit only.DELETE /sites/{site}/household/{member}(R) removes one. A resident never sets a role or another unit.
Passes
GET /sites/{site}/passes?unit_id=&state=&from_at_ms=&to_at_ms=(R own unit, C any) → paginated.POST /sites/{site}/passes{kind, visitor, party_size?, valid_from_at_ms, valid_until_at_ms, repeat?, note?, unit_id? (C only)} (R, C) → 201approved, withcode. 422 on an empty name, a closed window, or a party outside 1–20.party_sizeis B (a) and defaults to 1.POST /sites/{site}/passes/{pass}/answer{let_in} (R of that unit, C) →at_gateordenied.POST /sites/{site}/passes/{pass}/withdraw(R of that unit, C) →withdrawn.
The gate (G)
GET /sites/{site}/gate/queue→{at_gate[], waiting[], expected[]}. Each entry is{id, kind, visitor, party_size, unit: {id, label}, valid_from_at_ms, valid_until_at_ms, state}. No resident names.GET /sites/{site}/gate/expected?minutes=60→ the passes due in the next n minutes, at most 240: B (b), the guard's next hour.POST /sites/{site}/gate/verify{code, unit_id, device_id?} →{verdict: cleared|stopped, reason?, pass?}.clearedmoves the pass toat_gate. Throttled per guard and site, and after five refusals in five minutes the guard is held for five minutes: 429, which the app shows as a lockout, not a wrong code.waitingis never returned here: a walk-in waiting on its household is in the queue'swaitinglist.POST /sites/{site}/gate/passes/{pass}/check-in·…/check-out·…/refuse{note, required}.POST /sites/{site}/gate/walk-ins{kind, visitor, party_size?, unit_id, note?} → 201requested, and the household is told.
The log
GET /sites/{site}/log?from_at_ms=&to_at_ms=&unit_id=→ events, newest first. A resident sees their own unit's. A guard sees today's gate lines, without names. The committee sees all.GET /sites/{site}/log/export(C) → CSV of the same. The export itself is recorded in the audit chain (access.log.exported), not in the log, whose actions are the app's own.
The weekly brief (C), B (c)
GET /sites/{site}/brief?week=2026-W41→ visitors and passes by kind in Phase 1. Incidents, shifts, complaints and dues come with their phases. Until then each isnullbesideavailable: false, so the app shows "not yet" rather than a zero.
5. Notifications (factory/notify)
Phase 1 sends three messages under four catalogue keys, each in English, French, Chinese and
Arabic, shipped in factory/notify 0.11.1, the release before this shape:
access.walk_in.waiting→ every active resident of the unit;access.walk_in.let_inoraccess.walk_in.declined, by the household's answer → the guard who logged the walk-in;access.pass.arrived→ every active resident of the pass's unit, on check-in (once a day, for a recurring pass).
A failed send is repor
Dependencies
Dependencies
| ID | Version |
|---|---|
| factory/auth | ^0.6 |
| factory/infra | ^0.3 |
| factory/kernel | ^0.10.3 |
| factory/notify | ^0.11.1 |
| illuminate/database | ^10.0 || ^11.0 || ^12.0 || ^13.0 |
| illuminate/routing | ^10.0 || ^11.0 || ^12.0 || ^13.0 |
| illuminate/support | ^10.0 || ^11.0 || ^12.0 || ^13.0 |
| php | ^8.2 |
Development dependencies
| ID | Version |
|---|---|
| orchestra/testbench | ^8.0 || ^9.0 || ^10.0 || ^11.0 |
| phpunit/phpunit | ^10.1 || ^11.0 || ^12.0 |