Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Codefied-CodePix/Karokar-backend/llms.txt

Use this file to discover all available pages before exploring further.

The Fleet domain is the operational foundation of KaroKar. It manages every vehicle in the platform — from initial registration through active use, scheduled maintenance, and suspension — while exposing a purpose-built availability engine that determines whether a vehicle can be booked or assigned during any requested period. A key architectural decision is that vehicle status and vehicle availability are deliberately separate concerns: a vehicle can be ACTIVE in its lifecycle while simultaneously being RESERVED or ALLOCATED on the availability timeline.

Vehicle Entity

Each vehicle is owned by exactly one organization and carries its current lifecycle status.
FieldTypeDescription
iduuidUnique vehicle identifier (inherited from BaseEntity)
organizationIduuidThe owning organization (vendor or corporate)
ownershipTypeVehicleOwnershipTypeVENDOR_OWNED or CORPORATE_OWNED
makestringManufacturer name (e.g., Toyota)
modelstringModel name (e.g., Corolla)
yearnumberManufacturing year (1900–2100)
licensePlatestringRegistered plate number
statusVehicleStatusCurrent lifecycle state of the vehicle
createdAttimestamptzRecord creation timestamp
updatedAttimestamptzLast modification timestamp

Ownership Types

KaroKar supports two ownership models, each with a distinct operational workflow.

VENDOR_OWNED

A vendor registers and owns the vehicle. Corporate organizations discover it via search and initiate a booking that requires explicit vendor approval before any employee can receive the vehicle.
Vendor Lists Vehicle

Corporate Searches Vehicle

Corporate Creates Booking Request

Vendor Approves Booking

Corporate Assigns Employee

Employee Receives Vehicle

CORPORATE_OWNED

The corporate organization registers and owns the vehicle outright. There is no vendor, no booking approval step, and no marketplace negotiation — the vehicle moves directly into the assignment workflow.
Corporate Registers Vehicle

Vehicle Added to Corporate Fleet

Corporate Assigns Vehicle to Employee

Employee Receives Vehicle
Corporate-owned vehicles bypass the Booking domain entirely. They enter the Assignment domain directly, skipping the REQUESTED → APPROVED approval cycle that vendor-owned vehicles must pass through.

Vehicle Statuses

The VehicleStatus enum represents the lifecycle state of a vehicle — not its scheduling availability.
StatusMeaning
PENDINGVehicle registered but not yet reviewed or activated
ACTIVEVehicle is operational and eligible for booking or assignment
SUSPENDEDVehicle has been suspended (see Suspension section)
RETIREDVehicle has been permanently removed from the platform

The Availability Engine

Core principle (ADR-003): Vehicle status ≠ Vehicle availability.
A vehicle with status ACTIVE may simultaneously be RESERVED for a future booking, ALLOCATED to a current employee, or blocked for MAINTENANCE next week. A single status field cannot represent these overlapping, time-based states — so KaroKar models availability as a first-class business domain using dedicated VehicleAvailability records. The platform never asks “Is this vehicle available right now?” — it always asks “Is this vehicle available for the requested period?”

VehicleAvailability Entity

FieldTypeDescription
iduuidUnique availability record identifier
vehicleIduuidThe vehicle this record applies to
startDatetimestamptzStart of the blocked period
endDatetimestamptzEnd of the blocked period
sourceTypeAvailabilitySourceTypeWhat business event created this record
sourceIduuidID of the source entity (booking, assignment, etc.)
statusAvailabilityStatusThe kind of unavailability
createdAttimestamptzWhen the record was created

Availability Statuses

StatusMeaning
RESERVEDVehicle is reserved by an approved booking — not yet handed over
ALLOCATEDVehicle is actively allocated to an employee
MAINTENANCEVehicle is scheduled for or undergoing maintenance
SUSPENDEDVehicle is suspended and hidden from search
BLOCKEDVehicle is manually blocked from use

Availability Source Types

Each availability record is generated by a specific business event. The source type traces the record back to its origin:
Source TypeTriggered ByResulting Status
BOOKINGBooking approved by vendorRESERVED
ASSIGNMENTEmployee assigned to a vehicleALLOCATED
MAINTENANCEMaintenance window scheduledMAINTENANCE
SUSPENSIONVehicle suspension createdSUSPENDED
MANUAL_BLOCKOperational block applied by adminBLOCKED

Conflict Detection

AvailabilityService.detectConflict() performs date-range overlap validation before any new availability record is created. If an existing record overlaps the requested period, the request is rejected. Example:
Reservation A: 01-Jul → 10-Jul  ✅ Created
Reservation B: 05-Jul → 20-Jul  ❌ Conflict — overlaps with Reservation A
A vehicle is excluded from search results if it has any active availability record — regardless of status — that overlaps the search date range.

AvailabilityService Methods

// Check whether a vehicle is free for a given period
checkAvailability(vehicleId: string, startDate: Date, endDate: Date): Promise<boolean>

// Create a new time-based availability block
createAvailabilityRecord(
  vehicleId: string,
  startDate: Date,
  endDate: Date,
  sourceType: AvailabilitySourceType,
  sourceId: string,
): Promise<VehicleAvailability>

// Release a block when the source event completes or is cancelled
releaseAvailabilityRecord(sourceType: AvailabilitySourceType, sourceId: string): Promise<void>

// Explicitly check for overlapping records
detectConflict(vehicleId: string, startDate: Date, endDate: Date): Promise<boolean>

Search is availability-aware. VehicleService.searchAvailable() only returns vehicles that have no overlapping availability records for the requested period.

SearchVehiclesDto

class SearchVehiclesDto {
  @IsUUID()
  organizationId: string;    // Filter to a specific organization's fleet

  @IsDateString()
  startDate: string;         // ISO 8601 — start of requested period

  @IsDateString()
  endDate: string;           // ISO 8601 — end of requested period
}
Example usage:
GET /vehicles/search?organizationId=org-uuid&startDate=2026-07-01&endDate=2026-07-31
Only vehicles with no RESERVED, ALLOCATED, MAINTENANCE, SUSPENDED, or BLOCKED records overlapping 01-Jul → 31-Jul will be returned.

Registering a Vehicle

CreateVehicleDto

class CreateVehicleDto {
  @IsUUID()
  organizationId: string;           // Owning organization

  @IsEnum(VehicleOwnershipType)
  ownershipType: VehicleOwnershipType; // VENDOR_OWNED | CORPORATE_OWNED

  @IsString()
  make: string;                     // e.g., "Toyota"

  @IsString()
  model: string;                    // e.g., "Corolla"

  @IsInt() @Min(1900) @Max(2100)
  year: number;                     // e.g., 2023

  @IsString()
  licensePlate: string;             // e.g., "KHI-123"
}
Newly registered vehicles are created in PENDING status. They must be explicitly activated via VehicleService.activateVehicle(id) before they appear in search results.

Maintenance Scheduling

Maintenance is modeled as a first-class record that automatically removes the vehicle from availability during the service window.

MaintenanceRecord Entity

FieldTypeDescription
iduuidUnique record identifier
vehicleIduuidThe vehicle under maintenance
startDatetimestamptzMaintenance window start
endDatetimestamptzMaintenance window end
reasonstringHuman-readable description of the work
statusMaintenanceStatusCurrent state of this maintenance job

Maintenance Statuses

StatusMeaning
SCHEDULEDMaintenance has been booked; vehicle is removed from search
IN_PROGRESSMaintenance is actively being performed
COMPLETEDMaintenance finished; vehicle availability record released

ScheduleMaintenanceDto

class ScheduleMaintenanceDto {
  @IsDateString()
  startDate: string;   // ISO 8601

  @IsDateString()
  endDate: string;     // ISO 8601

  @IsString()
  reason: string;      // e.g., "Annual engine service"
}
When maintenance is scheduled, an availability record with sourceType: MAINTENANCE and status: MAINTENANCE is created, immediately blocking the vehicle for that window. Completing the maintenance record via MaintenanceService.completeMaintenance(id) releases the availability block.

Vehicle Suspension

Suspension represents a compliance or administrative hold that hides the vehicle from search and prevents new bookings.

VehicleSuspension Entity

FieldTypeDescription
iduuidUnique suspension identifier
vehicleIduuidThe suspended vehicle
reasonSuspensionReasonEnumerated reason for suspension
startDatetimestamptzWhen the suspension begins
endDatetimestamptz | nullWhen it ends (null = indefinite)
createdByuuidUser who created the suspension
createdAttimestamptzRecord creation timestamp

Suspension Reasons

ReasonDescription
INSURANCE_EXPIREDVehicle insurance has lapsed
REGISTRATION_EXPIREDVehicle registration has expired
FITNESS_CERTIFICATE_EXPIREDRoadworthiness certificate has expired
ADMIN_ACTIONPlatform administrator has suspended the vehicle
VENDOR_REQUESTVendor has requested the vehicle be suspended
A suspended vehicle has its vehicle status set to SUSPENDED and a VehicleAvailability record created with sourceType: SUSPENSION and status: SUSPENDED. Both must be resolved to restore the vehicle to an operational state.

Suspension Availability Impact

Vehicle Suspended

Availability Record Created (sourceType: SUSPENSION, status: SUSPENDED)

Vehicle Hidden from Search

New Bookings Blocked

Build docs developers (and LLMs) love