KaroKar operates in a regulated, trust-sensitive environment where corporate organizations, vehicle vendors, and employees exchange legal and financial obligations. Every business-critical action — booking approvals, vehicle suspensions, employee assignments, organization onboarding — must be traceable, attributable, and permanently recorded. The Audit domain fulfills this requirement by subscribing to domain events emitted by all other domains and automatically creating structured, immutable audit records. Business domains never create audit records directly; they simply emit events and the Audit domain takes care of the rest.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.
Core Principle
As established in ADR-008, the platform must always be able to answer five questions about any business action:Who?
Actor — which user, admin, or system process performed the action (
actorId)What?
Action — which operation was performed (e.g.,
Booking Approved, Vehicle Suspended)Which?
Entity — the specific record that was affected (
entityType + entityId)When?
Time — the exact UTC timestamp of the action (
timestamp)Whose tenant?
Organization — which organization performed the action (
organizationId), required for multi-tenant investigationsAuditRecord Entity
Every audit record is stored as a single, structured database row. Records are indexed by organization + timestamp, entity type + ID, and actor ID to support fast investigation queries.| Field | Type | Description |
|---|---|---|
id | uuid | Unique audit record identifier |
eventType | string | The domain event that triggered this record (e.g., VehicleSuspended) |
entityType | string | The kind of entity affected (e.g., Vehicle, Booking) |
entityId | uuid | The specific entity that was affected |
actorId | uuid | null | User who performed the action; null for system-generated events |
organizationId | uuid | The tenant organization context |
action | string | Human-readable description of what happened |
timestamp | timestamptz | UTC timestamp of the event |
metadata | jsonb | Structured payload with event-specific details (e.g., before/after state) |
Example Audit Record
How Audit Records Are Generated
The Audit domain uses NestJS event listeners to subscribe to domain events. Business domains emit events — the Audit domain converts them into records automatically throughmapDomainEventToAuditRecord().
Booking events are captured by BookingAuditListener:
FleetAuditListener:
AssignmentAuditListener:
OrganizationAuditListener:
VerificationAuditListener:
booking.*, vehicle.*, assignment.*, organization.*, verification.*) mean that every new domain event added to those channels is automatically audited — no additional listener code is required.
Business domains must never call
AuditService.createRecord() directly. The correct pattern is: domain emits an event → Audit domain listener handles it → audit record is created. This keeps audit creation decoupled from business logic and guarantees consistency.AuditService Query Methods
AuditService exposes three query methods for investigation workflows:
- “Show the complete lifecycle of Booking #XYZ” →
findByEntity('Booking', bookingId) - “What did this vendor admin do last week?” →
findByActor(userId) - “All audit events for this corporate organization” →
findByOrganization(orgId)
Audit Event Sources by Domain
All major business domains are audit producers. The following events are audited in Phase 01:Booking Domain
Booking Domain
| Event | Triggered When |
|---|---|
BookingRequested | Corporate submits a booking request to the vendor |
BookingApproved | Vendor approves the booking |
BookingRejected | Vendor rejects the booking |
BookingCancelled | Booking cancelled before vehicle handover |
BookingCompleted | Vehicle returned; booking reached planned conclusion |
BookingTerminated | Booking ended prematurely after becoming operational |
Assignment Domain
Assignment Domain
| Event | Triggered When |
|---|---|
AssignmentCreated | An assignment is created for an employee |
AssignmentAccepted | Employee accepts the vehicle handover |
AssignmentRejected | Employee declines the assignment |
AssignmentClosed | Assignment force-closed by a booking termination |
Fleet Domain
Fleet Domain
| Event | Triggered When |
|---|---|
VehicleCreated | A new vehicle is registered on the platform |
VehicleActivated | Vehicle status transitions from PENDING to ACTIVE |
VehicleSuspended | Vehicle is suspended (insurance, registration, admin, etc.) |
VehicleMaintenanceScheduled | A maintenance window is created for a vehicle |
VehicleMaintenanceCompleted | Maintenance is marked complete and availability released |
Verification Domain
Verification Domain
| Event | Triggered When |
|---|---|
VerificationRequested | A verification workflow is initiated |
VerificationApproved | Verification is approved |
VerificationRejected | Verification is rejected |
VerificationExpired | A verification document or record has expired |
VerificationRevoked | An approved verification is revoked |
Organization Domain
Organization Domain
| Event | Triggered When |
|---|---|
OrganizationCreated | A new vendor or corporate organization is registered |
OrganizationApproved | An organization is approved and onboarded |
OrganizationSuspended | An organization is suspended from the platform |
System Actor
Some audit events are generated by automated platform processes rather than a human user — for example, when a verification document expires or when availability is released on booking completion. For these events,actorId is set to null (the column is typed uuid | null and is nullable in the database):
System-generated audit records carry the same compliance weight as user-initiated ones. Automated actions are fully traceable and immutable.
Immutability
Audit records are strictly read-only once created. The system deliberately does not expose any endpoint or service method to edit or delete an audit record.Retention Policy
Phase 01 retention policy: All audit records are retained indefinitely. No deletion, archival, or expiry is applied. Future phases may introduce cold-storage archival and regulatory retention rules, but audit history will never be silently removed.
Change Tracking
For update operations, themetadata field stores a change set showing the state before and after the action: