Skip to main content
This guide walks you through creating a new booking chart component for the insights page, covering the entire stack from UI component to backend service.

Overview

The insights booking system follows this architecture:
1

Create the UI Component

Create your chart component in packages/features/insights/components/booking/:
2

Add Component to Barrel Export

Update the booking components index file:
3

Add Component to Insights View

Add your component to the main insights page:
4

Create tRPC Handler

Add the tRPC endpoint in the insights router using the getInsightsBookingService() DI container function:
5

Add Service Method to InsightsBookingBaseService

Add your new method to the InsightsBookingBaseService class:

Best Practices

  1. Use getInsightsBookingService(): Always use the DI container function for consistent service creation
  2. Raw SQL for Performance: Use $queryRaw for complex aggregations and better performance
  3. Base Conditions: Always use await this.getBaseConditions() for proper filtering and permissions
  4. Error Handling: Wrap service calls in try-catch blocks with TRPCError
  5. Loading States: Always show loading indicators with LoadingInsight
  6. Consistent Styling: Use recharts for new charts
  7. Date Handling: Use getDateRanges() and getTimeView() for time-based charts
  8. Prisma v6 Compatibility: Use Prisma.sql for the entire query instead of mixing template literals with SQL fragments