Skip to content

Company Onboarding

1. Purpose

Define the self-serve Company onboarding flow through Front Views, including Platform Admin approval, tier selection, and suspension behavior.

Sources: Architecture §5, Build Spec §1, §5.1, Domain §1, §2, API Conventions §5, §7, §9.

2. Supersession Notice

The preserved build spec states: "Onboarding is manual: the platform owner creates companies and bills by invoice. No payment gateway." This statement is superseded for TyteRide:

  • Company onboarding is self-serve through Front Views.
  • Platform Admin manually approves the application before the Company becomes active/usable as approved.
  • Billing remains invoice-only; there is no payment gateway.

This spec follows the TyteRide architecture and AGENTS terminology. Where the preserved spec conflicts, the TyteRide rework rules win.

3. Flow

sequenceDiagram
    autonumber
    participant V as Visitor (Front Views)
    participant A as API
    participant PA as Platform Admin
    participant M as Manager

    V->>A: POST /api/onboarding/companies (public, rate-limited)
    A->>A: Validate request
    A->>A: Create Company (pending approval)
    A->>A: Create Manager membership + first Company Code
    A-->>V: 201 { message, company, manager }

    A-->>PA: Application appears in Platform Admin queue
    PA->>A: Review application
    alt Approved
        PA->>A: Approve/activate Company + assign/confirm tier
        A-->>M: Company becomes usable; Manager can log in via phone+OTP
    else Rejected or held
        PA->>A: Reject/hold application
        A-->>V: Status communicated by defined channel
    end

    PA->>A: Suspend Company (if needed)
    A-->>M: Authenticated company routes return 403 with clear message

4. Contract

4.1 Public Submission

  • Surface: Front Views.
  • Endpoint: POST /api/onboarding/companies (public, rate-limited 3/hour/IP).
  • The API derives tenant/setup ownership from the onboarding flow; company_id is never accepted from clients on authenticated company routes.
  • The submission creates the Company, a Manager membership, and the first Company Code, per architecture.
  • No payment fields are accepted or processed. No extra company fields (city, address, CRN) are accepted in this slice.
  • notes is stored on the Company for Platform Admin review and is not returned in the public 201 response.

Request

Content-Type: application/json

{
  "company_name_en": "Acme Logistics",
  "company_name_ar": "أكمي للخدمات اللوجستية",
  "manager_name": "Ahmad Ali",
  "manager_phone": "+967700000000",
  "manager_email": "ahmad@acme.example",
  "tier_code": "starter",
  "locale": "en",
  "notes": "Optional note"
}
Field Type Rules
company_name_en string required, max 255
company_name_ar string required, max 255
manager_name string required, max 255
manager_phone string required
manager_email string required, email, max 255
tier_code string required, one of the tiers shown on the pricing page
locale string required, en or ar
notes string|null nullable, max 1000; stored for Platform Admin review, not returned in public responses

Response — 201 Created

{
  "message": "Application submitted for review.",
  "company": {
    "id": 1,
    "name_en": "Acme Logistics",
    "name_ar": "أكمي للخدمات اللوجستية",
    "status": "pending"
  },
  "manager": {
    "id": 1,
    "name": "Ahmad Ali",
    "phone": "+967700000000",
    "status": "pending"
  }
}

Error responses

Status Meaning Body
422 Validation failure { "message": "...", "errors": { "field": ["..."] } }
429 Rate limited (3/hour/IP) { "message": "..." }

Duplicate manager_phone or manager_email submissions return 422 with a field-level error on the conflicting field. The API must not expose whether a company already exists beyond the standard validation message.

4.2 Tier Selection

  • Company onboarding includes tier selection as part of the Front Views flow.
  • tier_code must be one of the tiers shown on the pricing page; invalid codes return 422.
  • Tier selection at signup is the requested tier; Platform Admin may assign/confirm the final tier during approval.
  • Tiers define min/max users; billing is invoice-only.
  • Front Views displays tier codes/limits and invoice-only labels (Invoice-only/Contact us), with no monthly prices and no placeholder field. The API seed is the source of truth for codes/limits: starter (1–50), growth (51–200), enterprise (201+/unlimited). max_users is null for enterprise. The API stores code, name_en, name_ar, min_users, and max_users; no price is accepted or charged by this endpoint.

