Architecture: hbf-reports
C4 Component Diagram
Key Flows
Scheduled Report Delivery (weekly or monthly cron)
SchedulerServicefires the cron job (weekly: Monday 00:00, monthly: 1st 00:05).ReportsService.sendWeeklyReports()(or monthly) queries MySQL for allScheduledReportrows withenabled=trueandweekly=true(ormonthly=true).- For each matching schedule:
a. Creates a
ScheduledReportExportrow withstatus=STARTED. b. CallsGenerateGraphsService.generateGraphs()which:- Fetches org and tenant metadata from hbf-core.
- Draws the index page and deployment page (if filtered by deployment).
- Iterates the configured sections and draws each one: fetches analytics data from hbf-core, transforms it, generates an SVG chart via echarts, embeds via
svg-to-pdfkit, draws the data table. - Adds page-number footers to every page.
- Returns the finished PDF as a base64 string.
c. Calls
nodemailer.sendMail()with the PDF attached and a branded HTML email body. d. Updates theScheduledReportExportrow withstatus=COMPLETEDand the base64 PDF.
On-Demand Export
- HTTP caller sends
POST /exportswithExportDto(org, tenants or tenantsFilter, date range, optional sections). ExportsControllerpasses the request through auth guards, then delegates toExportsService.exportReport().ExportsServicecallsGenerateGraphsService.generateGraphs()(same path as above).- The resulting base64 string is decoded into a
Buffer, wrapped in aReadablestream, and returned in the HTTP response.
PDF Section Rendering
Each section follows the same pattern inside GenerateGraphsService:
- Call the relevant
HbfCoreServicemethod to fetch section data. - Pass the response through a
coreDataToChartDatatransformer to get chart-ready and table-ready structures. - Add a new page to the pdfkit document.
- Call the matching
DrawPdfService.draw*Template()to paint the section header/background. - Generate the chart SVG via
GenerateChartsServiceand embed withSVGtoPDF. - Call
DrawPdfService.drawTable()to render the data table below the chart.