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
- Use
getInsightsBookingService(): Always use the DI container function for consistent service creation - Raw SQL for Performance: Use
$queryRawfor complex aggregations and better performance - Base Conditions: Always use
await this.getBaseConditions()for proper filtering and permissions - Error Handling: Wrap service calls in try-catch blocks with
TRPCError - Loading States: Always show loading indicators with
LoadingInsight - Consistent Styling: Use
rechartsfor new charts - Date Handling: Use
getDateRanges()andgetTimeView()for time-based charts - Prisma v6 Compatibility: Use
Prisma.sqlfor the entire query instead of mixing template literals with SQL fragments