This is a modern Invoice Generator application built with Next.js, React, TypeScript, and Shadcn UI. It allows you to create professional invoices by managing customers and products, calculating totals including GST, and generating PDF receipts using a pure PDFKit-based system.
The project is designed with modern practices, including TypeScript for type safety, separation of concerns for maintainability and testability, and a responsive web-based invoice viewing system.
For the fastest setup, use our automated script:
git clone <repository-url>
cd bakery-invoice-generator
./setup.sh # Automated setup (installs deps, creates env files, sets permissions)
./dev.sh # Start development serverOr validate existing configuration:
./validate-config.sh # Check configuration consistency- Node.js 18+ (Recommended: Node.js 22)
- npm or yarn
- Docker & Docker Compose (for containerized development)
-
Clone the repository:
git clone <repository-url> cd bakery-invoice-generator
-
Install dependencies:
npm install
-
Create environment file:
cp .env.example .env.dev # or create manually with default values: echo "PORT=9002" > .env.dev echo "NODE_ENV=development" >> .env.dev
-
Start the development server:
# Option 1: Use the development script (recommended) ./dev.sh # Option 2: Load environment and run manually source .env.dev && npm run dev # Option 3: Use npm script (requires manual env loading) npm run dev:script
-
Access the application: Open http://localhost:${PORT} in your browser (default: 9002)
-
Clone the repository:
git clone <repository-url> cd bakery-invoice-generator
-
Create environment file:
cp .env.example .env.dev # or create manually with default values: echo "PORT=9002" > .env.dev echo "NODE_ENV=development" >> .env.dev
-
Start with Docker Compose:
docker-compose up --build
-
Access the application: Open http://localhost:${PORT} in your browser (uses PORT from .env.dev)
npm testnpm run test:uinpm run typechecknpm run lintnpm run pretty# Option 1: Use the production script (recommended)
./start.sh
# Option 2: Manual build and start
source .env.prod && npm run build && npm run start
# Option 3: Use npm scripts
npm run build
npm run start:scriptThe Dockerfile uses multi-stage builds for optimized production images:
# Build with production environment variables
docker build --build-arg PORT=3000 -t invoice-generator .
# Run with environment variables
docker run -p ${PORT:-3000}:${PORT:-3000} -e PORT=${PORT:-3000} invoice-generatorThe application uses environment variables for configuration. Create the appropriate .env file based on your environment:
PORT=9002 # Development server port
NODE_ENV=development # Environment modePORT=3000 # Production server port
NODE_ENV=production # Environment mode- PORT: Server port (default: 9002 for dev, 3000 for prod)
- NODE_ENV: Environment mode (development/production)
- Script method (recommended):
./dev.sh- Automatically loads.env.dev - Docker method:
docker-compose up --build- Uses.env.devfile - Manual method:
source .env.dev && npm run dev- Manual env loading - Direct method:
PORT=9002 npm run dev- Inline environment variables
- Script method (recommended):
./start.sh- Automatically loads.env.prod - Docker method:
docker build -t app . && docker run -p 3000:3000 --env-file .env.prod app - Manual method:
source .env.prod && npm run build && npm run start
Before troubleshooting, validate your configuration:
# Run the configuration validator
./validate-config.sh
# Or use npm script
npm run validate-configThis will check:
- Environment files existence and content
- Port consistency across configurations
- Required scripts and permissions
- Essential files presence
Error: EADDRINUSE: address already in use :::${PORT}
Solution:
# Kill process using the port (replace ${PORT} with actual port number)
lsof -ti:${PORT} | xargs kill -9
# Or change the port in your .env file
echo "PORT=9003" > .env.dev
# Or use a different port for one session
PORT=9003 npm run devError: Font loading or PDF creation failures Solutions:
- Ensure PDFKit dependencies are installed:
npm install pdfkit @types/pdfkit - Check that fonts directory exists:
src/lib/fonts/ - Verify webpack configuration in
next.config.ts
Solution:
# Clear Next.js cache
rm -rf .next
# Clear TypeScript build info
rm -f tsconfig.tsbuildinfo
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm installProblem: Permission denied errors in Docker Solution:
# Ensure proper permissions for data directories
sudo chown -R 1000:1000 src/lib/data/Problem: Docker Compose not reflecting changes Solution:
# Rebuild containers
docker-compose down
docker-compose up --buildEnable detailed logging by setting environment variables:
export NODE_ENV=development
export DEBUG=*
# Or add to your .env.dev file:
echo "DEBUG=*" >> .env.devCheck web receipt viewing status:
- Navigate to
/receiptspage - Create a new receipt
- Click "View Receipt" to open the web view
- Monitor browser console for any loading or display issues
The application uses the PORT environment variable from multiple sources:
- Environment files:
.env.dev(development) or.env.prod(production) - Docker: Uses PORT from environment file via docker-compose
- Scripts:
./dev.shand./start.shautomatically load correct environment - Manual override:
PORT=<number> npm run devorPORT=<number> ./dev.sh
If you get permission errors with the startup scripts:
chmod +x dev.sh start.sh- Copy template:
cp .env.example .env.devorcp .env.example .env.prod - Check current config:
cat .env.devorcat .env.prod - Validate environment:
source .env.dev && echo "Port: $PORT, Environment: $NODE_ENV"
- Next.js 16 (Canary) - React framework with App Router
- React 19 (RC/Canary) - UI library
- TypeScript 5.8+ - Type-safe JavaScript
- Shadcn UI - Component library built on Radix UI
- Tailwind CSS 3.4+ - Utility-first CSS framework
- Lucide React - Icon library
- PDFKit 0.17.0 - Pure JavaScript PDF generation
- Custom Template System - Extensible PDF template architecture
- Vitest 3.1.4 - Fast unit testing framework
- ESLint - Code linting
- Prettier - Code formatting
- Docker - Containerization
- Zod - TypeScript-first schema validation
- Date-fns - Modern date utility library
- UUID - Unique identifier generation
src/
βββ app/ # Next.js App Router pages
β βββ api/ # API routes
β βββ customers/ # Customer management page
β βββ products/ # Product management page
β βββ receipts/ # Receipt/invoice page
β βββ settings/ # Settings page
βββ components/ui/ # Reusable UI components (Shadcn)
βββ lib/
β βββ actions/ # Server actions (data operations)
β βββ data/ # JSON data storage
β βββ data-access/ # Data access layer
β βββ services/ # Business logic services
β βββ fonts/ # Font files for display
βββ hooks/ # Custom React hooks
The application uses a web-based receipt viewing system:
-
ReceiptWebView Component (
src/components/receipts/ReceiptWebView.tsx)- Main component for displaying receipts in web format
- Handles receipt data fetching and error states
- Provides responsive design for various screen sizes
-
ReceiptContent Component (
src/components/receipts/components/ReceiptContent.tsx)- Renders the formatted receipt layout
- Handles business and individual customer display
- Calculates and displays GST and totals
-
PrintToolbar Component (
src/components/receipts/components/PrintToolbar.tsx)- Provides print and close functionality
- Hidden during print mode for clean output
- Allows easy window management
-
Receipt Components (
src/components/receipts/components/)- Modular components for different receipt sections
- Includes customer info, seller info, items table, and totals
- Reusable across different receipt views
graph TD
A[Receipt Action] --> B[Open Receipt URL]
B --> C[ReceiptWebView Component]
C --> D[Fetch Receipt Data]
D --> E[Display Receipt Content]
E --> F[Print/Close Options]
- User Input β Forms on frontend pages
- Server Actions β Handle form submissions and business logic
- Data Access Layer β Manages JSON file operations
- Web Receipt Display β Shows receipts in browser for viewing and printing
- Data Storage β Saves receipt data to JSON files
PORT- Application port (default: 9002)NODE_ENV- Environment mode (development/production)
Templates are configured in src/lib/services/pdfTemplates/templateRegistry.ts:
export const PDF_TEMPLATE_CONFIG = {
DEFAULT: "default",
// Add new templates here
} as const;
export const CURRENT_PDF_TEMPLATE = PDF_TEMPLATE_CONFIG.DEFAULT;- Create types in
src/lib/types.ts - Add data access methods in
src/lib/data-access/ - Implement server actions in
src/lib/actions/ - Create UI components using Shadcn patterns
- Add tests for new functionality
- Create new template class implementing
IPdfReceiptTemplate - Add to template registry in
templateRegistry.ts - Update configuration to use new template
- Test PDF generation with new template
The project enforces code quality through:
- TypeScript strict mode for type safety
- ESLint for code linting with Next.js recommended rules
- Prettier for consistent code formatting
- Vitest for comprehensive testing
- Environment Variables: Ensure all required env vars are set
- File Permissions: PDF directory must be writable
- Memory: PDF generation requires adequate memory allocation
- Fonts: Ensure font files are included in production builds
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make changes and add tests
- Run quality checks:
npm run lint && npm run typecheck && npm test - Commit changes:
git commit -m "Add your feature" - Push to branch:
git push origin feature/your-feature - Create a Pull Request
This project uses GitHub Actions for continuous integration and deployment. The pipelines automatically:
- β Run linters and type checks on every push/PR
- β Execute the full test suite
- β Build the application to verify it compiles
- β Create releases when version tags are pushed
- π Deploy to Vercel (can be activated manually)
For detailed information about the CI/CD setup, pipeline architecture, and how to work with releases and deployments, see:
π CI/CD Pipelines Documentation
The documentation includes:
- Complete pipeline architecture with Mermaid diagrams
- Detailed workflow descriptions
- Setup instructions for Vercel deployment
- Best practices and troubleshooting guides
This project is licensed under the MIT License.