npm installCreate a .env file in the root directory:
cp .env.example .envOr manually create .env with:
DATABASE_URL="file:./dev.db"
NEXTAUTH_SECRET="your-secret-key-here"
NEXTAUTH_URL="http://localhost:3000"
APP_NAME="POS System"
APP_URL="http://localhost:3000"Generate Prisma Client and create the database:
# Generate Prisma Client
npm run db:generate
# Push schema to database (creates tables)
npm run db:push
# Or use migrations (recommended for production)
npm run db:migrateYou can create an initial admin user using Prisma Studio:
npm run db:studioOr create a seed script (recommended):
Create prisma/seed.ts:
import { PrismaClient } from '@prisma/client'
import * as bcrypt from 'bcryptjs'
const prisma = new PrismaClient()
async function main() {
// Create default admin user
const hashedPassword = await bcrypt.hash('admin123', 10)
const admin = await prisma.user.upsert({
where: { username: 'admin' },
update: {},
create: {
username: 'admin',
password: hashedPassword,
fullName: 'Administrator',
role: 'OWNER',
status: 'ACTIVE',
},
})
console.log('Admin user created:', admin)
// Create default category
const category = await prisma.category.upsert({
where: { name: 'General' },
update: {},
create: {
name: 'General',
description: 'General category',
},
})
console.log('Default category created:', category)
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})Then add to package.json:
{
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
}
}Run seed:
npx prisma db seedInitialize Shadcn/UI:
npx shadcn-ui@latest initAdd components as needed:
npx shadcn-ui@latest add button
npx shadcn-ui@latest add input
npx shadcn-ui@latest add card
npx shadcn-ui@latest add dialog
npx shadcn-ui@latest add table
# ... add more as needednpm run devOpen http://localhost:3000 in your browser.
After running the seed script:
- Username:
admin - Password:
admin123
pos-js/
├── app/ # Next.js App Router
│ ├── (auth)/ # Authentication routes
│ ├── (dashboard)/ # Dashboard routes
│ ├── api/ # API routes
│ ├── layout.tsx # Root layout
│ └── page.tsx # Home page
├── components/ # React components
│ ├── ui/ # Shadcn UI components
│ └── ... # Feature components
├── lib/ # Utility functions
│ ├── prisma.ts # Prisma client
│ ├── utils.ts # Helper functions
│ ├── validations.ts # Zod schemas
│ ├── constants.ts # App constants
│ └── helpers.ts # Helper functions
├── stores/ # Zustand stores
│ ├── cart-store.ts # Shopping cart
│ └── session-store.ts # User session
├── types/ # TypeScript types
│ └── index.ts
├── prisma/ # Prisma files
│ └── schema.prisma # Database schema
└── ...
- ✅ Database schema is ready
- ✅ Basic project structure is set up
- ⏳ Create authentication pages (login, etc.)
- ⏳ Create dashboard layout
- ⏳ Implement POS interface
- ⏳ Build product management
- ⏳ Add other modules...
If you encounter database errors:
# Reset database (⚠️ deletes all data)
npx prisma migrate reset
# Or delete and recreate
rm prisma/dev.db
npm run db:pushIf Prisma Client is not generated:
npm run db:generateIf port 3000 is already in use:
# Use a different port
npm run dev -- -p 3001# Development
npm run dev # Start dev server
# Database
npm run db:generate # Generate Prisma Client
npm run db:push # Push schema changes
npm run db:migrate # Create migration
npm run db:studio # Open Prisma Studio
# Build
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint