Skip to content

Domain Model

This page describes the main TyteRide domain aggregates, entities, and relationships. It is a logical model for shared understanding; for physical table/column detail, see ../02-architecture/03-data-model.md.

1. Core aggregates and entities

Entity / Aggregate Role in the domain Key relationships
Company Tenant and operational boundary. Owns fleet, enrollment, trips, and company settings. Has many Managers, Drivers, Passengers (through Memberships), Vehicles, NavRoutes, Trips, Company Codes, Car Requests, and Reviews/analytics through trips. Belongs to a Tier.
Manager Company operator who manages fleet operations in the Fleet Dashboard. Represented as a Membership with role manager; belongs to a Company and User. Creates/approves company operations such as codes, trips, and car requests.
Driver Person who operates a vehicle on a trip. Represented as a Membership with role driver; belongs to a Company and User. Assigned to Trips and Car Requests.
Passenger Approved company employee who books and rides. Represented as a Membership with role passenger; belongs to a Company and User. Creates Bookings and Reviews.
Membership The user's company link, role, and approval/suspension state. memberships connects User and Company. Passenger memberships consume Seats when active.
Seat Subscription capacity consumed by an approved Passenger Membership; a Trip seat is separately derived from an approved Booking. No separate Trip-seat table. Subscription Seats derive from active Passenger Memberships against Tier max_users; Trip seats derive from approved Bookings against trips.seat_capacity.
Tier Subscription plan controlling seat limits and pricing. tiers referenced by Company. Used to block approvals beyond max_users.
Vehicle Virtual fleet record created by a Manager. Belongs to Company; assigned to Trips and Car Requests. Platform does not own vehicles.
NavRoute Named route with ordered stops. Belongs to Company; used by Trips. Includes localized names/labels (name_ar, stop label_ar).
Trip Scheduled run of a NavRoute by one Vehicle and Driver. Belongs to Company, NavRoute, Vehicle, and Driver assignment. Has many Bookings; may belong to a Trip Group via trip_group_code; has one Trip Analysis and many Reviews.
Trip Group Logical grouping of trips with same route and departure time, one per car. Represented by shared trip_group_code across Trip rows. Passenger selects a specific Trip/car in the group.
Booking Passenger reservation on a specific Trip. Belongs to Trip and Passenger/User membership context. Captures pickup type (route_stop or d2d), optional D2D points, and boarded_at.
Boarding Operational event/state of Passenger entering vehicle. Recorded on Booking as boarded_at; broadcast in Live Ops.
D2D Settings Company-owned D2D configuration. One d2d_settings row per Company: enablement, service zone/radius, pickup/drop-off rules, per-trip availability, detour limit.
D2D Request Passenger request for door-to-door pickup/drop-off on an approved Booking. Belongs to Company, Trip, Booking, and Passenger; carries pickup/drop-off address + coordinates and a pending\|approved\|rejected\|cancelled lifecycle. At most one active request per Booking.
Detour Extra minutes added by D2D routing. Limit stored on d2d_settings.max_detour_minutes; estimation is future work; reported separately in Trip Analysis.
Car Request Manager-created extra car for missed/unserved Passengers. Belongs to Company; references requesting Manager, Vehicle, Driver, and reason/status. Links Passengers through car_request_passengers.
Trip Analysis Post-trip computed metrics. Belongs to Trip (trip_analytics, one per trip). Stores delay, unexpected stops, slow segments, and D2D detour minutes.
Review Passenger feedback after trip completion. Belongs to Trip and User/Passenger; stores rating 1–5 and comment.

2. Entity relationship diagram

erDiagram
    COMPANY ||--o{ COMPANY_MEMBER : has
    COMPANY ||--o{ COMPANY_CODE : issues
    COMPANY ||--o{ VEHICLE : owns_record
    COMPANY ||--o{ NAV_ROUTE : defines
    COMPANY ||--o{ TRIP : schedules
    COMPANY ||--o{ CAR_REQUEST : creates
    COMPANY }o--|| SUBSCRIPTION_TIER : subscribes_to

    USER ||--o{ COMPANY_MEMBER : has
    USER ||--o{ BOOKING : makes
    USER ||--o{ TRIP_REVIEW : writes

    COMPANY_MEMBER }o--|| COMPANY : belongs_to
    COMPANY_MEMBER }o--|| USER : belongs_to

    NAV_ROUTE ||--o{ TRIP : used_by
    VEHICLE ||--o{ TRIP : assigned_to
    VEHICLE ||--o{ CAR_REQUEST : assigned_to

    TRIP ||--o{ BOOKING : contains
    TRIP ||--o{ TRIP_REVIEW : receives
    TRIP ||--|| TRIP_ANALYSIS : produces
    TRIP }o--o{ TRIP_GROUP : grouped_by_trip_group_code

    BOOKING }o--|| TRIP : for
    BOOKING }o--|| USER : passenger

    CAR_REQUEST }o--|| COMPANY : belongs_to
    CAR_REQUEST }o--|| VEHICLE : uses
    CAR_REQUEST }o--o{ USER : serves_passengers

    TRIP_GROUP {
      string trip_group_code
    }

3. Relationship notes

  • Tenant boundary: Company is the primary tenant boundary. Company-scoped records should not be reachable across companies. TenantContext holds the resolved Company for a request and CompanyScope filters company-owned models (memberships, company_codes, nav_routes, vehicles, trips, bookings); cross-tenant reads return 404 and a suspended Company returns 403 on company routes.
  • Onboarding (Slice 2): POST /api/onboarding/companies creates a pending Company, a Manager User, a pending manager Membership, and the first Company Code in one transaction. The requested Tier is stored on the Company; Platform Admin approval is deferred to Slice 8.
  • Membership as role link: Manager, Driver, and Passenger are roles on Memberships tied to a User and Company; a User has one company membership/company context. Enrollment creates a pending Passenger/Driver membership; Manager approval makes it active (exposed as approved by enrollment APIs) and rejection stores an optional reason.
  • Seat accounting: Subscription Seats are approved Passenger memberships and are constrained by Tier max_users. Drivers and Managers are free. Trip seats are approved Bookings constrained by Trip seat_capacity; pending/rejected/cancelled Bookings do not occupy capacity.
  • Trip grouping: Trip Group is a logical grouping by trip_group_code, not a separate business entity with independent lifecycle in the current spec.
  • Booking and D2D: A Booking is a route-stop reservation. D2D is requested separately through a D2D Request against an approved Booking; the D2D Request owns the pickup/drop-off points and its own approval lifecycle. D2D does not add columns to bookings or change seat accounting.
  • Post-trip outputs: Trip Analysis is one-per-trip computed output; Reviews are Passenger-submitted feedback and may be multiple records per trip depending on participating passengers.

4. Physical model reference

This document intentionally stays at the domain level. Field-level and storage details belong in the architecture/data-model docs, especially ../02-architecture/03-data-model.md and the build spec in ../product/b2b-rework-plan.md.