Reporting Engine
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Reporting Engine is a core module of the analiza-este-lovable-tamv project designed to facilitate the collection, processing, and visualization of data within the TAMV documentation ecosystem. It serves as the primary interface for generating structured reports based on user input and stored system data, ensuring that documentation remains accurate and accessible.
The engine operates by coordinating between frontend UI components, specialized hooks for data fetching, and backend Edge Functions that handle heavy processing tasks. It is essential for maintaining the integrity of the project's documentation standards.
Sources: README.md:1-2, src/components/ReportGenerator.tsx:1-10
Architecture and Data Flow
The Reporting Engine follows a decoupled architecture where the frontend triggers report generation requests which are then processed by serverless functions. This ensures scalability and minimizes the load on the client-side application.
Data Processing Flow
The following diagram illustrates how a report request moves from the user interface through the service layer to the backend processing unit.
The flow starts with user interaction in the ReportGenerator component, which utilizes the useReports custom hook to manage state and side effects. The service layer then communicates with Supabase Edge Functions to perform data aggregation.
Sources: src/components/ReportGenerator.tsx:15-40, src/services/reportService.ts:5-25
Key Components
ReportGenerator Component
This React component provides the user interface for selecting report types, date ranges, and output formats. It handles local form state and displays progress indicators during the generation process.
| Property | Type | Description |
|---|---|---|
reportType | string | The category of report (e.g., 'summary', 'detailed') |
dateRange | DateRange | The temporal scope for data inclusion |
onDownload | function | Callback executed when the report is ready |
Sources: src/components/ReportGenerator.tsx:45-60, src/types/reports.d.ts:10-15
reportService
The service module encapsulates the API logic required to interact with the backend. It handles authentication headers and error parsing for report-related requests.
// Example of the fetch logic used in the service
export const generateReport = async (params: ReportParams) => {
const { data, error } = await supabase.functions.invoke('generate-report', {
body: params,
});
if (error) throw error;
return data;
};
Sources: src/services/reportService.ts:12-30
Data Models
The system uses TypeScript interfaces to ensure type safety across the reporting pipeline. The primary data structure is the ReportMetadata object, which tracks the status and properties of every generated document.
Report Schema
| Field | Type | Description |
|---|---|---|
id | UUID | Unique identifier for the report |
created_at | Timestamp | Date and time of generation |
status | Enum | Current state: 'pending', 'completed', 'failed' |
url | string | Storage path for the generated file |
Sources: src/types/reports.d.ts:20-35
Backend Logic (Edge Functions)
The actual generation of PDF or CSV files occurs within Supabase Edge Functions. This offloads resource-intensive tasks from the main application thread.
The sequence shows the transition from a RESTful trigger to the generation of binary data and the return of a secure download link.
Sources: supabase/functions/generate-report/index.ts:5-50
Conclusion
The Reporting Engine provides a robust framework for data extraction and documentation within the TAMV project. By leveraging a microservices-oriented approach with Edge Functions and typed interfaces, it ensures that users can generate complex reports efficiently and reliably.
Sources: README.md:1-2, src/hooks/useReports.ts:20-25