- Docs
- Specs
- Notifications
Notifications¶
This page specifies user notifications and mobile device token registration for TyteRide. It covers device token upsert/revocation for Passenger/Driver apps, current-user notification listing, unread count, and read-state transitions.
Sources: API Conventions, Domain Glossary, Sessions and Roles, Passenger App, Mobile Porting Plan.
1. Purpose and scope¶
Slice 10 provides the notification read model and device token registry used by mobile clients. It does not implement push delivery, notification fan-out, realtime notification events, or domain-event producers; those remain future work. Notifications are created by application services in future slices or internal jobs; this slice exposes storage, ownership, and read APIs.
2. Authorization and tenancy¶
| Rule | Contract |
|---|---|
| Authentication | auth:sanctum required for all endpoints. |
| Device token registration | Authenticated Passenger or Driver only; User must have an active passenger or driver Membership. |
| Notification access | Current authenticated User only. Notifications are scoped by user_id; cross-user access returns 404. |
| Company scope | company_id is stored on notification/device token records when available from the User's membership; it is never accepted from clients. Company routes are not used; endpoints are user-scoped under /api/notifications. |
| Cross-tenant leakage | A notification/device token belonging to another User is never returned, even within the same Company. |
Manager/company notifications are only allowed when explicitly documented by the producing slice; this slice stores company_id and user_id so such notifications can be addressed to a specific Manager User without exposing other Company users.
3. Endpoints¶
All paths are relative to /api.
| Method | Path | Audience | Purpose |
|---|---|---|---|
POST |
/notifications/device-tokens |
Passenger/Driver (auth:sanctum + active passenger/driver membership) |
Register or refresh a device token. |
DELETE |
/notifications/device-tokens/{id} |
Passenger/Driver (owner only) | Revoke/delete a device token. |
GET |
/notifications |
Authenticated User | List current User notifications, newest first. |
GET |
/notifications/unread-count |
Authenticated User | Return unread notification count for current User. |
POST |
/notifications/{id}/read |
Authenticated User (owner only) | Mark one notification as read. |
POST |
/notifications/read-all |
Authenticated User | Mark all current User unread notifications as read. |
4. Device token contract¶
4.1 Register device token¶
POST /api/notifications/device-tokens
Request body:
{
"platform": "android",
"token": "fcm-or-apns-token"
}
| Field | Type | Rules |
|---|---|---|
platform |
string | Required; android, ios, or web. |
token |
string | Required; trimmed; max 4096 chars. |
Behavior:
- Upsert is keyed by token. If the token already exists, its user_id, company_id, platform, last_seen_at, and revoked_at=null are updated (token ownership moves to the current authenticated User).
- If the token does not exist, a new active device token is created.
- company_id is derived from the User's current membership when present; otherwise null.
201 for create, 200 for update/re-activation. Response (DeviceTokenResource, unwrapped):
{
"id": 1,
"platform": "android",
"token": "fcm-or-apns-token",
"last_seen_at": "2026-11-27T12:00:00Z",
"created_at": "2026-11-27T12:00:00Z",
"updated_at": "2026-11-27T12:00:00Z"
}
4.2 Revoke/delete device token¶
DELETE /api/notifications/device-tokens/{id}
- Deletes the device token owned by the current User.
- Missing/cross-user token returns
404. - Response:
200{ "message": "Device token deleted." }(localized).
5. Notification contract¶
5.1 Notification fields¶
NotificationResource:
{
"id": 10,
"type": "trip.extra_car_assigned",
"title": "Extra car assigned",
"body": "A new car has been assigned for your trip.",
"data": { "trip_id": 12 },
"read_at": null,
"created_at": "2026-11-27T12:00:00Z"
}
| Field | Type | Notes |
|---|---|---|
id |
integer | Notification ID. |
type |
string | Stable machine-readable type key. |
title |
string | Localized/display title stored at creation time. |
body |
string | Localized/display body stored at creation time. |
data |
object | JSON payload; defaults to {}. |
read_at |
string/null | ISO-8601 UTC when read. |
created_at |
string | ISO-8601 UTC. |
5.2 List notifications¶
GET /api/notifications
Query filters:
| Filter | Type | Default | Behavior |
|---|---|---|---|
page |
integer >=1 | 1 | Page number. |
per_page |
integer 1–100 | 15 | Page size. |
200 response uses the standard collection envelope (data, meta, links). Sorted by created_at desc, id desc.
5.3 Unread count¶
GET /api/notifications/unread-count
200:
{
"unread_count": 3
}
5.4 Mark one read¶
POST /api/notifications/{id}/read
- Marks the owned notification as read. If already read, returns the notification unchanged (idempotent).
- Missing/cross-user notification returns
404. 200returnsNotificationResource.
5.5 Mark all read¶
POST /api/notifications/read-all
- Marks all unread notifications owned by the current User as read.
200:
{
"message": "Notifications marked as read.",
"updated_count": 3
}
6. Validation and errors¶
Errors follow { "message": string, "errors"?: Record<string, string[]> }.
| Case | Status | Envelope |
|---|---|---|
| Invalid device token payload | 422 | message + field errors |
| Invalid pagination/filter format | 422 | message + field errors |
| Missing/invalid token | 401 | message only |
| Device token endpoint used without active passenger/driver membership | 403 | message only |
| Missing/cross-user notification or device token | 404 | message only |
7. Data model¶
device_tokens¶
| Field | Type / notes |
|---|---|
id |
bigint PK |
user_id |
FK users, cascade delete |
company_id |
nullable FK companies, null on delete |
platform |
string (android, ios, web) |
token |
text/string unique; device push token |
last_seen_at |
nullable timestamp |
revoked_at |
nullable timestamp (reserved; delete is used by Slice 10) |
| timestamps | created_at, updated_at |
Indexes: unique token, index (user_id, updated_at), index (company_id, platform).
notifications¶
| Field | Type / notes |
|---|---|
id |
bigint PK |
user_id |
FK users, cascade delete |
company_id |
nullable FK companies, null on delete |
type |
string(100) machine-readable key |
title |
string(255) |
body |
text |
data |
json, default {} |
read_at |
nullable timestamp |
| timestamps | created_at, updated_at |
Indexes: (user_id, read_at, created_at), (user_id, created_at), (company_id, created_at).
8. Open questions¶
- Push delivery: FCM/APNs/Web Push provider integration, token invalidation callbacks, and delivery retries are out of scope.
- Notification producers: Which domain events create notifications (extra car, booking decision, D2D decision, etc.) is slice-specific follow-up work.
- Localization strategy: Slice 10 stores
title/bodyas rendered strings; future slices may move to translation keys + params. - Retention/pruning: Notification TTL/archive policy is not defined.
- Manager/company broadcasts: Company-wide broadcasts need an explicit producer contract; this slice only supports per-user records.