Skip to content

Architecture

DDD layers

Request flow: FormRequest → DTO → Application Service → Domain → Infrastructure → JsonResource. Controllers stay thin; never return raw models. Repository interfaces in Domain, Eloquent implementations in Infrastructure bound via providers.

Tenancy

  • ResolveCompanyContext middleware derives company from authenticated membership; sets TenantContext.
  • Global CompanyScope on Eloquent models (vehicles, trips, bookings, etc.); cross-tenant reads return 404.
  • company_id never accepted from clients.

Auth

Phone → OTP → Sanctum token. Token scopes by role (Passenger, Driver, Manager, Platform Admin). Middleware: company (ResolveCompanyContext), manager, role.

Broadcasting

  • Channels: private-company.{companyId} (Managers), trip.{tripId} (participants).
  • Auth endpoint: POST /api/broadcasting/auth (Sanctum).
  • Backend: Reverb; channel auth in routes/channels.php.

Error envelope

{ "message": string, "errors"?: Record<string, string[]> }; errors only on 422. Localized via Accept-Language (en/ar).

Key directories

  • app/Domain/ — entities, value objects, services, repository interfaces, events, exceptions.
  • app/Application/ — use-case services + DTOs.
  • app/Infrastructure/ — Eloquent repos, providers, integrations, broadcasting events, tenancy.
  • app/Http/Middleware/ — middleware (ResolveCompanyContext, EnsureManager, EnsureActiveRole, SetLocale).
  • app/Interfaces/Http/ — controllers, FormRequests, JsonResources.
  • routes/ — api.php, channels.php, console.php, web.php.
  • tests/ — Unit + Feature.