13 KiB
Mobile Coding Agent Spec
This document is the frontend handoff spec for an AI coding agent working on the mobile applications against the v2 backend.
Use this as the primary implementation brief.
Base URL:
https://krow-api-v2-e3g6witsvq-uc.a.run.app
Supporting docs:
/Users/wiel/Development/krow-workforce/docs/BACKEND/API_GUIDES/V2/authentication.md/Users/wiel/Development/krow-workforce/docs/BACKEND/API_GUIDES/V2/unified-api.md/Users/wiel/Development/krow-workforce/docs/BACKEND/API_GUIDES/V2/mobile-frontend-implementation-spec.md/Users/wiel/Development/krow-workforce/docs/BACKEND/API_GUIDES/V2/staff-shifts.md
1) Non-negotiable rules
- Use the unified base URL only.
- Do not call
/query/*,/commands/*, or/core/*directly from frontend. - Send
Authorization: Bearer <firebase-id-token>on protected routes. - Send
Idempotency-Keyon every write route. - Treat
order,shift,shiftRole, andassignmentas different objects. - For staff shift applications,
roleIdmust come from the response ofGET /staff/shifts/open. - For staff order booking,
roleIdmust come from the response ofGET /staff/orders/available. - Treat API timestamp fields as UTC and convert them to local time in the app.
2) What is implemented now
Safe to build against now:
- client auth/session
- client dashboard, billing, coverage, hubs, vendors, managers, team members, orders, reports
- client coverage reviews, worker rating, block/unblock, late-worker cancellation
- client swap review and dispatch-team management
- staff auth/session
- staff dashboard, availability, payments, shifts, profile, tax forms, bank accounts, benefits, documents, attire, certificates
- staff clock-in, clock-out, location streaming, swap request, completed-shift submission
- upload, signed URL, verification, and rapid-order processing
Not part of this implementation spec:
- backend
/auth/refresh - SMS or email notification fallback
- AI-driven report insights
- AI-driven personalized shift matching
- full NFC attestation enforcement
- chat backend
3) Auth implementation
Client app
Use:
POST /auth/client/sign-inPOST /auth/client/sign-upGET /auth/sessionPOST /auth/client/sign-out
Do not build a separate refresh route.
Token refresh remains on the Firebase client SDK side.
Staff app
Use:
POST /auth/staff/phone/startPOST /auth/staff/phone/verifyGET /auth/sessionPOST /auth/staff/sign-out
Important:
POST /auth/staff/phone/startcan returnmode = CLIENT_FIREBASE_SDK- when that happens, the app must complete Firebase phone verification on-device
- after that, the app must call
POST /auth/staff/phone/verifywith the FirebaseidToken
Do not assume staff auth is a fully backend-managed OTP flow.
4) Core data model assumptions
order: client-facing staffing requestshift: a scheduled work instance under an ordershiftRole: a role slot inside a shiftapplication: worker applies to ashiftRoleassignment: worker is actually attached to a shift
Rules:
GET /staff/shifts/openreturns opportunities, not assignmentsGET /staff/orders/availablereturns grouped order opportunities for bookingGET /staff/shifts/assignedreturns active assigned shiftsGET /client/shifts/scheduledis the canonical timeline/read model for clientGET /client/orders/viewis now a deprecated compatibility aliasPOST /client/orders/:orderId/editandPOST /client/orders/:orderId/cancelapply to future shifts only
5) Client app screen mapping
Home
GET /client/sessionGET /client/dashboardGET /client/reorders
Billing
GET /client/billing/accountsGET /client/billing/invoices/pendingGET /client/billing/invoices/historyGET /client/billing/current-billGET /client/billing/savingsGET /client/billing/spend-breakdownPOST /client/billing/invoices/:invoiceId/approvePOST /client/billing/invoices/:invoiceId/dispute
Coverage
GET /client/coverage?date=YYYY-MM-DDGET /client/coverage/stats?date=YYYY-MM-DDGET /client/coverage/core-team?date=YYYY-MM-DDGET /client/coverage/incidents?startDate=YYYY-MM-DD&endDate=YYYY-MM-DDGET /client/coverage/blocked-staffGET /client/coverage/swap-requests?status=OPENGET /client/coverage/dispatch-teamsGET /client/coverage/dispatch-candidates?shiftId=uuid&roleId=uuidPOST /client/coverage/reviewsPOST /client/coverage/late-workers/:assignmentId/cancelPOST /client/coverage/swap-requests/:swapRequestId/resolvePOST /client/coverage/swap-requests/:swapRequestId/cancelPOST /client/coverage/dispatch-teams/membershipsDELETE /client/coverage/dispatch-teams/memberships/:membershipId
Coverage review payload:
{
"assignmentId": "uuid",
"rating": 4,
"comment": "Strong performance on the shift",
"markAsBlocked": false
}
Rules:
- worker rating happens through
POST /client/coverage/reviews - the same endpoint also supports
markAsFavoriteto add or remove a worker from business favorites - blocking a worker is done through the same endpoint using
markAsBlocked - coverage shift items now include
locationNameandlocationAddress - assigned worker items now include
hasReview - dispatch ranking order is:
CORECERTIFIED_LOCATIONMARKETPLACE
Swap management flow:
- worker requests swap
- backend moves original assignment to
SWAP_REQUESTED - replacement workers see the shift in
GET /staff/shifts/open - client/ops reads
GET /client/coverage/swap-requests - client/ops reads
GET /client/coverage/dispatch-candidates - client/ops resolves or cancels the swap request
- if unresolved and expired, backend auto-cancels it
Orders
GET /client/shifts/scheduledGET /client/orders/viewdeprecated aliasGET /client/orders/:orderId/reorder-previewPOST /client/orders/one-timePOST /client/orders/recurringPOST /client/orders/permanentPOST /client/orders/:orderId/editPOST /client/orders/:orderId/cancelPOST /rapid-orders/process
Rules:
- use
POST /rapid-orders/processfor the single-call rapid-order flow - recent orders should expect total price and hourly rate fields
- order edit and cancel only affect future shifts
Hubs and managers
GET /client/hubsGET /client/cost-centersGET /client/hubs/:hubId/managersGET /client/team-membersPOST /client/shift-managersPOST /client/hubsPUT /client/hubs/:hubIdDELETE /client/hubs/:hubIdPOST /client/hubs/:hubId/assign-nfcPOST /client/hubs/:hubId/managers
Rules:
POST /client/shift-managerscreates an invited manager identity- if
hubIdis present, backend links the manager to that hub too
Reports
GET /client/reports/summary?date=YYYY-MM-DDGET /client/reports/daily-ops?date=YYYY-MM-DDGET /client/reports/spend?date=YYYY-MM-DDGET /client/reports/coverage?date=YYYY-MM-DDGET /client/reports/forecast?date=YYYY-MM-DDGET /client/reports/performance?date=YYYY-MM-DDGET /client/reports/no-show?date=YYYY-MM-DD
Important:
- these are operational reports
- this is not the same as the separate AI insights research issue
6) Staff app screen mapping
Home
GET /staff/sessionGET /staff/dashboardGET /staff/profile/statsGET /staff/profile-completion
Availability
GET /staff/availabilityPUT /staff/availabilityPOST /staff/availability/quick-set
Find shifts
GET /staff/orders/availablePOST /staff/orders/:orderId/bookGET /staff/shifts/openPOST /staff/shifts/:shiftId/apply
Rule:
- use
roleIdfrom the order-available response when booking an order - that
roleIdis the role catalog id for the grouped order booking flow - use
roleIdfrom the open-shifts response only for shift-level apply - that
roleIdis the concreteshift_roles.id
My shifts
GET /staff/shifts/pendingGET /staff/shifts/assignedGET /staff/shifts/cancelledGET /staff/shifts/completedGET /staff/shifts/:shiftIdPOST /staff/shifts/:shiftId/acceptPOST /staff/shifts/:shiftId/declinePOST /staff/shifts/:shiftId/request-swapPOST /staff/shifts/:shiftId/submit-for-approval
Staff shift detail and list rules:
- assigned shifts include
clientName,hourlyRate,totalRate,startTime,endTime - shift detail includes
clientName,latitude,longitude,hourlyRate,totalRate - completed shifts include
date,clientName,startTime,endTime,hourlyRate,totalRate GET /staff/profile/statsreturnstotalShifts,averageRating,ratingCount,onTimeRate,noShowCount,cancellationCount,reliabilityScore
Clock in / clock out
GET /staff/clock-in/shifts/todayGET /staff/clock-in/statusPOST /staff/clock-inPOST /staff/clock-outPOST /staff/location-streams
Clock-in payload rules:
- if using NFC, send
nfcTagId - if using geo, send
latitude,longitude,accuracyMeters - send
overrideReasononly when geo override is allowed - send
proofNonceandproofTimestampon attendance writes - send
attestationProviderandattestationTokenonly if the device has them - if backend returns
ALREADY_CLOCKED_IN, treat it as a valid retry-state signal and refresh attendance/session state
Clock-in read rules:
GET /staff/clock-in/shifts/today returns fields including:
clientNamehourlyRatetotalRatelatitudelongitudeclockInModeallowClockInOverridegeofenceRadiusMetersnfcTagId
Policy values:
NFC_REQUIREDGEO_REQUIREDEITHER
Payments
GET /staff/payments/summaryGET /staff/payments/historyGET /staff/payments/chart
Profile
GET /staff/profile/sectionsGET /staff/profile/personal-infoGET /staff/profile/industriesGET /staff/profile/skillsGET /staff/profile/documentsGET /staff/profile/attireGET /staff/profile/tax-formsGET /staff/profile/emergency-contactsGET /staff/profile/certificatesGET /staff/profile/bank-accountsGET /staff/profile/benefitsGET /staff/profile/benefits/historyGET /staff/profile/time-cardGET /staff/profile/privacyPUT /staff/profile/personal-infoPUT /staff/profile/experiencePUT /staff/profile/locationsPOST /staff/profile/emergency-contactsPUT /staff/profile/emergency-contacts/:contactIdPUT /staff/profile/tax-forms/:formTypePOST /staff/profile/tax-forms/:formType/submitPOST /staff/profile/bank-accountsPUT /staff/profile/privacy
Profile data rules:
GET /staff/profile/documentsreturns documents onlyGET /staff/profile/attirereturns attire onlyGET /staff/profile/tax-formsreturns tax forms onlyGET /staff/profile/certificatesreturns certificates only- benefit summary and benefit history are separate endpoints
FAQ
GET /staff/faqsGET /staff/faqs/search?q=...
7) Upload flows
General upload pattern
For documents, attire, and certificates:
POST /upload-filePOST /create-signed-url- upload bytes to storage
POST /verifications- finalize using the appropriate staff route
Staff upload routes:
POST /staff/profile/photoPOST /staff/profile/documents/:documentId/uploadPUT /staff/profile/documents/:documentId/uploadPOST /staff/profile/attire/:documentId/uploadPUT /staff/profile/attire/:documentId/uploadPOST /staff/profile/certificatesDELETE /staff/profile/certificates/:certificateId
Rules:
- backend treats verification-linked file state as the source of truth
- frontend may still send
fileUriorphotoUrl, but verification linkage wins
8) What the coding agent should not assume
- do not invent a backend refresh route
- do not assume swap is staff-only; there is now a client/ops review side
- do not assume documents and attire share the same read endpoint
- do not assume backend direct CRUD on internal services
- do not assume AI reports, SMS fallback, or full NFC attestation are available
9) Suggested implementation order for the coding agent
- auth/session flows
- client home + orders + coverage
- staff home + shifts + clock-in
- profile sections and upload flows
- reports and billing polish
- swap review and dispatch-team management
10) Definition of done for frontend integration
Frontend implementation is aligned when:
- every screen calls the unified v2 routes only
- every write sends an
Idempotency-Key - staff shift apply uses
roleIdfrom open shifts - clock-in respects
clockInMode - swap request uses the staff endpoint and swap review uses the client coverage endpoints
- documents, attire, certificates, and tax forms use their correct route families