School operations
Feature flags, health, guardian cards, collaboration, Microsoft actions, the operator platform and the other small modules that keep a school running.
A set of small modules that don't fit a single feature. Every path starts with /api/v1.
| Module | What it does | Who can call it |
|---|---|---|
| Feature flags | Turns features on per school or campus | Any signed-in user reads their own |
| Health | Checks every dependency | Public summary; detail for platform_admin |
| Addresses | Operator address register | Super admin |
| Short links | 8-character redirect codes | Public |
| Guardian cards | QR cards checked at the gate | Staff issue; anyone verifies |
| Referrals | Commission for referred applicants | Staff with referral permissions |
| NCDC documents | National curriculum files for lesson planning | Platform admin; staff chat |
| Collaboration | Live editing over a websocket | Staff |
| Social accounts | WhatsApp and other campus accounts | Staff with social_connection |
| Microsoft actions | Drive, calendar, account creation | Staff |
| Platform and dev | Operator control plane; local-only tools | platform_admin; development only |
Feature flags
GET /feature-flags/me returns the flag rows for the caller's school, or an empty list when the token has no school. The Hub fetches it once per session.
How evaluateFeature decides:
| Row | Scope | Result |
|---|---|---|
| None, or not enabled | Any | Off, payload null |
| Enabled | School | On for every campus |
| Enabled | Campus, empty list, or no campus id in the check | On |
| Enabled | Campus, list without this campus | Off |
featureFlags.bypass turns every check on and keeps the stored payload.
From API 52aac0dc6, checks and the me list read a school's rows from the cache Redis (flags:{schoolId}, 60 seconds), falling back to Postgres. Saving flags deletes that key, so every API copy sees the change on its next check. A cache failure counts as a miss and never throws.
FeatureFlagGuard runs on routes with @RequireFeature. Public routes and platform admins pass. Everyone else needs one listed feature on for their school and the campus id in the path, query or body. Off throws FEATURE_DISABLED. See Authentication.
Saving a school's flags rejects a campus from another school, then upserts and emits feature-flag.updated.
Health
| Route | Access | Returns |
|---|---|---|
GET /health | Public | Overall status, plus up or down for Postgres, Redis, RabbitMQ, Centrifugo, worker, audit, server |
GET /health/detailed | platform_admin | Also versions, latency, queue counts, memory, and instances (copies that reported in the last 30 seconds) |
- Results are cached for 5 seconds. A failed probe reports
down; it never throws. - Overall is
uponly when every part isup. - A queue is
downat 100 or more waiting jobs, or when the count can't be read. - Worker and audit are
downunless they answer within 5 seconds and their queues areup. - The school Service Health screen polls the public summary. See Portal routes.
Addresses and short links
Addresses are an operator register for super admins, not the campus address on the website. Delete is a soft delete. A missing id is Address not found.
Short links (GET /short-links/:code) are public, left out of OpenAPI, and limited to 600 requests a minute per IP, counted in Redis across every API copy. The code resolves to its stored target. A missing, malformed, unknown or expired code goes to the Hub home page instead. When shortLink.url is unset, creating a link just returns the original URL.
Guardian cards
A guardian carries a QR card. A guard scans it at the gate with any phone; no login is needed.
The QR opens the Hub page /$reference/g/$token, which calls GET /guardian-cards/verify/:reference/:token.
Staff actions at guardians/:guardianId/card need Feature.GUARDIAN_CARDS:
| Action | Permission | Effect |
|---|---|---|
| Read | read on guardian | |
| Issue | update | Revokes any older card; new 16-byte token; expires in 5 years |
| Renew | update | Same token; expires 5 years from today |
| Expire | update | Expires now |
| Revoke | delete | Sets revokedAt |
What the gate check returns. The route is public, uncached (no-store) and limited to 20 requests a minute per IP.
| Card | Status | Shown to the guard |
|---|---|---|
| Unknown token, wrong school, or feature off | 404 | "Card not found" (all three look the same) |
| Revoked | invalid | "Not valid. Do not accept this card." Office phone only |
| Past expiry | expired | "Expired", expiry date, office phone |
| Good | valid | Guardian name, students (first name, class, campus; current-year active enrolments only), campuses, issue and expiry dates |
Only revoke and expiry make a card invalid or expired. A student leaving does not. The clock on the page is the phone's own.
NCDC documents
ncdc/documents needs Feature.LESSON_PLANNING. Platform admins upload and manage; staff can also chat with the documents.
- Uploading the same storage id twice returns the existing row.
- Delete removes the assistant file and the row, and the stored file only if no other document uses it.
- A subject with no indexed documents matches nothing in chat; it does not fall back to the whole set.
Collaboration
No HTTP controller. CollabService runs a websocket at /collab on each API process. Saves wait 5 seconds after the last edit and at most 30. Rover's writes go through the same document, so they merge with open sessions. How copies share documents through Redis is on Several copies.
Document names are type:id, where type is scheme, plan, record or template. Who can connect:
| Caller | Connects |
|---|---|
| Not staff, no school, bad token or bad name | Refused |
Feature.LESSON_PLANNING off | Refused |
| Viewer of a scheme or plan | Read only |
| Viewer of a record | Refused (the signed copy is read over REST) |
| Author, while a prefill is running or the year is locked | Read only |
| Author otherwise | Can edit |
Template: built-in, or caller can't manage template | Read only |
Locking a year closes every open scheme, plan and record in it without deleting stored documents.
Social accounts
campus/:campusId/social-connections checks social_connection permission on that campus for each action.
| Action | Rule |
|---|---|
| Connect | Refused if already connected. The sign-in link lasts 15 minutes, then a pending row shows disconnected |
| Reconnect | Keeps the row, drops the provider account, issues a new link |
| Pause | Only from connected. Campus WhatsApp falls back to the default line |
| Resume | Only from paused |
| Disconnect | Connected: clears the provider id. Any other status: deletes the row |
After sign-in the browser returns to the campus connection settings with status=connected or status=failed, on an allow-listed frontend origin. The webhook signature check is on HTTP surface.
Microsoft Drive, calendar and provisioning
Staff actions beside Microsoft 365 sync.
| Controller | Needs | Rules worth knowing |
|---|---|---|
drives | Feature.ONEDRIVE, staff, file consent | The root can't be deleted, renamed or moved. Name clashes return A file or folder with that name already exists |
calendars | Staff, calendar consent | End must be after start. Agenda looks a year ahead, up to 100 Outlook events. Outlook down still returns school events. Lessons need Feature.TIMETABLE |
| Provisioning | A school on the token | See below |
On main. Deployment was not verified. main is 6bfb9f6bdb004fd3a909405c2c826cf1e383249b (merge of PR #677, 25 November 2026, 04:29 GMT). It shares tree c02ff4560f9a809a1a213073f5651c40eba7b25f with staging 0d611c966e84961c64e909ab50f424a0f2510b6f. Compare d229592a...6bfb9f6b is 78 files and does not include these calendar files, so the writes below are the same as on d229592a. No request was sent and no host was checked. The design notes under docs/superpowers were not used as behaviour.
POST /calendars/events returns 201 and posts to Graph /me/events, the caller's main Outlook calendar, with a new transaction id. The Hub database does not store the event. PATCH /calendars/events/:id returns 200. DELETE /calendars/events/:id returns 204. All three are staff only.
The write uses a separate token. Its refresh scope is Calendars.ReadWrite. The read refresh stays Calendars.Read. The consent URL asks for both. Until the write refresh succeeds, the call is 409, message Outlook has not allowed the Hub to add events, code calendar_write_not_allowed. That refusal is remembered for 60 seconds on the server process that saw it. Saving a new connection clears that memory. Reading still works.
inviteeIds are staff user ids in the caller's school, at most 100. The caller is left out. Addresses come from those staff rows, not from the request. A missing person, or a person with no email, is Some of the people you picked cannot be invited. On update those people are added to whoever is already invited. removeInvitees are email addresses, at most 500, and apply only on update.
teamsLink true adds a Teams meeting. On update the link is only switched on. Outlook is not asked to remove one. Title is from 1 to 200 characters. Location is at most 200. Details are at most 4000. Leaving details out on update keeps the notes already in Outlook. Times are wall clock YYYY-MM-DDTHH:mm, with optional seconds, in the school timezone, or Africa/Kampala when the school has none. A timed event needs the end after the start. An all-day event may use the same day for both, and Outlook receives it from midnight to the midnight after the last day.
Only the organiser can change or delete the event. A Hub school-event copy, marked with the Naalya tag, is refused with Only the organiser can change this event, including when the caller organised it. A missing event is That event is no longer in your calendar.
The event shape gains canEdit (true when the caller organised it), invitees with reply of accepted, declined, maybe, or none (tentativelyAccepted is maybe), and joinUrl. The view and agenda use the same mapper, so those fields appear there too. Create and update pass an empty calendar id into that mapper. GET /calendars sets canEdit on the default calendar only, and only when a write token can be minted.
The Hub screens that call these routes are on Hub main 2dd88361, the same tree as staging 413b5cfe. The steps are on School calendar. A merge to Hub main is not a running deploy.
Creating a staff account:
Preview the address. A taken staff address gets the next free number, starting at 2. Student addresses are not numbered.
Create. The department, campus and role are checked first. The address must be the previewed one or a numbered version on the default domain.
Read the outcome. created, exists (no second account made), or failed with the step that stopped: licence, profile, department or role. The Microsoft account is kept on failure. The password comes back once and is never stored.
Deleting staff with their Microsoft account deletes in Microsoft first. If Microsoft refuses (403, often an admin role), the Hub user stays.
Platform, providers and the development module
| Module | What it is |
|---|---|
platform | Operator control plane. platform_admin plus manage on school. Creating, suspending, and impersonating are below |
PlatformAdminSeedService | At boot, creates a school-less platform_admin for each SUPERADMIN_EMAILS address on an allowed domain. Existing users are left alone |
providers | Clients only, no routes: Pinecone, Microsoft Graph, Cloudflare auto-RAG, Unipile |
dev | Mounted only when NODE_ENV is exactly development. A public PDF preview; never point it at a shared environment |
Operator schools
Every route under /api/v1/platform needs a platform admin with manage on school. Creating a school, suspending or activating it, and stepping into one of its users are below. No school was created, suspended, or impersonated.
POST /platform/schools (provisionSchool) creates an active school and its first staff user. The body is a name, an optional reference, an admin email, and the admin's first and last name.
The reference is the slug of the given reference, or of the name, or the word school when that slug is empty. slugify itself was not opened. A reference that is reserved or already used gets a suffix from 2 to 50 (north-2, then north-3). After north-50 is also taken, the call refuses with Could not generate a unique school reference. These words are reserved: staff-hub, student, guardian, guest, platform, auth, 403, system-status, pay, api, docs, queues, s, admin, app.
An admin email that already belongs to a user is A user with the admin email already exists. A new school also gets a config whose super-admin list is that one email, default branding, a clone of the system roles, and the Super Admin role at school scope, assigned by the operator.
provisionStaffUser writes that admin inside the same transaction. The user is active staff, local sign-in, with email not yet verified, and the create call sets no password hash. The staff profile stores the given first and last name and a generated staff access code. Nothing in this path sends a welcome mail. generateSlug was not re-opened. The reply is the school plus the admin user's id, email, and type.
That admin signs in on the school's one-time-code routes. The route table is on Authentication across the platforms. LoginOtpService treats an identifier that contains @ as an email and any other identifier as an access code. An email that isTempEmail marks as temporary is skipped. That helper was not opened. The account must be active. The service does not read emailVerified. A request that names a school matches only that school's users. A request with no school id matches only a platform admin, so this staff user does not.
The code is 6 digits and is kept as a SHA-256 hash. Schema defaults are 15 minutes, a wait of 30 seconds before another code, and 10 wrong tries, after which the code is dropped. The mail subject is Your Naalya login code. These are the refusals.
| What the caller did | Error thrown |
|---|---|
| A missing account, or one outside that school | No account found for this identifier |
| An inactive account | Account is deactivated |
| A bad, missing, or expired code | Invalid or expired code |
| Wrong tries reach 10 | Too many attempts. Please request a new code. |
| Another code during the wait | Please wait before requesting another code. |
30 wrong codes for that account within 24 hours (API staging 6308a8a1 only, not on main) | Too many wrong codes. Please try again tomorrow or sign in another way. |
loginWithOtp was not opened. No code was sent.
PATCH /platform/schools/:id/suspend sets the status to suspended. PATCH /platform/schools/:id/activate sets it back to active. Neither route looks at the current status. An unknown id is School not found. The status write does not revoke tokens.
A suspended school blocks a new session. Local, OTP, and magic-link sign-in throw School is suspended before any token is minted. Microsoft sign-in throws the same. On API staging ed0e56f8 (not on main d0fbb403), a soft-deleted match is a separate refusal: 403 This account was removed. Ask the school office for help., with an ACCESS deny. Detail is on Auth & Permissions. A refresh throws School is suspended and does not revoke the refresh token it was given. Guardian and guest self-registration throws Invalid school when the school is missing or not active. These were the SchoolStatus.SUSPENDED checks in AuthService and TokenService. naalya-ai.service.ts also names that status and was not opened. A guard that rejects an access token already issued was not found in the files that were opened.
On API staging 6308a8a1 (not on main d0fbb403), minting a token also refuses a deactivated account or a profile whose isActive is false, with 403 This account is suspended. That includes refresh, except an impersonation mint and a refresh of an impersonation token. An access token already issued is still not revoked. The wrong-code row above is the same commit: 30 failures, 429, counted for 24 hours from the first one. A correct code clears that count. token.service.ts, login-otp.service.ts, and login-otp.store.ts were read. The tests were not run. A merge to staging is not a running deploy.
POST /platform/schools/:id/impersonate takes a userId. The user must belong to that school, or the call is Target user does not belong to this school. It then uses the same AuthService.impersonate path as POST /auth/impersonate. Impersonating yourself is You cannot impersonate yourself. A missing user is User not found. A deactivated user is Cannot impersonate a deactivated user. A platform admin may impersonate a super admin. Any other caller gets Super admins cannot be impersonated. The reply is an access token and a refresh token. The access token's act claim is the operator, and the refresh row stores the same id. The platform route itself has no @Audit decorator. The access log is IMPERSONATE_START inside AuthService.
Operator accounts sit on the same controller. POST /platform/admins refuses an email outside PLATFORM_ADMIN_EMAIL_DOMAINS with Platform operator email must use an approved domain. When that variable is unset or empty, the schema falls back to chowbea.com. An email already in use is Email already in use, unless it belongs to a soft-deleted operator, who is restored and renamed. A new operator is a local user with an empty password hash. How that empty hash signs in was not traced. PATCH /platform/admins/:id changes the first and last name only, and an unknown id is Operator not found. DELETE /platform/admins/:id soft-deletes the user and the profile. Deleting yourself is You cannot delete your own operator account. A deleted operator returns Operator deleted.
Stats, per-school people lists, config, and branding are on this controller too. Their field lists were not copied. A logo upload accepts a PNG, JPEG, or WebP of at most 5 MB.