A modern point-of-sale system built with Next.js, Prisma, and PostgreSQL.
- Node.js 18+
- PostgreSQL database
- Yarn or npm
Create a .env.local file in the root directory with the following variables:
# Database Configuration
DATABASE_URL="postgresql://username:password@localhost:5432/your_database_name"
DIRECT_URL="postgresql://username:password@localhost:5432/your_database_name"
# Next.js Configuration
NEXTAUTH_SECRET="your-nextauth-secret"
NEXTAUTH_URL="http://localhost:3000"
# Supabase Configuration (if using Supabase)
NEXT_PUBLIC_SUPABASE_URL="your-supabase-url"
NEXT_PUBLIC_SUPABASE_ANON_KEY="your-supabase-anon-key"
SUPABASE_SERVICE_ROLE_KEY="your-supabase-service-role-key"
# Email Configuration (for nodemailer)
EMAIL_USER="your-email@gmail.com"
EMAIL_PASS="your-app-password"
# Text.lk SMS Configuration
# Get your API token from: https://text.lk/
TEXTLK_API_TOKEN="your_textlk_api_token_here"
TEXTLK_SENDER_ID="YourRestaurant"
# Base URL for bill links
BASE_URL="http://localhost:3000"This application uses Text.lk for sending SMS notifications to customers when bills are sent. To set up SMS functionality:
-
Get Text.lk API Token:
- Visit Text.lk
- Sign up for an account
- Get your API token from the dashboard
-
Configure Environment Variables:
- Add your
TEXTLK_API_TOKENto.env.local - Set your
TEXTLK_SENDER_ID(this will appear as the sender name in SMS)
- Add your
-
Phone Number Format:
- The system automatically formats phone numbers for Sri Lanka
- Supported formats:
0712345678,+94712345678,94712345678
-
SMS Features:
- SMS is sent automatically when a phone number is provided
- Includes order details, bill number, and bill link
- Works alongside email notifications
- Install dependencies:
yarn install- Set up the database:
# Generate Prisma client
yarn prisma generate
# Run database migrations
yarn prisma migrate dev
# Seed the database (optional)
yarn seed- Run the development server:
yarn devOpen http://localhost:3000 with your browser to see the result.
- Test your database connection:
# Visit the health check endpoint
curl /api/health
# or open in browser: http://localhost:3000/api/health- A cloud PostgreSQL database (Supabase, PlanetScale, Railway, etc.)
- Netlify account
-
Prepare Environment Variables:
- Create a
.envfile with your production environment variables - Ensure
DATABASE_URLpoints to your cloud database - Set
BASE_URLto your Netlify domain
- Create a
-
Configure Netlify:
- Connect your GitHub repository to Netlify
- Set build command:
npm run build - Set publish directory:
.next - Add all environment variables in Netlify dashboard
-
Required Environment Variables for Netlify:
DATABASE_URL="postgresql://username:password@host:port/database" DIRECT_URL="postgresql://username:password@host:port/database" BASE_URL="https://your-site.netlify.app" EMAIL_USER="your-email@gmail.com" EMAIL_PASS="your-app-password" TEXTLK_API_TOKEN="your_textlk_api_token" TEXTLK_SENDER_ID="YourRestaurant"
-
Deploy:
- Push your changes to GitHub
- Netlify will automatically build and deploy
- Check build logs for any errors
- Prisma CLI not found: Ensure
prismais indevDependencies - Database connection errors: Verify
DATABASE_URLis correct and accessible - API route errors: Check that all environment variables are set in Netlify
- Build failures: Ensure Node.js version is 18+ (specified in
.nvmrc)
If you're getting 400 or 404 errors on API routes:
-
Check Environment Variables in Netlify:
- Go to Site settings > Environment variables
- Ensure all required variables are set:
DATABASE_URLDIRECT_URLNEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYBASE_URL
-
Test API Routes:
- Visit
/api/testto check if API routes are working - Visit
/api/healthto check database connectivity
- Visit
-
Check Netlify Function Logs:
- Go to Functions tab in Netlify dashboard
- Look for any error messages in the function logs
-
Verify Database Connection:
- Ensure your database is accessible from Netlify's servers
- Check if your database allows external connections
-
Supabase Configuration:
- Verify Supabase project is active
- Check if Supabase authentication is properly configured
- Ensure staff users exist in both Supabase and your database
The application uses the following main models:
- Admin: System administrators
- Staff: Restaurant staff (waiters, cashiers, etc.)
- Customer: Customer information
- Category: Food categories
- FoodItem: Menu items
- Portion: Food portions (small, medium, large)
- Order: Customer orders
- OrderItem: Individual items in orders
- Payment: Payment records
- Admin Panel: Manage staff, menu items, categories, and view reports
- Waiter Interface: Take orders, manage tables, and process payments
- Kitchen Interface: View and update order status
- Manager Dashboard: Overview of restaurant operations
- Customer Management: Track customer information and order history
- Payment Processing: Multiple payment modes with receipt generation
- SMS Notifications: Send bill notifications via Text.lk SMS gateway
- Email Notifications: Send detailed bill emails with download links
To learn more about the technologies used:
The easiest way to deploy this Next.js app is to use the Vercel Platform.
Make sure to set up your environment variables in your deployment platform.
If you encounter database connection errors:
- Check your DATABASE_URL: Ensure your
.env.localfile has the correct database URL - Verify database is running: Make sure your PostgreSQL server is running
- Test connection: Visit
/api/healthto check database connectivity - Check credentials: Verify your database username and password are correct
- "Cannot read properties of undefined (reading 'findUnique')": Database connection not configured
- "ECONNREFUSED": Database server not running or wrong port
- "authentication failed": Incorrect database credentials
Run the setup script for automatic configuration:
yarn setupThis will:
- Create a
.env.localfile with template values - Install dependencies
- Generate Prisma client
- Provide next steps for database setup