4.3 Platform Admin Approval

  • The application appears in the Platform Admin queue (Filament, administrator role only).
  • Platform Admin approves or manages Company status.
  • Approval activates the Company for Manager access.
  • The Manager created during onboarding is pending until the Company is approved/activated through the Platform Admin flow.

4.4 Suspension

  • Company status includes suspended.
  • A suspended Company is blocked on the Dashboard and in both apps with a clear message.
  • Suspended Company returns 403 with a clear message on every authenticated company route.

5. Validation and Errors

  • Use standard error shape: { "message": string, "errors"?: Record<string, string[]> }.
  • Public onboarding endpoint is rate-limited at 3 requests/hour/IP (429).
  • Validation failures return 422 with field-level errors.
  • Duplicate manager_phone and manager_email return 422 with field-level errors.
  • Localized validation/message strings follow Accept-Language / lang/en, lang/ar; the request locale field records the applicant's preferred locale.
  • Front Views performs client-side validation for required fields, email format, phone format, max lengths, and tier selection before submit.

6. Security and Tenancy

  • POST /api/onboarding/companies is public; apply explicit rate limiting and abuse controls.
  • Do not expose internal approval/admin identifiers unnecessarily.
  • After onboarding, company-scoped access follows normal tenancy: company_id derived from membership; cross-tenant access returns 404.
  • Front Views must not hardcode API URLs; use PUBLIC_API_URL from environment.

7. Tests

  • Feature test: public onboarding submission creates Company, Manager membership, and first Company Code.
  • Contract test: request accepts only the documented fields; response 201 matches { message, company: {id, name_en, name_ar, status: "pending"}, manager: {id, name, phone, status: "pending"} }.
  • Error-shape contract: validation/rate-limit/errors conform to { message, errors? }.
  • Validation test: required fields, email, max lengths, locale enum, tier code, and notes max length return 422.
  • Duplicate test: duplicate manager_phone or manager_email returns 422 field-level error.
  • Rate-limit test: onboarding endpoint returns 429 when throttled.
  • Approval test: Platform Admin approval activates Company; Manager can authenticate and access allowed company routes.
  • Suspension test: suspended Company receives 403 with clear message on authenticated company routes.
  • Localization test: validation and messages localized for en/ar.
  • Security test: endpoint does not accept client-supplied privileged fields that bypass approval/tenancy.
  • Front Views test: form renders en/ar labels, validates required/email/phone/max/tier, submits to PUBLIC_API_URL, handles 201/422/429/network errors, disables submit while pending.

7.1 Slice 2 implementation status

Implemented: public submission, validation, duplicate phone/email, invalid tier, 3/hour/IP rate limiting, localized messages, Company/Manager User/Membership/Company Code creation, persisted onboarding notes for Platform Admin review (not returned publicly), /auth/me company shape, TenantContext/CompanyScope, and suspended-403 / cross-tenant-404 behavior on company routes. The contract defines only the /company/* prefix, not a concrete company profile route, so tenancy is verified through scoped repositories and test routes rather than a new production endpoint.

Deferred: Platform Admin approval/rejection queue and status transitions (Slice 8), applicant notification channel, resubmission after rejection, and E.164 phone normalization.

8. Open Questions

  • Company status lifecycle and naming around pending approval vs trial vs active (API returns pending for the onboarding application state; canonical company status transitions remain an implementation detail to confirm).
  • Tier selection semantics at signup: requested vs binding; Platform Admin override rules before/after approval.
  • Applicant notification channel for approval/rejection/hold.
  • Whether resubmission/edit is allowed after rejection or duplicate conflict.
  • Exact phone normalization/format rules beyond required string (E.164 normalization is recommended but not yet specified).
  • Abuse controls beyond 3/hour/IP rate limiting (captcha, email verification, etc.).