factory/shape-access-control (0.2.1)

Published 2026-11-12 10:22:16 +00:00 by bmiadmin

Installation

{
	"repositories": [{
			"type": "composer",
			"url": ""
		}
	]
}
composer config repositories.bmiadmin composer 
composer require factory/shape-access-control:0.2.1

About this package

The gate as a shape: sites, units and their people, visitor passes held on the server, and a gate that admits against them (Boma).

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 add factory.can:orders.read. Writes add factory.can:orders.write and throttle:factory-writes. Shapes ride the orders.* boundary, so this adds no new ability to the kernel.

  • People. Whoever a route adds by phone, names beside a record or notifies is found through the kernel's People seam (0.10.4), never a user model: factory/auth's users by default, the console's own per-project users where the console hosts the shape (docs/architecture/ONE_SIGN_IN.md).

  • The shape gate. A token whose product's shape does not include access-control gets 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_admin sees 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
    resident customer Resident their own unit: passes, walk-ins to answer, their household, their unit's log lines
    guard staff 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
    committee customer Committee the estate whole: units, members, every pass, the full log and its export, the weekly brief

    The operator (project_admin or platform_admin) creates sites and appoints each site's first committee. A binary opens on me.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, postJson and the rest read it that way.

  • Every change writes its audit row in the same transaction (AuditLog::record, the kernel's audit_entries chain), and one row in this shape's own acc_events. The log the app reads is acc_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), and status_timestamps is an object of state → time. Money is *_minor plus currency. 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-character code from ABCDEFGHJKLMNPQRSTUVWXYZ23456789, 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 stays approved across its days, and each day's arrival is a visit. used means "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.
  • Once a day (0.1.1). A pass admits at most once a day, a single pass once at all. Recurring help turned away today is refused again today (declined) and comes back on its next day. Two doors scanning one code in the same instant clear it once: the pass is re-read under its row lock before a visit opens, and a unique (pass, day) index on visits backs the rule.
  • 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, and wrong_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 with site_role, unit and active.
  • POST /sites/{site}/members {phone, site_role, unit_id?} (Op, C) → 201. The person must have signed in to the product once. Otherwise 422 not_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) → 201 approved, with code. 422 on an empty name, a closed window, or a party outside 1–20. party_size is B (a) and defaults to 1.
  • POST /sites/{site}/passes/{pass}/answer {let_in} (R of that unit, C) → at_gate or denied.
  • 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?}. cleared moves the pass to at_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. waiting is never returned here: a walk-in waiting on its household is in the queue's waiting list.
  • 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?} → 201 requested, 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

Dependencies

Dependencies

ID Version
factory/auth ^0.6
factory/infra ^0.3
factory/kernel ^0.10.4
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
Details
Composer
2026-11-12 10:22:16 +00:00
2
2026-11-12 11:42:58 +00:00
proprietary
72 KiB
Assets (1)
Versions (4) View all
0.2.1 2026-11-12
0.2.0 2026-10-20
0.1.1 2026-10-09
0.1.0 2026-10-08