- Docs
- Architecture
- Processing pipeline
Processing Pipeline¶
This document describes how requests and domain flows move through TyteRide. It combines the API request lifecycle from ../method.md with the core system flows in ../architecture.md.
1. Request pipeline¶
All API behavior follows the DDD request flow. Controllers are thin adapters; business rules live in the domain.
flowchart LR
A[Client Request] --> B[FormRequest\nHTTP validation]
B --> C[DTO\nTyped input]
C --> D[Application Service\nUse case orchestration\nTransaction boundary]
D --> E[Domain\nModels, Value Objects\nInvariants, Repository interfaces\nDomain events]
E --> F[Infrastructure\nEloquent repositories\nListeners, Providers\nBroadcasts/Reverb]
F --> G[JsonResource\nResponse shape]
G --> H[JSON Response]
D -->|dispatches| I[Domain Events]
I --> F
1.1 Pipeline responsibilities¶
| Stage | Responsibility | Must not do |
|---|---|---|
| FormRequest | HTTP input validation, shape/rule checks | Business invariants, persistence decisions |
| DTO | Typed use-case input | Validation or domain behavior |
| Application Service | Orchestrate one use case, transaction boundary, call repositories, dispatch events | Own business rules that belong to domain models/value objects |
| Domain | Invariants, state transitions, value objects, repository interfaces, domain events | Eloquent/framework coupling, HTTP concerns |
| Infrastructure | Eloquent repository implementations, event listeners, providers, Reverb broadcasts | Business-rule ownership |
| JsonResource | Stable response contract | Return raw models or ad-hoc arrays |
1.2 Cross-cutting pipeline concerns¶
- Auth: Phone + OTP issues Sanctum bearer tokens. Authenticated requests carry
Authorization: Bearer <token>. - Tenancy:
company_idis derived from authenticated membership, never accepted from client input.CompanyScopefilters company-owned records; bookings scope throughtrip.company_id. - Localization:
Accept-Language: en|arselects response language; validation and message fields are localized. - Errors: Every error uses
{ "message": string, "errors"?: Record<string, string[]> };errorsonly for validation failures. - Suspension: A suspended company returns 403 with a clear message on authenticated company routes.
2. Company onboarding flow¶
The first slice is self-serve company onboarding through Front Views with manual Platform Admin approval.
sequenceDiagram
autonumber
actor Visitor as Company Visitor
participant Front as Front Views
participant API as API / Onboarding
participant Domain as Application/Domain
participant DB as MySQL
participant Admin as Platform Admin (Filament)
participant Manager as Manager
Visitor->>Front: Complete onboarding form
Front->>API: POST /onboarding/companies
API->>API: FormRequest validation + rate limit
API->>Domain: CreateCompanyOnboarding DTO + service
Domain->>DB: Create Company (status=trial)
Domain->>DB: Create Manager Membership
Domain->>DB: Create first Company Code
Domain-->>API: Onboarding result
API-->>Front: JsonResource response
Front-->>Visitor: Submission received
Admin->>API: Review application queue
API->>DB: Read pending/trial company application
Admin->>API: Approve company
API->>Domain: ApproveCompany service
Domain->>DB: Set Company status=active
Domain-->>API: Updated company
API-->>Admin: Approval confirmed
Manager->>API: POST /auth/otp/send
API-->>Manager: OTP sent
Manager->>API: POST /auth/otp/verify
API-->>Manager: Sanctum token
Manager->>API: Authenticated Fleet Dashboard requests
Notes: - Public onboarding is rate-limited. - Platform Admin is Filament-only; company operations move to Fleet Dashboard. - Exact application-queue persistence model is source silent beyond "application appears in the platform-admin Filament queue".
3. Booking and reservation flow¶
Passengers join a company, get approved, choose a trip/car in a trip group, and book without payment. D2D pickup/drop-off is optional when eligible.
sequenceDiagram
autonumber
actor Passenger
participant App as Passenger App
participant API as Passenger/Company API
participant Domain as Application/Domain
participant DB as MySQL
participant Manager
participant Dash as Fleet Dashboard
Passenger->>App: Enter company code + gender
App->>API: POST /auth/enroll-company
API->>Domain: EnrollPassenger service
Domain->>DB: Create Membership (pending, passenger)
API-->>App: Pending membership state
App-->>Passenger: Blocked/waiting state
Manager->>Dash: Open enrollment queue
Dash->>API: GET /company/enrollments
Manager->>Dash: Approve member
Dash->>API: Approve enrollment
API->>Domain: ApproveEnrollment service
Domain->>Domain: Check tier max_users seat limit
Domain->>DB: Membership status=approved
API-->>Dash: Approved member + seat count update
Passenger->>App: List trips
App->>API: GET /passenger/trips
API->>DB: Company-scoped trips/trip groups
API-->>App: Trip groups (one trip per car)
Passenger->>App: Pick car and optional D2D points
App->>API: Create booking
API->>Domain: CreateBooking service
Domain->>Domain: Check reservation_deadline_at
Domain->>Domain: Check D2D eligibility + detour limit
Domain->>DB: Create Booking (no payment)
API-->>App: Booking JsonResource
Notes:
- Passengers pay nothing; no payment/wallet step exists.
- Booking after reservation_deadline_at is rejected.
- D2D points beyond d2d_max_detour_minutes are rejected.
- Booking creation should be idempotent where duplicate taps are likely (API convention).
4. D2D route planning flow¶
D2D extends the main route with door-to-door legs. The main route remains the base; D2D legs are secondary.
| Step | Input | Processing | Output |
|---|---|---|---|
| Eligibility check | Company + membership D2D flags | Both company and member must allow D2D | Eligible or rejected |
| Point capture | Pickup/drop-off lat,lng,label |
Validate and estimate detour | Accepted point or rejection |
| Route planning | NavRoute main route + D2D points | Use Directions API with waypoints first; custom snap-and-rejoin planner only if Directions insufficient | Route plan legs |
| Display | Route plan | Main route one color; each D2D leg another color with label | Driver/Dashboard/Passenger views |
| Analysis attribution | Completed trip tracking | D2D detour reported separately | trip_analytics.d2d_detour_minutes |
The preserved spec includes a route-plan response example under /coordinator/trips/{id}/route-plan; the TyteRide route prefix is /driver/* for Driver-facing endpoints. The response shape should be preserved unless a later contract change is explicitly documented.
5. Live tracking and boarding flow¶
sequenceDiagram
autonumber
actor Driver
participant DriverApp as Driver App
participant API
participant Reverb
participant DB as MySQL
participant Dash as Fleet Dashboard
participant PassengerApp as Passenger App
Driver->>DriverApp: Start active trip
loop Every 10-15 seconds during active trip
DriverApp->>API: Publish GPS position
API->>Reverb: Broadcast vehicle position
Reverb-->>Dash: private-company.{companyId} update
Reverb-->>PassengerApp: trip.{tripId} live update
end
Driver->>DriverApp: Mark passenger boarded (tap/QR)
DriverApp->>API: Boarding update
API->>DB: Set bookings.boarded_at
API->>Reverb: Broadcast passenger boarded
Reverb-->>Dash: Dashboard live boarded count update
Driver->>DriverApp: Send quick status message
DriverApp->>API: POST /driver/trips/{id}/feedback
API->>Reverb: Broadcast driver feedback
Reverb-->>Dash: Driver status feed update
Notes:
- Driver GPS cadence is 10–15 seconds during an active trip.
- Dashboard consumes company channel; Passenger live view consumes trip channel.
- Boarding is recorded as bookings.boarded_at.
- Driver feedback endpoint is /driver/trips/{id}/feedback in TyteRide naming; the preserved spec shows the legacy /coordinator/* prefix.
6. Trip analysis flow¶
Trip analysis runs after trip completion and stores computed metrics separately from live operational data.
| Step | Behavior | Output |
|---|---|---|
| Trigger | Trip completes | AnalyzeTrip job runs |
| Delay computation | Compare actual vs estimated arrival; actual vs scheduled departure | overall_delay_minutes, late_departure_minutes |
| Stop/speed analysis | Detect stationary periods away from scheduled stops; detect slow segments | unexpected_stops, slow_segments JSON |
| D2D attribution | Compute D2D detour separately | d2d_detour_minutes |
| Persistence | Store one analysis per trip | trip_analytics row with computed_at |
The Dashboard presents a per-trip view with map overlay and a one-line reason, for example: "Departed 12m late, 2 unexpected stops (+9m), D2D detour (+6m)".
7. Reverb event flow¶
Realtime uses Laravel Reverb with private channels and server-side authorization callbacks.
flowchart LR
DE[Domain / App Event] --> L[Infrastructure Listener]
L --> B[Broadcast Event]
B --> R[Reverb]
R --> C1[private-company.companyId\nManagers only]
R --> C2[trip.tripId\nPassenger booking / assigned Driver / company Manager]
C1 --> D[Fleet Dashboard Live]
C2 --> P[Passenger Live View]
C2 --> D2[Authorized Dashboard/Driver consumers]
7.1 Channel responsibilities¶
| Channel | Audience | Event examples | Authorization |
|---|---|---|---|
private-company.{companyId} |
Managers only | Trip status, vehicle position, passenger boarded, extra car assigned, driver feedback | Manager of that company only |
trip.{tripId} |
Trip-scoped participants | Live vehicle/ETA updates for passenger live view | Passenger with booking on trip, assigned Driver, or Manager of trip's company |
Rules: - Channel callbacks re-check membership; stale tokens must not retain access. - Existing notification channels stay. - Driver App publishes GPS every 10–15 seconds during active trip; Dashboard and Passenger live views consume broadcasts.