Skip to content

DDD Modeling Rules

These rules define how API slices are modeled in TyteRide. They apply to the Laravel 11 API and its Domain-Driven Design layering.

1. Request flow

Every API use case follows the same path from HTTP input to response:

flowchart LR
    R[Request] --> FR[FormRequest]
    FR --> DTO[DTO]
    DTO --> AS[Application Service]
    AS --> D[Domain]
    D --> I[Infrastructure]
    I --> JR[JsonResource]
  • FormRequest handles HTTP validation only. It contains no business rules.
  • DTO carries typed input across the application boundary.
  • Application Service orchestrates one use case and owns the transaction boundary. It may call repositories and dispatch domain events.
  • Domain holds the rich model, value objects, invariants, repository interfaces, and domain events.
  • Infrastructure provides Eloquent repository implementations, listeners, providers, and broadcasts.
  • JsonResource shapes the response. Controllers never return raw models.

2. Layering rules

  • Repository interfaces live in the Domain layer; Eloquent implementations live in Infrastructure. Bind them in a service provider.
  • Business invariants live on the model or value object, not in controllers or FormRequests.
  • One application service per use case.
  • Controllers stay thin: validate → DTO → service → resource.
  • Events and listeners live in Infrastructure and may broadcast via Reverb.
  • Do not put business rules in Filament resources, controllers, or Blade views. Filament is an adapter for the Platform Admin only.

3. Domain modeling rules

  • No framework leakage into the Domain. Domain code must not depend on HTTP, Eloquent, framework facades, or transport concerns. Keep framework details in Infrastructure and HTTP adapters.
  • Aggregates and value objects express invariants close to the data they protect. A state transition or limit check belongs in the model or value object when it is a domain rule.
  • Domain events capture meaningful state changes. Application services dispatch them; Infrastructure listeners handle side effects such as broadcasting or persistence-adjacent reactions.
  • Repository interfaces describe the persistence contract the use case needs. The Domain depends on the interface; Infrastructure supplies the implementation.

4. Bounded contexts

TyteRide uses seven bounded contexts, as defined in the domain glossary:

Context Owns Key entities
Identity & Enrollment Phone/OTP auth, users, memberships, company codes, approval queue User, Company, Membership, CompanyCode
Fleet Vehicles and drivers owned by a company Vehicle, Driver membership
Trips & Booking Routes, trips, trip groups, bookings, deadlines, duplication, extra cars NavRoute, Trip, Booking, CarRequest
Live Ops GPS publishing, realtime channels, boarding, driver feedback TripTracking, Boarding event, feedback
D2D Eligibility, pickup/drop-off points, detour estimation, route plan D2D points, RoutePlan legs
Billing & Tiers Tiers, seat limits, subscription status, suspension SubscriptionTier, Company status
Reviews & Analytics Post-trip ratings and computed trip metrics Review, TripAnalysis

Cross-context communication goes through application services and domain events, not direct model reach-through.