Feature: Sharing & PDF Export
Relevant source files
The following files were used as context for generating this wiki page:
The Sharing and PDF Export feature allows users to generate professional driveway project estimates and share them with external parties, such as contractors. The system supports generating unique, secure tokens for public web viewing and provides a service to export project details—including measurements, material selections, and pricing—into a standardized PDF document.
This feature is central to the project's goal of facilitating communication between homeowners and contractors by providing accurate, portable summaries of AI-detected driveway measurements and cost estimations. Sources: README.md:14, server/services/pdfExport.ts:5-8
Project Sharing System
The sharing system operates by generating a unique shareToken for a specific project. This token allows public, read-only access to a project summary page without requiring the viewer to authenticate.
Data Model and Persistence
Sharing is backed by the projectShares table, which relates a unique token to a projectId. It optionally stores a contractorEmail and tracks usage via a viewCount. Sources: drizzle/schema.ts:74-85
| Field | Type | Description |
|---|---|---|
id | int | Primary key |
projectId | int | Reference to the source project |
shareToken | varchar(64) | Unique nanoid-generated token for public access |
contractorEmail | varchar(320) | Email of the intended recipient |
viewCount | int | Number of times the shared link has been accessed |
Sources: drizzle/schema.ts:75-84
Sharing Workflow
The sharing flow is initiated from the Project Detail view. A user can optionally provide a contractor's email, which triggers an automated notification containing the public link. Sources: client/src/pages/ProjectDetail.tsx:50-59
PDF Export Service
The project provides a backend service and frontend utilities for generating PDF documents using the jsPDF library. These documents serve as formal "Driveway Estimates."
Backend PDF Generation
The server-side service uses jspdf to construct a document with a standard layout. It includes project headers, measurement tables, material details, pricing, and user-provided notes. Sources: server/services/pdfExport.ts:11-100
Key Components of the PDF Layout:
- Header: Displays "Driveway Estimate" and the project name. Sources: server/services/pdfExport.ts:28-36
- Measurements: Lists Area (sq ft), Depth (inches), and Zip Code. Sources: server/services/pdfExport.ts:47-60
- Material details: Shows material type (e.g., Hot Mix Asphalt), quantity, and unit price. Sources: server/services/pdfExport.ts:68-83
- Pricing: A highlighted section showing the total estimated cost. Sources: server/services/pdfExport.ts:89-94
- Notes: Supports multi-line project notes with automatic page wrapping. Sources: server/services/pdfExport.ts:99-114
Implementation Logic
The service returns the generated PDF as a Buffer, which is then converted to a Base64 string for transmission via tRPC. Sources: server/services/pdfExport.ts:122, server/routers/projects.ts:318-320
API Endpoints (tRPC)
The projectsRouter defines specific procedures for managing shares and exports. Sources: server/routers/projects.ts:241-326
| Procedure | Access | Input | Description |
|---|---|---|---|
createShareLink | Protected | projectId, contractorEmail? | Generates a share token and notifies contractor. |
getSharedProject | Public | shareToken | Retrieves project data for public viewing. |
downloadPDF | Protected | projectId | Generates and returns a Base64 encoded PDF. |
Sources: server/routers/projects.ts:241, server/routers/projects.ts:279, server/routers/projects.ts:305
Client-Side Integration
Both the authenticated ProjectDetail page and the public SharedProject page implement PDF downloading, though they utilize different approaches.
Authenticated Download
The ProjectDetail page calls the downloadPDF tRPC mutation. Upon success, it converts the Base64 response into a Blob, creates a temporary object URL, and triggers a browser download. Sources: client/src/pages/ProjectDetail.tsx:64-81
Public Download
The SharedProject page performs client-side PDF generation using dynamic imports of jsPDF. This allows the public viewer to generate the document directly in the browser without requiring a specialized backend call for the shared view. Sources: client/src/pages/SharedProject.tsx:28-30
// Example of client-side PDF trigger
const handleDownloadPDF = async () => {
const { jsPDF } = await import("jspdf");
const doc = new jsPDF();
// ... drawing logic similar to server-side service
doc.save(`driveway-estimate-${project.projectName}.pdf`);
};
Sources: client/src/pages/SharedProject.tsx:32-88
Conclusion
The Sharing & PDF Export feature bridges the gap between digital estimates and professional documentation. By utilizing unique share tokens, the system maintains a secure but accessible way for external contractors to view project details. The standardized PDF export ensures that homeowners have a portable and formal record of their driveway measurements and estimated costs, whether generated on the server for owners or on the client for public guests.