A full-stack invoice generation system built with React, Netlify Functions, PostgreSQL, and Netlify Blobs.
- PDF Template Upload: Upload PDF templates to Netlify Blobs
- Field Configuration: Define text fields with precise X/Y coordinates on templates
- Dynamic Invoice Generation: Generate invoices by filling configured fields with data
- Template Management: List, select, and delete templates
- Real-time Preview: View generated invoices in the browser
- Frontend: React with TypeScript, Tailwind CSS, and Radix UI components
- Backend: Netlify Functions 2.0 (serverless with custom endpoints)
- Database: PostgreSQL for metadata and configurations
- File Storage: Netlify Blobs for PDF templates
- PDF Processing: pdf-lib for PDF manipulation and overlay
- Create a PostgreSQL database (local or cloud provider like Supabase, Neon, etc.)
- Run the schema from
database/schema.sqlto create the required tables - Set the
DATABASE_URLenvironment variable in your Netlify site settings
Set these environment variables in your Netlify site settings:
DATABASE_URL=postgresql://username:password@host:port/database
-
Install dependencies:
bun install
-
Start the development server:
bun run dev
-
For local Netlify Functions development, install Netlify CLI:
npm install -g netlify-cli netlify dev
- Connect your repository to Netlify
- Set the build command:
bun run build - Set the publish directory:
dist - Set the functions directory:
netlify/functions - Add the
DATABASE_URLenvironment variable
- Click "Upload Template" and select a PDF file
- Enter a name for your template
- The template will be stored in Netlify Blobs
- Select a template from the list
- Add fields by specifying:
- Field name (e.g., "customer_name")
- X and Y coordinates (in PDF points)
- Font size
- Field type (text, number, date)
- Select the configured template
- Fill in the invoice data form with the required information
- Click "Generate Invoice" to create the PDF
- View or download the generated invoice
GET /api/templates- List all templatesPOST /api/templates- Upload a PDF templateDELETE /api/templates?id={id}- Delete a templateGET /api/templates?id={id}- Get single template
POST /api/save-configuration- Save field configurationGET /api/get-configuration- Get field configuration
POST /api/generate-invoice- Generate invoice PDF
All endpoints use custom URLs defined in the function config, providing cleaner REST API routes.
templates- Template metadatatemplate_fields- Field configurations for each templateinvoices- Generated invoice records
- Templates:
id,name,blob_key,created_at,updated_at - Template Fields:
id,template_id,field_name,x_position,y_position,font_size,field_type - Invoices:
id,template_id,invoice_data,generated_at,pdf_blob_key
- Load the template PDF using pdf-lib
- For each configured field, draw text at the specified coordinates
- Save the modified PDF and return as base64 data URL
- Custom Endpoints: Clean API URLs without
.netlify/functions/prefix - Better Performance: Enhanced runtime with improved cold start times
- Modern API: Uses standard
RequestandResponseobjects - Enhanced Context: Access to full context object for advanced features
- PDF coordinates start from the bottom-left corner
- X increases to the right, Y increases upward
- The system automatically adjusts Y coordinates to account for font size
text: Regular text inputnumber: Numeric input with decimal supportdate: Date input (formatted as string)
- Uses Bun as the package manager and runtime
- Form validation with Zod and react-hook-form
- TypeScript for type safety
- Tailwind CSS for styling
- Radix UI for accessible components
- Database Connection: Ensure
DATABASE_URLis correctly set - PDF Upload: Check file size limits and PDF format
- Field Positioning: Use PDF viewer to determine accurate coordinates
- CORS Issues: Ensure API endpoints are properly configured
- Check Netlify Functions logs in the Netlify dashboard
- Use browser developer tools to inspect API responses
- Verify database connectivity and table structure